Accounts on Steem Blockchain have daily “Free” Downvote Power – which has 20% of the upvoting Mana. We can use the following Javascript/NodeJs function to calculate the downvote power.
We can access the “last” seen downvote mana and the timestamp in the getAccounts API – then we need to calculate the mana restored since the timestamp.
And by using async/await, you can await getting the downvote power in a function that is marked async.
function getDownvotePower(id) {
return new Promise((resolve, reject) => {
steem.api.getAccounts([id], function(err, response) {
if (err) reject(err);
const current_mana = response[0].voting_manabar.current_mana;
const downvote_mana = response[0].downvote_manabar.current_mana;
const downvote_last_update_time = response[0].downvote_manabar.last_update_time;
const downvote_per = downvote_mana / (current_mana / (response[0].voting_power / 100) / 4);
const secondsago = (new Date - new Date(downvote_last_update_time * 1000)) / 1000;
let vpow = downvote_per * 100 + (10000 * secondsago / 432000);
resolve(Math.min(vpow / 100, 100).toFixed(2));
});
});
}
// Sample Usage
(async function() {
const val = await getDownvotePower('justyy');
log(val);
})();
Run the code at SteemJS Editor.
See the JS function to compute the upvote power/mana: Compute the Account Voting Power (Mana) for Accounts on Steem Blockchain using Javascript/NodeJs Function
–EOF (The Ultimate Computing & Technology Blog) —
516 wordsLast Post: Teaching Kids Programming - Breadth First Search Algorithm to Compute Average of Levels in Binary Tree
Next Post: Teaching Kids Programming - Average Level of Binary Tree via Depth First Search Algorithm
