From b88fc5b0ed41c48c9020ffd653cf3faa12e24b43 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 13 Mar 2016 04:40:07 -0700 Subject: [PATCH] cleanup chaindb. --- lib/bcoin/chaindb.js | 78 ++++---------------------------------------- 1 file changed, 7 insertions(+), 71 deletions(-) diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index b478b57b..579c3726 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -791,7 +791,7 @@ ChainDB.prototype.fillTX = function fillTX(tx, callback) { if (tx.isCoinbase()) return callback(null, tx); - if (self.prune) { + if (this.prune) { return utils.forEachSerial(tx.inputs, function(input, next) { if (input.output) return next(); @@ -1212,46 +1212,6 @@ ChainDB.prototype.getBlock = function getBlock(hash, callback) { }); }; -ChainDB.prototype.hasBlock = function hasBlock(hash, callback) { - var self = this; - var id = 'b/b/' + hash; - - if (typeof hash === 'number') { - return this.getHash(hash, function(err, hash) { - if (err) - return callback(err); - if (!hash) - return callback(); - return self.hasBlock(hash, callback); - }); - } - - this.db.get(id, function(err, data) { - if (err && err.type !== 'NotFoundError') - return callback(err); - - if (!data) - return callback(null, false); - - return callback(null, true); - }); -}; - -ChainDB.prototype.hasCoin = function hasCoin(hash, index, callback) { - var self = this; - var id = 'u/t/' + hash + '/' + index; - - this.db.get(id, function(err, data) { - if (err && err.type !== 'NotFoundError') - return callback(err); - - if (!data) - return callback(null, false); - - return callback(null, true); - }); -}; - ChainDB.prototype._getTX = function _getTX(hash, callback) { if (hash instanceof bcoin.tx) return callback(null, hash); @@ -1299,45 +1259,21 @@ ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) { }); }; -ChainDB.prototype.hasTX = function hasTX(hash, callback) { - var self = this; - var id = 't/t/' + hash; - - this.db.get(id, function(err, data) { - if (err && err.type !== 'NotFoundError') - return callback(err); - - if (!data) - return callback(null, false); - - return callback(null, true); - }); -}; - -ChainDB.prototype.isSpent = function isSpent(hash, index, callback) { - return this.hasCoin(hash, index, function(err, result) { - if (err) - return callback(err); - - return callback(null, !result); - }); -}; - ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) { var self = this; var futureHeight; - if (self.options.spv) + if (this.options.spv) return callback(); - if (!self.prune) + if (!this.prune) return callback(); // Keep the genesis block if (block.isGenesis()) return callback(); - futureHeight = pad32(block.height + self.keepBlocks); + futureHeight = pad32(block.height + this.keepBlocks); batch.put('b/q/' + futureHeight, block.hash()); @@ -1361,13 +1297,13 @@ ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) { }); }); - self._pruneQueue(block, batch, callback); + this._pruneQueue(block, batch, callback); }; ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) { var self = this; var key = 'b/q/' + pad32(block.height); - self.db.get(key, function(err, hash) { + this.db.get(key, function(err, hash) { if (err && err.type !== 'NotFoundError') return callback(err); @@ -1404,7 +1340,7 @@ ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) { ChainDB.prototype._pruneCoinQueue = function _pruneQueue(block, batch, callback) { var self = this; - var iter = self.db.db.iterator({ + var iter = this.db.db.iterator({ gte: 'u/q/' + pad32(block.height), lte: 'u/q/' + pad32(block.height) + '~', keys: true,