bitcoind: emit block events
This commit is contained in:
parent
d0937fea55
commit
52f05f3027
|
@ -70,6 +70,7 @@ Bitcoin.prototype._initCaches = function() {
|
|||
this.rawBlockCache = LRU(72);
|
||||
this.blockHeaderCache = LRU(288);
|
||||
this.zmqKnownTransactions = LRU(50);
|
||||
this.zmqKnownBlocks = LRU(50);
|
||||
this.zmqLastBlock = 0;
|
||||
this.zmqUpdateTipTimeout = false;
|
||||
};
|
||||
|
@ -322,7 +323,7 @@ Bitcoin.prototype._zmqBlockHandler = function(node, message) {
|
|||
}
|
||||
}
|
||||
|
||||
// Prevent a rapid succession of updates
|
||||
// Prevent a rapid succession of tip updates
|
||||
if (new Date() - self.zmqLastBlock > 1000) {
|
||||
self.zmqLastBlock = new Date();
|
||||
updateChain();
|
||||
|
@ -334,8 +335,15 @@ Bitcoin.prototype._zmqBlockHandler = function(node, message) {
|
|||
}
|
||||
|
||||
// Notify block subscribers
|
||||
for (var i = 0; i < this.subscriptions.block.length; i++) {
|
||||
this.subscriptions.block[i].emit('bitcoind/block', message.toString('hex'));
|
||||
var id = message.toString('binary');
|
||||
if (!self.zmqKnownBlocks[id]) {
|
||||
self.zmqKnownBlocks[id] = true;
|
||||
self.emit('block', message);
|
||||
|
||||
for (var i = 0; i < this.subscriptions.block.length; i++) {
|
||||
this.subscriptions.block[i].emit('bitcoind/block', message.toString('hex'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue