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.on('packet:parsed', function(packet) {
|
||||||
bitcoind.log(packets);
|
bitcoind.log(packet);
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -144,7 +144,7 @@ Bitcoin.prototype.start = function(options, callback) {
|
|||||||
|
|
||||||
if (!packets) {
|
if (!packets) {
|
||||||
if (self.debug) {
|
if (self.debug) {
|
||||||
bitcoind.error('Error polling packet queue.');
|
self.error('Error polling packet queue.');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -153,63 +153,46 @@ Bitcoin.prototype.start = function(options, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.emit('packets', packets);
|
self.emit('_packets', packets);
|
||||||
|
|
||||||
packets.forEach(function(packet) {
|
packets.forEach(function(packet) {
|
||||||
setImmediate(function() {
|
setImmediate(function() {
|
||||||
self.emit('packet:' + packet.name, packet);
|
self.emit('raw:' + packet.name, packet);
|
||||||
self.emit('packet', packet);
|
self.emit('raw', packet);
|
||||||
if (packet.name === 'version') {
|
|
||||||
self.emit(packet.name, packet);
|
if (packet.name === 'addr') {
|
||||||
self.emit('peer', packet);
|
|
||||||
} else if (packet.name === 'verack') {
|
|
||||||
self.emit(packet.name, packet);
|
|
||||||
} else if (packet.name === 'addr') {
|
|
||||||
self.emit(packet.name, packet.addresses);
|
self.emit(packet.name, packet.addresses);
|
||||||
} else if (packet.name === 'inv') {
|
self.emit('parsed', packet.addresses);
|
||||||
self.emit(packet.name, packet);
|
return;
|
||||||
} else if (packet.name === 'getdata') {
|
}
|
||||||
self.emit(packet.name, packet);
|
|
||||||
} else if (packet.name === 'getblocks') {
|
if (packet.name === 'block') {
|
||||||
self.emit(packet.name, packet);
|
var block = self.block(packet.block);
|
||||||
} 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(packet.name, block);
|
self.emit(packet.name, block);
|
||||||
|
self.emit('parsed', block);
|
||||||
block.tx.forEach(function(tx) {
|
block.tx.forEach(function(tx) {
|
||||||
setImmediate(function() {
|
setImmediate(function() {
|
||||||
|
tx = self.tx(tx);
|
||||||
self.emit('tx', tx);
|
self.emit('tx', tx);
|
||||||
self.emit('parsed', tx);
|
self.emit('parsed', tx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (packet.name === 'getaddr') {
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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);
|
}, 50);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user