Fixed getAddressHistory.

This commit is contained in:
Chris Kleeschulte 2017-11-07 21:37:54 -05:00
parent b701ab31cf
commit 9a00622de4
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F

View File

@ -50,7 +50,6 @@ AddressService.dependencies = [
// in are [addr1, addr2, addr3], then if addr3 has tx1 at height 10, addr2 has tx2 at height 9 and tx1 has no txs, // in are [addr1, addr2, addr3], then if addr3 has tx1 at height 10, addr2 has tx2 at height 9 and tx1 has no txs,
// then I would pass back [tx1, tx2] in that order // then I would pass back [tx1, tx2] in that order
AddressService.prototype.getAddressHistory = function(addresses, options, callback) { AddressService.prototype.getAddressHistory = function(addresses, options, callback) {
var self = this; var self = this;
options = options || {}; options = options || {};
@ -78,7 +77,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
options.txIdList = lodash.uniqWith(options.txIdList, lodash.isEqual); options.txIdList = lodash.uniqWith(options.txIdList, lodash.isEqual);
options.txIdList = lodash.orderBy(options.txIdList, ['height'], ['desc']); options.txIdList = lodash.orderBy(options.txIdList, ['height'], ['desc']);
console.log(options.txIdList);
self._getAddressTxHistory(options, function(err, txList) { self._getAddressTxHistory(options, function(err, txList) {
if (err) { if (err) {
@ -423,6 +422,8 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal
options.start = options.start || 0; options.start = options.start || 0;
options.end = options.end || 0xffffffff; options.end = options.end || 0xffffffff;
var results = [];
options.endHeightBuf = new Buffer(4); options.endHeightBuf = new Buffer(4);
options.endHeightBuf.writeUInt32BE(options.end); options.endHeightBuf.writeUInt32BE(options.end);
@ -449,7 +450,7 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal
return next(); return next();
} }
options.txIdList = mempoolTxids; results = mempoolTxids;
next(); next();
}, },
// stream the rest of the confirmed txids out of the address index // stream the rest of the confirmed txids out of the address index
@ -468,12 +469,13 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal
}); });
txIdTransformStream.on('end', function() { txIdTransformStream.on('end', function() {
options.txIdList = options.txIdList.concat(results);
next(); next();
}); });
txIdTransformStream._transform = function(chunk, enc, callback) { txIdTransformStream._transform = function(chunk, enc, callback) {
var txInfo = self._encoding.decodeAddressIndexKey(chunk); var txInfo = self._encoding.decodeAddressIndexKey(chunk);
options.txIdList.push({ txid: txInfo.txid, height: txInfo.height }); results.push({ txid: txInfo.txid, height: txInfo.height });
callback(); callback();
}; };