Skip to content

Commit

Permalink
Fixed getAddressHistory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Kleeschulte committed Nov 7, 2017
1 parent a808573 commit 6b8129f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 136 deletions.
13 changes: 6 additions & 7 deletions contrib/expensiveQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@

var request = require('request');
var config = require('./config.json');
var addresses = require('/tmp/large_amounts_utxos.json');

// each of those addresses has a large number of utxos

// we are going to act like this group of addresses is our wallet, this ought to be fun!

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

var url = config.old;
var url = config.txs.new;

if (process.argv[2] === 'old') {
url = config.new;
url = config.txs.old;
}

var options = {
console.log(url);

var options = {
url: url,
method: 'POST',
qs: { from: 0, to: 5, noAsm: 1, noScriptSig: 1, noSpent: 1 },
json: { addrs: '1H4drU7anmDUdJKAcJXfoExPPNJbwiM7nJ' }
//json: { addrs: addresses }
json: { addrs: config.addrs }
};

request(options, function(err, response, body) {
console.log(JSON.stringify(body));
console.log(body);
});


Expand Down
67 changes: 3 additions & 64 deletions lib/services/address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
addresses = [addresses];
}

async.eachSeries(addresses, function(address, next) {
async.eachLimit(addresses, 4, function(address, next) {

self._getAddressTxidHistory(address, options, next);

Expand All @@ -76,7 +76,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
return callback(err);
}

// armed with our complete list of txids and heights, we will go and get the actual txs
options.txIdList = lodash.uniqWith(lodash.flattenDeep(options.txIdList), lodash.isEqual);
self._getAddressTxHistory(options, function(err, txList) {

if (err) {
Expand Down Expand Up @@ -387,57 +387,6 @@ AddressService.prototype._getTxidStream = function(address, options) {
return txidStream;
};

AddressService.prototype._transformTxForAddressHistory = function(opts, chunk, enc, callback) {

var self = this;

var txid = _.isString(chunk) ? chunk : self._encoding.decodeAddressIndexKey(chunk).txid;

opts.txCount++;

// no need to look up the tx if the tx is outside the range of the query.
if (opts.txCount >= (opts.to + 1) || opts.txCount < (opts.from + 1)) {
return callback();
}

self._transaction.getTransaction(txid, opts, function(err, tx) {

if (err) {
log.error('Address Service: gettransaction ' + err);
opts.stream.emit('error', err);
return callback();
}

if (!tx) {
log.error('Address Service: Could not find tx for txid: ' + txid + '. This should not be possible, check indexes.');
opts.stream.emit('error', err);
return callback();
}

opts.results.push(tx);
callback();

});

};

AddressService.prototype._getTxStream = function(address, options) {

var txStream = new Transform({ objectMode: true, highWaterMark: 1000 });

options.stream = txStream;

txStream._flush = function(callback) {
txStream.emit('end');
callback();
};

txStream._transform = this._transformTxForAddressHistory.bind(this, options);

return txStream;

};

AddressService.prototype._getAddressTxHistory = function(options, callback) {

var self = this;
Expand Down Expand Up @@ -524,7 +473,7 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal

txIdTransformStream._transform = function(chunk, enc, callback) {
var txInfo = self._encoding.decodeAddressIndexKey(chunk);
self._pushTxInfo(txInfo, options);
options.txIdList.push({ txid: txInfo.txid, height: txInfo.height });
callback();
};

Expand All @@ -536,16 +485,6 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal

};

AddressService.prototype._pushTxInfo = function(info, options) {
// look back to see if there are dupes of this record
// we can do this because the addresses stream out in order
if (options.txIdList.length > 0 &&
info.txid === options.txIdList[options.txIdList.length - 1].txid) {
return;
}
options.txIdList.push({ txid: info.txid, height: info.height });
};

AddressService.prototype._removeBlock = function(block, callback) {

var self = this;
Expand Down
65 changes: 0 additions & 65 deletions package.json-e

This file was deleted.

0 comments on commit 6b8129f

Please sign in to comment.