bitcoind: emit block events

This commit is contained in:
Braydon Fuller 2016-04-11 10:15:20 -04:00
parent d0937fea55
commit 52f05f3027

View File

@ -70,6 +70,7 @@ Bitcoin.prototype._initCaches = function() {
this.rawBlockCache = LRU(72); this.rawBlockCache = LRU(72);
this.blockHeaderCache = LRU(288); this.blockHeaderCache = LRU(288);
this.zmqKnownTransactions = LRU(50); this.zmqKnownTransactions = LRU(50);
this.zmqKnownBlocks = LRU(50);
this.zmqLastBlock = 0; this.zmqLastBlock = 0;
this.zmqUpdateTipTimeout = false; 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) { if (new Date() - self.zmqLastBlock > 1000) {
self.zmqLastBlock = new Date(); self.zmqLastBlock = new Date();
updateChain(); updateChain();
@ -334,8 +335,15 @@ Bitcoin.prototype._zmqBlockHandler = function(node, message) {
} }
// Notify block subscribers // Notify block subscribers
for (var i = 0; i < this.subscriptions.block.length; i++) { var id = message.toString('binary');
this.subscriptions.block[i].emit('bitcoind/block', message.toString('hex')); 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'));
}
} }
}; };