-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.js
More file actions
58 lines (46 loc) · 1.63 KB
/
metadata.js
File metadata and controls
58 lines (46 loc) · 1.63 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
const argv = require('yargs').argv;
const log = require('loglevel');
const Web3Client = require('./src/classes/Web3Client.js');
const Database = require('./src/database/Database.js');
const BlockchainQueries = require('./src/database/queries/BlockchainQueries.js');
const ContractController = require('./src/controller/ContractController.js');
const LIMIT = 50;
Database.connect(async (Client) => {
// Kick it off
Client.query(BlockchainQueries.getBlockchainsAndNodes(), (result) => {
// Kill the client
Client.release();
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] = [];
}
nodeSetups[row.blockchain_id].push(row.endpoint);
}
for (let blockchain_id in nodeSetups) {
// Create a new monitor instance
const evmClient = new Web3Client({
"endpoints" : nodeSetups[blockchain_id]
});
// Now do the whole thing
const cc = new ContractController(evmClient);
cc.iterateMetadataUpdates(LIMIT, callback);
function callback(numUpdated) {
if (numUpdated > 0) {
console.log("More metadata to update:", numUpdated);
cc.iterateMetadataUpdates(LIMIT, callback);
} else {
console.log("No metadata to update, waiting...");
setTimeout(cc.iterateMetadataUpdates.bind(cc, LIMIT, callback), 5000);
}
}
log.debug(`Spun up metadata monitor for blockchain ID: ${blockchain_id}`);
}
log.debug("Started metadata monitors.");
});
});