Update index.js

This commit is contained in:
sairajzero 2023-02-05 18:08:03 +05:30
parent f05d83ff6d
commit 373600dbb9

View File

@ -189,6 +189,13 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
options.queryMempool = true; options.queryMempool = true;
} }
//Quick support for `from` and `to` options (DEPRECATED! Not recommeded to use)
if( !_.isUndefined(options.from) || !_.isUndefined(options.to)) {
options.old_support = true;
options.from = options.from || 0;
options.to = options.to || 0xffffffff; //Max value of to will actually be MAX_TX_QUERY_LIMIT
}
if (_.isString(addresses)) { if (_.isString(addresses)) {
addresses = [addresses]; addresses = [addresses];
} }
@ -213,8 +220,9 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
if(results.items.length > MAX_TX_QUERY_LIMIT) { if(results.items.length > MAX_TX_QUERY_LIMIT) {
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid())); results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
let del_count = results.items.length - MAX_TX_QUERY_LIMIT; let del_count = options.old_support ? results.items.length : results.items.length - MAX_TX_QUERY_LIMIT;
results.items.splice(0, del_count); let start_index = options.old_support ? MAX_TX_QUERY_LIMIT : 0;
results.items.splice(start_index, del_count);
} }
} }
@ -235,9 +243,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
results.totalCount = parseInt(results.totalCount.toFixed()); results.totalCount = parseInt(results.totalCount.toFixed());
//Quick support for `from` and `to` options (DEPRECATED! Not recommeded to use) //Quick support for `from` and `to` options (DEPRECATED! Not recommeded to use)
if( !_.isUndefined(options.from) || !_.isUndefined(options.to)) { if(options.old_support) {
options.from = options.from || 0;
options.to = options.to || 0xffffffff; //Max value of to will actually be MAX_TX_QUERY_LIMIT
results.items = results.items.slice(options.from, options.to); results.items = results.items.slice(options.from, options.to);
} }