pool/peer: fixes. cleanup.

This commit is contained in:
Christopher Jeffrey 2017-01-21 13:03:53 -08:00
parent 58f8035add
commit be4145e163
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 19 additions and 19 deletions

View File

@ -1581,17 +1581,10 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) {
if (this.onPacket) if (this.onPacket)
yield this.onPacket(packet); yield this.onPacket(packet);
if (entry)
entry.resolve(packet);
this.emit('packet', packet); this.emit('packet', packet);
if (packet.type === packetTypes.UNKNOWN) { if (entry)
this.emit('unknown', packet); entry.resolve(packet);
return;
}
this.emit(packet.cmd, packet);
}); });
/** /**

View File

@ -161,6 +161,10 @@ Pool.prototype._init = function _init() {
self.emit('listening', data); self.emit('listening', data);
}); });
this.chain.on('block', function(block, entry) {
self.emit('block', block, entry);
});
this.chain.on('reset', function() { this.chain.on('reset', function() {
self.resetChain(); self.resetChain();
self.forceSync(); self.forceSync();
@ -172,6 +176,12 @@ Pool.prototype._init = function _init() {
self.logger.info('Chain is fully synced (height=%d).', self.chain.height); 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.options.selfish && !this.options.spv) {
if (this.mempool) { if (this.mempool) {
this.mempool.on('tx', function(tx) { this.mempool.on('tx', function(tx) {
@ -1058,13 +1068,6 @@ Pool.prototype.handlePacket = co(function* handlePacket(peer, packet) {
} }
this.emit('packet', packet, peer); 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; return;
} }
if (!this.mempool) if (!this.mempool) {
this.emit('tx', tx);
return; return;
}
try { try {
missing = yield this.mempool.addTX(tx); missing = yield this.mempool.addTX(tx);
@ -2104,6 +2109,8 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) {
this.getTX(peer, missing); this.getTX(peer, missing);
} }
this.emit('tx', tx);
}); });
/** /**

View File

@ -135,11 +135,11 @@ SPVNode.prototype._init = function _init() {
if (this.http) if (this.http)
this.http.on('error', onError); this.http.on('error', onError);
this.pool.on('tx', function(packet) { this.pool.on('tx', function(tx) {
if (self.rescanJob) if (self.rescanJob)
return; return;
self.emit('tx', packet.tx); self.emit('tx', tx);
}); });
this.chain.on('block', function(block) { this.chain.on('block', function(block) {