cleanup chaindb.
This commit is contained in:
parent
39265bfb6b
commit
b88fc5b0ed
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user