bitcoind: emit block events

This commit is contained in:
Braydon Fuller 2016-04-11 10:15:20 -04:00
parent d0937fea55
commit 52f05f3027
1 changed files with 11 additions and 3 deletions

View File

@ -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'));
}
}
};