check block-tx cache from db.
This commit is contained in:
parent
fbbc8f5fb2
commit
add618c1e5
@ -572,14 +572,15 @@ Bitcoin.prototype.__defineGetter__('chainHeight', function() {
|
|||||||
|
|
||||||
Bitcoin.prototype.getBlockByTxid =
|
Bitcoin.prototype.getBlockByTxid =
|
||||||
Bitcoin.prototype.getBlockByTx = function(txid, callback) {
|
Bitcoin.prototype.getBlockByTx = function(txid, callback) {
|
||||||
return bitcoindjs.getBlockByTx(txid, function(err, block) {
|
return bitcoin.db.get('block-tx/' + txid, function(err, block) {
|
||||||
if (err) return callback(err);
|
if (block) {
|
||||||
bitcoin.db.get('block-tx/' + txid, function(err, blocks) {
|
return self.getBlock(block.hash, callback);
|
||||||
blocks = blocks || [];
|
}
|
||||||
blocks.push({ hash: block.hash });
|
return bitcoindjs.getBlockByTx(txid, function(err, block) {
|
||||||
bitcoin.db.set('block-tx/' + txid, blocks, utils.NOOP);
|
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));
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user