rpc: add selectwallet call.

This commit is contained in:
Christopher Jeffrey 2016-10-05 00:52:38 -07:00
parent 279df328d1
commit 402996ba74
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 23 additions and 2 deletions

View File

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

View File

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