Previously, we learn how to use Javascript/NodeJs function to compute the real downvote mana/power for accounts on steem blockchain via the steem.api.getAccounts API. Today, we are going to compute the upvote mana/power instead.
Computing the upvote mana/power for accounts on Steem Blockchain is a bit easier than the downvote power. We still need to apply the restored mana since users’ last upvoting activity.
function getUpvotePower(id) {
return new Promise((resolve, reject) => {
steem.api.getAccounts([id], function(err, response) {
if (err) reject(err);
const secondsago = (new Date - new Date(response[0].last_vote_time + "Z")) / 1000;
let vpow = response[0].voting_power + (10000 * secondsago / 432000);
resolve(Math.min(vpow / 100, 100).toFixed(2));
});
});
}
(async function() {
const val = await getUpvotePower('justyy');
log(val);
})();
Run this code on Steem JS Editor.
Similarly, the function returns a promise so that you can use await in an async function.
To compute the downvote power/mana: Javascript (NodeJS) Function to Get the Downvote Power of Account on Steem Blockchain
–EOF (The Ultimate Computing & Technology Blog) —
415 wordsLast Post: Teaching Kids Programming - Average Level of Binary Tree via Depth First Search Algorithm
Next Post: Teaching Kids Programming - Using Hash Set to Find Out Almost Same Strings
