-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe49400
commit 27803fa
Showing
8 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
|
||
### SEP-0006 - TransferServerService | ||
|
||
Helps clients to interact with anchors in a standard way defined by [SEP-0006: Deposit and Withdrawal API](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md). | ||
|
||
|
||
|
||
### Create a TransferServerService instance | ||
|
||
**By providing the domain hosting the stellar.toml file** | ||
|
||
```dart | ||
final transferService = await TransferServerService.fromDomain("place.domain.com"); | ||
``` | ||
|
||
This will automatically load and parse the stellar.toml file. It will then create the TransferServerService instance by using the transfer server url provided in the stellar.toml file. | ||
|
||
**Or by providing the service url** | ||
|
||
Alternatively one can create a TransferServerService instance by providing the transfer server url directly via the constructor: | ||
|
||
```dart | ||
final transferService = TransferServerService("http://api.stellar-anchor.org/transfer"); | ||
``` | ||
|
||
|
||
|
||
### Info | ||
|
||
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#info)) allows an anchor to communicate basic info about what their TRANSFER_SERVER supports to wallets and clients. With the flutter sdk you can use the ```info``` method of your ```TransferServerService``` instance to get the info: | ||
|
||
```dart | ||
// uses the jwt token received from stellar web auth - sep-0010 | ||
InfoResponse response = await transferService.info("en", jwtToken); | ||
print(response.feeInfo.enabled); | ||
``` | ||
|
||
|
||
|
||
### Deposit | ||
|
||
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#deposit)) is used when a user sends an external token (BTC via Bitcoin, USD via bank transfer, etc...) to an address held by an anchor. With the flutter sdk you can use the ```deposit``` method of your ```TransferServerService``` instance to get the deposit information: | ||
|
||
```dart | ||
DepositRequest request = DepositRequest(); | ||
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010 | ||
request.assetCode = "BTC"; | ||
request.account = accountId; // The stellar account ID of the user that wants to deposit. | ||
// ... | ||
try { | ||
DepositResponse response = await transferService.deposit(request); | ||
print(response.how); | ||
print(response.feeFixed); | ||
} on CustomerInformationNeededException catch (e) { | ||
print(e.response.fields); | ||
} on CustomerInformationStatusException catch (e) { | ||
print(e.response.status); | ||
} // ... | ||
``` | ||
|
||
|
||
|
||
### Withdraw | ||
|
||
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#withdraw)) is used when a user redeems an asset currently on the Stellar network for it's equivalent off-chain asset via the Anchor. For instance, a user redeeming their NGNT in exchange for fiat NGN. With the flutter sdk you can use the ```withdraw``` method of your ```TransferServerService``` instance to get the withdrawal information: | ||
|
||
```dart | ||
WithdrawRequest request = WithdrawRequest(); | ||
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010 | ||
request.assetCode = "NGNT"; | ||
request.amount = "129.01"; | ||
// ... | ||
try { | ||
WithdrawResponse response = await transferService.withdraw(request); | ||
print(response.accountId); | ||
print(response.feeFixed); | ||
} on CustomerInformationNeededException catch (e) { | ||
print(e.response.fields); | ||
} on CustomerInformationStatusException catch (e) { | ||
print(e.response.status); | ||
} // ... | ||
``` | ||
|
||
|
||
|
||
### Fee | ||
|
||
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#fee)) allows an anchor to report the fee that would be charged for a given deposit or withdraw operation. With the flutter sdk you can use the ```fee``` method of your ```TransferServerService``` instance to get the info if supported by the anchor: | ||
|
||
```dart | ||
FeeRequest request = FeeRequest(); | ||
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010 | ||
request.operation = "deposit"; | ||
request.assetCode = "NGN"; | ||
request.amount = 123.09; | ||
// ... | ||
FeeResponse response = await transferService.fee(request); | ||
print(response.fee); | ||
``` | ||
|
||
|
||
|
||
### Transaction History | ||
|
||
From this endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#transaction-history)) wallets can receive the status of deposits and withdrawals while they process and a history of past transactions with the anchor. With the flutter sdk you can use the ```transactions``` method of your ```TransferServerService``` instance to get the transactions: | ||
|
||
```dart | ||
AnchorTransactionsRequest request = AnchorTransactionsRequest(); | ||
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010 | ||
request.account = "GCTTGO5ABSTHABXWL2FMHPZ2XFOZDXJYJN5CKFRKXMPAAWZW3Y3JZ3JK"; | ||
request.assetCode = "XLM"; | ||
AnchorTransactionsResponse response = await transferService.transactions(request); | ||
print(response.transactions.length); | ||
print(response.transactions.first.id); | ||
// ... | ||
``` | ||
|
||
|
||
|
||
### Single Historical Transaction | ||
|
||
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#single-historical-transaction)) enables clients to query/validate a specific transaction at an anchor. With the flutter sdk you can use the ```transaction``` method of your ```TransferServerService``` instance to get the data: | ||
|
||
```dart | ||
AnchorTransactionRequest request = AnchorTransactionRequest(); | ||
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010 | ||
request.id = "82fhs729f63dh0v4"; | ||
AnchorTransactionResponse response = await transferService.transaction(request); | ||
print(response.transaction.kind); | ||
print(response.transaction.status); | ||
// ... | ||
``` | ||
|
||
|
||
|
||
### Update Transaction | ||
|
||
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#update)) is used when the anchor requests more info via the pending_transaction_info_update status. With the flutter sdk you can use the ```patchTransaction``` method of your ```TransferServerService``` instance to update the data: | ||
|
||
```dart | ||
PatchTransactionRequest request = PatchTransactionRequest(); | ||
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010 | ||
request.id = "82fhs729f63dh0v4"; | ||
request.fields = {}; | ||
request.fields["dest"] = "12345678901234"; | ||
request.fields["dest_extra"] = "021000021"; | ||
http.Response response = await transferService.patchTransaction(request); | ||
print(response.status); | ||
// ... | ||
``` | ||
|
||
|
||
|
||
### Further readings | ||
|
||
For more info, see also the class documentation of ```TransferServerService``` and the sdk's sep-0006 test cases. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters