-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.js
72 lines (65 loc) · 2.14 KB
/
scanner.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
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
const rp = require('request-promise');
var JSONbig = require('json-bigint');
const config = {
url: "http://localhost:26680/",
defaultUrl: "http://45.125.197.45:46658",
firstBlock: 1,
lastBlock: 100,
frequency: 1,
}
const maxYearlyDistributedReward = 60000000
async function getDelegationTotal(block) {
var options = {
method: 'GET',
uri: config.url + '/dpos_state?height=' + block,
};
try {
const res = await rp(options);
const data = JSONbig.parse(res);
if (data.error != undefined) {
console.log(data.error)
return 0
}
let rawDelegationTotal = data.result.total_validator_delegations.Value.toString(10);
console.log(rawDelegationTotal)
return Number(rawDelegationTotal.substring(0, rawDelegationTotal.length - 18))
} catch (err) {
console.log(err)
return 0
}
}
async function getBlockTime(block) {
var options = {
method: 'GET',
uri: config.defaultUrl + '/rpc/block?height=' + block,
};
try {
const res = await rp(options);
const data = JSONbig.parse(res);
if (data.error != undefined) {
console.log(data.error)
return 0
}
return data.result.block_meta.header.time;
} catch (err) {
console.log(err)
return 0
}
}
(async function () {
try {
for (var i = config.firstBlock; i < config.lastBlock; i = i + config.frequency) {
const totalDelegation = await getDelegationTotal(i)
const blockTime = await getBlockTime(i)
const yearlyDistributedRewards = (totalDelegation * 0.05)
let percentage = 100
if (yearlyDistributedRewards > maxYearlyDistributedReward) {
percentage = maxYearlyDistributedReward * 100 / yearlyDistributedRewards
}
const lostRewards = ((yearlyDistributedRewards - maxYearlyDistributedReward) / 365) / 48
console.log("block (" + i + ")", blockTime, percentage + "%", yearlyDistributedRewards, lostRewards, )
}
} catch (err) {
console.log(err)
}
})();