Skip to content

Commit

Permalink
refactor transaction, move network passphrase to signing
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jul 27, 2020
1 parent be58dd7 commit 3a66bdd
Show file tree
Hide file tree
Showing 32 changed files with 591 additions and 749 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.0.4] - 28.Jul.2020.
- refactor transaction, move network passphrase to signing
- improve examples
- add SEP-0011 MVP (experimental)

## [1.0.3] - 16.Jul.2020.
- SEP-0005 implementation:
- Key Derivation Methods for Stellar Keys
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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.0.3
stellar_flutter_sdk: ^1.0.4
```
2. Install it (command line or IDE):
```
Expand Down Expand Up @@ -131,12 +131,12 @@ KeyPair keyB = KeyPair.random();
CreateAccountOperationBuilder createAccBuilder = CreateAccountOperationBuilder(keyB.accountId, "3"); // send 3 XLM (lumen)
// Create the transaction.
Transaction transaction = new TransactionBuilder(accA, Network.PUBLIC)
Transaction transaction = new TransactionBuilder(accA)
.addOperation(createAccBuilder.build())
.build();
/// Sign the transaction with the key pair of your existing account.
transaction.sign(keyA);
transaction.sign(keyA, Network.PUBLIC);
/// Submit the transaction to the stellar network.
SubmitTransactionResponse response = await sdk.submitTransaction(transaction);
Expand Down Expand Up @@ -241,12 +241,12 @@ String destination = "GDXPJR65A6EXW7ZIWWIQPO6RKTPG3T2VWFBS3EAHJZNFW6ZXG3VWTTSK";
AccountResponse sender = await sdk.accounts.account(senderKeyPair.accountId);
// Build the transaction to send 100 XLM native payment from sender to destination
Transaction transaction = new TransactionBuilder(sender, Network.TESTNET)
Transaction transaction = new TransactionBuilder(sender)
.addOperation(PaymentOperationBuilder(destination,Asset.NATIVE, "100").build())
.build();
// Sign the transaction with the sender's key pair.
transaction.sign(senderKeyPair);
transaction.sign(senderKeyPair, Network.TESTNET);
// Submit the transaction to the stellar network.
SubmitTransactionResponse response = await sdk.submitTransaction(transaction);
Expand Down
Binary file modified documentation/sdk_api_doc.zip
Binary file not shown.
56 changes: 28 additions & 28 deletions documentation/sdk_examples/allow_trust.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ If the issuer clears the ```authorized``` flag, all offers owned by the trustor

```dart
// Create two random key pairs, we will need them later for signing.
KeyPair issuerKeipair = KeyPair.random();
KeyPair trustorKeipair = KeyPair.random();
KeyPair issuerKeypair = KeyPair.random();
KeyPair trustorKeypair = KeyPair.random();
// Account Ids.
String issuerAccountId = issuerKeipair.accountId;
String trustorAccountId = trustorKeipair.accountId;
String issuerAccountId = issuerKeypair.accountId;
String trustorAccountId = trustorKeypair.accountId;
// Create trustor account.
await FriendBot.fundTestAccount(trustorAccountId);
Expand All @@ -24,8 +24,8 @@ AccountResponse trustorAccount = await sdk.accounts.account(trustorAccountId);
// Create the issuer account.
CreateAccountOperation cao = CreateAccountOperationBuilder(issuerAccountId, "10").build();
Transaction transaction = TransactionBuilder(trustorAccount, Network.TESTNET).addOperation(cao).build();
transaction.sign(trustorKeipair);
Transaction transaction = TransactionBuilder(trustorAccount).addOperation(cao).build();
transaction.sign(trustorKeypair, Network.TESTNET);
SubmitTransactionResponse response = await sdk.submitTransaction(transaction);
// Load the issuer account.
Expand All @@ -34,9 +34,9 @@ AccountResponse issuerAccount = await sdk.accounts.account(issuerAccountId);
SetOptionsOperationBuilder sopb = SetOptionsOperationBuilder();
sopb.setSetFlags(3); // Auth required, auth revocable
// Build the transaction.
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(sopb.build()).build();
transaction = TransactionBuilder(issuerAccount).addOperation(sopb.build()).build();
// Sign.
transaction.sign(issuerKeipair);
transaction.sign(issuerKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand All @@ -56,10 +56,10 @@ Asset astroDollar = AssetTypeCreditAlphaNum12(assetCode, issuerAccountId);
// Build the trustline.
String limit = "10000";
ChangeTrustOperation cto = ChangeTrustOperationBuilder(astroDollar, limit).build();
transaction = TransactionBuilder(trustorAccount, Network.TESTNET)
transaction = TransactionBuilder(trustorAccount)
.addOperation(cto)
.build();
transaction.sign(trustorKeipair);
transaction.sign(trustorKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Reload the trustor account to see if the trustline has been created.
Expand All @@ -74,10 +74,10 @@ for (Balance balance in trustorAccount.balances) {
// Now lets try to send some custom asset funds to the trustor account.
// This should not work, because the issuer must authorize the trustline first.
PaymentOperation po = PaymentOperationBuilder(trustorAccountId, astroDollar, "100").build();
transaction = TransactionBuilder(issuerAccount, Network.TESTNET)
transaction = TransactionBuilder(issuerAccount)
.addOperation(po)
.build();
transaction.sign(issuerKeipair);
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
if(!response.success) { // not authorized.
print("trustline is not authorized");
Expand All @@ -86,14 +86,14 @@ if(!response.success) { // not authorized.
// Now let's authorize the trustline.
// Build the allow trust operation. Set the authorized flag to 1.
AllowTrustOperation aop = AllowTrustOperationBuilder(trustorAccountId, assetCode, 1).build(); // authorize
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(aop).build();
transaction.sign(issuerKeipair);
transaction = TransactionBuilder(issuerAccount).addOperation(aop).build();
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Try again to send the payment. Should work now.
po = PaymentOperationBuilder(trustorAccountId, astroDollar, "100").build();
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(po).build();
transaction.sign(issuerKeipair);
transaction = TransactionBuilder(issuerAccount).addOperation(po).build();
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
if(response.success) { // authorized.
print("sccess - trustline is now authorized.");
Expand All @@ -103,8 +103,8 @@ if(response.success) { // authorized.
String amountSelling = "100";
String price = "0.5";
CreatePassiveSellOfferOperation cpso = CreatePassiveSellOfferOperationBuilder(astroDollar, Asset.NATIVE, amountSelling, price).build();
transaction = TransactionBuilder(trustorAccount, Network.TESTNET).addOperation(cpso).build();
transaction.sign(trustorKeipair);
transaction = TransactionBuilder(trustorAccount).addOperation(cpso).build();
transaction.sign(trustorKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Check if the offer has been added.
Expand All @@ -117,8 +117,8 @@ if(offer.buying == Asset.NATIVE && offer.selling == astroDollar) {
// Now lets remove the authorization. To do so, we set the authorized flag to 0.
// This should also delete the offer.
aop = AllowTrustOperationBuilder(trustorAccountId, assetCode, 0).build(); // not authorized
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(aop).build();
transaction.sign(issuerKeipair);
transaction = TransactionBuilder(issuerAccount).addOperation(aop).build();
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Check if the offer has been deleted.
Expand All @@ -129,14 +129,14 @@ if(offers.length == 0) {
// Now, let's authorize the trustline again and then authorize it only to maintain liabilities.
aop = AllowTrustOperationBuilder(trustorAccountId, assetCode, 1).build(); // authorize
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(aop).build();
transaction.sign(issuerKeipair);
transaction = TransactionBuilder(issuerAccount).addOperation(aop).build();
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Create the offer again.
cpso = CreatePassiveSellOfferOperationBuilder(astroDollar, Asset.NATIVE, amountSelling, price).build();
transaction = TransactionBuilder(trustorAccount, Network.TESTNET).addOperation(cpso).build();
transaction.sign(trustorKeipair);
transaction = TransactionBuilder(trustorAccount).addOperation(cpso).build();
transaction.sign(trustorKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Check that the offer has been created.
Expand All @@ -148,8 +148,8 @@ if(offers.length == 1) {
// Now let's deautorize the trustline but allow the trustor to maintain his offer.
// For this, we set the authorized flag to 2.
aop = AllowTrustOperationBuilder(trustorAccountId, assetCode, 2).build(); // authorized to maintain liabilities.
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(aop).build();
transaction.sign(issuerKeipair);
transaction = TransactionBuilder(issuerAccount).addOperation(aop).build();
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Load the offers to see if our offer is still there.
Expand All @@ -161,8 +161,8 @@ if(offers.length == 1) {
// Next, let's try to send some ASTRO to the trustor account.
// This should not work, since the trustline has been deauthorized before.
po = PaymentOperationBuilder(trustorAccountId, astroDollar, "100").build();
transaction = TransactionBuilder(issuerAccount, Network.TESTNET).addOperation(po).build();
transaction.sign(issuerKeipair);
transaction = TransactionBuilder(issuerAccount).addOperation(po).build();
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
if(!response.success); {// is not authorized for new funds
print("payment correctly blocked.");
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 @@ -24,12 +24,12 @@ BumpSequenceOperationBuilder bumpSequenceOpB =
BumpSequenceOperationBuilder(startSequence + 10);
// Prepare the transaction.
Transaction transaction = TransactionBuilder(account, Network.TESTNET)
Transaction transaction = TransactionBuilder(account)
.addOperation(bumpSequenceOpB.build())
.build();
// Sign the transaction.
transaction.sign(accountKeyPair);
transaction.sign(accountKeyPair, Network.TESTNET);
// Submit the transaction.
await sdk.submitTransaction(transaction);
Expand Down
24 changes: 12 additions & 12 deletions documentation/sdk_examples/change_trust.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ We will let one account, called trustor, trust another account that is the issue

```dart
// Create two random key pairs, we will need them later for signing.
KeyPair issuerKeipair = KeyPair.random();
KeyPair trustorKeipair = KeyPair.random();
KeyPair issuerKeypair = KeyPair.random();
KeyPair trustorKeypair = KeyPair.random();
// Account Ids.
String issuerAccountId = issuerKeipair.accountId;
String trustorAccountId = trustorKeipair.accountId;
String issuerAccountId = issuerKeypair.accountId;
String trustorAccountId = trustorKeypair.accountId;
// Create trustor account.
await FriendBot.fundTestAccount(trustorAccountId);
Expand All @@ -22,10 +22,10 @@ AccountResponse trustorAccount = await sdk.accounts.account(trustorAccountId);
// Create the issuer account.
CreateAccountOperation cao = CreateAccountOperationBuilder(issuerAccountId, "10").build();
Transaction transaction = TransactionBuilder(trustorAccount, Network.TESTNET)
Transaction transaction = TransactionBuilder(trustorAccount)
.addOperation(cao)
.build();
transaction.sign(trustorKeipair);
transaction.sign(trustorKeypair, Network.TESTNET);
SubmitTransactionResponse response = await sdk.submitTransaction(transaction);
// Creat our custom asset.
Expand All @@ -37,11 +37,11 @@ String limit = "10000";
// Build the operation.
ChangeTrustOperation cto = ChangeTrustOperationBuilder(astroDollar, limit).build();
// Build the transaction.
transaction = TransactionBuilder(trustorAccount, Network.TESTNET)
transaction = TransactionBuilder(trustorAccount)
.addOperation(cto)
.build();
// Sign.
transaction.sign(trustorKeipair);
transaction.sign(trustorKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand All @@ -63,9 +63,9 @@ limit = "40000";
// Build the change trust operation.
cto = ChangeTrustOperationBuilder(astroDollar, limit).build();
// Build the transaction.
transaction = TransactionBuilder(trustorAccount, Network.TESTNET).addOperation(cto).build();
transaction = TransactionBuilder(trustorAccount).addOperation(cto).build();
// Sign.
transaction.sign(trustorKeipair);
transaction.sign(trustorKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand All @@ -87,9 +87,9 @@ limit = "0";
// Build the operation.
cto = ChangeTrustOperationBuilder(astroDollar, limit).build();
// Build the transaction.
transaction = TransactionBuilder(trustorAccount, Network.TESTNET).addOperation(cto).build();
transaction = TransactionBuilder(trustorAccount).addOperation(cto).build();
// Sign.
transaction.sign(trustorKeipair);
transaction.sign(trustorKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand Down
4 changes: 2 additions & 2 deletions documentation/sdk_examples/create_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ AccountResponse existingAccount = await sdk.accounts.account(existingAccountId);
// Build a transaction containing a create account operation to create the new account.
// Starting balance: 10 XLM.
Transaction transaction = new TransactionBuilder(existingAccount, Network.TESTNET)
Transaction transaction = new TransactionBuilder(existingAccount)
.addOperation(new CreateAccountOperationBuilder(newAccountKeyPair.accountId, "10").build())
.build();
// Sign the transaction with the key pair of the existing account.
transaction.sign(existingAccountKeyPair);
transaction.sign(existingAccountKeyPair, Network.TESTNET);
// Submit the transaction to stellar.
await sdk.submitTransaction(transaction);
Expand Down
32 changes: 16 additions & 16 deletions documentation/sdk_examples/create_passive_sell_offer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ First we are going to prepare the example by creating a seller account, an issue

```dart
// Create two random key pairs, we will need them later for signing.
KeyPair issuerKeipair = KeyPair.random();
KeyPair sellerKeipair = KeyPair.random();
KeyPair issuerKeypair = KeyPair.random();
KeyPair sellerKeypair = KeyPair.random();
// Account Ids.
String issuerAccountId = issuerKeipair.accountId;
String sellerAccountId = sellerKeipair.accountId;
String issuerAccountId = issuerKeypair.accountId;
String sellerAccountId = sellerKeypair.accountId;
// Create seller account.
await FriendBot.fundTestAccount(sellerAccountId);
// Create issuer account.
AccountResponse sellerAccount = await sdk.accounts.account(sellerAccountId);
CreateAccountOperation co = CreateAccountOperationBuilder(issuerAccountId, "10").build();
Transaction transaction = TransactionBuilder(sellerAccount, Network.TESTNET)
Transaction transaction = TransactionBuilder(sellerAccount)
.addOperation(co).build();
transaction.sign(sellerKeipair);
transaction.sign(sellerKeypair, Network.TESTNET);
SubmitTransactionResponse response = await sdk.submitTransaction(transaction);
// Load issuer account so that we can send some custom asset funds to the seller account.
Expand All @@ -33,17 +33,17 @@ Asset marsDollar = AssetTypeCreditAlphaNum4("MARS", issuerAccountId);
// Let the seller account trust our issuer and custom asset.
ChangeTrustOperation cto = ChangeTrustOperationBuilder(marsDollar, "10000").build();
transaction = TransactionBuilder(sellerAccount, Network.TESTNET)
transaction = TransactionBuilder(sellerAccount)
.addOperation(cto)
.build();
transaction.sign(sellerKeipair);
transaction.sign(sellerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Send a couple of custom asset MARS funds from the issuer to the seller account so that the seller can offer them.
PaymentOperation po = PaymentOperationBuilder(sellerAccountId, marsDollar, "2000").build();
transaction = TransactionBuilder(issuerAccount, Network.TESTNET)
transaction = TransactionBuilder(issuerAccount)
.addOperation(po).build();
transaction.sign(issuerKeipair);
transaction.sign(issuerKeypair, Network.TESTNET);
response = await sdk.submitTransaction(transaction);
// Create the offer.
Expand All @@ -55,11 +55,11 @@ String price = "0.5";
CreatePassiveSellOfferOperation cpso = CreatePassiveSellOfferOperationBuilder(
marsDollar, Asset.NATIVE, amountSelling, price).build();
// Build the transaction.
transaction = TransactionBuilder(sellerAccount, Network.TESTNET)
transaction = TransactionBuilder(sellerAccount)
.addOperation(cpso)
.build();
// Sign.
transaction.sign(sellerKeipair);
transaction.sign(sellerKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand All @@ -85,9 +85,9 @@ ManageSellOfferOperation ms = ManageSellOfferOperationBuilder(marsDollar, Asset.
.setOfferId(offerId) // set id of the offer to be modified.
.build();
// Build the transaction.
transaction = TransactionBuilder(sellerAccount, Network.TESTNET).addOperation(ms).build();
transaction = TransactionBuilder(sellerAccount).addOperation(ms).build();
// Sign.
transaction.sign(sellerKeipair);
transaction.sign(sellerKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand All @@ -108,9 +108,9 @@ ms = ManageSellOfferOperationBuilder(marsDollar, Asset.NATIVE, amountSelling, pr
.setOfferId(offerId) // Set the id of the offer to be deleted.
.build();
// Build the transaction.
transaction = TransactionBuilder(sellerAccount, Network.TESTNET).addOperation(ms).build();
transaction = TransactionBuilder(sellerAccount).addOperation(ms).build();
// Sign.
transaction.sign(sellerKeipair);
transaction.sign(sellerKeypair, Network.TESTNET);
// Submit.
response = await sdk.submitTransaction(transaction);
Expand Down
Loading

0 comments on commit 3a66bdd

Please sign in to comment.