From a2af2f5a0b806759f46542b5b09de4d43067ba4e Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Tue, 7 Aug 2018 11:12:12 -0700 Subject: [PATCH 1/2] bwallet-cli: new API derive address at any index --- bin/bwallet-cli | 42 +++++++++++++++++++++++++++++++--- lib/wallet.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/bin/bwallet-cli b/bin/bwallet-cli index 03efd1e..c4c6a53 100755 --- a/bin/bwallet-cli +++ b/bin/bwallet-cli @@ -189,6 +189,30 @@ class CLI { this.log(addr); } + async deriveReceive() { + const account = this.config.str([0, 'account']); + const index = this.config.uint([1, 'index']); + const addr = await this.wallet.deriveReceive(account, index); + + this.log(addr); + } + + async deriveChange() { + const account = this.config.str([0, 'account']); + const index = this.config.uint([1, 'index']); + const addr = await this.wallet.deriveChange(account, index); + + this.log(addr); + } + + async deriveNested() { + const account = this.config.str([0, 'account']); + const index = this.config.uint([1, 'index']); + const addr = await this.wallet.deriveNested(account, index); + + this.log(addr); + } + async getAccounts() { const accounts = await this.wallet.getAccounts(); this.log(accounts); @@ -541,6 +565,15 @@ class CLI { case 'nested': await this.createNested(); break; + case 'derivereceive': + await this.deriveReceive(); + break; + case 'derivechange': + await this.deriveChange(); + break; + case 'derivenested': + await this.deriveNested(); + break; case 'retoken': await this.retoken(); break; @@ -607,9 +640,12 @@ class CLI { this.log(' $ account list: List account names.'); this.log(' $ account create [account-name]: Create account.'); this.log(' $ account get [account-name]: Get account details.'); - this.log(' $ address: Derive new address.'); - this.log(' $ change: Derive new change address.'); - this.log(' $ nested: Derive new nested address.'); + this.log(' $ address: Create new address.'); + this.log(' $ change: Create new change address.'); + this.log(' $ nested: Create new nested address.'); + this.log(' $ derivereceive: Derive receive address.'); + this.log(' $ derivechange: Derive change address.'); + this.log(' $ derivenested: Derive nested address.'); this.log(' $ retoken: Create new api key.'); this.log(' $ send [address] [value]: Send transaction.'); this.log(' $ mktx [address] [value]: Create transaction.'); diff --git a/lib/wallet.js b/lib/wallet.js index b146b68..490120e 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -435,6 +435,36 @@ class WalletClient extends Client { return this.post(`/wallet/${id}/nested`, { account }); } + /** + * Derive receive address. + * @param {Object} options + * @returns {Promise} + */ + + deriveReceive(id, account, index) { + return this.post(`/wallet/${id}/derivereceive`, { account, index }); + } + + /** + * Derive change address. + * @param {Object} options + * @returns {Promise} + */ + + deriveChange(id, account, index) { + return this.post(`/wallet/${id}/derivechange`, { account, index }); + } + + /** + * Derive nested address. + * @param {Object} options + * @returns {Promise} + */ + + deriveNested(id, account, index) { + return this.post(`/wallet/${id}/derivenested`, { account, index }); + } + /** * Change or set master key`s passphrase. * @param {String|Buffer} passphrase @@ -871,6 +901,36 @@ class Wallet extends EventEmitter { return this.client.createNested(this.id, account); } + /** + * Derive address. + * @param {Object} options + * @returns {Promise} + */ + + deriveReceive(account, index ) { + return this.client.deriveReceive(this.id, account, index); + } + + /** + * Derive change address. + * @param {Object} options + * @returns {Promise} + */ + + deriveChange(account, index) { + return this.client.deriveChange(this.id, account, index); + } + + /** + * Derive nested address. + * @param {Object} options + * @returns {Promise} + */ + + deriveNested(account, index) { + return this.client.deriveNested(this.id, account, index); + } + /** * Change or set master key`s passphrase. * @param {String|Buffer} passphrase From e03edbf75af904df519e8e0610c42ac2b258263c Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Wed, 8 Aug 2018 13:03:40 -0700 Subject: [PATCH 2/2] GET not POST --- bin/bwallet-cli | 9 ++++++--- lib/wallet.js | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bin/bwallet-cli b/bin/bwallet-cli index c4c6a53..b5b708c 100755 --- a/bin/bwallet-cli +++ b/bin/bwallet-cli @@ -192,7 +192,8 @@ class CLI { async deriveReceive() { const account = this.config.str([0, 'account']); const index = this.config.uint([1, 'index']); - const addr = await this.wallet.deriveReceive(account, index); + const force = this.config.bool([2, 'force']); + const addr = await this.wallet.deriveReceive(account, index, force); this.log(addr); } @@ -200,7 +201,8 @@ class CLI { async deriveChange() { const account = this.config.str([0, 'account']); const index = this.config.uint([1, 'index']); - const addr = await this.wallet.deriveChange(account, index); + const force = this.config.bool([2, 'force']); + const addr = await this.wallet.deriveChange(account, index, force); this.log(addr); } @@ -208,7 +210,8 @@ class CLI { async deriveNested() { const account = this.config.str([0, 'account']); const index = this.config.uint([1, 'index']); - const addr = await this.wallet.deriveNested(account, index); + const force = this.config.bool([2, 'force']); + const addr = await this.wallet.deriveNested(account, index, force); this.log(addr); } diff --git a/lib/wallet.js b/lib/wallet.js index 490120e..ad6f966 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -441,8 +441,8 @@ class WalletClient extends Client { * @returns {Promise} */ - deriveReceive(id, account, index) { - return this.post(`/wallet/${id}/derivereceive`, { account, index }); + deriveReceive(id, account, index, force) { + return this.get(`/wallet/${id}/address`, { account, index, force }); } /** @@ -451,8 +451,8 @@ class WalletClient extends Client { * @returns {Promise} */ - deriveChange(id, account, index) { - return this.post(`/wallet/${id}/derivechange`, { account, index }); + deriveChange(id, account, index, force) { + return this.get(`/wallet/${id}/change`, { account, index, force }); } /** @@ -461,8 +461,8 @@ class WalletClient extends Client { * @returns {Promise} */ - deriveNested(id, account, index) { - return this.post(`/wallet/${id}/derivenested`, { account, index }); + deriveNested(id, account, index, force) { + return this.get(`/wallet/${id}/nested`, { account, index, force }); } /** @@ -907,8 +907,8 @@ class Wallet extends EventEmitter { * @returns {Promise} */ - deriveReceive(account, index ) { - return this.client.deriveReceive(this.id, account, index); + deriveReceive(account, index, force ) { + return this.client.deriveReceive(this.id, account, index, force); } /** @@ -917,8 +917,8 @@ class Wallet extends EventEmitter { * @returns {Promise} */ - deriveChange(account, index) { - return this.client.deriveChange(this.id, account, index); + deriveChange(account, index, force) { + return this.client.deriveChange(this.id, account, index, force); } /** @@ -927,8 +927,8 @@ class Wallet extends EventEmitter { * @returns {Promise} */ - deriveNested(account, index) { - return this.client.deriveNested(this.id, account, index); + deriveNested(account, index, force) { + return this.client.deriveNested(this.id, account, index, force); } /**