Skip to content

Commit

Permalink
Merge pull request #316 from Bucko13/lock-coin-bug
Browse files Browse the repository at this point in the history
use req.wallet for lock coin endpoints
  • Loading branch information
chjj authored Oct 19, 2017
2 parents a4858e2 + e27408d commit 5ba79e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/http/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};

/**
Expand Down Expand Up @@ -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 });
};

/**
Expand All @@ -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 });
};

/**
Expand All @@ -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`);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/http/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down
9 changes: 5 additions & 4 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,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)
Expand All @@ -660,8 +660,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
Expand All @@ -675,7 +675,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
Expand Down

0 comments on commit 5ba79e4

Please sign in to comment.