refactor. drop dumbcache.

This commit is contained in:
Christopher Jeffrey 2016-03-10 14:14:19 -08:00
parent 7058611456
commit 419ba83058
2 changed files with 25 additions and 89 deletions

View File

@ -333,44 +333,23 @@ BlockDB.prototype.disconnectBlock = function disconnectBlock(hash, callback, bat
});
};
BlockDB.prototype.fillCoins = function fillCoins(txs, callback) {
var self = this;
var pending = txs.length;
callback = utils.asyncify(callback);
utils.forEach(txs, function(tx, next) {
self.fillCoin(tx, function(err) {
if (err)
return next(err);
next();
});
}, callback);
};
BlockDB.prototype.fillTXs = function fillTXs(txs, callback) {
var self = this;
callback = utils.asyncify(callback);
utils.forEach(txs, function(tx, next) {
self.fillTX(tx, function(err) {
if (err)
return next(err);
next();
});
}, callback);
};
BlockDB.prototype.fillCoin = function fillCoin(tx, callback) {
var self = this;
callback = utils.asyncify(callback);
if (Array.isArray(tx)) {
return utils.forEach(tx, function(tx, next) {
self.fillCoin(tx, next);
}, function(err) {
if (err)
return callback(err);
return callback(null, tx);
});
}
if (tx.isCoinbase())
return callback();
return callback(null, tx);
utils.forEach(tx.inputs, function(input, next) {
if (input.output)
@ -397,8 +376,18 @@ BlockDB.prototype.fillTX = function fillTX(tx, callback) {
callback = utils.asyncify(callback);
if (Array.isArray(tx)) {
return utils.forEach(tx, function(tx, next) {
self.fillTX(tx, next);
}, function(err) {
if (err)
return callback(err);
return callback(null, tx);
});
}
if (tx.isCoinbase())
return callback();
return callback(null, tx);
utils.forEach(tx.inputs, function(input, next) {
if (input.output)
@ -659,7 +648,7 @@ BlockDB.prototype.getFullBlock = function getFullBlock(hash, callback) {
if (!block)
return callback();
return self.fillTXs(block.txs, function(err) {
return self.fillTX(block.txs, function(err) {
if (err)
return callback(err);
@ -705,7 +694,7 @@ BlockDB.prototype._getTXBlock = function _getTXBlock(hash, callback) {
BlockDB.prototype.fillBlock = function fillBlock(block, callback) {
var self = this;
return this.fillCoins(block.txs, function(err) {
return this.fillCoin(block.txs, function(err) {
var coins, i, tx, hash, j, input, id;
if (err)
@ -737,7 +726,7 @@ BlockDB.prototype.fillBlock = function fillBlock(block, callback) {
BlockDB.prototype.fillTXBlock = function fillTXBlock(block, callback) {
var self = this;
return this.fillTXs(block.txs, function(err) {
return this.fillTX(block.txs, function(err) {
var coins, i, tx, hash, j, input, id;
if (err)

View File

@ -529,59 +529,6 @@ ChainDB.prototype.batch = function batch() {
return this.db.batch();
};
function DumbCache(size) {
this.data = {};
this.count = 0;
this.size = size;
}
DumbCache.prototype.set = function set(key, value) {
key = key + '';
assert(value !== undefined);
if (this.count > this.size)
this.reset();
if (this.data[key] === undefined)
this.count++;
this.data[key] = value;
};
DumbCache.prototype.remove = function remove(key) {
key = key + '';
if (this.data[key] === undefined)
return;
this.count--;
delete this.data[key];
};
DumbCache.prototype.get = function get(key) {
key = key + '';
return this.data[key];
};
DumbCache.prototype.has = function has(key) {
key = key + '';
return this.data[key] !== undefined;
};
DumbCache.prototype.reset = function reset() {
this.data = {};
this.count = 0;
};
function NullCache(size) {}
NullCache.prototype.set = function set(key, value) {};
NullCache.prototype.remove = function remove(key) {};
NullCache.prototype.get = function get(key) {};
NullCache.prototype.has = function has(key) {};
NullCache.prototype.reset = function reset() {};
/**
* Expose
*/