walletdb: fixes and lint.

This commit is contained in:
Christopher Jeffrey 2016-08-15 04:54:46 -07:00
parent 5519ecdfec
commit e503b7ecad
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 37 additions and 15 deletions

View File

@ -1126,10 +1126,13 @@ ChainDB.prototype.scan = function scan(start, filter, iter, callback) {
var total = 0;
var i, j, hashes, address, tx, txs;
if (!start)
if (start == null)
start = this.network.genesis.hash;
this.logger.info('Scanning from block %s.', utils.revHex(start));
if (typeof start === 'number')
this.logger.info('Scanning from height %d.', start);
else
this.logger.info('Scanning from block %s.', utils.revHex(start));
if (Array.isArray(filter))
filter = utils.toMap(filter);
@ -1160,7 +1163,7 @@ ChainDB.prototype.scan = function scan(start, filter, iter, callback) {
return next();
self.logger.info('Scanning block %s (%d).',
utils.revHex(hash),
utils.revHex(entry.hash),
block.height);
txs = [];
@ -1179,12 +1182,12 @@ ChainDB.prototype.scan = function scan(start, filter, iter, callback) {
}
if (txs.length === 0)
return self.getNextHash(hash, next);
return self.getNextHash(entry.hash, next);
iter(entry, txs, function(err) {
if (err)
return next(err);
self.getNextHash(hash, next);
self.getNextHash(entry.hash, next);
});
});
});

View File

@ -1024,7 +1024,7 @@ HTTPServer.prototype._initIO = function _initIO() {
if (typeof callback !== 'function')
return socket.destroy();
if (typeof start !== 'string')
if (typeof start !== 'string' && !utils.isNumber(start))
return callback({ error: 'Invalid parameter.' });
try {
@ -1351,7 +1351,8 @@ ClientSocket.prototype.scan = function scan(start, callback) {
var self = this;
var i;
start = utils.revHex(start);
if (typeof start === 'string')
start = utils.revHex(start);
this.chain.db.scan(start, this.filter, function(entry, txs, next) {
for (i = 0; i < txs.length; i++)

View File

@ -1796,10 +1796,20 @@ Pool.prototype.getLoaderHost = function getLoaderHost() {
return this.seeds[0];
host = this.getRandom(this.seeds);
if (host)
return host;
return this.getRandom(this.hosts);
host = this.getRandom(this.hosts);
if (host)
return host;
this.logger.warning('All seeds banned or ignored. Clearing...');
this.peers.ignored = {};
this.peers.misbehaving = {};
return this.getRandom(this.seeds);
};
/**
@ -1815,6 +1825,7 @@ Pool.prototype.getHost = function getHost() {
return;
host = this.getRandom(this.seeds, true);
if (host)
return host;

View File

@ -140,6 +140,11 @@ WalletDB.prototype._open = function open(callback) {
return callback(err);
self.depth = depth;
self.logger.info(
'WalletDB loaded (depth=%d, height=%d).',
depth, self.height);
self.loadFilter(callback);
});
});
@ -176,7 +181,7 @@ WalletDB.prototype._close = function close(callback) {
*/
WalletDB.prototype.getDepth = function getDepth(callback) {
var opt, iter, parts, depth;
var iter, parts, depth;
// This may seem like a strange way to do
// this, but updating a global state when
@ -365,6 +370,7 @@ WalletDB.prototype.unregister = function unregister(wallet) {
*/
WalletDB.prototype.getWalletID = function getWalletID(id, callback) {
var self = this;
var wid;
if (!id)
@ -1172,6 +1178,7 @@ WalletDB.prototype.setTip = function setTip(hash, height, callback) {
*/
WalletDB.prototype.writeBlock = function writeBlock(block, matches, callback) {
var self = this;
var batch = this.db.batch();
var i, hash, wallets;
@ -1205,6 +1212,7 @@ WalletDB.prototype.writeBlock = function writeBlock(block, matches, callback) {
*/
WalletDB.prototype.unwriteBlock = function unwriteBlock(block, callback) {
var self = this;
var batch = this.db.batch();
var prev = new WalletBlock(block.prevBlock, block.height - 1);
@ -1252,7 +1260,7 @@ WalletDB.prototype.getWalletsByTX = function getWalletsByTX(hash, callback) {
WalletDB.prototype.addBlock = function addBlock(entry, txs, callback, force) {
var self = this;
var i, block, matches, hash, unlock;
var block, matches, hash, unlock;
unlock = this.txLock.lock(addBlock, [entry, txs, callback], force);
@ -1548,8 +1556,6 @@ Path.prototype.toPath = function() {
Path.prototype.toJSON = function toJSON() {
return {
wid: this.wid,
id: this.id,
name: this.name,
change: this.change === 1,
path: this.toPath()
@ -1834,9 +1840,9 @@ WalletBlock.prototype.fromEntry = function fromEntry(entry) {
WalletBlock.prototype.fromJSON = function fromJSON(json) {
this.hash = utils.revHex(json.hash);
this.height = entry.height;
if (entry.prevBlock)
this.prevBlock = utils.revHex(entry.prevBlock);
this.height = json.height;
if (json.prevBlock)
this.prevBlock = utils.revHex(json.prevBlock);
return this;
};
@ -1850,6 +1856,7 @@ WalletBlock.prototype.fromRaw = function fromRaw(hash, data) {
};
WalletBlock.prototype.fromTip = function fromTip(data) {
var p = new BufferReader(data);
this.hash = p.readHash('hex');
this.height = p.readU32();
return this;