Simplify EscrowCreate parameters

This commit is contained in:
wilsonianb
2017-03-30 19:01:58 -07:00
parent f300a412d7
commit 016e82ab5d
7 changed files with 51 additions and 124 deletions

View File

@@ -524,38 +524,22 @@ See [Transaction Types](#transaction-types) for a description.
Name | Type | Description
---- | ---- | -----------
source | object | Fields pertaining to the source of the payment.
*source.* address | [address](#ripple-address) | The address to send from.
*source.* maxAmount | [laxAmount](#amount) | The maximum amount to send. (This field is exclusive with source.amount)
*source.* tag | integer | *Optional* An arbitrary unsigned 32-bit integer that identifies a reason for payment or a non-Ripple account.
destination | object | Fields pertaining to the destination of the payment.
*destination.* address | [address](#ripple-address) | The address to receive at.
*destination.* amount | [laxAmount](#amount) | An exact amount to deliver to the recipient. If the counterparty is not specified, amounts with any counterparty may be used. (This field is exclusive with destination.minAmount).
*destination.* tag | integer | *Optional* An arbitrary unsigned 32-bit integer that identifies a reason for payment or a non-Ripple account.
amount | [value](#value) | Amount of XRP for sender to escrow.
destination | [address](#ripple-address) | Address to receive escrowed XRP.
allowCancelAfter | date-time string | *Optional* If present, the escrow may be cancelled after this time.
allowExecuteAfter | date-time string | *Optional* If present, the escrow can not be executed before this time.
condition | string | *Optional* If present, fulfillment is required upon execution.
destinationTag | integer | *Optional* Destination tag.
memos | [memos](#transaction-memos) | *Optional* Array of memos to attach to the transaction.
sourceTag | integer | *Optional* Source tag.
### Example
```json
{
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": "0.01",
"allowCancelAfter": "2014-09-24T21:21:50.000Z"
}
```
@@ -3165,20 +3149,8 @@ instructions | object | The instructions for how to execute the transaction afte
```javascript
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
const escrowCreation = {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": "0.01",
"allowCancelAfter": "2014-09-24T21:21:50.000Z"
};
return api.prepareEscrowCreation(address, escrowCreation).then(prepared =>

View File

@@ -4,13 +4,13 @@
"link": "escrow-creation",
"type": "object",
"properties": {
"source": {
"$ref": "maxAdjustment",
"description": "Fields pertaining to the source of the payment."
"amount": {
"$ref": "value",
"description": "Amount of XRP for sender to escrow."
},
"destination": {
"$ref": "destinationExactAdjustment",
"description": "Fields pertaining to the destination of the payment."
"$ref": "address",
"description": "Address to receive escrowed XRP."
},
"memos": {"$ref": "memos"},
"condition": {
@@ -27,8 +27,16 @@
"type": "string",
"format": "date-time",
"description": "If present, the escrow can not be executed before this time."
},
"sourceTag": {
"$ref": "tag",
"description": "Source tag."
},
"destinationTag": {
"$ref": "tag",
"description": "Destination tag."
}
},
"required": ["source", "destination"],
"required": ["amount", "destination"],
"additionalProperties": false
}

View File

@@ -5,34 +5,18 @@ const assert = require('assert')
const utils = require('./utils')
const parseAmount = require('./amount')
function removeGenericCounterparty(amount, address) {
return amount.counterparty === address ?
_.omit(amount, 'counterparty') : amount
}
function parseEscrowCreation(tx: Object): Object {
assert(tx.TransactionType === 'EscrowCreate')
const source = {
address: tx.Account,
maxAmount: removeGenericCounterparty(
parseAmount(tx.SendMax || tx.Amount), tx.Account),
tag: tx.SourceTag
}
const destination = {
address: tx.Destination,
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination),
tag: tx.DestinationTag
}
return utils.removeUndefined({
source: utils.removeUndefined(source),
destination: utils.removeUndefined(destination),
amount: parseAmount(tx.Amount).value,
destination: tx.Destination,
memos: utils.parseMemos(tx),
condition: tx.Condition,
allowCancelAfter: utils.parseTimestamp(tx.CancelAfter),
allowExecuteAfter: utils.parseTimestamp(tx.FinishAfter)
allowExecuteAfter: utils.parseTimestamp(tx.FinishAfter),
sourceTag: tx.SourceTag,
destinationTag: tx.DestinationTag
})
}

View File

@@ -2,18 +2,20 @@
'use strict' // eslint-disable-line strict
const _ = require('lodash')
const utils = require('./utils')
const {validate, iso8601ToRippleTime, toRippledAmount} = utils.common
const {validate, iso8601ToRippleTime, xrpToDrops} = utils.common
const ValidationError = utils.common.errors.ValidationError
import type {Instructions, Prepare} from './types.js'
import type {Adjustment, MaxAdjustment, Memo} from '../common/types.js'
type EscrowCreation = {
source: MaxAdjustment,
destination: Adjustment,
amount: string,
destination: string,
memos?: Array<Memo>,
condition?: string,
allowCancelAfter?: string,
allowExecuteAfter?: string
allowExecuteAfter?: string,
sourceTag?: number,
destinationTag?: number
}
function createEscrowCreationTransaction(account: string,
@@ -22,13 +24,10 @@ function createEscrowCreationTransaction(account: string,
const txJSON: Object = {
TransactionType: 'EscrowCreate',
Account: account,
Destination: payment.destination.address,
Amount: toRippledAmount(payment.destination.amount)
Destination: payment.destination,
Amount: xrpToDrops(payment.amount),
}
if (txJSON.Amount.currency !== undefined) {
throw new ValidationError('"Amount" currency must be XRP')
}
if (payment.condition !== undefined) {
txJSON.Condition = payment.condition
}
@@ -38,11 +37,11 @@ function createEscrowCreationTransaction(account: string,
if (payment.allowExecuteAfter !== undefined) {
txJSON.FinishAfter = iso8601ToRippleTime(payment.allowExecuteAfter)
}
if (payment.source.tag !== undefined) {
txJSON.SourceTag = payment.source.tag
if (payment.sourceTag !== undefined) {
txJSON.SourceTag = payment.sourceTag
}
if (payment.destination.tag !== undefined) {
txJSON.DestinationTag = payment.destination.tag
if (payment.destinationTag !== undefined) {
txJSON.DestinationTag = payment.destinationTag
}
if (payment.memos !== undefined) {
txJSON.Memos = _.map(payment.memos, utils.convertMemo)

View File

@@ -1,20 +1,6 @@
{
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "0.01",
"currency": "XRP"
},
"tag": 1
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "0.01",
"currency": "XRP"
},
"tag": 2
},
"destination": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": "0.01",
"condition": "8F434346648F6B96DF89DDA901C5176B10A6D83961DD3C1AC88B59B2DC327AA4",
"allowExecuteAfter": "2014-09-24T21:21:50.000Z",
"memos": [
@@ -22,5 +8,7 @@
"type": "test",
"data": "texted data"
}
]
],
"destinationTag": 2,
"sourceTag": 1
}

View File

@@ -1,17 +1,5 @@
{
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": "0.01",
"allowCancelAfter": "2014-09-24T21:21:50.000Z"
}

View File

@@ -4,22 +4,8 @@
"sequence": 10,
"id": "144F272380BDB4F1BD92329A2178BABB70C20F59042C495E10BF72EBFB408EE1",
"specification": {
"source": {
"address": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
"maxAmount": {
"currency": "XRP",
"value": "0.000002"
},
"tag": 1
},
"destination": {
"address": "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw",
"amount": {
"currency": "XRP",
"value": "0.000002"
},
"tag": 2
},
"amount": "0.000002",
"destination": "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw",
"memos": [
{
"type": "x2",
@@ -29,7 +15,9 @@
],
"condition": "8F434346648F6B96DF89DDA901C5176B10A6D83961DD3C1AC88B59B2DC327AA4",
"allowCancelAfter": "2015-11-16T06:53:42.000Z",
"allowExecuteAfter": "2015-11-16T06:47:42.000Z"
"allowExecuteAfter": "2015-11-16T06:47:42.000Z",
"destinationTag": 2,
"sourceTag": 1
},
"outcome": {
"result": "tesSUCCESS",