Skip to content

Commit

Permalink
Allow setting maxLedgerVersion to null to specify no maximum
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Clark committed Nov 30, 2015
1 parent cfc21fd commit 82613e7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
20 changes: 10 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,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.
Expand Down Expand Up @@ -2793,7 +2793,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

Expand Down Expand Up @@ -2862,7 +2862,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

Expand Down Expand Up @@ -2929,7 +2929,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

Expand Down Expand Up @@ -2994,7 +2994,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

Expand Down Expand Up @@ -3046,7 +3046,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

Expand Down Expand Up @@ -3111,7 +3111,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

Expand Down Expand Up @@ -3183,7 +3183,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

Expand Down Expand Up @@ -3240,7 +3240,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

Expand Down
9 changes: 6 additions & 3 deletions src/common/schemas/objects/instructions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions src/common/schemas/output/prepare.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/transaction/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -36,7 +37,9 @@ function prepareTransaction(txJSON: Object, api: Object,

function prepareMaxLedgerVersion(): Promise<Object> {
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 ?
Expand Down
7 changes: 7 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/responses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 82613e7

Please sign in to comment.