Fixed getAddressHistory.
This commit is contained in:
parent
a808573a9d
commit
6b8129fdb3
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var config = require('./config.json');
|
var config = require('./config.json');
|
||||||
var addresses = require('/tmp/large_amounts_utxos.json');
|
|
||||||
|
|
||||||
// each of those addresses has a large number of utxos
|
// each of those addresses has a large number of utxos
|
||||||
|
|
||||||
@ -10,23 +9,23 @@ var addresses = require('/tmp/large_amounts_utxos.json');
|
|||||||
|
|
||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||||
|
|
||||||
var url = config.old;
|
var url = config.txs.new;
|
||||||
|
|
||||||
if (process.argv[2] === 'old') {
|
if (process.argv[2] === 'old') {
|
||||||
url = config.new;
|
url = config.txs.old;
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = {
|
console.log(url);
|
||||||
|
|
||||||
|
var options = {
|
||||||
url: url,
|
url: url,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
qs: { from: 0, to: 5, noAsm: 1, noScriptSig: 1, noSpent: 1 },
|
qs: { from: 0, to: 5, noAsm: 1, noScriptSig: 1, noSpent: 1 },
|
||||||
json: { addrs: '1H4drU7anmDUdJKAcJXfoExPPNJbwiM7nJ' }
|
json: { addrs: config.addrs }
|
||||||
//json: { addrs: addresses }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
request(options, function(err, response, body) {
|
request(options, function(err, response, body) {
|
||||||
console.log(JSON.stringify(body));
|
console.log(body);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
|||||||
addresses = [addresses];
|
addresses = [addresses];
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachSeries(addresses, function(address, next) {
|
async.eachLimit(addresses, 4, function(address, next) {
|
||||||
|
|
||||||
self._getAddressTxidHistory(address, options, next);
|
self._getAddressTxidHistory(address, options, next);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
|||||||
return callback(err);
|
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) {
|
self._getAddressTxHistory(options, function(err, txList) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -387,57 +387,6 @@ AddressService.prototype._getTxidStream = function(address, options) {
|
|||||||
return txidStream;
|
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) {
|
AddressService.prototype._getAddressTxHistory = function(options, callback) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -524,7 +473,7 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal
|
|||||||
|
|
||||||
txIdTransformStream._transform = function(chunk, enc, callback) {
|
txIdTransformStream._transform = function(chunk, enc, callback) {
|
||||||
var txInfo = self._encoding.decodeAddressIndexKey(chunk);
|
var txInfo = self._encoding.decodeAddressIndexKey(chunk);
|
||||||
self._pushTxInfo(txInfo, options);
|
options.txIdList.push({ txid: txInfo.txid, height: txInfo.height });
|
||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -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) {
|
AddressService.prototype._removeBlock = function(block, callback) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|||||||
@ -1,65 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "bitcore-node",
|
|
||||||
"description": "Full node with extended capabilities using Bitcore and Bitcoin Core",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0.0"
|
|
||||||
},
|
|
||||||
"author": "BitPay <dev@bitpay.com>",
|
|
||||||
"version": "5.0.0-beta.34",
|
|
||||||
"main": "./index.js",
|
|
||||||
"repository": "git://github.com/bitpay/bitcore-node.git",
|
|
||||||
"homepage": "https://github.com/bitpay/bitcore-node",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/bitpay/bitcore-node/issues"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"bitcore-node": "./bin/bitcore-node"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "NODE_ENV=test mocha -R spec --recursive test"
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"bitcoin",
|
|
||||||
"bitcoind",
|
|
||||||
"bcoin",
|
|
||||||
"bitcoin full node",
|
|
||||||
"bitcoin index",
|
|
||||||
"block explorer",
|
|
||||||
"wallet backend"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"async": "^2.5.0",
|
|
||||||
"bcoin": "bitpay/bcoin#v1.0.0-beta.14+cash",
|
|
||||||
"bitcoind-rpc": "^0.6.0",
|
|
||||||
"bitcore-lib": "5.0.0-beta.1",
|
|
||||||
"bitcore-p2p": "5.0.0-beta.1",
|
|
||||||
"bn.js": "^4.11.8",
|
|
||||||
"body-parser": "^1.13.3",
|
|
||||||
"colors": "^1.1.2",
|
|
||||||
"commander": "^2.8.1",
|
|
||||||
"errno": "^0.1.4",
|
|
||||||
"express": "^4.13.3",
|
|
||||||
"leveldown": "^2.0.0",
|
|
||||||
"levelup": "^2.0.0",
|
|
||||||
"liftoff": "^2.2.0",
|
|
||||||
"lodash": "^4.17.4",
|
|
||||||
"lru-cache": "^4.0.2",
|
|
||||||
"memwatch-next": "^0.3.0",
|
|
||||||
"mkdirp": "0.5.0",
|
|
||||||
"path-is-absolute": "^1.0.0",
|
|
||||||
"socket.io": "^1.4.5",
|
|
||||||
"socket.io-client": "^1.4.5"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"chai": "^3.5.0",
|
|
||||||
"coveralls": "^2.11.9",
|
|
||||||
"istanbul": "^0.4.3",
|
|
||||||
"jshint": "^2.9.2",
|
|
||||||
"jshint-stylish": "^2.1.0",
|
|
||||||
"mocha": "3.2.0",
|
|
||||||
"proxyquire": "^1.3.1",
|
|
||||||
"rimraf": "^2.4.2",
|
|
||||||
"sinon": "^1.15.4"
|
|
||||||
},
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user