Fixed getting txs from memory pool from calls to getAddressHistory.
This commit is contained in:
parent
f10106f9a0
commit
ce653b5a12
@ -70,7 +70,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
||||
}
|
||||
|
||||
txList = utils.dedupByTxid(txList);
|
||||
txList = utils.orderByConfirmationsDesc(txList);
|
||||
txList = utils.orderByConfirmations(txList);
|
||||
|
||||
var results = {
|
||||
totalCount: txList.length,
|
||||
@ -313,9 +313,10 @@ AddressService.prototype._getTxidStream = function(address, options) {
|
||||
AddressService.prototype._transformTxForAddressHistory = function(opts, chunk, enc, callback) {
|
||||
|
||||
var self = this;
|
||||
var key = self._encoding.decodeAddressIndexKey(chunk);
|
||||
|
||||
self._tx.getTransaction(key.txid, opts, function(err, tx) {
|
||||
var txid = _.isString(chunk) ? chunk : self._encoding.decodeAddressIndexKey(chunk).txid;
|
||||
|
||||
self._tx.getTransaction(txid, opts, function(err, tx) {
|
||||
|
||||
if (err) {
|
||||
log.error('Address Service: gettransaction ' + err);
|
||||
@ -324,7 +325,7 @@ AddressService.prototype._transformTxForAddressHistory = function(opts, chunk, e
|
||||
}
|
||||
|
||||
if (!tx) {
|
||||
log.error('Address Service: Could not find tx for txid: ' + key.txid + '. This should not be possible, check indexes.');
|
||||
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();
|
||||
}
|
||||
@ -353,6 +354,7 @@ AddressService.prototype._getTxStream = function(address, options) {
|
||||
|
||||
};
|
||||
|
||||
// main api function for insight-api/bws
|
||||
AddressService.prototype._getAddressHistory = function(address, options, callback) {
|
||||
|
||||
var self = this;
|
||||
@ -371,7 +373,6 @@ AddressService.prototype._getAddressHistory = function(address, options, callbac
|
||||
|
||||
async.waterfall([
|
||||
|
||||
// get all the txs from the mempool that involve our address
|
||||
function(next) {
|
||||
|
||||
if (!options.queryMempool) {
|
||||
@ -396,12 +397,16 @@ AddressService.prototype._getAddressHistory = function(address, options, callbac
|
||||
});
|
||||
|
||||
if (mempoolTxids.length > 0) {
|
||||
var mempoolxidStream = new Stream.Readable({ objectMode: true });
|
||||
mempoolxidStream.pipe(txStream);
|
||||
|
||||
var mempoolTxidStream = new Stream.Readable({ objectMode: true });
|
||||
|
||||
mempoolTxidStream.pipe(txStream);
|
||||
|
||||
mempoolTxids.forEach(function(txid) {
|
||||
mempoolxidStream.push(txid);
|
||||
mempoolTxidStream.push(txid);
|
||||
});
|
||||
mempoolxidStream.unpipe();
|
||||
|
||||
mempoolTxidStream.push(null);
|
||||
}
|
||||
|
||||
var txidStream = self._getTxidStream(address, options);
|
||||
|
||||
@ -386,17 +386,24 @@ BlockService.prototype.stop = function(callback) {
|
||||
setImmediate(callback);
|
||||
};
|
||||
|
||||
BlockService.prototype._getTimeSinceLastBlock = function(blockHash, prevBlockHash, callback) {
|
||||
BlockService.prototype._getTimeSinceLastBlock = function(callback) {
|
||||
|
||||
var self = this;
|
||||
|
||||
async.map([ blockHash, prevBlockHash ], function(hash, next) {
|
||||
self._timestamp.getTimestamp(hash, next);
|
||||
}, function(err, times) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
self._header.getBlockHeader(Math.max(self._tip.height - 1, 0), function(err, header) {
|
||||
|
||||
if(err || !header) {
|
||||
return callback(err || new Error('Block Service: we should have a header in order to get time since last block.'));
|
||||
}
|
||||
return callback(null, utils.convertMillisecondsToHumanReadable((times[0] * 1000) - (times[1] * 1000)));
|
||||
|
||||
async.map([ self._tip.hash, header.hash ], function(hash, next) {
|
||||
self._timestamp.getTimestamp(hash, next);
|
||||
}, function(err, times) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, utils.convertMillisecondsToHumanReadable((times[0] * 1000) - (times[1] * 1000)));
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
@ -413,7 +420,7 @@ BlockService.prototype._queueBlock = function(block) {
|
||||
return self._handleError(err);
|
||||
}
|
||||
|
||||
self._logSynced(block.rhash(), true);
|
||||
self._logSynced(block.rhash());
|
||||
self._blocksInQueue--;
|
||||
|
||||
});
|
||||
@ -837,7 +844,7 @@ BlockService.prototype._setTip = function(tip, callback) {
|
||||
this._saveTip(tip, callback);
|
||||
};
|
||||
|
||||
BlockService.prototype._logSynced = function(blockHash, noHeight) {
|
||||
BlockService.prototype._logSynced = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
@ -845,58 +852,14 @@ BlockService.prototype._logSynced = function(blockHash, noHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
var blockHeight;
|
||||
var timeDiff;
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
|
||||
if (noHeight) {
|
||||
return next(null, null);
|
||||
}
|
||||
|
||||
self._header.getBlockHeader(blockHash, function(err, header) {
|
||||
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!header) {
|
||||
return next(null, null);
|
||||
}
|
||||
|
||||
blockHeight = header.height;
|
||||
next(null, header.prevHash);
|
||||
});
|
||||
},
|
||||
function(prevBlockHash, next) {
|
||||
|
||||
if (!prevBlockHash) {
|
||||
return next();
|
||||
}
|
||||
|
||||
self._getTimeSinceLastBlock(blockHash, prevBlockHash, function(err, diff) {
|
||||
|
||||
if (err) {
|
||||
return self._handleError(err);
|
||||
}
|
||||
|
||||
timeDiff = diff;
|
||||
next();
|
||||
});
|
||||
}
|
||||
], function(err) {
|
||||
self._getTimeSinceLastBlock(function(err, diff) {
|
||||
|
||||
if (err) {
|
||||
return self._handleError(err);
|
||||
}
|
||||
|
||||
var supplementals = '';
|
||||
if (blockHeight && timeDiff) {
|
||||
supplementals += ' at height: ' + blockHeight + '. Time between the last 2 blocks (adjusted): ' + timeDiff;
|
||||
}
|
||||
|
||||
log.info('Block Service: The best block hash is: ' + blockHash + supplementals);
|
||||
log.info('Block Service: The best block hash is: ' + self._tip.hash +
|
||||
' at height: ' + self._tip.height + '. Time between the last 2 blocks (adjusted): ' + diff);
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ MempoolService.prototype.getTxidsByAddress = function(address, callback) {
|
||||
stream.on('data', function(data) {
|
||||
var tx = self._encoding.decodeMempoolTransactionValue(data.value);
|
||||
var txid = self._involvesAddress(tx, address);
|
||||
if (tx) {
|
||||
if (txid) {
|
||||
results.push(txid);
|
||||
}
|
||||
});
|
||||
|
||||
@ -142,8 +142,8 @@ TransactionService.prototype._getSupplementaryTransactionInfo = function(txid, t
|
||||
|
||||
if (header) {
|
||||
// Do we need both of these?
|
||||
tx.blockHash = header.hash;
|
||||
tx.__blockHash = header.hash;
|
||||
tx.blockhash = header.hash;
|
||||
tx.__blockhash = header.hash;
|
||||
}
|
||||
|
||||
callback(null, txid, tx, options);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user