diff --git a/src/common/schemas/output/get-settings.json b/src/common/schemas/output/get-settings.json index 32b0bd7f..4fbefeb9 100644 --- a/src/common/schemas/output/get-settings.json +++ b/src/common/schemas/output/get-settings.json @@ -77,8 +77,11 @@ "description": "TODO" }, "regularKey": { - "$ref": "address", - "description": "The public key of a new keypair, to use as the regular key to this account, as a base-58-encoded string in the same format as an account address." + "oneOf": [ + {"$ref": "address"}, + {"type": "null"} + ], + "description": "The public key of a new keypair, to use as the regular key to this account, as a base-58-encoded string in the same format as an account address. Use `null` to remove the regular key." } }, "additionalProperties": false diff --git a/src/transaction/settings.js b/src/transaction/settings.js index 54d58c94..138e98d3 100644 --- a/src/transaction/settings.js +++ b/src/transaction/settings.js @@ -1,5 +1,6 @@ /* @flow */ 'use strict'; +const _ = require('lodash'); const assert = require('assert'); const BigNumber = require('bignumber.js'); const utils = require('./utils'); @@ -71,12 +72,15 @@ function convertTransferRate(transferRate: number | string): number | string { function createSettingsTransaction(account: string, settings: Settings ): Object { - if (settings.regularKey) { - return { + if (settings.regularKey !== undefined) { + const removeRegularKey = { TransactionType: 'SetRegularKey', - Account: account, - RegularKey: settings.regularKey + Account: account }; + if (settings.regularKey === null) { + return removeRegularKey; + } + return _.assign({}, removeRegularKey, {RegularKey: settings.regularKey}); } const txJSON: Object = { diff --git a/test/api-test.js b/test/api-test.js index 0eecbbce..3ce1deba 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -119,6 +119,13 @@ describe('RippleAPI', function() { _.partial(checkResult, responses.prepareSettings.regularKey, 'prepare')); }); + it('prepareSettings - remove regularKey', function() { + const regularKey = {regularKey: null}; + return this.api.prepareSettings(address, regularKey, instructions).then( + _.partial(checkResult, responses.prepareSettings.removeRegularKey, + 'prepare')); + }); + it('prepareSettings - flag set', function() { const settings = {requireDestinationTag: true}; return this.api.prepareSettings(address, settings, instructions).then( diff --git a/test/fixtures/requests/compute-ledger-hash.json b/test/fixtures/requests/compute-ledger-hash.json index cf8ff0d1..e2a76348 100644 --- a/test/fixtures/requests/compute-ledger-hash.json +++ b/test/fixtures/requests/compute-ledger-hash.json @@ -1,5 +1,4 @@ { - "accepted": true, "stateHash": "D9ABF622DA26EEEE48203085D4BC23B0F77DC6F8724AC33D975DA3CA492D2E44", "closeTime": "2015-08-12T01:01:10.000Z", "parentCloseTime": "2015-08-12T01:01:00.000Z", diff --git a/test/fixtures/responses/index.js b/test/fixtures/responses/index.js index b2cf8c4e..c594dbcf 100644 --- a/test/fixtures/responses/index.js +++ b/test/fixtures/responses/index.js @@ -51,6 +51,7 @@ module.exports = { }, prepareSettings: { regularKey: require('./prepare-settings-regular-key.json'), + removeRegularKey: require('./prepare-settings-remove-regular-key.json'), flags: require('./prepare-settings.json'), flagSet: require('./prepare-settings-flag-set.json'), flagClear: require('./prepare-settings-flag-clear.json'), diff --git a/test/fixtures/responses/prepare-settings-remove-regular-key.json b/test/fixtures/responses/prepare-settings-remove-regular-key.json new file mode 100644 index 00000000..650a918d --- /dev/null +++ b/test/fixtures/responses/prepare-settings-remove-regular-key.json @@ -0,0 +1,8 @@ +{ + "txJSON": "{\"Flags\":2147483648,\"TransactionType\":\"SetRegularKey\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8820051 + } +}