From 3406a09cd5609dc061e66b5595583de3be069c7c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 5 Aug 2016 14:49:59 -0700 Subject: [PATCH] rpc: listsinceblock. --- lib/bcoin/http/rpc.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/bcoin/http/rpc.js b/lib/bcoin/http/rpc.js index a9c4e646..08d43c96 100644 --- a/lib/bcoin/http/rpc.js +++ b/lib/bcoin/http/rpc.js @@ -2606,7 +2606,7 @@ RPC.prototype.listreceivedbyaddress = function listreceivedbyaddress(args, callb RPC.prototype.listsinceblock = function listsinceblock(args, callback) { var self = this; - var block, conf, out; + var block, conf, out, highest; if (args.help) { return callback(new Error('listsinceblock' @@ -2620,6 +2620,8 @@ RPC.prototype.listsinceblock = function listsinceblock(args, callback) { block = utils.revHex(block); } + conf = 0; + if (args.length > 1) { conf = Number(args[1]); if (!utils.isNumber(conf) || conf < 0) @@ -2642,6 +2644,13 @@ RPC.prototype.listsinceblock = function listsinceblock(args, callback) { utils.forEachSerial(txs, function(tx, next, i) { if (tx.height < height) return next(); + + if (tx.getConfirmations() < conf) + return next(); + + if (!highest || tx.height > highest) + highest = tx; + self._toListTX(tx, function(err, json) { if (err) return next(err); @@ -2651,7 +2660,13 @@ RPC.prototype.listsinceblock = function listsinceblock(args, callback) { }, function(err) { if (err) return callback(err); - callback(null, out); + + callback(null, { + transactions: out, + lastblock: highest && highest.block + ? utils.revHex(highest.block) + : constants.NULL_HASH + }); }); }); });