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 Name | Type | Description
---- | ---- | ----------- ---- | ---- | -----------
source | object | Fields pertaining to the source of the payment. amount | [value](#value) | Amount of XRP for sender to escrow.
*source.* address | [address](#ripple-address) | The address to send from. destination | [address](#ripple-address) | Address to receive escrowed XRP.
*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.
allowCancelAfter | date-time string | *Optional* If present, the escrow may be cancelled after this time. 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. 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. 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. memos | [memos](#transaction-memos) | *Optional* Array of memos to attach to the transaction.
sourceTag | integer | *Optional* Source tag.
### Example ### Example
```json ```json
{ {
"source": { "destination": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", "amount": "0.01",
"maxAmount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "0.01",
"currency": "XRP"
}
},
"allowCancelAfter": "2014-09-24T21:21:50.000Z" "allowCancelAfter": "2014-09-24T21:21:50.000Z"
} }
``` ```
@@ -3165,20 +3149,8 @@ instructions | object | The instructions for how to execute the transaction afte
```javascript ```javascript
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
const escrowCreation = { const escrowCreation = {
"source": { "destination": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", "amount": "0.01",
"maxAmount": {
"value": "0.01",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "0.01",
"currency": "XRP"
}
},
"allowCancelAfter": "2014-09-24T21:21:50.000Z" "allowCancelAfter": "2014-09-24T21:21:50.000Z"
}; };
return api.prepareEscrowCreation(address, escrowCreation).then(prepared => return api.prepareEscrowCreation(address, escrowCreation).then(prepared =>

View File

@@ -4,13 +4,13 @@
"link": "escrow-creation", "link": "escrow-creation",
"type": "object", "type": "object",
"properties": { "properties": {
"source": { "amount": {
"$ref": "maxAdjustment", "$ref": "value",
"description": "Fields pertaining to the source of the payment." "description": "Amount of XRP for sender to escrow."
}, },
"destination": { "destination": {
"$ref": "destinationExactAdjustment", "$ref": "address",
"description": "Fields pertaining to the destination of the payment." "description": "Address to receive escrowed XRP."
}, },
"memos": {"$ref": "memos"}, "memos": {"$ref": "memos"},
"condition": { "condition": {
@@ -27,8 +27,16 @@
"type": "string", "type": "string",
"format": "date-time", "format": "date-time",
"description": "If present, the escrow can not be executed before this 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 "additionalProperties": false
} }

View File

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

View File

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

View File

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

View File

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