-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
31 lines (25 loc) · 999 Bytes
/
index.js
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
const axios = require("axios");
const URL = "http://xrn-us-west-1.regen.network:26657/status";
const UPDATE_BLOCK = 1722050;
const BLOCK_INTERVAL = 5660; // in milliseconds
async function getBlockInfo(url) {
const response = await axios.get(url);
const sync = response.data.result.sync_info;
return {
height: parseInt(sync.latest_block_height),
time: Date.parse(sync.latest_block_time)
}
}
async function estimateUpgradeTime(url, updateBlock, blockInterval) {
const {height, time} = await getBlockInfo(url);
if (updateBlock <= height) {
throw new Error("Upgrade already active");
}
const msLeft = (updateBlock - height) * blockInterval;
const upgrade = new Date();
upgrade.setTime(time + msLeft);
return upgrade;
}
estimateUpgradeTime(URL, UPDATE_BLOCK, BLOCK_INTERVAL).
then(x => console.log(`Upgrade at block ${UPDATE_BLOCK} will occur approximately ${x.toUTCString()}`)).
catch(err => console.log(`Error: ${err}`))