use other method for obtaining addr txs. cache them.

This commit is contained in:
Christopher Jeffrey 2014-11-18 16:55:24 -08:00
parent 0c19633da9
commit 0be9143e32
2 changed files with 22 additions and 5 deletions

View File

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

View File

@ -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 {