packet events.
This commit is contained in:
parent
bbc18ee764
commit
7977247b79
@ -113,8 +113,8 @@ bitcoind.on('open', function(status) {
|
||||
});
|
||||
}
|
||||
|
||||
bitcoind.on('packets', function(packets) {
|
||||
bitcoind.log(packets);
|
||||
bitcoind.on('packet:parsed', function(packet) {
|
||||
bitcoind.log(packet);
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
@ -144,7 +144,7 @@ Bitcoin.prototype.start = function(options, callback) {
|
||||
|
||||
if (!packets) {
|
||||
if (self.debug) {
|
||||
bitcoind.error('Error polling packet queue.');
|
||||
self.error('Error polling packet queue.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -153,63 +153,46 @@ Bitcoin.prototype.start = function(options, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.emit('packets', packets);
|
||||
self.emit('_packets', packets);
|
||||
|
||||
packets.forEach(function(packet) {
|
||||
setImmediate(function() {
|
||||
self.emit('packet:' + packet.name, packet);
|
||||
self.emit('packet', packet);
|
||||
if (packet.name === 'version') {
|
||||
self.emit(packet.name, packet);
|
||||
self.emit('peer', packet);
|
||||
} else if (packet.name === 'verack') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'addr') {
|
||||
self.emit('raw:' + packet.name, packet);
|
||||
self.emit('raw', packet);
|
||||
|
||||
if (packet.name === 'addr') {
|
||||
self.emit(packet.name, packet.addresses);
|
||||
} else if (packet.name === 'inv') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'getdata') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'getblocks') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'getheaders') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'tx') {
|
||||
if (!packet.tx.blockhash) {
|
||||
packet.name = 'mptx';
|
||||
}
|
||||
self.emit(packet.name, bitcoind.tx(packet.tx));
|
||||
} else if (packet.name === 'block') {
|
||||
var block = bitcoind.block(packet.block);
|
||||
self.emit('parsed', packet.addresses);
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.name === 'block') {
|
||||
var block = self.block(packet.block);
|
||||
self.emit(packet.name, block);
|
||||
self.emit('parsed', block);
|
||||
block.tx.forEach(function(tx) {
|
||||
setImmediate(function() {
|
||||
tx = self.tx(tx);
|
||||
self.emit('tx', tx);
|
||||
self.emit('parsed', tx);
|
||||
});
|
||||
});
|
||||
} else if (packet.name === 'getaddr') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'mempool') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'ping') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'pong') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'alert') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'filterload') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'filteradd') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'filterclear') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'reject') {
|
||||
self.emit(packet.name, packet);
|
||||
} else if (packet.name === 'unknown') {
|
||||
self.emit(packet.name, packet);
|
||||
return;
|
||||
}
|
||||
self.emit('parsed', packet.addresses || packet.block || packet.tx);
|
||||
|
||||
if (packet.name === 'tx') {
|
||||
var tx = self.tx(packet.tx);
|
||||
var name = packet.name;
|
||||
if (!packet.tx.blockhash) {
|
||||
name = 'mptx';
|
||||
}
|
||||
self.emit(name, tx);
|
||||
self.emit('parsed', tx);
|
||||
return;
|
||||
}
|
||||
|
||||
self.emit(packet.name, packet);
|
||||
self.emit('parsed', packet);
|
||||
});
|
||||
});
|
||||
}, 50);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user