-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (60 loc) · 1.97 KB
/
index.js
File metadata and controls
73 lines (60 loc) · 1.97 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const argv = require('yargs').argv;
const log = require('loglevel');
const db = require('./src/database/Database.js');
const BlockchainQueries = require('./src/database/queries/BlockchainQueries.js');
const Web3Client = require('./src/classes/Web3Client.js');
const CacheMonitor = require('./src/monitor/CacheMonitor.js');
let pool = db.getPool();
pool.connect((err, client, release) => {
if (err) {
log.error('Error acquiring client', err.stack);
process.exit(1);
}
client.query(BlockchainQueries.getBlockchainsAndNodes(), (err, result) => {
release();
if (err) {
log.error('Error executing query', err.stack);
process.exit(1);
}
if (!result || !result.rowCount) {
log.error('No blockchain nodes found in database.');
process.exit();
}
// Get all of the endpoint nodes for this blockchain
let nodeSetups = {};
for (let row of result.rows) {
if (!nodeSetups.hasOwnProperty(row.blockchain_id)) {
nodeSetups[row.blockchain_id] = [];
}
if (row.hasOwnProperty('skip') && row.skip === true) {
console.log(`Skipping ${row.endpoint}`)
continue;
}
nodeSetups[row.blockchain_id].push(row.endpoint);
}
for (let blockchain_id in nodeSetups) {
// Create a new monitor instance
let client = new Web3Client({
"endpoints" : nodeSetups[blockchain_id]
});
// Allow the user to set overrides
let startBlockOverride = argv.hasOwnProperty('start') && parseInt(argv.start, 10);
let endBlockOverride = argv.hasOwnProperty('end') && parseInt(argv.end, 10);
let rewriteBlocks = argv.hasOwnProperty('rewriteBlocks');
if (rewriteBlocks) {
log.info("Will be force-rewriting all blocks encountered.");
}
// Start the monitor
let cm = new CacheMonitor({
blockchain_id : blockchain_id,
client,
startBlockOverride,
endBlockOverride,
rewriteBlocks
});
cm.start();
log.debug(`Spun up client monitor for blockchain ID: ${blockchain_id}`);
}
log.debug("Started client monitors.");
});
});