From add618c1e521836a6af9ec7e492e939f1af2def3 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 9 Dec 2014 09:50:15 -0800 Subject: [PATCH] check block-tx cache from db. --- lib/bitcoind.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index caa19695..68fdd033 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -572,14 +572,15 @@ Bitcoin.prototype.__defineGetter__('chainHeight', function() { Bitcoin.prototype.getBlockByTxid = Bitcoin.prototype.getBlockByTx = function(txid, callback) { - return bitcoindjs.getBlockByTx(txid, function(err, block) { - if (err) return callback(err); - bitcoin.db.get('block-tx/' + txid, function(err, blocks) { - blocks = blocks || []; - blocks.push({ hash: block.hash }); - bitcoin.db.set('block-tx/' + txid, blocks, utils.NOOP); + return bitcoin.db.get('block-tx/' + txid, function(err, block) { + if (block) { + return self.getBlock(block.hash, callback); + } + return bitcoindjs.getBlockByTx(txid, function(err, block) { + 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)); }); };