From 0be9143e322c9fba0ceb42beb2b281b7b3ebe722 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 18 Nov 2014 16:55:24 -0800 Subject: [PATCH] use other method for obtaining addr txs. cache them. --- lib/bitcoind.js | 15 +++++++++++++++ src/bitcoindjs.cc | 12 +++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index d46518b7..c0a6f5a5 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -414,10 +414,25 @@ Bitcoin.prototype.getMiningInfo = function() { return bitcoindjs.getMiningInfo(); }; +Bitcoin._addrCache = {}; +Bitcoin._collectAddrGarbage = null; Bitcoin.prototype.getAddrTransactions = function(addr, callback) { + if (!Bitcoin._collectAddrGarbage) { + Bitcoin._collectAddrGarbage = setInterval(function() { + Bitcoin._addrCache = {}; + }, 20 * 60 * 1000); + } + var cached = Bitcoin._addrCache[addr]; + if (cached && Date.now() <= (cached.time + 10 * 60 * 1000)) { + return callback(null, cached.addr); + } return bitcoindjs.getAddrTransactions(addr, function(err, addr) { if (err) return callback(err); addr = bitcoin.addr(addr); + Bitcoin._addrCache[addr.address] = { + addr: addr, + time: Date.now() + }; return callback(null, addr); }); }; diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 319f42b8..ba144c37 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -2029,7 +2029,7 @@ async_get_addrtx(uv_work_t *req) { return; } -#if 0 +#if 1 CScript expected = GetScriptForDestination(address.Get()); int64_t i = 0; @@ -2045,8 +2045,9 @@ async_get_addrtx(uv_work_t *req) { if (txin.scriptSig.ToString() == expected.ToString()) { ctx_list *item = new ctx_list(); item->ctx = ctx; - uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex()); - item->blockhash = hash; + //uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex()); + //item->blockhash = hash; + item->blockhash = cblock.GetHash(); if (data->ctxs == NULL) { data->ctxs = item; } else { @@ -2070,8 +2071,9 @@ async_get_addrtx(uv_work_t *req) { if (data->addr == str_addr) { ctx_list *item = new ctx_list(); item->ctx = ctx; - uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex()); - item->blockhash = hash; + //uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex()); + //item->blockhash = hash; + item->blockhash = cblock.GetHash(); if (data->ctxs == NULL) { data->ctxs = item; } else {