diff --git a/docs/index.md b/docs/index.md index 8e625d3b..b0952b4c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. 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. -maxLedgerVersionOffset | integer | *Optional* Offset from current legder version to 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 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. 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.* 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 | *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 @@ -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.* 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 | *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 @@ -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.* 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 | *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 @@ -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.* 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 | *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 @@ -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.* 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 | *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 @@ -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.* 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 | *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 @@ -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.* 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 | *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 @@ -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.* 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 | *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 diff --git a/src/common/schemas/objects/instructions.json b/src/common/schemas/objects/instructions.json index 38d68ff9..a267e0f7 100644 --- a/src/common/schemas/objects/instructions.json +++ b/src/common/schemas/objects/instructions.json @@ -18,11 +18,14 @@ "$ref": "value" }, "maxLedgerVersion": { - "description": "The highest ledger version that the transaction can be included in.", - "$ref": "ledgerVersion" + "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.", + "oneOf": [ + {"$ref": "ledgerVersion"}, + {"type": "null"} + ] }, "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", "minimum": 0 } diff --git a/src/common/schemas/output/prepare.json b/src/common/schemas/output/prepare.json index 0ceff494..73340463 100644 --- a/src/common/schemas/output/prepare.json +++ b/src/common/schemas/output/prepare.json @@ -21,12 +21,15 @@ "description": "The initiating account's sequence number for this transaction." }, "maxLedgerVersion": { - "$ref": "ledgerVersion", - "description": "The highest ledger version that the transaction can be included in." + "oneOf": [ + {"$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, - "required": ["fee", "sequence"] + "required": ["fee", "sequence", "maxLedgerVersion"] } }, "additionalProperties": false, diff --git a/src/transaction/utils.js b/src/transaction/utils.js index a5b33463..532e67d9 100644 --- a/src/transaction/utils.js +++ b/src/transaction/utils.js @@ -10,7 +10,8 @@ function formatPrepareResponse(txJSON: Object): Object { const instructions = { fee: common.dropsToXrp(txJSON.Fee), sequence: txJSON.Sequence, - maxLedgerVersion: txJSON.LastLedgerSequence + maxLedgerVersion: txJSON.LastLedgerSequence === undefined ? + null : txJSON.LastLedgerSequence }; return { txJSON: JSON.stringify(txJSON), @@ -36,7 +37,9 @@ function prepareTransaction(txJSON: Object, api: Object, function prepareMaxLedgerVersion(): Promise { if (instructions.maxLedgerVersion !== undefined) { - txJSON.LastLedgerSequence = instructions.maxLedgerVersion; + if (instructions.maxLedgerVersion !== null) { + txJSON.LastLedgerSequence = instructions.maxLedgerVersion; + } return Promise.resolve(txJSON); } const offset = instructions.maxLedgerVersionOffset !== undefined ? diff --git a/test/api-test.js b/test/api-test.js index da00be84..79fddb1a 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -186,6 +186,13 @@ describe('RippleAPI', function() { _.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() { return this.api.prepareSettings( address, requests.prepareSettings).then( diff --git a/test/fixtures/responses/index.js b/test/fixtures/responses/index.js index 967bbfd5..d9004049 100644 --- a/test/fixtures/responses/index.js +++ b/test/fixtures/responses/index.js @@ -86,7 +86,8 @@ module.exports = { setTransferRate: require('./prepare-settings-set-transfer-rate.json'), fieldClear: require('./prepare-settings-field-clear.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: { normal: require('./prepare-suspended-payment-creation'), diff --git a/test/fixtures/responses/prepare-settings-no-maxledgerversion.json b/test/fixtures/responses/prepare-settings-no-maxledgerversion.json new file mode 100644 index 00000000..9e207bc3 --- /dev/null +++ b/test/fixtures/responses/prepare-settings-no-maxledgerversion.json @@ -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 + } +}