server: add get wallets call.

This commit is contained in:
Christopher Jeffrey 2016-12-19 08:04:30 -08:00
parent b38d859382
commit 37f8d45c25
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 24 additions and 3 deletions

View File

@ -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.');

View File

@ -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}
*/

View File

@ -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());