From f05d83ff6dd8c825772a6c92a76738e19d508d0f Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sun, 5 Feb 2023 17:42:22 +0530 Subject: [PATCH] Update index.js --- lib/services/address/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/services/address/index.js b/lib/services/address/index.js index ee657f91..bbe8bd3d 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -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); + } }