Update index.js
This commit is contained in:
parent
88c276ad49
commit
6e9f946607
@ -207,9 +207,12 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
|
||||
if(err)
|
||||
return log.error(err);
|
||||
|
||||
if(!options.txNotNeeded && results.items.length < MAX_TX_QUERY_LIMIT)
|
||||
if(!results.items.some(x => x.txid() === tx.txid())) //push only if tx not already in array
|
||||
if(!options.txNotNeeded) {
|
||||
let count = self._getOccurrenceCount(tx, address);
|
||||
results.totalCount += 1 / count; //fix for duplication
|
||||
if(results.items.length < MAX_TX_QUERY_LIMIT && !results.items.some(x => x.txid() === tx.txid())) //push only if tx not already in array
|
||||
results.items.push(tx);
|
||||
}
|
||||
|
||||
streamer(null, tx);
|
||||
|
||||
@ -223,7 +226,6 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
|
||||
|
||||
//sort items in desc block-height, then asc txid (if same height)
|
||||
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
|
||||
console.debug("ITEMS:", results.items)
|
||||
|
||||
//TODO: sorting of tx list (results.items)
|
||||
callback(null, results);
|
||||
@ -405,6 +407,31 @@ AddressService.prototype._getAddressSummaryResult = function(txs, address, resul
|
||||
return result;
|
||||
};
|
||||
|
||||
AddressService.prototype._getOccurrenceCount = function(tx, address) {
|
||||
let count = 0;
|
||||
|
||||
for(var i = 0; i < tx.inputs.length; i++) {
|
||||
|
||||
var input = tx.inputs[i];
|
||||
|
||||
if(utils.getAddress(input, this._network) === address)
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
for(var j = 0; j < tx.outputs.length; j++) {
|
||||
|
||||
var output = tx.outputs[j];
|
||||
|
||||
if(utils.getAddress(output, this._network) === address)
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
AddressService.prototype._getOutputResults = function(tx, address) {
|
||||
|
||||
let result = { value: 0, count:0 };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user