计算RC比例

in hive-180932 •  4 years ago 

没找到计算RC的方法,所以经过研究写了一个查询实时RC比例的代码

steemjs不支持查RC,所以只能用dsteem查

通过rc_api返回的RC数据并不是实时的,所以还需要通过计算算出实时的RC数值

和VP的计算方法一样,RC 五天恢复100%,所以每秒的恢复速度是1/(52460*60)=1/432000

rc_api返回的数据有最后更新RC的时间,计算最后更新时间和现在时间差就可以算出这之间RC需要恢复多少

具体代码如下:

const dsteem = require('dsteem');
let client = new dsteem.Client("https://api.steemit.com");

calculateRc('xiaoyuanwmm');


async function calculateRc(steemid) {
    let accountRc = await getRC(steemid);
    let secondsago = Math.round(Number((new Date()).getTime() / 1000) - Number(accountRc.rc_accounts[0].rc_manabar.last_update_time));
    let rcPercent = Math.min(accountRc.rc_accounts[0].rc_manabar.current_mana / accountRc.rc_accounts[0].max_rc * 100 + (100 * secondsago / 432000), 100).toFixed(2);
    console.log(rcPercent);

}


async function getRC(username) {
    return client.call('rc_api', 'find_rc_accounts', {
        accounts: [username]
    });
}


结果:

85.55%

和steemd的数据一样

image.png

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!