-
Notifications
You must be signed in to change notification settings - Fork 8
/
voting_power.js
39 lines (30 loc) · 1.32 KB
/
voting_power.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
var steem = require('steem');
steem.api.setOptions({url: 'https://api.steemit.com'});
/**
* Gets the voting power of an account. code mostly by @asgarth
* @param {String} account - account of whom we want to check the steem power
* @param {String} callback - callback which will have the voting power as parameter
*/
function getvotingpower(account_name, callback) {
return new Promise(resolve => {
steem.api.getAccounts([account_name], function (err, account) {
account = account[0];
const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares) - parseFloat(account.vesting_withdraw_rate);
const elapsed = Math.floor(Date.now() / 1000) - account.voting_manabar.last_update_time;
const maxMana = totalShares * 1000000;
// 432000 sec = 5 days
let currentMana = parseFloat(account.voting_manabar.current_mana) + elapsed * maxMana / 432000;
if (currentMana > maxMana) {
currentMana = maxMana;
}
const currentManaPerc = currentMana * 100 / maxMana;
return resolve(currentManaPerc);
});
});
}
async function example()
{
const vp = await getvotingpower("howo");
console.log(vp);
}
example();