diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 5e0d6bf9..c2582f94 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -388,10 +388,12 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) { blockhash = options.blockhash || options.block; traverse = options.traverse !== false; } + if (typeof blockhash === 'function') { callback = blockhash; blockhash = ''; } + if (typeof blockhash !== 'string') { if (blockhash) { blockhash = blockhash.hash @@ -402,6 +404,12 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) { blockhash = ''; } } + + return bitcoindjs.getTransaction(txid, blockhash, traverse, function(err, tx) { + if (err) return callback(err); + return callback(null, bitcoin.tx(tx)); + }); + if (blockhash && typeof blockhash === 'string') { return bitcoindjs.getTransaction(txid, blockhash, traverse, function(err, tx) { if (err) return callback(err); @@ -412,6 +420,7 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) { return callback(null, bitcoin.tx(tx)); }); } + return bitcoin.db.get('tx-block/' + txid, function(err, block) { // Will traverse blockchain if no block - slow: return bitcoinjs.getTransaction(txid, block ? block.hash : '', traverse, function(err, tx) {