Skip to content

Commit ec9499d

Browse files
add protocol 14 support
1 parent c9bc26a commit ec9499d

15 files changed

+234
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [1.1.0] - 09.Oct.2020.
2+
- add protocol 14 support
3+
14
## [1.0.7] - 23.Aug.2020.
25
- make sep-0005 functions async
36
- minor improvements

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
![Dart](https://img.shields.io/badge/Dart-green.svg)
44
![Flutter](https://img.shields.io/badge/Flutter-blue.svg)
5-
![Supports Stellar Horizon v1.4.0](https://img.shields.io/badge/Horizon-v1.4.0-blue.svg)
6-
![Supports Stellar Horizon v1.5.0](https://img.shields.io/badge/Horizon-v1.5.0-blue.svg)
75
![Supports Stellar Core v13](https://img.shields.io/badge/Core-v13-blue.svg)
6+
![Supports Stellar Core v14](https://img.shields.io/badge/Core-v14-blue.svg)
87

98
The Soneso open source Stellar SDK for Flutter is build with Dart and provides APIs to build and sign transactions, connect and query [Horizon](https://github.com/stellar/horizon).
109

@@ -14,7 +13,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
1413
1. Add the dependency to your pubspec.yaml file:
1514
```
1615
dependencies:
17-
stellar_flutter_sdk: ^1.0.7
16+
stellar_flutter_sdk: ^1.1.0
1817
```
1918
2. Install it (command line or IDE):
2019
```

documentation/sdk_api_doc.zip

1.49 MB
Binary file not shown.

lib/src/assets.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'xdr/xdr_asset.dart';
66
import 'key_pair.dart';
77
import 'util.dart';
88
import 'asset_type_native.dart';
9+
import 'asset_type_credit_alphanum.dart';
910
import 'asset_type_credit_alphanum4.dart';
1011
import 'asset_type_credit_alphanum12.dart';
1112

@@ -59,6 +60,16 @@ abstract class Asset {
5960
return null;
6061
}
6162

63+
static String canonicalForm(Asset asset) {
64+
if (asset is AssetTypeNative) {
65+
return 'native';
66+
} else if (asset is AssetTypeCreditAlphaNum) {
67+
AssetTypeCreditAlphaNum creditAsset = asset;
68+
return creditAsset.code + ":" + creditAsset.issuerId;
69+
} else {
70+
throw Exception("unsupported asset " + asset.type);
71+
}
72+
}
6273
/// Generates an Asset object from a given XDR object [xdr_asset].
6374
static Asset fromXdr(XdrAsset xdrAsset) {
6475
switch (xdrAsset.discriminant) {

lib/src/claimant.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Claimant {
6363
XdrClaimPredicateType.CLAIM_PREDICATE_BEFORE_RELATIVE_TIME;
6464
XdrInt64 i = XdrInt64();
6565
i.int64 = seconds;
66-
pred.absBefore = i;
66+
pred.relBefore = i;
6767
return pred;
6868
}
6969

lib/src/requests/claimable_balance_request_builder.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:http/http.dart' as http;
6+
import '../assets.dart';
67
import '../responses/claimable_balance_response.dart';
78
import 'dart:async';
89
import '../responses/response.dart';
@@ -11,6 +12,8 @@ import 'request_builder.dart';
1112
/// See <a href="https://developers.stellar.org/api/resources/claimablebalances/" target="_blank">Claimable Balance</a>
1213
class ClaimableBalancesRequestBuilder extends RequestBuilder {
1314
static const String SPONSOR_PARAMETER_NAME = "sponsor";
15+
static const String CLAIMANT_PARAMETER_NAME = "claimant";
16+
static const String ASSET_PARAMETER_NAME = "asset";
1417

1518
ClaimableBalancesRequestBuilder(http.Client httpClient, Uri serverURI)
1619
: super(httpClient, serverURI, ["claimable_balances"]);
@@ -31,7 +34,7 @@ class ClaimableBalancesRequestBuilder extends RequestBuilder {
3134

3235
/// Requests details about the claimable balance to fetch by [balanceId].
3336
/// See <a href="https://developers.stellar.org/api/resources/claimablebalances/" target="_blank">Claimable Balances</a>
34-
Future<ClaimableBalanceResponse> account(String balanceId) {
37+
Future<ClaimableBalanceResponse> forBalanceId(String balanceId) {
3538
this.setSegments(["claimable_balances", balanceId]);
3639
return this.claimableBalance(this.buildUri());
3740
}
@@ -43,10 +46,25 @@ class ClaimableBalancesRequestBuilder extends RequestBuilder {
4346
return this;
4447
}
4548

49+
/// Returns all claimable balances for the accountId of a claimant.
50+
/// See: <a href="https://developers.stellar.org/api/resources/accounts/" target="_blank">Claimable Balances</a>
51+
ClaimableBalancesRequestBuilder forClaimant(String claimantAccountId) {
52+
queryParameters.addAll({CLAIMANT_PARAMETER_NAME: claimantAccountId});
53+
return this;
54+
}
55+
56+
/// Returns all claimable balances for an asset.
57+
/// See: <a href="https://developers.stellar.org/api/resources/accounts/" target="_blank">Claimable Balances</a>
58+
ClaimableBalancesRequestBuilder forAsset(Asset asset) {
59+
queryParameters.addAll({ASSET_PARAMETER_NAME: Asset.canonicalForm(asset)});
60+
return this;
61+
}
62+
4663
/// Requests specific uri and returns Page of ClaimableBalanceResponse.
4764
/// This method is helpful for getting the next set of results.
4865
static Future<Page<ClaimableBalanceResponse>> requestExecute(
4966
http.Client httpClient, Uri uri) async {
67+
print(uri.toString());
5068
TypeToken type = new TypeToken<Page<ClaimableBalanceResponse>>();
5169
ResponseHandler<Page<ClaimableBalanceResponse>> responseHandler =
5270
new ResponseHandler<Page<ClaimableBalanceResponse>>(type);

lib/src/responses/claimable_balance_response.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Use of this source code is governed by a license that can be
33
// found in the LICENSE file.
44

5-
import 'package:stellar_flutter_sdk/src/responses/asset_response.dart';
5+
import '../assets.dart';
66
import 'response.dart';
77

88
class ClaimableBalanceResponse extends Response {
99
String balanceId;
10-
AssetResponse asset;
10+
Asset asset;
1111
String amount;
1212
String sponsor;
1313
int lastModifiedLedger;
@@ -30,7 +30,7 @@ class ClaimableBalanceResponse extends Response {
3030
json['id'] as String,
3131
json['asset'] == null
3232
? null
33-
: new AssetResponse.fromJson(json['asset'] as Map<String, dynamic>),
33+
: Asset.createFromCanonicalForm(json['asset'] as String),
3434
json['amount'] as String,
3535
json['sponsor'] as String,
3636
convertInt(json['last_modified_ledger']),

lib/src/responses/response.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:http/http.dart' as http;
6+
import 'package:stellar_flutter_sdk/src/responses/claimable_balance_response.dart';
67
import 'dart:async';
78
import '../util.dart';
89
import '../requests/request_builder.dart';
@@ -185,6 +186,8 @@ class ResponseConverter {
185186
return TransactionResponse.fromJson(json);
186187
case FederationResponse:
187188
return FederationResponse.fromJson(json);
189+
case ClaimableBalanceResponse:
190+
return ClaimableBalanceResponse.fromJson(json);
188191
}
189192

190193
switch (T.toString()) {
@@ -216,6 +219,8 @@ class ResponseConverter {
216219
return Page<TradeResponse>.fromJson(json);
217220
case "Page<TransactionResponse>":
218221
return Page<TransactionResponse>.fromJson(json);
222+
case "Page<ClaimableBalanceResponse>":
223+
return Page<ClaimableBalanceResponse>.fromJson(json);
219224
}
220225
}
221226
}

lib/src/revoke_sponsorship_operation.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ class RevokeSponsorshipOperation extends Operation {
3333
if (_ledgerKey != null) {
3434
op.discriminant =
3535
XdrRevokeSponsorshipType.REVOKE_SPONSORSHIP_LEDGER_ENTRY;
36+
op.ledgerKey = this._ledgerKey;
3637
} else {
3738
op.discriminant = XdrRevokeSponsorshipType.REVOKE_SPONSORSHIP_SIGNER;
38-
}
39-
40-
XdrAccountID signerId = XdrAccountID();
41-
signerId.accountID =
42-
KeyPair.fromAccountId(this._signerAccountId).xdrPublicKey;
39+
XdrAccountID signerId = XdrAccountID();
40+
signerId.accountID =
41+
KeyPair.fromAccountId(this._signerAccountId).xdrPublicKey;
4342

44-
XdrRevokeSponsorshipSigner signer = XdrRevokeSponsorshipSigner();
45-
signer.accountId = signerId;
46-
signer.signerKey = _signerKey;
43+
XdrRevokeSponsorshipSigner signer = XdrRevokeSponsorshipSigner();
44+
signer.accountId = signerId;
45+
signer.signerKey = _signerKey;
4746

48-
op.signer = signer;
47+
op.signer = signer;
48+
}
4949

5050
XdrOperationBody body = XdrOperationBody();
5151
body.discriminant = XdrOperationType.REVOKE_SPONSORSHIP;

lib/src/stellar_sdk.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:http/http.dart' as http;
6+
import 'package:stellar_flutter_sdk/src/requests/claimable_balance_request_builder.dart';
67
import 'dart:async';
78
import 'dart:convert';
89
import 'assets.dart';
@@ -95,6 +96,9 @@ class StellarSDK {
9596
TradesRequestBuilder get trades =>
9697
new TradesRequestBuilder(httpClient, _serverURI);
9798

99+
ClaimableBalancesRequestBuilder get claimableBalances =>
100+
new ClaimableBalancesRequestBuilder(httpClient, _serverURI);
101+
98102
/// Returns TradeAggregationsRequestBuilder instance.
99103
TradeAggregationsRequestBuilder tradeAggregations(
100104
Asset baseAsset,

lib/src/xdr/xdr_account.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,11 @@ class XdrRevokeSponsorshipOp {
834834

835835
XdrLedgerKey _ledgerKey;
836836
XdrLedgerKey get ledgerKey => this._ledgerKey;
837-
set ledgerKey(XdrLedgerKey value) => this.ledgerKey = value;
837+
set ledgerKey(XdrLedgerKey value) => this._ledgerKey = value;
838838

839839
XdrRevokeSponsorshipSigner _signer;
840840
XdrRevokeSponsorshipSigner get signer => this._signer;
841-
set signer(XdrRevokeSponsorshipSigner value) => this.signer = value;
841+
set signer(XdrRevokeSponsorshipSigner value) => this._signer = value;
842842

843843
static void encode(
844844
XdrDataOutputStream stream, XdrRevokeSponsorshipOp encoded) {

lib/src/xdr/xdr_ledger.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class XdrClaimPredicate {
144144

145145
XdrClaimPredicate _notPredicate;
146146
XdrClaimPredicate get notPredicate => this._notPredicate;
147-
set notPredicate(XdrClaimPredicate value) => this.notPredicate = value;
147+
set notPredicate(XdrClaimPredicate value) => this._notPredicate = value;
148148

149149
XdrInt64 _absBefore; // Predicate will be true if closeTime < absBefore
150150
XdrInt64 get absBefore => this._absBefore;
@@ -178,7 +178,12 @@ class XdrClaimPredicate {
178178
}
179179
break;
180180
case XdrClaimPredicateType.CLAIM_PREDICATE_NOT:
181-
XdrClaimPredicate.encode(stream, encodedClaimPredicate.notPredicate);
181+
if (encodedClaimPredicate.notPredicate != null) {
182+
stream.writeInt(1);
183+
XdrClaimPredicate.encode(stream, encodedClaimPredicate.notPredicate);
184+
} else {
185+
stream.writeInt(0);
186+
}
182187
break;
183188
case XdrClaimPredicateType.CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME:
184189
XdrInt64.encode(stream, encodedClaimPredicate.absBefore);
@@ -256,7 +261,7 @@ class XdrClaimant {
256261

257262
XdrClaimantV0 _v0;
258263
XdrClaimantV0 get v0 => this._v0;
259-
set v0(XdrClaimantV0 value) => this.v0 = value;
264+
set v0(XdrClaimantV0 value) => this._v0 = value;
260265

261266
static void encode(XdrDataOutputStream stream, XdrClaimant encodedClaimant) {
262267
stream.writeInt(encodedClaimant.discriminant.value);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: stellar_flutter_sdk
22
description: A stellar blockchain sdk that query's horizon, build, signs and submits transactions to the stellar netweok.
3-
version: 1.0.7
3+
version: 1.1.0
44
homepage: https://github.com/Soneso/stellar_flutter_sdk
55

66
environment:

test/claimable_balance_test.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
3+
4+
void main() {
5+
StellarSDK sdk = StellarSDK.TESTNET;
6+
7+
test('test claimable balance', () async {
8+
KeyPair sourceAccountKeyxPair = KeyPair.random();
9+
String sourceAccountId = sourceAccountKeyxPair.accountId;
10+
await FriendBot.fundTestAccount(sourceAccountId);
11+
AccountResponse sourceAccount = await sdk.accounts.account(sourceAccountId);
12+
13+
KeyPair firstClaimantKp = KeyPair.random();
14+
String fistClaimantId = firstClaimantKp.accountId;
15+
KeyPair secondClaimantKp = KeyPair.random();
16+
Claimant firstClaimant =
17+
Claimant(fistClaimantId, Claimant.predicateUnconditional());
18+
XdrClaimPredicate predicateA = Claimant.predicateBeforeRelativeTime(100);
19+
XdrClaimPredicate predicateB =
20+
Claimant.predicateBeforeAbsoluteTime(1634000400);
21+
XdrClaimPredicate predicateC = Claimant.predicateNot(predicateA);
22+
XdrClaimPredicate predicateD =
23+
Claimant.predicateAnd(predicateC, predicateB);
24+
XdrClaimPredicate predicateE =
25+
Claimant.predicateBeforeAbsoluteTime(1601671345);
26+
XdrClaimPredicate predicateF = Claimant.predicateOr(predicateD, predicateE);
27+
Claimant secondClaimant = Claimant(secondClaimantKp.accountId, predicateF);
28+
List<Claimant> claimants = List<Claimant>();
29+
claimants.add(firstClaimant);
30+
claimants.add(secondClaimant);
31+
CreateClaimableBalanceOperationBuilder opb =
32+
CreateClaimableBalanceOperationBuilder(
33+
claimants, Asset.NATIVE, "12.33");
34+
35+
Transaction transaction = new TransactionBuilder(sourceAccount)
36+
.addOperation(opb.build())
37+
.addMemo(Memo.text("createclaimablebalance"))
38+
.build();
39+
40+
transaction.sign(sourceAccountKeyxPair, Network.TESTNET);
41+
42+
SubmitTransactionResponse response =
43+
await sdk.submitTransaction(transaction);
44+
assert(response.success);
45+
46+
Page<ClaimableBalanceResponse> claimableBalances = await sdk
47+
.claimableBalances
48+
.forClaimant(firstClaimantKp.accountId)
49+
.execute();
50+
assert(claimableBalances.records.length == 1);
51+
ClaimableBalanceResponse cb = claimableBalances.records[0];
52+
await FriendBot.fundTestAccount(fistClaimantId);
53+
54+
ClaimClaimableBalanceOperationBuilder opc =
55+
ClaimClaimableBalanceOperationBuilder(cb.balanceId);
56+
57+
transaction = new TransactionBuilder(sourceAccount)
58+
.addOperation(opb.build())
59+
.addMemo(Memo.text("claimclaimablebalance"))
60+
.build();
61+
62+
transaction.sign(sourceAccountKeyxPair, Network.TESTNET);
63+
64+
response = await sdk.submitTransaction(transaction);
65+
assert(response.success);
66+
});
67+
}

0 commit comments

Comments
 (0)