From be4145e1632c18bd6b0834706d8c34e845f0a318 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 21 Jan 2017 13:03:53 -0800 Subject: [PATCH] pool/peer: fixes. cleanup. --- lib/net/peer.js | 11 ++--------- lib/net/pool.js | 23 +++++++++++++++-------- lib/node/spvnode.js | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/net/peer.js b/lib/net/peer.js index 23d2fdd0..d0db2287 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -1581,17 +1581,10 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) { if (this.onPacket) yield this.onPacket(packet); - if (entry) - entry.resolve(packet); - this.emit('packet', packet); - if (packet.type === packetTypes.UNKNOWN) { - this.emit('unknown', packet); - return; - } - - this.emit(packet.cmd, packet); + if (entry) + entry.resolve(packet); }); /** diff --git a/lib/net/pool.js b/lib/net/pool.js index 589e71e2..f0c1f131 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -161,6 +161,10 @@ Pool.prototype._init = function _init() { self.emit('listening', data); }); + this.chain.on('block', function(block, entry) { + self.emit('block', block, entry); + }); + this.chain.on('reset', function() { self.resetChain(); self.forceSync(); @@ -172,6 +176,12 @@ Pool.prototype._init = function _init() { self.logger.info('Chain is fully synced (height=%d).', self.chain.height); }); + if (this.mempool) { + this.mempool.on('tx', function(tx) { + self.emit('tx', tx); + }); + } + if (!this.options.selfish && !this.options.spv) { if (this.mempool) { this.mempool.on('tx', function(tx) { @@ -1058,13 +1068,6 @@ Pool.prototype.handlePacket = co(function* handlePacket(peer, packet) { } this.emit('packet', packet, peer); - - if (packet.type === packetTypes.UNKNOWN) { - this.emit('unknown', packet, peer); - return; - } - - this.emit(packet.cmd, packet, peer); }); /** @@ -2083,8 +2086,10 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) { return; } - if (!this.mempool) + if (!this.mempool) { + this.emit('tx', tx); return; + } try { missing = yield this.mempool.addTX(tx); @@ -2104,6 +2109,8 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) { this.getTX(peer, missing); } + + this.emit('tx', tx); }); /** diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index f66a4e45..a896ad13 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -135,11 +135,11 @@ SPVNode.prototype._init = function _init() { if (this.http) this.http.on('error', onError); - this.pool.on('tx', function(packet) { + this.pool.on('tx', function(tx) { if (self.rescanJob) return; - self.emit('tx', packet.tx); + self.emit('tx', tx); }); this.chain.on('block', function(block) {