From 06d6d74081697d6ee1f152c9feeadd6cf0b13661 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 19 Feb 2016 22:10:38 -0800 Subject: [PATCH] more renaming. --- lib/bcoin/pool.js | 85 +++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 416435e2..4bd6e032 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -233,8 +233,8 @@ Pool.prototype._init = function _init() { self.loadOrphan(self.peers.load, null, data.hash); }); - this.options.wallets.forEach(function(w) { - self.addWallet(w); + this.options.wallets.forEach(function(wallet) { + self.addWallet(wallet); }); // Chain is full and up-to-date @@ -1186,18 +1186,18 @@ Pool.prototype.isWatched = function(tx, bloom) { return false; }; -Pool.prototype.addWallet = function addWallet(w) { +Pool.prototype.addWallet = function addWallet(wallet) { var self = this; var e; if (this.loading) - return this.once('load', this.addWallet.bind(this, w)); + return this.once('load', this.addWallet.bind(this, wallet)); - if (this.wallets.indexOf(w) !== -1) + if (this.wallets.indexOf(wallet) !== -1) return false; - this.watchWallet(w); - this.wallets.push(w); + this.watchWallet(wallet); + this.wallets.push(wallet); e = new EventEmitter(); @@ -1205,7 +1205,7 @@ Pool.prototype.addWallet = function addWallet(w) { // Relay pending TXs // NOTE: It is important to do it after search, because search could // add TS to pending TXs, thus making them confirmed - w.pending().forEach(function(tx) { + wallet.pending().forEach(function(tx) { self.sendTX(tx); }); @@ -1223,21 +1223,21 @@ Pool.prototype.addWallet = function addWallet(w) { }); } - if (w.loading) - w.once('load', search); + if (wallet.loading) + wallet.once('load', search); else search(); return e; }; -Pool.prototype.removeWallet = function removeWallet(w) { - var i = this.wallets.indexOf(w); +Pool.prototype.removeWallet = function removeWallet(wallet) { + var i = this.wallets.indexOf(wallet); assert(!this.loading); if (i == -1) return; this.wallets.splice(i, 1); - this.unwatchWallet(w); + this.unwatchWallet(wallet); }; Pool.prototype.watchAddress = function watchAddress(address) { @@ -1268,66 +1268,64 @@ Pool.prototype.unwatchAddress = function unwatchAddress(address) { this.unwatch(address.getPublicKey()); }; -Pool.prototype.watchWallet = function watchWallet(w) { +Pool.prototype.watchWallet = function watchWallet(wallet) { var self = this; - w.addresses.forEach(function(address) { + wallet.addresses.forEach(function(address) { this.watchAddress(address); }, this); - w.on('add address', w._poolOnAdd = function(address) { + wallet.on('add address', wallet._poolOnAdd = function(address) { self.watchAddress(address); }); - w.on('remove address', w._poolOnRemove = function(address) { + wallet.on('remove address', wallet._poolOnRemove = function(address) { self.unwatchAddress(address); }); }; -Pool.prototype.unwatchWallet = function unwatchWallet(w) { - w.addresses.forEach(function(address) { +Pool.prototype.unwatchWallet = function unwatchWallet(wallet) { + wallet.addresses.forEach(function(address) { this.unwatchAddress(address); }, this); - w.removeListener('add address', w._poolOnAdd); - w.removeListener('remove address', w._poolOnRemove); - delete w._poolOnAdd; - delete w._poolOnRemove; + wallet.removeListener('add address', wallet._poolOnAdd); + wallet.removeListener('remove address', wallet._poolOnRemove); + delete wallet._poolOnAdd; + delete wallet._poolOnRemove; }; -Pool.prototype.searchWallet = function(w, h) { +Pool.prototype.searchWallet = function(ts, height) { var self = this; - var ts, height; + var wallet; assert(!this.loading); if (!this.options.spv) return; - if (w == null) { - height = this.wallets.reduce(function(height, w) { - if (w.lastHeight < height) - return w.lastHeight; + if (ts == null) { + height = this.wallets.reduce(function(height, wallet) { + if (wallet.lastHeight < height) + return wallet.lastHeight; return height; }, Infinity); assert(height !== Infinity); - ts = this.wallets.reduce(function(ts, w) { - if (w.lastTs < ts) - return w.lastTs; + ts = this.wallets.reduce(function(ts, wallet) { + if (wallet.lastTs < ts) + return wallet.lastTs; return ts; }, Infinity); assert(ts !== Infinity); - } else if (typeof w === 'number') { - ts = w; - height = h; - } else { - if (w.loading) { - w.once('load', function() { - self.searchWallet(w); + } else if (typeof ts !== 'number') { + wallet = ts; + if (wallet.loading) { + wallet.once('load', function() { + self.searchWallet(wallet); }); return; } - ts = w.lastTs; - height = w.lastHeight; + ts = wallet.lastTs; + height = wallet.lastHeight; } // Always prefer height @@ -1342,8 +1340,9 @@ Pool.prototype.searchWallet = function(w, h) { utils.debug('Wallet height: %s', height); utils.debug( - 'Reverted chain to height=%d', - self.chain.height + 'Reverted chain to height=%d (%s)', + self.chain.height, + new Date(self.chain.tip.ts * 1000) ); });