Hello,
If you are unfamiliar with steemsnippets I encourage you to read the genesis post : @howo/introducting-steemsnippets
And to check out the repository : https://github.com/drov0/steemsnippets
Since hard fork 21 is out, I see a ton of downvotes, which is great, and I suppose that you will grow tired of manually downvoting, so here's a few snippets to allow you to calculate the remaining downvoting power of an user.
the logic is similar in dsteem and steem-js so I'll only post the dsteem version on the chain :
function get_downvoting_power(username) {
return new Promise(async resolve => {
let account = await client.database.getAccounts([username]);
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.downvote_manabar.last_update_time;
const maxMana = totalShares * 1000000 / 4;
// 432000 sec = 5 days
let currentMana = parseFloat(account.downvote_manabar.current_mana) + elapsed * maxMana / 432000;
if (currentMana > maxMana) {
currentMana = maxMana;
}
const currentManaPerc = currentMana * 100 / maxMana;
return resolve(currentManaPerc);
});
}
// example
async function test()
{
console.log(await get_downvoting_power("howo"));
}
test();
If you'd rather read them with colors here are the github links :
dsteem :
https://github.com/drov0/steemsnippets/tree/master/dsteem/get_downvoting_power
steem-js :
https://github.com/drov0/steemsnippets/tree/master/steemjs/downvoting_power
That's it for today :)
newsteem on !