Added sort options to get address history.
This commit is contained in:
parent
1d7c998468
commit
f10106f9a0
@ -12,6 +12,7 @@ var Encoding = require('./encoding');
|
||||
var Transform = require('stream').Transform;
|
||||
var assert = require('assert');
|
||||
var Stream = require('stream');
|
||||
var utils = require('../../utils');
|
||||
|
||||
var AddressService = function(options) {
|
||||
|
||||
@ -54,8 +55,6 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
||||
options.to = options.to || 0xffffffff;
|
||||
options.queryMempool = _.isUndefined(options.queryMempool) ? true : false;
|
||||
|
||||
var txIdList = [];
|
||||
|
||||
if (_.isString(addresses)) {
|
||||
addresses = [addresses];
|
||||
}
|
||||
@ -64,25 +63,14 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
||||
|
||||
self._getAddressHistory(address, options, next);
|
||||
|
||||
}, function(err, txLists) {
|
||||
}, function(err, txList) {
|
||||
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
txLists = _.compact(_.flattenDeep(txLists));
|
||||
var txList = [];
|
||||
|
||||
for(var i = 0; i < txLists.length; i++) {
|
||||
var tx = txLists[i];
|
||||
if (txIdList.indexOf(tx.txid()) !== -1) {
|
||||
continue;
|
||||
}
|
||||
txIdList.push(tx.txid());
|
||||
txList.push(tx);
|
||||
}
|
||||
|
||||
txList.reverse();
|
||||
txList = utils.dedupByTxid(txList);
|
||||
txList = utils.orderByConfirmationsDesc(txList);
|
||||
|
||||
var results = {
|
||||
totalCount: txList.length,
|
||||
|
||||
16
lib/utils.js
16
lib/utils.js
@ -149,4 +149,20 @@ utils.convertMillisecondsToHumanReadable = function(ms) {
|
||||
|
||||
};
|
||||
|
||||
utils.dedupByTxid = function(list) {
|
||||
var used = [];
|
||||
return _.compact(_.flattenDeep(list)).filter(function(item) {
|
||||
var pass = used.indexOf(item.txid()) === -1;
|
||||
used.push(item.txid());
|
||||
return pass;
|
||||
});
|
||||
};
|
||||
|
||||
utils.orderByConfirmations = function(list) {
|
||||
// newly confirmed first
|
||||
return _.sortBy(list, function(item) {
|
||||
return item.confirmations;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user