From e872f5985c7259cfdc8468ae5c3422b83e6d42e0 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 10 Aug 2016 20:51:47 -0700 Subject: [PATCH] rpc: getreceivedbyaccount. --- lib/bcoin/http/rpc.js | 44 ++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/bcoin/http/rpc.js b/lib/bcoin/http/rpc.js index 9a4d3e8e..b07e431a 100644 --- a/lib/bcoin/http/rpc.js +++ b/lib/bcoin/http/rpc.js @@ -2814,6 +2814,7 @@ RPC.prototype.getreceivedbyaccount = function getreceivedbyaccount(args, callbac var self = this; var minconf = 0; var total = 0; + var filter = {}; var i, j, account, tx, output; if (args.help || args.length < 1 || args.length > 2) @@ -2827,25 +2828,34 @@ RPC.prototype.getreceivedbyaccount = function getreceivedbyaccount(args, callbac if (args.length === 2) minconf = Number(args[1]); - this.wallet.getHistory(account, function(err, txs) { + this.wallet.getAddresses(function(err, hashes) { if (err) return callback(err); - for (i = 0; i < txs.length; i++) { - tx = txs[i]; - if (minconf) { - if (tx.height === -1) - continue; - if (!(self.chain.height - tx.height + 1 >= minconf)) - continue; - } - for (j = 0; j < tx.outputs.length; j++) { - output = tx.outputs[j]; - total += output.value; - } - } + for (i = 0; i < hashes.length; i++) + filter[hashes[i]] = true; - callback(null, +utils.btc(total)); + self.wallet.getHistory(account, function(err, txs) { + if (err) + return callback(err); + + for (i = 0; i < txs.length; i++) { + tx = txs[i]; + if (minconf) { + if (tx.height === -1) + continue; + if (!(self.chain.height - tx.height + 1 >= minconf)) + continue; + } + for (j = 0; j < tx.outputs.length; j++) { + output = tx.outputs[j]; + if (filter[output.getHash('hex')]) + total += output.value; + } + } + + callback(null, +utils.btc(total)); + }); }); }; @@ -3105,6 +3115,10 @@ RPC.prototype.listreceivedbyaccount = function listreceivedbyaccount(args, callb }; RPC.prototype.listreceivedbyaddress = function listreceivedbyaddress(args, callback) { + if (args.help || args.length > 3) { + return callback(new RPCError('listreceivedbyaddress' + + ' ( minconf includeempty includeWatchonly)')); + } callback(new Error('Not implemented.')); };