From 458fe2f2b6262e5f001996646b0e27a60f80811d Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Tue, 19 Apr 2016 16:53:00 -0400 Subject: [PATCH] bitcoind: emit block events while polling before subscribing to zmq events --- lib/services/bitcoind.js | 1 + test/services/bitcoind.unit.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 7cba2e03..570bab42 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -443,6 +443,7 @@ Bitcoin.prototype._checkSyncedAndSubscribeZmqEvents = function(node) { return callback(self._wrapRPCError(err)); } var blockhash = new Buffer(response.result, 'hex'); + self.emit('block', blockhash); self._updateTip(node, blockhash); // check if synced diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 7a2ab905..d0ee746a 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -681,6 +681,10 @@ describe('Bitcoin Service', function() { var bitcoind = new BitcoinService(baseConfig); bitcoind._updateTip = sinon.stub(); bitcoind._subscribeZmqEvents = sinon.stub(); + var blockEvents = 0; + bitcoind.on('block', function() { + blockEvents++; + }); var getBestBlockHash = sinon.stub().callsArgWith(0, null, { result: '00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45' }); @@ -712,6 +716,7 @@ describe('Bitcoin Service', function() { bitcoind._checkSyncedAndSubscribeZmqEvents(node); setTimeout(function() { log.error.callCount.should.equal(2); + blockEvents.should.equal(10); bitcoind._updateTip.callCount.should.equal(10); bitcoind._subscribeZmqEvents.callCount.should.equal(1); done();