From 6b8129fdb3b3dbc9d75fb16da9f46ad5cb2eff3f Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Tue, 7 Nov 2017 00:30:26 -0500 Subject: [PATCH] Fixed getAddressHistory. --- contrib/expensiveQueries.js | 13 ++++--- lib/services/address/index.js | 67 ++--------------------------------- package.json-e | 65 --------------------------------- 3 files changed, 9 insertions(+), 136 deletions(-) delete mode 100644 package.json-e diff --git a/contrib/expensiveQueries.js b/contrib/expensiveQueries.js index 76af0d09..23f107bd 100644 --- a/contrib/expensiveQueries.js +++ b/contrib/expensiveQueries.js @@ -2,7 +2,6 @@ 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 @@ -10,23 +9,23 @@ var addresses = require('/tmp/large_amounts_utxos.json'); 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); }); diff --git a/lib/services/address/index.js b/lib/services/address/index.js index 81bd4be2..c76ec1df 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -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); @@ -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) { @@ -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; @@ -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(); }; @@ -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; diff --git a/package.json-e b/package.json-e deleted file mode 100644 index fd4b40f7..00000000 --- a/package.json-e +++ /dev/null @@ -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 ", - "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" -}