Skip to content

Commit a794c83

Browse files
fix fee bump transaction and add test
1 parent 95ec716 commit a794c83

8 files changed

+90
-13
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.8.3] - 01.Jul.2020.
2+
- Add fee stats implementation
3+
- Add max operation fee
4+
- Fix fee bump transaction
5+
16
## [0.8.2] - 28.Jun.2020.
27
- Add query tests for accounts, efffects, ledgers.
38
- Fix ledger response parsing.

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# [Stellar SDK for Flutter](https://github.com/Soneso/stellar_flutter_sdk)
22

3-
![Beta Version](https://img.shields.io/badge/Beta-v0.8.2-yellow.svg)
3+
![Beta Version](https://img.shields.io/badge/Beta-v0.8.3-yellow.svg)
44
![Dart](https://img.shields.io/badge/Dart-green.svg)
55
![Flutter](https://img.shields.io/badge/Flutter-blue.svg)
66
![Supports Stellar Horizon v1.4.0](https://img.shields.io/badge/Horizon-v1.4.0-blue.svg)
7+
![Supports Stellar Horizon v1.5.0](https://img.shields.io/badge/Horizon-v1.5.0-blue.svg)
78
![Supports Stellar Core v13](https://img.shields.io/badge/Core-v13-blue.svg)
89

910
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).
1011

11-
The SDK is currently in beta stage - v. 0.8.2.
12+
The SDK is currently in beta stage - v. 0.8.3.
1213

1314
## Installation
1415

1516
### From pub.dev
1617
1. Add the dependency to your pubspec.yaml file:
1718
```
1819
dependencies:
19-
stellar_flutter_sdk: ^0.8.2
20+
stellar_flutter_sdk: ^0.8.3
2021
```
2122
2. Install it (command line or IDE):
2223
```

lib/src/stellar_sdk.dart

+15-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import 'requests/trades_request_builder.dart';
2727

2828
/// Main class of the flutter stellar sdk.
2929
class StellarSDK {
30-
static const versionNumber = "0.8.2";
30+
static const versionNumber = "0.8.3";
3131

3232
static final StellarSDK PUBLIC =
3333
new StellarSDK("https://horizon.stellar.org");
@@ -126,12 +126,25 @@ class StellarSDK {
126126
/// Submits a [transaction] to the network.
127127
Future<SubmitTransactionResponse> submitTransaction(
128128
Transaction transaction) async {
129+
return submitTransactionEnvelopeXdrBase64(
130+
transaction.toEnvelopeXdrBase64());
131+
}
132+
133+
/// Submits a [feeBumpTransaction] to the network.
134+
Future<SubmitTransactionResponse> submitFeeBumpTransaction(
135+
FeeBumpTransaction feeBumpTransaction) async {
136+
return submitTransactionEnvelopeXdrBase64(
137+
feeBumpTransaction.toEnvelopeXdrBase64());
138+
}
139+
140+
Future<SubmitTransactionResponse> submitTransactionEnvelopeXdrBase64(
141+
String transactionEnvelopeXdrBase64) async {
129142
Uri callURI = _serverURI.replace(pathSegments: ["transactions"]);
130143

131144
//print("Envelope XDR: " + transaction.toEnvelopeXdrBase64());
132145
SubmitTransactionResponse result = await _httpClient
133146
.post(callURI,
134-
body: {"tx": transaction.toEnvelopeXdrBase64()},
147+
body: {"tx": transactionEnvelopeXdrBase64},
135148
headers: RequestBuilder.headers)
136149
.then((response) {
137150
SubmitTransactionResponse submitTransactionResponse;

lib/src/transaction.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ class TransactionBuilder {
372372
TransactionBuilder setMaxOperationFee(int maxOperationFee) {
373373
checkNotNull(maxOperationFee, "maxOperationFee cannot be null");
374374
if (maxOperationFee < AbstractTransaction.MIN_BASE_FEE) {
375-
throw new Exception("maxOperationFee cannot be smaller than the BASE_FEE (${AbstractTransaction.MIN_BASE_FEE}): ${maxOperationFee}");
375+
throw new Exception(
376+
"maxOperationFee cannot be smaller than the BASE_FEE (${AbstractTransaction.MIN_BASE_FEE}): $maxOperationFee");
376377
}
377378
_mMaxOperationFee = maxOperationFee;
378379
return this;
@@ -413,6 +414,7 @@ class FeeBumpTransaction extends AbstractTransaction {
413414
: super(innerTransaction.network) {
414415
_mFeeAccount = checkNotNull(feeAccount, "feeAccount cannot be null");
415416
_mFee = checkNotNull(fee, "fee cannot be null");
417+
_mInner = innerTransaction;
416418
}
417419

418420
static FeeBumpTransaction fromFeeBumpTransactionEnvelope(

lib/src/xdr/xdr_transaction.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class XdrFeeBumpTransactionInnerTx {
158158
static void encode(XdrDataOutputStream stream,
159159
XdrFeeBumpTransactionInnerTx encodedTransaction) {
160160
stream.writeInt(encodedTransaction.discriminant.value);
161-
switch (encodedTransaction.discriminant.value) {
161+
switch (encodedTransaction.discriminant) {
162162
case XdrEnvelopeType.ENVELOPE_TYPE_TX:
163163
XdrTransactionV1Envelope.encode(stream, encodedTransaction.v1);
164164
break;
@@ -168,7 +168,7 @@ class XdrFeeBumpTransactionInnerTx {
168168
static XdrFeeBumpTransactionInnerTx decode(XdrDataInputStream stream) {
169169
XdrFeeBumpTransactionInnerTx decoded = XdrFeeBumpTransactionInnerTx();
170170
decoded.discriminant = XdrEnvelopeType.decode(stream);
171-
switch (decoded.discriminant.value) {
171+
switch (decoded.discriminant) {
172172
case XdrEnvelopeType.ENVELOPE_TYPE_TX:
173173
decoded.v1 = XdrTransactionV1Envelope.decode(stream);
174174
break;

pubspec.yaml

+1-1
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: 0.8.2
3+
version: 0.8.3
44
homepage: https://github.com/Soneso/stellar_flutter_sdk
55

66
environment:

test/fee_bump_transaction_test.dart

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@Timeout(const Duration(seconds: 300))
2+
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
5+
6+
void main() {
7+
StellarSDK sdk = StellarSDK.TESTNET;
8+
9+
test('submit fee bump transaction', () async {
10+
KeyPair sourceKeyPair = KeyPair.random();
11+
String sourceId = sourceKeyPair.accountId;
12+
KeyPair destinationKeyPair = KeyPair.random();
13+
String destinationId = destinationKeyPair.accountId;
14+
KeyPair payerKeyPair = KeyPair.random();
15+
String payerId = payerKeyPair.accountId;
16+
17+
await FriendBot.fundTestAccount(sourceId);
18+
await FriendBot.fundTestAccount(payerId);
19+
20+
AccountResponse sourceAccount = await sdk.accounts.account(sourceId);
21+
22+
// fund account C.
23+
Transaction innerTx = new TransactionBuilder(sourceAccount, Network.TESTNET)
24+
.addOperation(
25+
new CreateAccountOperationBuilder(destinationId, "10").build())
26+
.build();
27+
28+
innerTx.sign(sourceKeyPair);
29+
30+
FeeBumpTransaction feeBump = new FeeBumpTransactionBuilder(innerTx)
31+
.setBaseFee(200)
32+
.setFeeAccount(payerId)
33+
.build();
34+
feeBump.sign(payerKeyPair);
35+
36+
SubmitTransactionResponse response =
37+
await sdk.submitFeeBumpTransaction(feeBump);
38+
assert(response.success);
39+
40+
AccountResponse destination = await sdk.accounts.account(destinationId);
41+
for (Balance balance in destination.balances) {
42+
if (balance.assetType == Asset.TYPE_NATIVE) {
43+
assert(double.parse(balance.balance) > 9);
44+
break;
45+
}
46+
}
47+
48+
TransactionResponse transaction =
49+
await sdk.transactions.transaction(response.hash);
50+
assert(transaction.feeBumpTransaction != null);
51+
assert(transaction.feeBumpTransaction.signatures.length > 0);
52+
assert(transaction.innerTransaction.hash != null);
53+
assert(transaction.innerTransaction.maxFee == 100);
54+
55+
transaction =
56+
await sdk.transactions.transaction(transaction.innerTransaction.hash);
57+
assert(transaction.sourceAccount == sourceId);
58+
});
59+
}

test/query_test.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,16 @@ void main() {
182182
});
183183

184184
test('test query ledgers', () async {
185-
186185
Page<LedgerResponse> ledgersPage =
187-
await sdk.ledgers.limit(1).order(RequestBuilderOrder.DESC).execute();
186+
await sdk.ledgers.limit(1).order(RequestBuilderOrder.DESC).execute();
188187
assert(ledgersPage.records.length == 1);
189188
LedgerResponse ledger = ledgersPage.records.first;
190189

191190
LedgerResponse ledger2 = await sdk.ledgers.ledger(ledger.sequence);
192191
assert(ledger.sequence == ledger2.sequence);
193-
194192
});
195193

196194
test('test query fee stats', () async {
197-
198195
FeeStatsResponse feeStats = await sdk.feeStats.execute();
199196
assert(feeStats.lastLedger.isNotEmpty);
200197
assert(feeStats.lastLedgerBaseFee.isNotEmpty);

0 commit comments

Comments
 (0)