From 3a75002efc62c6590dc67e988a3eefffd44340c2 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sat, 4 Feb 2023 20:29:41 +0530 Subject: [PATCH] API Query options - Fixed: option `start` to query from blockheight - Added option `after`: pass this option in API to get list after the given txid Note: If both `start` and `after` are given, then greater height will be used Note: invalid or unconfirmed txid cannot be used in `after` option and will be ignored --- lib/services/address/index.js | 48 ++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/services/address/index.js b/lib/services/address/index.js index 08de11c6..0cf0d0fb 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -658,10 +658,19 @@ AddressService.prototype.stop = function(callback) { AddressService.prototype._getTxidStream = function(address, options) { - var start = this._encoding.encodeAddressIndexKey(address); + var start; + if(options.after) { + start = this._encoding.encodeAddressIndexKey(address, options.start, options.after, 0xffffffff, 1, 0xffffffff); //0xffffffff is for getting after the txid + } else { + start = this._encoding.encodeAddressIndexKey(address, options.start); + } + + var endHeightBuf = new Buffer(4); + endHeightBuf.writeUInt32BE(options.end); + var end = Buffer.concat([ start.slice(0, address.length + 4), - options.endHeightBuf, + endHeightBuf, new Buffer(new Array(83).join('f'), 'hex') ]); @@ -718,9 +727,6 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal var results = []; - options.endHeightBuf = new Buffer(4); - options.endHeightBuf.writeUInt32BE(options.end); - if (_.isUndefined(options.queryMempool)) { options.queryMempool = true; } @@ -801,13 +807,6 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre options.queryMempool = true; } - options.endHeightBuf = new Buffer(4); - options.endHeightBuf.writeUInt32BE(options.end); - - if (_.isUndefined(options.queryMempool)) { - options.queryMempool = true; - } - //declare the queue to process tx data var tmpTxList = {}; //store processed txid temporarily to ignore duplication @@ -889,6 +888,31 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre mempoolTxids.map(id => q.push(id, chunkCallback)); next(); }, + + function(next){ + + if(_.isUndefined(options.after)) { + return next(); + } + + self._transaction.getTransaction(id.txid, options, function(err, tx) { + + if(tx && tx.confirmations && tx.height >= options.start) { + + options.start = tx.height; + + } else { + + delete options.after; + + } + + next(); + + }); + + }, + // stream the rest of the confirmed txids out of the address index function(next) {