Snippets to get the downvoting power of an user for dsteem and steem-js
development·@howo·
0.000 HBDSnippets to get the downvoting power of an user for dsteem and steem-js

Hello,
If you are unfamiliar with steemsnippets I encourage you to read the genesis post : https://steemit.com/programming/@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 !
@howo👍 liucixin, steemexpress, fredrikaa, cryptouno, redes, mangos, ilyasismail, howo, jacekw.dev, boosta, drakos, pcourtnier, acidyo, kevinwong, ikibaru-san, realgoodcontent, kreesher, tombstone, mrwang, arconite, nurhayati, nerengot, kuri12, the.circle, lemouth, jonmagnusson, ammar0344, omstavan, zcool, funcounts, katesmith, openledgerio, icmarkets, alexs1320, jamzed, coolguy123, saqibnazir, milarose, corsica, michaelizer, rosepac, drsensor, jiva34, aminealaoui, manimanitour, arcange, laissez-faire, pele23, netuoso, smartsteem, raphaelle, cpufronz, waleedtee, spreadfire1, kgakakillerg, indextrader24, eagle2, tactive, bewarecenterbase, aotearoa, steamsteem, coininstant, honusurf, kdtkaren, firealiean, imisstheoldkanye, trafalgar, raindrop, traf, inzouikroft, firealien,