Merge pull request #660 from clark800/null-max

Allow setting maxLedgerVersion to null to specify no maximum
This commit is contained in:
Chris Clark
2015-11-30 16:13:41 -08:00
7 changed files with 44 additions and 19 deletions

View File

@@ -284,8 +284,8 @@ Name | Type | Description
---- | ---- | ----------- ---- | ---- | -----------
fee | [value](#value) | *Optional* An exact fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information. fee | [value](#value) | *Optional* An exact fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information.
maxFee | [value](#value) | *Optional* The maximum fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information. maxFee | [value](#value) | *Optional* The maximum fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information.
maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. maxLedgerVersion | integer,null | *Optional* The highest ledger version that the transaction can be included in. If this option and `maxLedgerVersionOffset` are both omitted, the `maxLedgerVersion` option will default to 3 greater than the current validated ledger version (equivalent to `maxLedgerVersionOffset=3`). Use `null` to not set a maximum ledger version.
maxLedgerVersionOffset | integer | *Optional* Offset from current legder version to highest ledger version that the transaction can be included in. maxLedgerVersionOffset | integer | *Optional* Offset from current validated legder version to highest ledger version that the transaction can be included in.
sequence | [sequence](#account-sequence-number) | *Optional* The initiating account's sequence number for this transaction. sequence | [sequence](#account-sequence-number) | *Optional* The initiating account's sequence number for this transaction.
We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the network ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method. We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the network ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method.
@@ -2800,7 +2800,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -2869,7 +2869,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -2936,7 +2936,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -3001,7 +3001,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -3053,7 +3053,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -3118,7 +3118,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -3190,7 +3190,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example
@@ -3247,7 +3247,7 @@ txJSON | string | The prepared transaction in rippled JSON format.
instructions | object | The instructions for how to execute the transaction after adding automatic defaults. 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.* 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.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction.
*instructions.* maxLedgerVersion | integer | *Optional* The highest ledger version that the transaction can be included in. *instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum.
### Example ### Example

View File

@@ -18,11 +18,14 @@
"$ref": "value" "$ref": "value"
}, },
"maxLedgerVersion": { "maxLedgerVersion": {
"description": "The highest ledger version that the transaction can be included in.", "description": "The highest ledger version that the transaction can be included in. If this option and `maxLedgerVersionOffset` are both omitted, the `maxLedgerVersion` option will default to 3 greater than the current validated ledger version (equivalent to `maxLedgerVersionOffset=3`). Use `null` to not set a maximum ledger version.",
"$ref": "ledgerVersion" "oneOf": [
{"$ref": "ledgerVersion"},
{"type": "null"}
]
}, },
"maxLedgerVersionOffset": { "maxLedgerVersionOffset": {
"description": "Offset from current legder version to highest ledger version that the transaction can be included in.", "description": "Offset from current validated legder version to highest ledger version that the transaction can be included in.",
"type": "integer", "type": "integer",
"minimum": 0 "minimum": 0
} }

View File

@@ -21,12 +21,15 @@
"description": "The initiating account's sequence number for this transaction." "description": "The initiating account's sequence number for this transaction."
}, },
"maxLedgerVersion": { "maxLedgerVersion": {
"$ref": "ledgerVersion", "oneOf": [
"description": "The highest ledger version that the transaction can be included in." {"$ref": "ledgerVersion"},
{"type": "null"}
],
"description": "The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum."
} }
}, },
"additionalProperties": false, "additionalProperties": false,
"required": ["fee", "sequence"] "required": ["fee", "sequence", "maxLedgerVersion"]
} }
}, },
"additionalProperties": false, "additionalProperties": false,

View File

@@ -10,7 +10,8 @@ function formatPrepareResponse(txJSON: Object): Object {
const instructions = { const instructions = {
fee: common.dropsToXrp(txJSON.Fee), fee: common.dropsToXrp(txJSON.Fee),
sequence: txJSON.Sequence, sequence: txJSON.Sequence,
maxLedgerVersion: txJSON.LastLedgerSequence maxLedgerVersion: txJSON.LastLedgerSequence === undefined ?
null : txJSON.LastLedgerSequence
}; };
return { return {
txJSON: JSON.stringify(txJSON), txJSON: JSON.stringify(txJSON),
@@ -36,7 +37,9 @@ function prepareTransaction(txJSON: Object, api: Object,
function prepareMaxLedgerVersion(): Promise<Object> { function prepareMaxLedgerVersion(): Promise<Object> {
if (instructions.maxLedgerVersion !== undefined) { if (instructions.maxLedgerVersion !== undefined) {
if (instructions.maxLedgerVersion !== null) {
txJSON.LastLedgerSequence = instructions.maxLedgerVersion; txJSON.LastLedgerSequence = instructions.maxLedgerVersion;
}
return Promise.resolve(txJSON); return Promise.resolve(txJSON);
} }
const offset = instructions.maxLedgerVersionOffset !== undefined ? const offset = instructions.maxLedgerVersionOffset !== undefined ?

View File

@@ -186,6 +186,13 @@ describe('RippleAPI', function() {
_.partial(checkResult, responses.prepareSettings.flags, 'prepare')); _.partial(checkResult, responses.prepareSettings.flags, 'prepare'));
}); });
it('prepareSettings - no maxLedgerVersion', function() {
return this.api.prepareSettings(
address, requests.prepareSettings, {maxLedgerVersion: null}).then(
_.partial(checkResult, responses.prepareSettings.noMaxLedgerVersion,
'prepare'));
});
it('prepareSettings - no instructions', function() { it('prepareSettings - no instructions', function() {
return this.api.prepareSettings( return this.api.prepareSettings(
address, requests.prepareSettings).then( address, requests.prepareSettings).then(

View File

@@ -86,7 +86,8 @@ module.exports = {
setTransferRate: require('./prepare-settings-set-transfer-rate.json'), setTransferRate: require('./prepare-settings-set-transfer-rate.json'),
fieldClear: require('./prepare-settings-field-clear.json'), fieldClear: require('./prepare-settings-field-clear.json'),
noInstructions: require('./prepare-settings-no-instructions.json'), noInstructions: require('./prepare-settings-no-instructions.json'),
signed: require('./prepare-settings-signed.json') signed: require('./prepare-settings-signed.json'),
noMaxLedgerVersion: require('./prepare-settings-no-maxledgerversion.json')
}, },
prepareSuspendedPaymentCreation: { prepareSuspendedPaymentCreation: {
normal: require('./prepare-suspended-payment-creation'), normal: require('./prepare-suspended-payment-creation'),

View File

@@ -0,0 +1,8 @@
{
"txJSON": "{\"TransactionType\":\"AccountSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"Domain\":\"726970706C652E636F6D\",\"Flags\":2147483648,\"Fee\":\"12\",\"Sequence\":23}",
"instructions": {
"fee": "0.000012",
"sequence": 23,
"maxLedgerVersion": null
}
}