Fixed get raw tx calls that failed when input values were also in
mempool.
This commit is contained in:
parent
a6a123a62d
commit
fba71ee1aa
@ -195,9 +195,6 @@ TransactionService.prototype._getMempoolTransaction = function(txid, tx, options
|
||||
var self = this;
|
||||
var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool;
|
||||
|
||||
if (!tx) {
|
||||
console.log(txid);
|
||||
}
|
||||
if (tx || !queryMempool) {
|
||||
return callback(null, tx, options);
|
||||
}
|
||||
@ -212,6 +209,7 @@ TransactionService.prototype._getMempoolTransaction = function(txid, tx, options
|
||||
return callback(null, tx, options);
|
||||
}
|
||||
|
||||
// the tx's that contain these input values could, themselves be unconfirmed
|
||||
self._getInputValues(tx, options, function(err, inputValues) {
|
||||
|
||||
if (err) {
|
||||
@ -268,6 +266,8 @@ TransactionService.prototype._getInputValues = function(tx, options, callback) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var _tx = tx;
|
||||
|
||||
async.mapLimit(tx.inputs, 4, function(input, next) {
|
||||
|
||||
if (input.isCoinbase()) {
|
||||
@ -276,18 +276,42 @@ TransactionService.prototype._getInputValues = function(tx, options, callback) {
|
||||
|
||||
var outputIndex = input.prevout.index;
|
||||
|
||||
self._getTransaction(input.prevout.txid(), options, function(err, txid, _tx) {
|
||||
async.waterfall([
|
||||
// check tx index first, most likely place
|
||||
function(next) {
|
||||
self._getTransaction(input.prevout.txid(), options, next);
|
||||
},
|
||||
// if not there, then check mempool
|
||||
function(txid, tx, options, next) {
|
||||
if (tx) {
|
||||
return next(null, txid, tx);
|
||||
}
|
||||
self._mempool.getMempoolTransaction(input.prevout.txid(), function(err, memTx) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(null, txid, memTx);
|
||||
});
|
||||
},
|
||||
// if not in mempool or tx index, we just don't have it, yet?
|
||||
function(txid, tx, next) {
|
||||
if (!tx) {
|
||||
return next(new Error('Transaction Service: prev transacion: (' + input.prevout.txid() + ') for tx: ' +
|
||||
_tx.txid() + ' at input index: ' + outputIndex + ' is missing from the index or not in the memory pool. It could be' +
|
||||
' that the parent tx has not yet been relayed to us, but will be relayed in the near future.'));
|
||||
}
|
||||
var output = tx.outputs[outputIndex];
|
||||
|
||||
if (err || !_tx) {
|
||||
return next(err || new Error('Transaction Service: tx not found for tx id: ' + input.prevout.txid()));
|
||||
assert(output, 'Expected an output, but did not get one for tx: ' + tx.txid() + ' outputIndex: ' + outputIndex);
|
||||
|
||||
next(null, output.value);
|
||||
}
|
||||
|
||||
var output = _tx.outputs[outputIndex];
|
||||
assert(output, 'Expected an output, but did not get one for tx: ' + _tx.txid() + ' outputIndex: ' + outputIndex);
|
||||
next(null, output.value);
|
||||
|
||||
], function(err, val) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(null, val);
|
||||
});
|
||||
|
||||
}, callback);
|
||||
|
||||
};
|
||||
|
||||
@ -94,7 +94,7 @@ describe('Transaction Service', function() {
|
||||
var put = sandbox.stub().callsArgWith(2, null);
|
||||
txService._db = { put: put };
|
||||
|
||||
sandbox.stub(txService, '_getTransaction').callsArgWith(2, null, tx.txid(), tx);
|
||||
sandbox.stub(txService, '_getTransaction').callsArgWith(2, null, tx.txid(), tx, {});
|
||||
|
||||
tx.__inputValues = [];
|
||||
|
||||
@ -103,8 +103,10 @@ describe('Transaction Service', function() {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
values.should.deep.equal([1139033, 1139033, 500000, 1139033]);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user