-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaccount_monitor.js
More file actions
39 lines (33 loc) · 1.13 KB
/
account_monitor.js
File metadata and controls
39 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function BlockchainAccountMonitor(options) {
this.lastBlockHash = options.lastBlockHash;
this.blockchainClient = options.blockchainClient;
this.timeout = options.timeout || 2000;
this.onBlock = options.onBlock;
this.onError = options.onError || function(error) {
console.log('BlockchainAccountMonitor::Error', error);
}
}
BlockchainAccountMonitor.prototype = {
_getNextBlockWithTransactions: function getNextBlockWithTransactions() {
var _this = this;
_this.blockchainClient.listNextBlock(_this.lastBlockHash, function(error, block) {
if (error) {
_this.onError(error);
return setTimeout(_this._getNextBlockWithTransactions.bind(_this), _this.timeout);
}
if (!block) {
return setTimeout(_this._getNextBlockWithTransactions.bind(_this), _this.timeout);
} else {
return _this.onBlock(block, function() {
_this.lastBlockHash = block[0].blockhash;
_this._getNextBlockWithTransactions();
});
}
});
},
start: function() {
var _this = this;
_this._getNextBlockWithTransactions();
}
}
module.exports = BlockchainAccountMonitor;