diff --git a/lib/bitcoind.js b/lib/bitcoind.js index a2eb71f1..6c129dab 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -435,6 +435,50 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) { }); }; +Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) { + var slow = true; + + if (typeof txid === 'object' && txid) { + var options = txid; + callback = blockhash; + txid = options.txid || options.tx || options.txhash || options.id || options.hash; + blockhash = options.blockhash || options.block; + slow = options.slow !== false; + } + + if (typeof blockhash === 'function') { + callback = blockhash; + blockhash = ''; + } + + if (typeof blockhash !== 'string') { + if (blockhash) { + blockhash = blockhash.hash + || blockhash.blockhash + || (blockhash.getHash && blockhash.getHash()) + || ''; + } else { + blockhash = ''; + } + } + + return bitcoindjs.getTransaction(txid, blockhash, function(err, tx) { + if (err) return callback(err); + + if (slow && !tx.blockhash) { + return bitcoindjs.getBlockByTx(txid, function(err, block) { + if (err) return callback(err); + return callback(null, bitcoin.tx(tx), bitcoin.block(block)); + }); + } + + return bitcoindjs.getBlock(tx.blockhash, function(err, block) { + if (err) return callback(err); + return callback(null, bitcoin.tx(tx), bitcoin.block(block)); + }); + }); +}; + Bitcoin.prototype.getInfo = function() { return bitcoindjs.getInfo(); };