chaindb: minor.
This commit is contained in:
parent
5f43c429a9
commit
911e4f541e
@ -210,8 +210,6 @@ var layout = {
|
|||||||
* data, only entries.
|
* data, only entries.
|
||||||
* @param {Number?} [options.keepBlocks=288] - Number of
|
* @param {Number?} [options.keepBlocks=288] - Number of
|
||||||
* blocks to keep when pruning.
|
* blocks to keep when pruning.
|
||||||
* @param {Boolean?} options.paranoid - Perform some paranoid checks
|
|
||||||
* against hashes. Will throw if corruption is detected.
|
|
||||||
* @param {String?} options.name - Database name
|
* @param {String?} options.name - Database name
|
||||||
* @param {String?} options.location - Database location
|
* @param {String?} options.location - Database location
|
||||||
* @param {String?} options.db - Database backend name
|
* @param {String?} options.db - Database backend name
|
||||||
@ -892,7 +890,7 @@ ChainDB.prototype.removeBlock = function removeBlock(hash, batch, callback) {
|
|||||||
|
|
||||||
ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callback) {
|
ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callback) {
|
||||||
var undo = new BufferWriter();
|
var undo = new BufferWriter();
|
||||||
var i, j, tx, input, output, prev, addresses, address, hash, coins, raw;
|
var i, j, tx, input, output, prev, hashes, address, hash, coins, raw;
|
||||||
|
|
||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
return utils.asyncify(callback)(null, block);
|
return utils.asyncify(callback)(null, block);
|
||||||
@ -908,9 +906,9 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
|
|||||||
if (this.options.indexTX) {
|
if (this.options.indexTX) {
|
||||||
batch.put(layout.t(hash), tx.toExtended());
|
batch.put(layout.t(hash), tx.toExtended());
|
||||||
if (this.options.indexAddress) {
|
if (this.options.indexAddress) {
|
||||||
addresses = tx.getHashes();
|
hashes = tx.getHashes();
|
||||||
for (j = 0; j < addresses.length; j++) {
|
for (j = 0; j < hashes.length; j++) {
|
||||||
address = addresses[j];
|
address = hashes[j];
|
||||||
batch.put(layout.T(address, hash), DUMMY);
|
batch.put(layout.T(address, hash), DUMMY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -982,7 +980,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
|
|||||||
|
|
||||||
ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callback) {
|
ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var i, j, tx, input, output, prev, addresses, address, hash, coins, raw;
|
var i, j, tx, input, output, prev, hashes, address, hash, coins, raw;
|
||||||
|
|
||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
return utils.asyncify(callback)(null, block);
|
return utils.asyncify(callback)(null, block);
|
||||||
@ -998,9 +996,9 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callb
|
|||||||
if (self.options.indexTX) {
|
if (self.options.indexTX) {
|
||||||
batch.del(layout.t(hash));
|
batch.del(layout.t(hash));
|
||||||
if (self.options.indexAddress) {
|
if (self.options.indexAddress) {
|
||||||
addresses = tx.getHashes();
|
hashes = tx.getHashes();
|
||||||
for (j = 0; j < addresses.length; j++) {
|
for (j = 0; j < hashes.length; j++) {
|
||||||
address = addresses[j];
|
address = hashes[j];
|
||||||
batch.del(layout.T(address, hash));
|
batch.del(layout.T(address, hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1281,15 +1279,7 @@ ChainDB.prototype.getTX = function getTX(hash, callback) {
|
|||||||
|
|
||||||
this.db.fetch(layout.t(hash), function(data) {
|
this.db.fetch(layout.t(hash), function(data) {
|
||||||
return bcoin.tx.fromExtended(data);
|
return bcoin.tx.fromExtended(data);
|
||||||
}, function(err, tx) {
|
}, callback);
|
||||||
if (err)
|
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
if (self.options.paranoid)
|
|
||||||
assert(tx.hash('hex') === hash, 'Database is corrupt.');
|
|
||||||
|
|
||||||
return callback(null, tx);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1318,14 +1308,14 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, call
|
|||||||
addresses = [addresses];
|
addresses = [addresses];
|
||||||
|
|
||||||
utils.forEachSerial(addresses, function(address, next) {
|
utils.forEachSerial(addresses, function(address, next) {
|
||||||
address = bcoin.address.getHash(address);
|
var hash = bcoin.address.getHash(address);
|
||||||
|
|
||||||
if (!address)
|
if (!hash)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self.db.iterate({
|
self.db.iterate({
|
||||||
gte: layout.C(address, constants.ZERO_HASH, 0),
|
gte: layout.C(hash, constants.ZERO_HASH, 0),
|
||||||
lte: layout.C(address, constants.MAX_HASH, 0xffffffff),
|
lte: layout.C(hash, constants.MAX_HASH, 0xffffffff),
|
||||||
transform: layout.Cc
|
transform: layout.Cc
|
||||||
}, function(err, keys) {
|
}, function(err, keys) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -1382,14 +1372,14 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
|
|||||||
addresses = [addresses];
|
addresses = [addresses];
|
||||||
|
|
||||||
utils.forEachSerial(addresses, function(address, next) {
|
utils.forEachSerial(addresses, function(address, next) {
|
||||||
address = bcoin.address.getHash(address);
|
var hash = bcoin.address.getHash(address);
|
||||||
|
|
||||||
if (!address)
|
if (!hash)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self.db.lookup({
|
self.db.lookup({
|
||||||
gte: layout.T(address, constants.ZERO_HASH),
|
gte: layout.T(hash, constants.ZERO_HASH),
|
||||||
lte: layout.T(address, constants.MAX_HASH),
|
lte: layout.T(hash, constants.MAX_HASH),
|
||||||
transform: function(key) {
|
transform: function(key) {
|
||||||
var hash = layout.Tt(key);
|
var hash = layout.Tt(key);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user