chaindb: minor.

This commit is contained in:
Christopher Jeffrey 2016-08-17 13:16:16 -07:00
parent 5f43c429a9
commit 911e4f541e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -210,8 +210,6 @@ var layout = {
* data, only entries.
* @param {Number?} [options.keepBlocks=288] - Number of
* 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.location - Database location
* @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) {
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)
return utils.asyncify(callback)(null, block);
@ -908,9 +906,9 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
if (this.options.indexTX) {
batch.put(layout.t(hash), tx.toExtended());
if (this.options.indexAddress) {
addresses = tx.getHashes();
for (j = 0; j < addresses.length; j++) {
address = addresses[j];
hashes = tx.getHashes();
for (j = 0; j < hashes.length; j++) {
address = hashes[j];
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) {
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)
return utils.asyncify(callback)(null, block);
@ -998,9 +996,9 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callb
if (self.options.indexTX) {
batch.del(layout.t(hash));
if (self.options.indexAddress) {
addresses = tx.getHashes();
for (j = 0; j < addresses.length; j++) {
address = addresses[j];
hashes = tx.getHashes();
for (j = 0; j < hashes.length; j++) {
address = hashes[j];
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) {
return bcoin.tx.fromExtended(data);
}, function(err, tx) {
if (err)
return callback(err);
if (self.options.paranoid)
assert(tx.hash('hex') === hash, 'Database is corrupt.');
return callback(null, tx);
});
}, callback);
};
/**
@ -1318,14 +1308,14 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, call
addresses = [addresses];
utils.forEachSerial(addresses, function(address, next) {
address = bcoin.address.getHash(address);
var hash = bcoin.address.getHash(address);
if (!address)
if (!hash)
return next();
self.db.iterate({
gte: layout.C(address, constants.ZERO_HASH, 0),
lte: layout.C(address, constants.MAX_HASH, 0xffffffff),
gte: layout.C(hash, constants.ZERO_HASH, 0),
lte: layout.C(hash, constants.MAX_HASH, 0xffffffff),
transform: layout.Cc
}, function(err, keys) {
if (err)
@ -1382,14 +1372,14 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
addresses = [addresses];
utils.forEachSerial(addresses, function(address, next) {
address = bcoin.address.getHash(address);
var hash = bcoin.address.getHash(address);
if (!address)
if (!hash)
return next();
self.db.lookup({
gte: layout.T(address, constants.ZERO_HASH),
lte: layout.T(address, constants.MAX_HASH),
gte: layout.T(hash, constants.ZERO_HASH),
lte: layout.T(hash, constants.MAX_HASH),
transform: function(key) {
var hash = layout.Tt(key);