Skip to content

Commit

Permalink
protocol 19 support
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed May 9, 2022
1 parent ee749e0 commit 993c893
Show file tree
Hide file tree
Showing 15 changed files with 603 additions and 257 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.3.3] - 09.Mai.2022.
- protocol 19 support

## [1.3.2] - 26.Apr.2022.
- bugfix stack overflow error

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.3.2
stellar_flutter_sdk: ^1.3.3
```
2. Install it (command line or IDE):
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension SubmitTransactionResponseExtrasX on SubmitTransactionResponseExtras {
XdrTransactionResult get resultXdrDecoded {
final result = XdrTransactionResult.decode(
XdrDataInputStream(
base64Decode(resultXdr!),
base64Decode(resultXdr),
),
);
return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/key_pair.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class SignerKey {
return signerKey;
}

/// Create <code>preAuthTx</code> XdrSignerKey from a transaction [hash].
/// Create <code>preAuthTxHash</code> XdrSignerKey from a preAuthTxHash[hash].
static XdrSignerKey preAuthTxHash(Uint8List hash) {
checkNotNull(hash, "hash cannot be null");
XdrSignerKey signerKey = new XdrSignerKey();
Expand Down
103 changes: 80 additions & 23 deletions lib/src/responses/submit_transaction_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class SubmitTransactionResponse extends Response {
int? ledger;
String? strEnvelopeXdr;
String? strResultXdr;
String? strMetaXdr;
SubmitTransactionResponseExtras? extras;

SubmitTransactionResponse(
this.extras, this.ledger, this.hash, this.strEnvelopeXdr, this.strResultXdr);
SubmitTransactionResponse(this.extras, this.ledger, this.hash,
this.strEnvelopeXdr, this.strResultXdr, this.strMetaXdr);

bool get success => ledger != null;

Expand All @@ -44,14 +45,48 @@ class SubmitTransactionResponse extends Response {
}
}

String? get resultMetaXdr {
if (this.success) {
return this.strMetaXdr;
} else {
if (this.extras != null) {
return this.extras!.strMetaXdr;
}
return null;
}
}

XdrTransactionResult? getTransactionResultXdr() {
XdrDataInputStream xdrInputStream =
XdrDataInputStream(base64Decode(this.resultXdr!));

try {
return XdrTransactionResult.decode(xdrInputStream);
} catch (e) {
return null;
}
}

XdrTransactionMeta? getTransactionMetaResultXdr() {
XdrDataInputStream xdrInputStream =
XdrDataInputStream(base64Decode(this.resultMetaXdr!));

try {
return XdrTransactionMeta.decode(xdrInputStream);
} catch (e) {
return null;
}
}

/// Helper method that returns Offer ID for ManageOffer from TransactionResult Xdr.
/// This is helpful when you need the ID of an offer to update it later.
int? getOfferIdFromResult(int position) {
if (!this.success) {
return null;
}

XdrDataInputStream xdrInputStream = XdrDataInputStream(base64Decode(this.resultXdr!));
XdrDataInputStream xdrInputStream =
XdrDataInputStream(base64Decode(this.resultXdr!));
XdrTransactionResult result;

try {
Expand All @@ -65,8 +100,11 @@ class SubmitTransactionResponse extends Response {
}

XdrOperationType? disc =
(result.result!.results[position] as XdrOperationResult).tr!.discriminant;
if (disc != XdrOperationType.MANAGE_SELL_OFFER && disc != XdrOperationType.MANAGE_BUY_OFFER) {
(result.result!.results[position] as XdrOperationResult)
.tr!
.discriminant;
if (disc != XdrOperationType.MANAGE_SELL_OFFER &&
disc != XdrOperationType.MANAGE_BUY_OFFER) {
return null;
}

Expand Down Expand Up @@ -97,7 +135,8 @@ class SubmitTransactionResponse extends Response {
return null;
}

XdrDataInputStream xdrInputStream = XdrDataInputStream(base64Decode(this.resultXdr!));
XdrDataInputStream xdrInputStream =
XdrDataInputStream(base64Decode(this.resultXdr!));
XdrTransactionResult result;

try {
Expand All @@ -111,32 +150,40 @@ class SubmitTransactionResponse extends Response {
}

XdrOperationType? disc =
(result.result!.results[position] as XdrOperationResult).tr!.discriminant;
(result.result!.results[position] as XdrOperationResult)
.tr!
.discriminant;
if (disc != XdrOperationType.CREATE_CLAIMABLE_BALANCE) {
return null;
}

if ((result.result!.results[position] as XdrOperationResult?)
?.tr!
.createClaimableBalanceResult!
.balanceID ==
?.tr!
.createClaimableBalanceResult!
.balanceID ==
null) {
return null;
}

return Util.bytesToHex((result.result!.results[0] as XdrOperationResult)
.tr!
.createClaimableBalanceResult!
.balanceID!.v0!.hash!);
.balanceID!
.v0!
.hash!);
}

factory SubmitTransactionResponse.fromJson(Map<String, dynamic> json) =>
SubmitTransactionResponse(
json['extras'] == null ? null : SubmitTransactionResponseExtras.fromJson(json['extras']),
convertInt(json['ledger']),
json['hash'],
json['envelope_xdr'],
json['result_xdr'])
json['extras'] == null
? null
: SubmitTransactionResponseExtras.fromJson(json['extras']),
convertInt(json['ledger']),
json['hash'],
json['envelope_xdr'],
json['result_xdr'],
json['result_meta_xdr'],
)
..rateLimitLimit = convertInt(json['rateLimitLimit'])
..rateLimitRemaining = convertInt(json['rateLimitRemaining'])
..rateLimitReset = convertInt(json['rateLimitReset']);
Expand All @@ -149,23 +196,33 @@ class ExtrasResultCodes {

ExtrasResultCodes(this.transactionResultCode, this.operationsResultCodes);

factory ExtrasResultCodes.fromJson(Map<String, dynamic> json) => ExtrasResultCodes(
factory ExtrasResultCodes.fromJson(Map<String, dynamic> json) =>
ExtrasResultCodes(
json['transaction'],
json['operations'] != null ? List<String>.from(json['operations'].map((e) => e)) : null,
json['operations'] != null
? List<String>.from(json['operations'].map((e) => e))
: null,
);
}

/// Additional information returned by the horizon server.
class SubmitTransactionResponseExtras {
String? envelopeXdr;
String? resultXdr;
String envelopeXdr;
String resultXdr;
String? strMetaXdr;
ExtrasResultCodes? resultCodes;

SubmitTransactionResponseExtras(this.envelopeXdr, this.resultXdr, this.resultCodes);
SubmitTransactionResponseExtras(
this.envelopeXdr, this.resultXdr, this.strMetaXdr, this.resultCodes);

factory SubmitTransactionResponseExtras.fromJson(Map<String, dynamic> json) =>
SubmitTransactionResponseExtras(json['envelope_xdr'], json['result_xdr'],
json['result_codes'] == null ? null : ExtrasResultCodes.fromJson(json['result_codes']));
SubmitTransactionResponseExtras(
json['envelope_xdr'],
json['result_xdr'],
json['result_meta_xdr'],
json['result_codes'] == null
? null
: ExtrasResultCodes.fromJson(json['result_codes']));
}

class SubmitTransactionTimeoutResponseException implements Exception {
Expand Down
25 changes: 14 additions & 11 deletions lib/src/responses/transaction_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ class InnerTransaction {
}

class PreconditionsTimeBoundsResponse {
int? minTime;
int? maxTime;
String? minTime;
String? maxTime;

PreconditionsTimeBoundsResponse(this.minTime, this.maxTime);

factory PreconditionsTimeBoundsResponse.fromJson(Map<String, dynamic> json) {
return PreconditionsTimeBoundsResponse(
convertInt(json['min_ledger']), convertInt(json['max_ledger']));
json['min_time'], json['max_time']);
}
}

Expand All @@ -173,7 +173,7 @@ class PreconditionsLedgerBoundsResponse {
: convertInt(json['min_ledger'])!,
convertInt(json['max_ledger']) == null
? 0
: convertInt(json['min_ledger'])!);
: convertInt(json['max_ledger'])!);
}
}

Expand All @@ -182,7 +182,7 @@ class TransactionPreconditionsResponse {
PreconditionsLedgerBoundsResponse? ledgerBounds;
String? minAccountSequence;
String? minAccountSequenceAge;
String? minAccountSequenceLedgerGap;
int? minAccountSequenceLedgerGap;
List<String?>? extraSigners;

TransactionPreconditionsResponse(
Expand All @@ -195,18 +195,21 @@ class TransactionPreconditionsResponse {

factory TransactionPreconditionsResponse.fromJson(Map<String, dynamic> json) {
var signersFromJson = json['extra_signers'];
List<String> signersList = List<String>.from(signersFromJson);
List<String> signersList = [];
if (signersFromJson != null) {
signersList = List<String>.from(signersFromJson);
}

return TransactionPreconditionsResponse(
json['time_bounds'] == null
json['timebounds'] == null
? null
: PreconditionsTimeBoundsResponse.fromJson(json['time_bounds']),
json['ledger_bounds'] == null
: PreconditionsTimeBoundsResponse.fromJson(json['timebounds']),
json['ledgerbounds'] == null
? null
: PreconditionsLedgerBoundsResponse.fromJson(json['ledger_bounds']),
: PreconditionsLedgerBoundsResponse.fromJson(json['ledgerbounds']),
json['min_account_sequence'],
json['min_account_sequence_age'],
json['min_account_sequence_ledger_gap'],
convertInt(json['min_account_sequence_ledger_gap']),
signersList);
}
}
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 @@ -29,7 +29,7 @@ import 'requests/liquidity_pools_request_builder.dart';

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

static final StellarSDK PUBLIC = StellarSDK("https://horizon.stellar.org");
static final StellarSDK TESTNET =
Expand Down
58 changes: 31 additions & 27 deletions lib/src/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,11 @@ class LedgerBounds {
return true;
}

if (o == null || !(o is LedgerBounds)) {
if (!(o is LedgerBounds)) {
return false;
}

LedgerBounds that = o as LedgerBounds;
LedgerBounds that = o;

if (_minLedger != that.minLedger) return false;
return _maxLedger == that.maxLedger;
Expand Down Expand Up @@ -751,19 +751,13 @@ class TransactionPreconditions {
if (xdr.v2!.sequenceNumber != null) {
result.minSeqNumber = xdr.v2!.sequenceNumber!.uint64!;
}
if (xdr.v2!.minSeqAge != null) {
result.minSeqAge = xdr.v2!.minSeqAge!.uint64!;
}
if (xdr.v2!.minSeqLedgerGap != null) {
result.minSeqLedgerGap = xdr.v2!.minSeqLedgerGap!.uint32!;
}
if (xdr.v2!.extraSigners != null) {
List<XdrSignerKey> keys = [];
for (var i = 0; i < xdr.v2!.extraSigners!.length; i++) {
keys.add(xdr.v2!.extraSigners![i]);
}
result.extraSigners = keys;
result.minSeqAge = xdr.v2!.minSeqAge.uint64!;
result.minSeqLedgerGap = xdr.v2!.minSeqLedgerGap.uint32!;
List<XdrSignerKey> keys = [];
for (var i = 0; i < xdr.v2!.extraSigners.length; i++) {
keys.add(xdr.v2!.extraSigners[i]);
}
result.extraSigners = keys;
} else {
if (xdr.timeBounds != null) {
result.timeBounds = TimeBounds.fromXdr(xdr.timeBounds!);
Expand All @@ -789,31 +783,41 @@ class TransactionPreconditions {
}
XdrPreconditions result = XdrPreconditions(type);
if (hasV2()) {
XdrPreconditionsV2 v2 = XdrPreconditionsV2();
if (_minSeqNumber != null) {
XdrUint64 sn = XdrUint64();
sn.uint64 = _minSeqNumber;
v2.sequenceNumber = sn;
}
XdrUint64 sa = XdrUint64();
if (_minSeqAge != null) {
XdrUint64 sa = XdrUint64();
sa.uint64 = _minSeqAge;
v2.minSeqAge = sa;
} else {
sa.uint64 = 0;
}

XdrUint32 sl = XdrUint32();
if (_minSeqLedgerGap != null) {
XdrUint32 sl = XdrUint32();
sl.uint32 = _minSeqLedgerGap;
v2.minSeqLedgerGap = sl;
} else {
sl.uint32 = 0;
}

List<XdrSignerKey> es = [];
if (_extraSigners != null) {
es = _extraSigners!;
}

XdrPreconditionsV2 v2 = XdrPreconditionsV2(sa, sl, es);

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

if (_timeBounds != null) {
v2.timeBounds = _timeBounds!.toXdr();
}

if (_ledgerBounds != null) {
v2.ledgerBounds = _ledgerBounds!.toXdr();
}
if (_extraSigners != null) {
v2.extraSigners = _extraSigners;
}

result.v2 = v2;
} else if (_timeBounds != null) {
result.timeBounds = _timeBounds!.toXdr();
Expand Down
2 changes: 0 additions & 2 deletions lib/src/xdr/xdr_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ class XdrAccountEntryV3 {
XdrExtensionPoint.decode(stream),
XdrUint32.decode(stream),
XdrUint64.decode(stream));

decoded.seqTime = XdrUint64.decode(stream);
return decoded;
}
}
Expand Down
Loading

0 comments on commit 993c893

Please sign in to comment.