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
This commit is contained in:
sairajzero 2023-02-04 20:29:41 +05:30
parent d9579853ad
commit 3a75002efc

View File

@ -658,10 +658,19 @@ AddressService.prototype.stop = function(callback) {
AddressService.prototype._getTxidStream = function(address, options) { 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([ var end = Buffer.concat([
start.slice(0, address.length + 4), start.slice(0, address.length + 4),
options.endHeightBuf, endHeightBuf,
new Buffer(new Array(83).join('f'), 'hex') new Buffer(new Array(83).join('f'), 'hex')
]); ]);
@ -718,9 +727,6 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal
var results = []; var results = [];
options.endHeightBuf = new Buffer(4);
options.endHeightBuf.writeUInt32BE(options.end);
if (_.isUndefined(options.queryMempool)) { if (_.isUndefined(options.queryMempool)) {
options.queryMempool = true; options.queryMempool = true;
} }
@ -801,13 +807,6 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
options.queryMempool = true; 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 //declare the queue to process tx data
var tmpTxList = {}; //store processed txid temporarily to ignore duplication 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)); mempoolTxids.map(id => q.push(id, chunkCallback));
next(); 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 // stream the rest of the confirmed txids out of the address index
function(next) { function(next) {