Skip to content

Commit

Permalink
change sequence number from int to BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jul 16, 2024
1 parent 0404cbf commit c8d91a8
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 87 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.8.3] - 16.Jul.2024.
- improve request headers handling
- change sequence number from int to BigInt (web issue)

## [1.8.2] - 1.Jul.2024.
- null safety improvements
- add support for large amounts on web
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
1. Add the dependency to your pubspec.yaml file:
```
dependencies:
stellar_flutter_sdk: ^1.8.2
stellar_flutter_sdk: ^1.8.3
```
2. Install it (command line or IDE):
```
Expand Down
4 changes: 2 additions & 2 deletions documentation/sdk_examples/bump_sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int startSequence = account.sequenceNumber;
// Prepare the bump sequence operation to bump the sequence number to current + 10.
BumpSequenceOperationBuilder bumpSequenceOpB =
BumpSequenceOperationBuilder(startSequence + 10);
BumpSequenceOperationBuilder(startSequence + BigInt.from(10));
// Prepare the transaction.
Transaction transaction = TransactionBuilder(account)
Expand All @@ -38,7 +38,7 @@ await sdk.submitTransaction(transaction);
account = await sdk.accounts.account(accountId);
// Check that the new sequence number has correctly been bumped.
if(startSequence + 10 == account.sequenceNumber) {
if(startSequence + BigInt.from(10) == account.sequenceNumber) {
print("success");
} else {
print("failed");
Expand Down
14 changes: 7 additions & 7 deletions lib/src/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ abstract class TransactionBuilderAccount {
String get accountId;

/// Returns current sequence number ot this Account.
int get sequenceNumber;
BigInt get sequenceNumber;

/// Returns sequence number incremented by one, but does not increment internal counter.
int get incrementedSequenceNumber;
BigInt get incrementedSequenceNumber;

// Muxed account object created from this account object.
MuxedAccount get muxedAccount;
Expand All @@ -26,15 +26,15 @@ abstract class TransactionBuilderAccount {
/// Account object is required to build a [Transaction].
class Account implements TransactionBuilderAccount {
String _accountId;
int _mSequenceNumber;
BigInt _mSequenceNumber;
late MuxedAccount _muxedAccount;

Account(this._accountId, this._mSequenceNumber,
{int? muxedAccountMed25519Id}) {
this._muxedAccount = MuxedAccount(this._accountId, muxedAccountMed25519Id);
}

static Account fromAccountId(String accountId, int sequenceNumber) {
static Account fromAccountId(String accountId, BigInt sequenceNumber) {
MuxedAccount mux = MuxedAccount.fromAccountId(accountId)!;
return new Account(mux.ed25519AccountId, sequenceNumber,
muxedAccountMed25519Id: mux.id);
Expand All @@ -44,16 +44,16 @@ class Account implements TransactionBuilderAccount {
String get accountId => _accountId;

@override
int get sequenceNumber => _mSequenceNumber;
BigInt get sequenceNumber => _mSequenceNumber;

@override
MuxedAccount get muxedAccount => _muxedAccount;

@override
int get incrementedSequenceNumber => _mSequenceNumber + 1;
BigInt get incrementedSequenceNumber => _mSequenceNumber + BigInt.one;

/// Increments sequence number in this account object by one.
void incrementSequenceNumber() {
_mSequenceNumber = _mSequenceNumber + 1;
_mSequenceNumber = _mSequenceNumber + BigInt.one;
}
}
10 changes: 5 additions & 5 deletions lib/src/bump_sequence_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import 'xdr/xdr_type.dart';
/// Represents <a href="https://developers.stellar.org/docs/start/list-of-operations/#bump-sequence" target="_blank">Bump Sequence</a> operation.
/// See: <a href="https://developers.stellar.org/docs/start/list-of-operations/" target="_blank">List of Operations</a>
class BumpSequenceOperation extends Operation {
int _bumpTo;
BigInt _bumpTo;

BumpSequenceOperation(this._bumpTo);

int get bumpTo => _bumpTo;
BigInt get bumpTo => _bumpTo;

@override
XdrOperationBody toOperationBody() {
XdrInt64 bumpTo = new XdrInt64(this._bumpTo);
XdrBigInt64 bumpTo = new XdrBigInt64(this._bumpTo);
XdrOperationBody body =
new XdrOperationBody(XdrOperationType.BUMP_SEQUENCE);
body.bumpSequenceOp = new XdrBumpSequenceOp(XdrSequenceNumber(bumpTo));
Expand All @@ -31,12 +31,12 @@ class BumpSequenceOperation extends Operation {

/// Construct a new BumpSequence builder from a BumpSequence XDR.
static BumpSequenceOperationBuilder builder(XdrBumpSequenceOp op) {
return BumpSequenceOperationBuilder(op.bumpTo.sequenceNumber.int64);
return BumpSequenceOperationBuilder(op.bumpTo.sequenceNumber.bigInt);
}
}

class BumpSequenceOperationBuilder {
int _bumpTo;
BigInt _bumpTo;
MuxedAccount? _mSourceAccount;

/// Creates a new BumpSequence builder.
Expand Down
10 changes: 5 additions & 5 deletions lib/src/responses/account_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'response.dart';
/// See: <a href="https://developers.stellar.org/api/resources/accounts/" target="_blank">Account documentation</a>.
class AccountResponse extends Response implements TransactionBuilderAccount {
String accountId;
int _sequenceNumber;
BigInt _sequenceNumber;
String pagingToken;
int subentryCount;
String? inflationDestination;
Expand Down Expand Up @@ -61,13 +61,13 @@ class AccountResponse extends Response implements TransactionBuilderAccount {
KeyPair get keypair => KeyPair.fromAccountId(accountId);

@override
int get sequenceNumber => _sequenceNumber;
BigInt get sequenceNumber => _sequenceNumber;

@override
int get incrementedSequenceNumber => _sequenceNumber + 1;
BigInt get incrementedSequenceNumber => _sequenceNumber + BigInt.one;

@override
void incrementSequenceNumber() => _sequenceNumber = _sequenceNumber + 1;
void incrementSequenceNumber() => _sequenceNumber = _sequenceNumber + BigInt.one;

@override
MuxedAccount get muxedAccount =>
Expand All @@ -76,7 +76,7 @@ class AccountResponse extends Response implements TransactionBuilderAccount {
factory AccountResponse.fromJson(Map<String, dynamic> json) =>
AccountResponse(
json['account_id'],
convertInt(json['sequence'])!,
BigInt.parse(json['sequence']),
json['paging_token'],
convertInt(json['subentry_count'])!,
json['inflation_destination'],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sep/0010/webauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class WebAuth {

final transaction = envelopeXdr.v1!.tx;

if (transaction.seqNum.sequenceNumber.int64 != 0) {
if (transaction.seqNum.sequenceNumber.bigInt != BigInt.zero) {
throw ChallengeValidationErrorInvalidSeqNr(
"Invalid transaction, sequence number not 0");
}
Expand Down
22 changes: 7 additions & 15 deletions lib/src/sep/0011/txrep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,11 @@ class TxRep {
}

String? seqNr = _removeComment(map['${prefix}seqNum']);
int? sequenceNumber;
BigInt? sequenceNumber;
if (seqNr == null) {
throw Exception('missing ${prefix}seqNum');
} else {
try {
sequenceNumber = int.tryParse(seqNr);
} catch (e) {
throw Exception('invalid ${prefix}seqNum');
}
sequenceNumber = BigInt.tryParse(seqNr);
}
if (sequenceNumber == null) {
throw Exception('invalid ${prefix}seqNum');
Expand All @@ -155,7 +151,7 @@ class TxRep {
}

MuxedAccount? mux = MuxedAccount.fromAccountId(sourceAccountId);
Account sourceAccount = Account(mux!.ed25519AccountId, sequenceNumber - 1,
Account sourceAccount = Account(mux!.ed25519AccountId, sequenceNumber - BigInt.one,
muxedAccountMed25519Id: mux.id);
TransactionBuilder txBuilder = TransactionBuilder(sourceAccount);
txBuilder.addPreconditions(_getPreconditions(map, prefix));
Expand Down Expand Up @@ -300,8 +296,8 @@ class TxRep {

if (_removeComment(map['${precondPrefix}minSeqNum._present']) == 'true' &&
map['${precondPrefix}minSeqNum'] != null) {
int? minSeqNum =
int.tryParse(_removeComment(map['${precondPrefix}minSeqNum'])!);
BigInt? minSeqNum =
BigInt.tryParse(_removeComment(map['${precondPrefix}minSeqNum'])!);
if (minSeqNum == null) {
throw Exception('invalid ${precondPrefix}minSeqNum');
}
Expand Down Expand Up @@ -2701,12 +2697,8 @@ class TxRep {
throw Exception('missing $opPrefix' + 'bumpTo');
}

int? bumpTo;
try {
bumpTo = int.tryParse(bumpToStr);
} catch (e) {
throw Exception('invalid $opPrefix' + 'bumpTo');
}
BigInt? bumpTo = BigInt.tryParse(bumpToStr);

if (bumpTo == null) {
throw Exception('invalid $opPrefix' + 'bumpTo');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/soroban/soroban_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SorobanServer {
String accountId =
KeyPair.fromXdrPublicKey(accountEntry.accountID.accountID)
.accountId;
int seqNr = accountEntry.seqNum.sequenceNumber.int64;
BigInt seqNr = accountEntry.seqNum.sequenceNumber.bigInt;
return Account(accountId, seqNr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/stellar_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import 'requests/liquidity_pools_request_builder.dart';

/// Main class of the flutter stellar sdk.
class StellarSDK {
static const versionNumber = "1.8.2";
static const versionNumber = "1.8.3";

static final StellarSDK PUBLIC = StellarSDK("https://horizon.stellar.org");
static final StellarSDK TESTNET = StellarSDK("https://horizon-testnet.stellar.org");
Expand Down
24 changes: 12 additions & 12 deletions lib/src/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Transaction extends AbstractTransaction {
set fee(int value) => this._mFee = value;

MuxedAccount _mSourceAccount;
int _mSequenceNumber;
BigInt _mSequenceNumber;
List<Operation> _mOperations;
Memo? _mMemo;
TransactionPreconditions? _mPreconditions;
Expand Down Expand Up @@ -144,7 +144,7 @@ class Transaction extends AbstractTransaction {

MuxedAccount get sourceAccount => _mSourceAccount;

int get sequenceNumber => _mSequenceNumber;
BigInt get sequenceNumber => _mSequenceNumber;

Memo? get memo => _mMemo;

Expand All @@ -163,7 +163,7 @@ class Transaction extends AbstractTransaction {
// fee
XdrUint32 fee = XdrUint32(_mFee);
// sequenceNumber
XdrInt64 sequenceNumberUint = XdrInt64(_mSequenceNumber);
XdrBigInt64 sequenceNumberUint = XdrBigInt64(_mSequenceNumber);

XdrPublicKey sourcePublickKey =
KeyPair.fromAccountId(_mSourceAccount.ed25519AccountId).xdrPublicKey;
Expand Down Expand Up @@ -202,7 +202,7 @@ class Transaction extends AbstractTransaction {
XdrUint32 fee = XdrUint32(_mFee);

// sequenceNumber
XdrInt64 sequenceNumberUint = XdrInt64(_mSequenceNumber);
XdrBigInt64 sequenceNumberUint = XdrBigInt64(_mSequenceNumber);

// operations
List<XdrOperation> operations = List<XdrOperation>.empty(
Expand Down Expand Up @@ -238,7 +238,7 @@ class Transaction extends AbstractTransaction {
XdrTransaction? tx = envelope.tx;
int mFee = tx.fee.uint32;

int mSequenceNumber = tx.seqNum.sequenceNumber.int64;
BigInt mSequenceNumber = tx.seqNum.sequenceNumber.bigInt;
Memo? mMemo = Memo.fromXdr(tx.memo);
TransactionPreconditions mPreconditions =
TransactionPreconditions.fromXdr(tx.preconditions);
Expand Down Expand Up @@ -272,7 +272,7 @@ class Transaction extends AbstractTransaction {
int? mFee = tx.fee.uint32;
String mSourceAccount =
KeyPair.fromPublicKey(tx.sourceAccountEd25519.uint256).accountId;
int mSequenceNumber = tx.seqNum.sequenceNumber.int64;
BigInt mSequenceNumber = tx.seqNum.sequenceNumber.bigInt;
Memo mMemo = Memo.fromXdr(tx.memo);
TimeBounds? mTimeBounds = TimeBounds.fromXdr(tx.timeBounds!);

Expand Down Expand Up @@ -683,21 +683,21 @@ class TransactionPreconditions {

TimeBounds? _timeBounds;
LedgerBounds? _ledgerBounds;
int? _minSeqNumber;
BigInt? _minSeqNumber;
int? _minSeqAge;
int? _minSeqLedgerGap;
List<XdrSignerKey>? _extraSigners;

TimeBounds? get timeBounds => _timeBounds;
LedgerBounds? get ledgerBounds => _ledgerBounds;
int? get minSeqNumber => _minSeqNumber;
BigInt? get minSeqNumber => _minSeqNumber;
int? get minSeqAge => _minSeqAge;
int? get minSeqLedgerGap => _minSeqLedgerGap;
List<XdrSignerKey>? get extraSigners => _extraSigners;

set timeBounds(TimeBounds? value) => _timeBounds = value;
set ledgerBounds(LedgerBounds? value) => _ledgerBounds = value;
set minSeqNumber(int? value) => _minSeqNumber = value;
set minSeqNumber(BigInt? value) => _minSeqNumber = value;
set minSeqAge(int? value) => _minSeqAge = value;
set minSeqLedgerGap(int? value) => _minSeqLedgerGap = value;
set extraSigners(List<XdrSignerKey>? value) => _extraSigners = value;
Expand All @@ -712,7 +712,7 @@ class TransactionPreconditions {
result.ledgerBounds = LedgerBounds.fromXdr(xdr.v2!.ledgerBounds!);
}
if (xdr.v2!.sequenceNumber != null) {
result.minSeqNumber = xdr.v2!.sequenceNumber!.uint64;
result.minSeqNumber = xdr.v2!.sequenceNumber!.bigInt;
}
result.minSeqAge = xdr.v2!.minSeqAge.uint64;
result.minSeqLedgerGap = xdr.v2!.minSeqLedgerGap.uint32;
Expand All @@ -733,7 +733,7 @@ class TransactionPreconditions {
return _ledgerBounds != null ||
(_minSeqLedgerGap != null && _minSeqLedgerGap! > 0) ||
(_minSeqAge != null && _minSeqAge! > 0) ||
(_minSeqNumber != null && _minSeqNumber! > 0) ||
(_minSeqNumber != null && _minSeqNumber! > BigInt.zero) ||
(_extraSigners != null && _extraSigners!.length > 0);
}

Expand Down Expand Up @@ -766,7 +766,7 @@ class TransactionPreconditions {
XdrPreconditionsV2 v2 = XdrPreconditionsV2(sa, sl, es);

if (_minSeqNumber != null) {
XdrUint64 sn = XdrUint64(_minSeqNumber!);
XdrBigInt64 sn = XdrBigInt64(_minSeqNumber!);
v2.sequenceNumber = sn;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/xdr/xdr_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2172,21 +2172,21 @@ class XdrSetOptionsOp {
}

class XdrSequenceNumber {
XdrInt64 _sequenceNumber;
XdrBigInt64 _sequenceNumber;

XdrInt64 get sequenceNumber => this._sequenceNumber;
XdrBigInt64 get sequenceNumber => this._sequenceNumber;

set sequenceNumber(XdrInt64 value) => this._sequenceNumber = value;
set sequenceNumber(XdrBigInt64 value) => this._sequenceNumber = value;

XdrSequenceNumber(this._sequenceNumber);

static void encode(
XdrDataOutputStream stream, XdrSequenceNumber encodedSequenceNumber) {
XdrInt64.encode(stream, encodedSequenceNumber._sequenceNumber);
XdrBigInt64.encode(stream, encodedSequenceNumber._sequenceNumber);
}

static XdrSequenceNumber decode(XdrDataInputStream stream) {
return XdrSequenceNumber(XdrInt64.decode(stream));
return XdrSequenceNumber(XdrBigInt64.decode(stream));
}
}

Expand Down
Loading

0 comments on commit c8d91a8

Please sign in to comment.