bitcoind: emit block events while polling before subscribing to zmq events
This commit is contained in:
parent
b092adcc21
commit
458fe2f2b6
@ -443,6 +443,7 @@ Bitcoin.prototype._checkSyncedAndSubscribeZmqEvents = function(node) {
|
|||||||
return callback(self._wrapRPCError(err));
|
return callback(self._wrapRPCError(err));
|
||||||
}
|
}
|
||||||
var blockhash = new Buffer(response.result, 'hex');
|
var blockhash = new Buffer(response.result, 'hex');
|
||||||
|
self.emit('block', blockhash);
|
||||||
self._updateTip(node, blockhash);
|
self._updateTip(node, blockhash);
|
||||||
|
|
||||||
// check if synced
|
// check if synced
|
||||||
|
|||||||
@ -681,6 +681,10 @@ describe('Bitcoin Service', function() {
|
|||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
bitcoind._updateTip = sinon.stub();
|
bitcoind._updateTip = sinon.stub();
|
||||||
bitcoind._subscribeZmqEvents = sinon.stub();
|
bitcoind._subscribeZmqEvents = sinon.stub();
|
||||||
|
var blockEvents = 0;
|
||||||
|
bitcoind.on('block', function() {
|
||||||
|
blockEvents++;
|
||||||
|
});
|
||||||
var getBestBlockHash = sinon.stub().callsArgWith(0, null, {
|
var getBestBlockHash = sinon.stub().callsArgWith(0, null, {
|
||||||
result: '00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45'
|
result: '00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45'
|
||||||
});
|
});
|
||||||
@ -712,6 +716,7 @@ describe('Bitcoin Service', function() {
|
|||||||
bitcoind._checkSyncedAndSubscribeZmqEvents(node);
|
bitcoind._checkSyncedAndSubscribeZmqEvents(node);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
log.error.callCount.should.equal(2);
|
log.error.callCount.should.equal(2);
|
||||||
|
blockEvents.should.equal(10);
|
||||||
bitcoind._updateTip.callCount.should.equal(10);
|
bitcoind._updateTip.callCount.should.equal(10);
|
||||||
bitcoind._subscribeZmqEvents.callCount.should.equal(1);
|
bitcoind._subscribeZmqEvents.callCount.should.equal(1);
|
||||||
done();
|
done();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user