fix getBlockByTx.

This commit is contained in:
Christopher Jeffrey 2014-12-10 16:28:35 -08:00
parent 0508bc54d8
commit 70d19eb6d6
2 changed files with 11 additions and 5 deletions

View File

@ -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_));
});
});
};

View File

@ -2276,7 +2276,7 @@ async_block_tx_after(uv_work_t *req) {
Local<Object> jstx = NanNew<Object>();
ctx_to_jstx(ctx, cblock.GetHash(), jstx);
const unsigned argc = 2;
const unsigned argc = 3;
Local<Value> argv[argc] = {
Local<Value>::New(Null()),
Local<Value>::New(jsblock),