diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 3b765a51..78d55dde 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -445,7 +445,7 @@ Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) if (err) return callback(err); if (slow && !tx.blockhash) { - return bitcoindjs.getBlockByTx(txid, function(err, block) { + return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) { if (err) return callback(err); return callback(null, bitcoin.tx(tx), bitcoin.block(block)); }); @@ -553,12 +553,18 @@ Bitcoin.prototype.getBlockByTxid = Bitcoin.prototype.getBlockByTx = function(txid, callback) { return bitcoin.db.get('block-tx/' + txid, function(err, block) { if (block) { - return self.getBlock(block.hash, callback); + return self.getBlock(block.hash, function(err, block) { + if (err) return callback(err); + var tx_ = block.tx.filter(function(tx) { + return tx.txid === txid; + })[0]; + return callback(null, block, tx_); + }); } - return bitcoindjs.getBlockByTx(txid, function(err, block) { + return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) { if (err) return callback(err); bitcoin.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP); - return callback(null, bitcoin.block(block)); + return callback(null, bitcoin.block(block), bitcoin.tx(tx_)); }); }); }; diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 709bdba9..073d803b 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -2276,7 +2276,7 @@ async_block_tx_after(uv_work_t *req) { Local jstx = NanNew(); ctx_to_jstx(ctx, cblock.GetHash(), jstx); - const unsigned argc = 2; + const unsigned argc = 3; Local argv[argc] = { Local::New(Null()), Local::New(jsblock),