From bd9a41dcbef4424b9ed9ae3a8cf8524bf02b920c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 16 Aug 2016 13:39:14 -0700 Subject: [PATCH] http: get account. --- lib/bcoin/http/client.js | 12 ++++++++++++ lib/bcoin/http/server.js | 13 +++++++++++++ lib/bcoin/http/wallet.js | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/bcoin/http/client.js b/lib/bcoin/http/client.js index 20f9ba18..6cc08c0f 100644 --- a/lib/bcoin/http/client.js +++ b/lib/bcoin/http/client.js @@ -786,6 +786,18 @@ HTTPClient.prototype.getAccounts = function getAccounts(id, callback) { return this._get(path, callback); }; +/** + * Get wallet account. + * @param {WalletID} id + * @param {String} account + * @param {Function} callback - Returns [Error, Array]. + */ + +HTTPClient.prototype.getAccount = function getAccount(id, account, callback) { + var path = '/wallet/' + id + '/account/' + account; + return this._get(path, callback); +}; + /** * Create account. * @param {WalletID} id diff --git a/lib/bcoin/http/server.js b/lib/bcoin/http/server.js index 0d8ad92a..49b3a298 100644 --- a/lib/bcoin/http/server.js +++ b/lib/bcoin/http/server.js @@ -601,6 +601,19 @@ HTTPServer.prototype._init = function _init() { }); }); + // Get account + this.get('/wallet/:id/account/:account', function(req, res, next, send) { + req.wallet.getAccount(req.options.account, function(err, account) { + if (err) + return next(err); + + if (!account) + return send(404); + + send(200, account.toJSON()); + }); + }); + // Create/get account this.post('/wallet/:id/account/:account?', function(req, res, next, send) { req.wallet.createAccount(req.options, function(err, account) { diff --git a/lib/bcoin/http/wallet.js b/lib/bcoin/http/wallet.js index d73b8837..6ad7d8d2 100644 --- a/lib/bcoin/http/wallet.js +++ b/lib/bcoin/http/wallet.js @@ -275,8 +275,8 @@ HTTPWallet.prototype.getAccounts = function getAccounts(callback) { * @see Wallet#getAccount */ -HTTPWallet.prototype.getAccount = function getAccount(options, callback) { - return this.client.getAccount(this.id, options, callback); +HTTPWallet.prototype.getAccount = function getAccount(account, callback) { + return this.client.getAccount(this.id, account, callback); }; /**