add getTransactionWithBlock.

This commit is contained in:
Christopher Jeffrey 2014-12-08 14:37:51 -08:00
parent f6758c0e6f
commit 7ce053ab05
1 changed files with 44 additions and 0 deletions

View File

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