Update index.js

This commit is contained in:
sairajzero 2023-02-05 17:42:22 +05:30
parent bcfe9741bd
commit f05d83ff6d

View File

@ -208,11 +208,14 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
if(!options.txNotNeeded) {
results.totalCount++;
if(results.items.length < MAX_TX_QUERY_LIMIT && !results.items.some(x => x.txid() === tx.txid())) //push only if tx not already in array
if(!results.items.some(x => x.txid() === tx.txid())) //push only if tx not already in array
results.items.unshift(tx); //using unshift, so that recent tx (low) are at front
if(results.items.length >= MAX_TX_QUERY_LIMIT) //indicate max array limit is reached, the sub process can stop
options.flag_stop = true;
if(results.items.length > MAX_TX_QUERY_LIMIT) {
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
let del_count = results.items.length - MAX_TX_QUERY_LIMIT;
results.items.splice(0, del_count);
}
}