Skip to content

Commit

Permalink
extend and fix sep-0011 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Aug 1, 2020
1 parent 0644477 commit 3d0af19
Show file tree
Hide file tree
Showing 12 changed files with 759 additions and 362 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.5] - 31.Jul.2020.
- add SEP-0011 implementation (txrep)
- add SEP-0011 examples and test

## [1.0.4] - 28.Jul.2020.
- refactor transaction, move network passphrase to signing
- improve examples
Expand Down
4 changes: 3 additions & 1 deletion 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.4
stellar_flutter_sdk: ^1.0.5
```
2. Install it (command line or IDE):
```
Expand Down Expand Up @@ -297,6 +297,7 @@ print(response.memo);
| [SEP-0001: stellar.toml](documentation/sdk_examples/sep-0001-toml.md) | In this example you can find out how to obtain data about an organization’s Stellar integration.| [SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)|
| [SEP-0002: Federation](documentation/sdk_examples/sep-0002-federation.md) | This example shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|
| [SEP-0005: Key derivation](documentation/sdk_examples/sep-0005-key-derivation.md) | In this examples you can see how to generate 12 or 24 words mnemonics for different languages using the Flutter SDK, how to generate key pairs from a mnemonic (with and without BIP 39 passphrase) and how to generate key pairs from a BIP 39 seed. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|
| [SEP-0011: Txrep](documentation/sdk_examples/sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|

Additional examples can be found in the [tests](https://github.com/Soneso/stellar_flutter_sdk/blob/master/test/).

Expand All @@ -309,6 +310,7 @@ You can fild additional documentation including the API documentation in the [do
- [SEP-0001 (stellar.toml)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)
- [SEP-0002 (Federation)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)
- [SEP-0005 (Key derivation)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)
- [SEP-0011 (Txrep)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)

## How to contribute

Expand Down
3 changes: 2 additions & 1 deletion documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
| [SEP-0001: stellar.toml](sdk_examples/sep-0001-toml.md) | In this example you can find out how to obtain data about an organization’s Stellar integration.| [SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)|
| [SEP-0002: Federation](sdk_examples/sep-0002-federation.md) | This examples shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|
| [SEP-0005: Key derivation](sdk_examples/sep-0005-key-derivation.md) | In this examples you can see how to generate 12 or 24 words mnemonics for different languages using the Flutter SDK, how to generate key pairs from a mnemonic (with and without BIP 39 passphrase) and how to generate key pairs from a BIP 39 seed. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|
| [SEP-0011: Txrep](sdk_examples/sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|

More examples and use cases can be found in the [test classes](../test).

An additional [example App](../example) is in progress.
An additional [example App](../example) is in progress.
Binary file modified documentation/sdk_api_doc.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion documentation/sdk_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ The [Soneso open source Stellar SDK for Flutter](https://github.com/Soneso/stell
| [Muxed accounts](muxed_account_payment.md) | In this example we will see how to use a muxed account in a payment operation.| [First-class multiplexed accounts](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md)|
| [SEP-0001: stellar.toml](sep-0001-toml.md) | In this example you can find out how to obtain data about an organization’s Stellar integration.| [SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)|
| [SEP-0002: Federation](sep-0002-federation.md) | This examples shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|
| [SEP-0005: Key derivation](sdk_examples/sep-0005-key-derivation.md) | In this examples you can see how to generate 12 or 24 words mnemonics for different languages using the Flutter SDK, how to generate key pairs from a mnemonic (with and without BIP 39 passphrase) and how to generate key pairs from a BIP 39 seed. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|
| [SEP-0005: Key derivation](sep-0005-key-derivation.md) | In this examples you can see how to generate 12 or 24 words mnemonics for different languages using the Flutter SDK, how to generate key pairs from a mnemonic (with and without BIP 39 passphrase) and how to generate key pairs from a BIP 39 seed. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|
| [SEP-0011: Txrep](sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|

99 changes: 99 additions & 0 deletions documentation/sdk_examples/sep-0011-txrep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

### SEP-0011 - Txrep: human-readable low-level representation of Stellar transactions

Txrep: human-readable low-level representation of Stellar transactions is described in [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md).

In the following examples show how to generate Txrep from a transaction and how to create a transaction object from a Txrep string.

FeeBumpTransaction and muxed accounts are currently not supported.

### Generate Txrep from transaction

```dart
// Prepare accounts.
KeyPair sourceKeyPair = KeyPair.random();
String sourceAccountId = sourceKeyPair.accountId;
// Fund the source account
await FriendBot.fundTestAccount(sourceAccountId);
// Load the account data including the sequence number
AccountResponse sourceAccount = await sdk.accounts.account(sourceAccountId);
// Generate accountId for a new account to be created.
String newAccountId = KeyPair.random().accountId;
// Build the CreateAccountOperation.
Operation createAccount = new CreateAccountOperationBuilder(newAccountId, "220.09").build();
// Add memo.
MemoText mt = MemoText("Enjoy this transaction");
// Create the transaction.
Transaction transaction = new TransactionBuilder(sourceAccount)
.addMemo(mt)
.addOperation(createAccount)
.build();
// Sign the transaction.
transaction.sign(sourceKeyPair, Network.TESTNET);
// Generate and print the txrep
String txrep = TxRep.toTxRep(transaction);
print(txrep);
```
**Result:**

```
type: ENVELOPE_TYPE_TX
tx.sourceAccount: GAVVTEXNKEQ7G7XVJJ2JMBIY5WUKE73PWFVMMIW4DY7Z2E6F7NXXIVUH
tx.fee: 100
tx.seqNum: 238563958456321
tx.timeBounds._present: false
tx.memo.type: MEMO_TEXT
tx.memo.text: "Enjoy this transaction"
tx.operations.len: 1
tx.operation[0].sourceAccount._present: false
tx.operation[0].body.type: CREATE_ACCOUNT
tx.operation[0].body.createAccountOp.destination: GC5ICOW2G64VZXON6DNAWPZ46TZZYV6DYEKZE42KWTBMXCVNTS3EENHC
tx.operation[0].body.createAccountOp.startingBalance: 2200900000
tx.signatures.len: 1
tx.signatures[0].hint: c5fb6f74
tx.signatures[0].signature: e0611076f402005942b27807c0702e0976c14c9a9bb8bc46d1c4740060b5125da1d02c2d9ee10b58acfdaa009f57867506d188d1ee0ab3d00877db22c4101709
tx.ext.v: 0
```

### Create a transaction object from a Txrep string

```dart
String txRepString = '''
type: ENVELOPE_TYPE_TX
tx.sourceAccount: GAVVTEXNKEQ7G7XVJJ2JMBIY5WUKE73PWFVMMIW4DY7Z2E6F7NXXIVUH
tx.fee: 100
tx.seqNum: 238563958456321
tx.timeBounds._present: false
tx.memo.type: MEMO_TEXT
tx.memo.text: "Enjoy this transaction"
tx.operations.len: 1
tx.operation[0].sourceAccount._present: false
tx.operation[0].body.type: CREATE_ACCOUNT
tx.operation[0].body.createAccountOp.destination: GC5ICOW2G64VZXON6DNAWPZ46TZZYV6DYEKZE42KWTBMXCVNTS3EENHC
tx.operation[0].body.createAccountOp.startingBalance: 2200900000
tx.signatures.len: 1
tx.signatures[0].hint: c5fb6f74
tx.signatures[0].signature: e0611076f402005942b27807c0702e0976c14c9a9bb8bc46d1c4740060b5125da1d02c2d9ee10b58acfdaa009f57867506d188d1ee0ab3d00877db22c4101709
tx.ext.v: 0''';
// Create a transaction object by parsing the txRepString.
Transaction tx = TxRep.fromTxRep(txRepString);
print(tx.sourceAccount.accountId);
// GAVVTEXNKEQ7G7XVJJ2JMBIY5WUKE73PWFVMMIW4DY7Z2E6F7NXXIVUH
print(tx.fee);
// 100
print(tx.sequenceNumber);
// 238563958456321
print(tx.operations.length);
// 1
```
Loading

0 comments on commit 3d0af19

Please sign in to comment.