diff --git a/bin/cli b/bin/cli index 8225d825..07998461 100755 --- a/bin/cli +++ b/bin/cli @@ -33,6 +33,11 @@ CLI.prototype.getInfo = co(function* getInfo() { this.log(info); }); +CLI.prototype.getWallets = co(function* getWallets() { + var wallets = yield this.client.getWallets(); + this.log(wallets); +}); + CLI.prototype.createWallet = co(function* createWallet() { var options = { id: this.argv[0] }; var wallet; @@ -613,6 +618,8 @@ CLI.prototype.handleNode = co(function* handleNode() { switch (this.argv.shift()) { case 'info': return yield this.getInfo(); + case 'wallets': + return yield this.getWallets(); case 'mkwallet': return yield this.createWallet(); case 'broadcast': @@ -639,6 +646,7 @@ CLI.prototype.handleNode = co(function* handleNode() { this.log('Unrecognized command.'); this.log('Commands:'); this.log(' $ info: Get server info.'); + this.log(' $ wallets: List all wallets.'); this.log(' $ wallet create [id]: Create wallet.'); this.log(' $ broadcast [tx-hex]: Broadcast transaction.'); this.log(' $ mempool: Get mempool snapshot.'); diff --git a/lib/http/client.js b/lib/http/client.js index 3ca7040e..0afd5090 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -460,8 +460,16 @@ HTTPClient.prototype.none = function none() { }; /** - * Request the raw wallet JSON (will create wallet if it does not exist). - * @private + * Get list of all wallet IDs. + * @returns {Promise} + */ + +HTTPClient.prototype.getWallets = function getWallets() { + return this._get('/wallets'); +}; + +/** + * Create a wallet. * @param {Object} options - See {@link Wallet}. * @returns {Promise} */ @@ -472,7 +480,6 @@ HTTPClient.prototype.createWallet = function createWallet(options) { /** * Get the raw wallet JSON. - * @private * @param {WalletID} id * @returns {Promise} */ diff --git a/lib/http/server.js b/lib/http/server.js index 5f401095..0aa014c2 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -835,6 +835,12 @@ HTTPServer.prototype._init = function _init() { send(200, { success: true }); })); + // List wallets + this.get('/wallets', con(function* (req, res, send, next) { + var wallets = yield this.walletdb.getWallets(); + send(200, wallets); + })); + // Get wallet this.get('/wallet/:id', function(req, res, send, next) { send(200, req.wallet.toJSON());