From e3ac717ada0234c1cc11ac8717c33202ab92ea0c Mon Sep 17 00:00:00 2001 From: Bucko Date: Mon, 18 Sep 2017 18:55:44 -0700 Subject: [PATCH 1/3] use req.wallet for lock coin endpoints --- lib/wallet/http.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/wallet/http.js b/lib/wallet/http.js index 6f60391e..c0f68fcb 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -636,7 +636,7 @@ HTTPServer.prototype.initRouter = function initRouter() { // Locked coins this.get('/:id/locked', async (req, res) => { - const locked = this.wallet.getLocked(); + const locked = await req.wallet.getLocked(); const result = []; for (const outpoint of locked) @@ -655,8 +655,8 @@ HTTPServer.prototype.initRouter = function initRouter() { enforce(index != null, 'Index is required.'); const outpoint = new Outpoint(hash, index); - - this.wallet.lockCoin(outpoint); + await req.wallet.lockCoin(outpoint); + res.send(200, { success: true }); }); // Unlock coin @@ -670,7 +670,8 @@ HTTPServer.prototype.initRouter = function initRouter() { const outpoint = new Outpoint(hash, index); - this.wallet.unlockCoin(outpoint); + await req.wallet.unlockCoin(outpoint); + res.send(200, { success: true }); }); // Wallet Coin From d9ebfcc2f9d2be7fa41c803645676586699a7cdd Mon Sep 17 00:00:00 2001 From: Bucko Date: Tue, 19 Sep 2017 14:28:26 -0700 Subject: [PATCH 2/3] coin lock methods weren't handling parameters correctly in http client --- lib/http/client.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/http/client.js b/lib/http/client.js index b9e1ac2a..02755134 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -823,8 +823,8 @@ HTTPClient.prototype.importAddress = function importAddress(id, account, address * @returns {Promise} */ -HTTPClient.prototype.lockCoin = function lockCoin(id, hash, index) { - return this._put(`/wallet/${id}/coin/locked`, { hash, index }); +HTTPClient.prototype.lockCoin = function lockCoin(id, hash, index, passphrase) { + return this._put(`/wallet/${id}/locked/${hash}/${index}`, { passphrase }); }; /** @@ -835,8 +835,8 @@ HTTPClient.prototype.lockCoin = function lockCoin(id, hash, index) { * @returns {Promise} */ -HTTPClient.prototype.unlockCoin = function unlockCoin(id, hash, index) { - return this._del(`/wallet/${id}/coin/locked`, { hash, index }); +HTTPClient.prototype.unlockCoin = function unlockCoin(id, hash, index, passphrase) { + return this._del(`/wallet/${id}/locked/${hash}/${index}`, { passphrase }); }; /** @@ -846,7 +846,7 @@ HTTPClient.prototype.unlockCoin = function unlockCoin(id, hash, index) { */ HTTPClient.prototype.getLocked = function getLocked(id) { - return this._get(`/wallet/${id}/coin/locked`); + return this._get(`/wallet/${id}/locked`); }; /** From e27408dc5861a08da78527e71db923b192af1d5e Mon Sep 17 00:00:00 2001 From: Bucko Date: Tue, 19 Sep 2017 15:43:34 -0700 Subject: [PATCH 3/3] getCoin was unnecessarily passing account --- lib/http/client.js | 4 ++-- lib/http/wallet.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/http/client.js b/lib/http/client.js index 02755134..5e8f3eea 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -624,8 +624,8 @@ HTTPClient.prototype.getWalletBlock = function getWalletBlock(id, height) { * @returns {Promise} */ -HTTPClient.prototype.getWalletCoin = function getWalletCoin(id, account, hash, index) { - return this._get(`/wallet/${id}/coin/${hash}/${index}`, { account }); +HTTPClient.prototype.getWalletCoin = function getWalletCoin(id, hash, index) { + return this._get(`/wallet/${id}/coin/${hash}/${index}`); }; /** diff --git a/lib/http/wallet.js b/lib/http/wallet.js index 8111ff99..4cff6777 100644 --- a/lib/http/wallet.js +++ b/lib/http/wallet.js @@ -232,8 +232,8 @@ HTTPWallet.prototype.getBlock = function getBlock(height) { * @see Wallet#getCoin */ -HTTPWallet.prototype.getCoin = function getCoin(account, hash, index) { - return this.client.getWalletCoin(this.id, account, hash, index); +HTTPWallet.prototype.getCoin = function getCoin(hash, index) { + return this.client.getWalletCoin(this.id, hash, index); }; /**