This commit is contained in:
Matias Alejo Garcia 2016-03-01 16:25:53 -03:00
parent 2dc2c4106c
commit f23f114e9e
2 changed files with 20 additions and 22 deletions

View File

@ -48,7 +48,6 @@ var getAddrs = function(req, res, next) {
var s = addrStrs.split(',');
if (s.length === 0) return as;
var enableDeadAddresses = s.length > 100;
console.log('[addresses.js.50:enableDeadAddresses:]',enableDeadAddresses); //TODO
for (var i = 0; i < s.length; i++) {
var a = new Address(s[i], enableDeadAddresses);
as.push(a);
@ -191,6 +190,19 @@ exports.multitxs = function(req, res, next) {
// no longer at bitcoind (for example a double spend)
var transactions = _.compact(_.pluck(txs, 'info'));
//rm not used items
_.each(transactions, function(t) {
t.vin = _.map(t.vin, function(i) {
return _.pick(i, ['addr', 'valueSat']);
});
t.vout = _.map(t.vout, function(o) {
return _.pick(o, ['scriptPubKey', 'value']);
});
delete t.locktime;
delete t.version;
});
transactions = {
totalItems: nbTxs,
from: +from,
@ -207,7 +219,7 @@ exports.multitxs = function(req, res, next) {
if (cache[addrStrs] && from > 0) {
//logtime('Cache hit');
txs =cache[addrStrs];
txs = cache[addrStrs];
return processTxs(txs, from, to, function(err, transactions) {
//logtime('After process Txs');
if (err) return common.handleErrors(err, res)
@ -243,12 +255,12 @@ exports.multitxs = function(req, res, next) {
});
if (!cache[addrStrs] || from == 0) {
cache[addrStrs] = txs;
cache[addrStrs] = txs;
// 5 min. just to purge memory. Cache is overwritten in from=0 requests.
setTimeout(function(){
console.log('Deleting cache:', addrStrs.substr(0,20));
setTimeout(function() {
console.log('Deleting cache:', addrStrs.substr(0, 20));
delete cache[addrStrs];
}, 5 * 60 * 1000);
}, 5 * 60 * 1000);
}
processTxs(txs, from, to, function(err, transactions) {

View File

@ -13,14 +13,14 @@ var TransactionDb = imports.TransactionDb || require('../../lib/TransactionDb').
var BlockDb = imports.BlockDb || require('../../lib/BlockDb').default();
var config = require('../../config/config');
var CONCURRENCY = 5;
var DAYS_TO_DEAD = 2;
var DAYS_TO_DEAD = 40;
var deadCache = {};
function Address(addrStr, deadCacheEnable) {
if (deadCacheEnable && deadCache[addrStr]) {
console.log('DEAD CACHE HIT:', addrStr, deadCache[addrStr].cached);
// console.log('DEAD CACHE HIT:', addrStr, deadCache[addrStr].cached);
return deadCache[addrStr];
}
@ -100,9 +100,7 @@ Address.prototype.setCache = function() {
this.cached = true;
deadCache[this.addrStr] = this;
console.log('%%%%%%%% setting DEAD cache for ', this.addrStr, this.unspent.length, this.transactions.length); //TODO
console.log('%%%%%%%% cache size:', _.keys(deadCache).length); //TODO
// TODO expire it...
};
@ -200,17 +198,11 @@ Address.prototype.update = function(next, opts) {
return cb('Bad params');
if (!opts.ignoreCache && this.cached) {
console.log('[Address.js.203] CACHED????', this.addrStr, opts.onlyUnspent, opts.includeTxInfo); //TODO
if (opts.onlyUnspent && this.unspent) {
console.log('[Address.js.206] YES (unspent)'); //TODO
return next();
}
if (opts.includeTxInfo && this.transactions.length) {
console.log('[Address.js.206] YES (TXS)'); //TODO
return next();
}
}
@ -272,18 +264,12 @@ console.log('[Address.js.206] YES (TXS)'); //TODO
});
} else {
console.log('[Address.js.273]'); //TODO
txOut.forEach(function(txItem) {
self._addTxItem(txItem, txList, opts.includeTxInfo);
});
if (txList)
self.transactions = txList;
console.log('[Address.js.279]', self.addrStr, self.deadCacheEnable , self.cached); //TODO
if (self.deadCacheEnable && self.cached) {
console.log('[Address.js.281] WASS DEAD ALREADY! CACHING HISTORY'); //TODO
self.setCache();
}