From a467b4e4757c6975d8570740d2f08c9ed38250b7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 29 Sep 2016 15:18:43 -0700 Subject: [PATCH] refactor: misc. --- lib/chain/chaindb.js | 6 +----- lib/net/peer.js | 5 ++--- lib/net/pool.js | 2 +- lib/wallet/walletdb.js | 11 +++++------ 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/chain/chaindb.js b/lib/chain/chaindb.js index 46583747..6e8954cf 100644 --- a/lib/chain/chaindb.js +++ b/lib/chain/chaindb.js @@ -148,7 +148,6 @@ if (utils.isBrowser) * @param {String?} options.location - Database location * @param {String?} options.db - Database backend name * @property {Boolean} prune - * @property {Boolean} loaded * @property {Number} keepBlocks * @emits ChainDB#open * @emits ChainDB#error @@ -181,8 +180,6 @@ function ChainDB(chain) { this.pending = null; this.current = null; - this.loaded = false; - // We want at least 1 retarget interval cached // for retargetting, but we need at least two // cached for optimal versionbits state checks. @@ -1368,12 +1365,11 @@ ChainDB.prototype.getFullTX = co(function* getFullTX(hash) { ChainDB.prototype.getFullBlock = co(function* getFullBlock(hash) { var block = yield this.getBlock(hash); - var view; if (!block) return; - view = yield this.getUndoView(block); + yield this.getUndoView(block); return block; }); diff --git a/lib/net/peer.js b/lib/net/peer.js index 8d9ecec1..ef03fc9c 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -366,7 +366,7 @@ Peer.prototype._bip150 = co(function* _bip150() { if (this.bip150.outbound) { if (!this.bip150.peerIdentity) - return this.error('No known identity for peer.'); + throw new Error('No known identity for peer.'); this.send(this.bip150.toChallenge()); } @@ -2315,9 +2315,8 @@ Peer.prototype.sendReject = function sendReject(code, reason, obj) { */ Peer.prototype.sendCompact = function sendCompact() { - var cmpct = new packets.SendCmpctPacket(0, 1); this.logger.info('Initializing compact blocks (%s).', this.hostname); - this.send(cmpct); + this.send(new packets.SendCmpctPacket(0, 1)); }; /** diff --git a/lib/net/pool.js b/lib/net/pool.js index ed77a425..ae6c6cab 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -2496,7 +2496,7 @@ BroadcastItem.prototype.start = function start() { BroadcastItem.prototype.refresh = function refresh() { var self = this; - if (this.timeout) { + if (this.timeout != null) { clearTimeout(this.timeout); this.timeout = null; } diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 6896d0ae..0193eaa8 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -1025,9 +1025,8 @@ WalletDB.prototype.getPendingKeys = function getPendingKeys() { */ WalletDB.prototype.resend = co(function* resend() { - var i, keys, key, data, tx; - - keys = yield this.getPendingKeys(); + var keys = yield this.getPendingKeys(); + var i, key, data, tx; if (keys.length > 0) this.logger.info('Rebroadcasting %d transactions.', keys.length); @@ -1094,7 +1093,7 @@ WalletDB.prototype.getPathInfo = co(function* getPathInfo(wallet, tx) { WalletDB.prototype.getTable = co(function* getTable(hashes) { var table = {}; - var count = 0; + var match = false; var i, j, keys, values, hash, paths; for (i = 0; i < hashes.length; i++) { @@ -1115,10 +1114,10 @@ WalletDB.prototype.getTable = co(function* getTable(hashes) { assert(!table[hash]); table[hash] = values; - count += values.length; + match = true; } - if (count === 0) + if (!match) return; return table;