From 402996ba74fd4927f2359bab8f6f5521e3e28077 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 5 Oct 2016 00:52:38 -0700 Subject: [PATCH] rpc: add `selectwallet` call. --- lib/http/rpc.js | 20 +++++++++++++++++++- lib/wallet/wallet.js | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index c625c177..31d52242 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -299,6 +299,8 @@ RPC.prototype.execute = function execute(json) { case 'getmemory': return this.getmemory(json.params); + case 'selectwallet': + return this.selectwallet(json.params); default: return Promise.reject(new Error('Method not found: ' + json.method + '.')); @@ -3171,6 +3173,7 @@ RPC.prototype.getwalletinfo = co(function* getwalletinfo(args) { hashes = yield this.wallet.txdb.getHistoryHashes(this.wallet.id); return { + walletid: this.wallet.id, walletversion: 0, balance: +utils.btc(balance.total), unconfirmed_balance: +utils.btc(balance.unconfirmed), @@ -4042,7 +4045,7 @@ RPC.prototype.importprunedfunds = co(function* importprunedfunds(args) { tx.ts = block.ts; tx.height = height; - added = yield this.wallet.addTX(tx); + added = yield this.wallet.add(tx); if (!added) throw new RPCError('No tracked address for TX.'); @@ -4085,6 +4088,21 @@ RPC.prototype.getmemory = function getmemory(args) { }); }; +RPC.prototype.selectwallet = co(function* selectwallet(args) { + var id, wallet; + + if (args.help || args.length !== 1) + return Promise.reject(new RPCError('selectwallet "id"')); + + id = toString(args[0]); + wallet = yield this.walletdb.get(id); + + if (!wallet) + throw new RPCError('Wallet not found.'); + + this.wallet = wallet; +}); + /* * Helpers */ diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 24430957..674e5a95 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -1846,11 +1846,12 @@ Wallet.prototype.add = co(function* add(tx) { Wallet.prototype._add = co(function* add(tx) { var info = yield this.getPathInfo(tx); + var result; this.start(); try { - yield this.txdb._add(tx, info); + result = yield this.txdb._add(tx, info); yield this.syncOutputDepth(info); yield this.updateBalances(); } catch (e) { @@ -1859,6 +1860,8 @@ Wallet.prototype._add = co(function* add(tx) { } yield this.commit(); + + return result; }); /**