-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DepositPreauth #958
Add DepositPreauth #958
Changes from 6 commits
66462b6
a7c723d
3888032
ba52fa7
07fd6c2
cd1be9d
d40790b
1d2bf4f
ff4e552
0a4ba7c
d456958
e9229a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ | |
- [getAccountObjects](#getaccountobjects) | ||
- [getPaymentChannel](#getpaymentchannel) | ||
- [getLedger](#getledger) | ||
- [parseAccountFlags](#parseaccountflags) | ||
- [prepareTransaction](#preparetransaction) | ||
- [preparePayment](#preparepayment) | ||
- [prepareTrustline](#preparetrustline) | ||
- [prepareOrder](#prepareorder) | ||
|
@@ -4103,6 +4105,109 @@ return api.getLedger() | |
``` | ||
|
||
|
||
## parseAccountFlags | ||
|
||
`parseAccountFlags(Flags: number): object` | ||
|
||
Parse an `AccountRoot` object's [`Flags`](https://developers.ripple.com/accountroot.html#accountroot-flags). | ||
|
||
### Parameters | ||
|
||
This method takes one parameter, the `Flags` number to parse. | ||
|
||
### Return Value | ||
|
||
This method returns an object with containing a key for each parsed flag. Each flag has a boolean value of `true` or `false`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example implies that flags that are |
||
|
||
### Example | ||
|
||
```javascript | ||
const account_info = await api.request('account_info', {account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'}) | ||
const flags = api.parseAccountFlags(account_info.account_data.Flags) | ||
console.log(JSON.stringify([account_info, flags], null, 2)) | ||
``` | ||
|
||
```json | ||
[ | ||
{ | ||
"account_data": { | ||
"Account": "rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N", | ||
"Balance": "9997999496", | ||
"Flags": 16777216, | ||
"LedgerEntryType": "AccountRoot", | ||
"OwnerCount": 2, | ||
"PreviousTxnID": "22C2B172891F92470E37D8E3AA9A9C950751C13EB059B21DADF3A5A0B120C147", | ||
"PreviousTxnLgrSeq": 13558089, | ||
"Sequence": 9, | ||
"index": "8D40979208F658354384E9D069C0EC56814997807378651E39575CFE8A483EB9" | ||
}, | ||
"ledger_current_index": 13752642, | ||
"validated": false | ||
}, | ||
{ | ||
"depositAuth": true | ||
} | ||
] | ||
``` | ||
|
||
## prepareTransaction | ||
|
||
`prepareTransaction(address: string, transaction: object, instructions: object): Promise<object>` | ||
|
||
Prepare a transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). | ||
|
||
This method works with any of [the transaction types supported by rippled](https://developers.ripple.com/transaction-types.html). | ||
|
||
Notably, this is the preferred method for preparing a `DepositPreauth` transaction (added in rippled 1.1.0). | ||
|
||
### Parameters | ||
|
||
Name | Type | Description | ||
---- | ---- | ----------- | ||
transaction | [transaction](https://developers.ripple.com/transaction-formats.html) | The specification (JSON) of the transaction to prepare. Set `Account` to the address of the account that is creating the transaction. Common fields like `Fee`, `Flags`, and `Sequence` may be omitted; `prepareTransaction` will set them automatically. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the rippled API documentation, we use the term "Auto-fillable fields" for fields whose values can be automatically provided, and "Common fields" for fields that apply to all transactions (but whose values cannot be automatically provided, such as |
||
instructions | [instructions](#transaction-instructions) | *Optional* Instructions for executing the transaction | ||
|
||
### Return Value | ||
|
||
This method returns a promise that resolves with an object with the following structure: | ||
|
||
<aside class="notice"> | ||
All "prepare*" methods have the same return type. | ||
</aside> | ||
|
||
Name | Type | Description | ||
---- | ---- | ----------- | ||
txJSON | string | The prepared transaction in rippled JSON format. | ||
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. | ||
*instructions.* fee | [value](#value) | An exact fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information. | ||
*instructions.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction. | ||
*instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum. | ||
*instructions.* maxLedgerVersion | string,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum. | ||
|
||
### Example | ||
|
||
```javascript | ||
async function preparedPreauth() { | ||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; | ||
return api.prepareTransaction({ | ||
TransactionType: 'DepositPreauth', | ||
Account: address, | ||
Authorize: 'rMyVso4p83khNyHdV1m1PggV9QNadCj8wM' | ||
}); | ||
} | ||
``` | ||
|
||
```javascript | ||
{ | ||
txJSON: '{"TransactionType":"DepositPreauth","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Authorize":"rMyVso4p83khNyHdV1m1PggV9QNadCj8wM","Flags":2147483648,"LastLedgerSequence":13561714,"Fee":"12","Sequence":1}', | ||
instructions: { | ||
fee: '0.000012', | ||
sequence: 1, | ||
maxLedgerVersion: 13561714 | ||
} | ||
} | ||
``` | ||
|
||
## preparePayment | ||
|
||
`preparePayment(address: string, payment: object, instructions: object): Promise<object>` | ||
|
@@ -4955,6 +5060,10 @@ sign(txJSON: string, keypair: object, options: object): {signedTransaction: stri | |
|
||
Sign a prepared transaction. The signed transaction must subsequently be [submitted](#submit). | ||
|
||
This method can sign any of [the transaction types supported by ripple-binary-codec](https://github.com/ripple/ripple-binary-codec/blob/cfcde79c19c359e9a0466d7bc3dc9a3aef47bb99/src/enums/definitions.json#L1637). When a new transaction type is added, it will be unrecognized until ripple-binary-codec is updated. An error will be thrown: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For style reasons, avoid future tense and passive voice except when talking about future events. (In this paragraph, there are two instances of future tense, one of which is appropriate and one of which isn't.) Here's a suggested rephrase:
|
||
|
||
`Error: [TRANSACTION_TYPE] is not a valid name or ordinal for TransactionType` | ||
|
||
### Parameters | ||
|
||
Name | Type | Description | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## parseAccountFlags | ||
|
||
`parseAccountFlags(Flags: number): object` | ||
|
||
Parse an `AccountRoot` object's [`Flags`](https://developers.ripple.com/accountroot.html#accountroot-flags). | ||
|
||
### Parameters | ||
|
||
This method takes one parameter, the `Flags` number to parse. | ||
|
||
### Return Value | ||
|
||
This method returns an object with containing a key for each parsed flag. Each flag has a boolean value of `true` or `false`. | ||
|
||
### Example | ||
|
||
```javascript | ||
const account_info = await api.request('account_info', {account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'}) | ||
const flags = api.parseAccountFlags(account_info.account_data.Flags) | ||
console.log(JSON.stringify([account_info, flags], null, 2)) | ||
``` | ||
|
||
```json | ||
[ | ||
{ | ||
"account_data": { | ||
"Account": "rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N", | ||
"Balance": "9997999496", | ||
"Flags": 16777216, | ||
"LedgerEntryType": "AccountRoot", | ||
"OwnerCount": 2, | ||
"PreviousTxnID": "22C2B172891F92470E37D8E3AA9A9C950751C13EB059B21DADF3A5A0B120C147", | ||
"PreviousTxnLgrSeq": 13558089, | ||
"Sequence": 9, | ||
"index": "8D40979208F658354384E9D069C0EC56814997807378651E39575CFE8A483EB9" | ||
}, | ||
"ledger_current_index": 13752642, | ||
"validated": false | ||
}, | ||
{ | ||
"depositAuth": true | ||
} | ||
] | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## prepareTransaction | ||
|
||
`prepareTransaction(address: string, transaction: object, instructions: object): Promise<object>` | ||
|
||
Prepare a transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). | ||
|
||
This method works with any of [the transaction types supported by rippled](https://developers.ripple.com/transaction-types.html). | ||
|
||
Notably, this is the preferred method for preparing a `DepositPreauth` transaction (added in rippled 1.1.0). | ||
|
||
### Parameters | ||
|
||
Name | Type | Description | ||
---- | ---- | ----------- | ||
transaction | [transaction](https://developers.ripple.com/transaction-formats.html) | The specification (JSON) of the transaction to prepare. Set `Account` to the address of the account that is creating the transaction. Common fields like `Fee`, `Flags`, and `Sequence` may be omitted; `prepareTransaction` will set them automatically. | ||
instructions | [instructions](#transaction-instructions) | *Optional* Instructions for executing the transaction | ||
|
||
### Return Value | ||
|
||
This method returns a promise that resolves with an object with the following structure: | ||
|
||
<aside class="notice"> | ||
All "prepare*" methods have the same return type. | ||
</aside> | ||
|
||
<%- renderSchema("output/prepare.json") %> | ||
|
||
### Example | ||
|
||
```javascript | ||
async function preparedPreauth() { | ||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; | ||
return api.prepareTransaction({ | ||
TransactionType: 'DepositPreauth', | ||
Account: address, | ||
Authorize: 'rMyVso4p83khNyHdV1m1PggV9QNadCj8wM' | ||
}); | ||
} | ||
``` | ||
|
||
```javascript | ||
{ | ||
txJSON: '{"TransactionType":"DepositPreauth","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Authorize":"rMyVso4p83khNyHdV1m1PggV9QNadCj8wM","Flags":2147483648,"LastLedgerSequence":13561714,"Fee":"12","Sequence":1}', | ||
instructions: { | ||
fee: '0.000012', | ||
sequence: 1, | ||
maxLedgerVersion: 13561714 | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as assert from 'assert' | ||
import {removeUndefined} from '../../common' | ||
|
||
export type FormattedDepositPreauth = { | ||
// account (address) of the sender to preauthorize | ||
authorize: string, | ||
|
||
// account (address) of the sender whose preauthorization should be revoked | ||
unauthorize: string | ||
} | ||
|
||
function parseDepositPreauth(tx: any): FormattedDepositPreauth { | ||
assert(tx.TransactionType === 'DepositPreauth') | ||
|
||
return removeUndefined({ | ||
authorize: tx.Authorize, | ||
unauthorize: tx.Unauthorize | ||
}) | ||
} | ||
|
||
export default parseDepositPreauth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a note that this only works for AccountRoot
Flags
since the flags have different mappings on other types of objects or in transactions like AccountSet.