[steemmonsters] 내 계정들의 잔여 RC 정보 확인하기

avatar

서두

  • 개인적으로 기록 보관 목적으로 글을 남겨 봅니다.
  • 소스는 필요한 부분이 있다면 마음것 사용하셔도 됩니다.

개요

RC를 손쉽게 확인하기 위해 만들어 봤습니다. 예전에는 스몬팀에서 계정당 20SP를 무상으로 임대해 줬으나, 이제 모두 회수해 갔네요 ㅜㅜ 그래서 부캐들이 자동 대전 중 정지되는 상황이 발생 되어 어떤 계정이 RC를 어느정도 보유하고 있는지 한눈에 볼 수 있도록 제작해 봤습니다. ( 덤으로 보팅파워 계산기 까지 만들어 봄 )

처리 로직

  1. API 호출
  2. 시간 흐름에 따른 추가분 연산 (마지막 엑션 시점 정보를 가지고 있기 때문)
  3. 조회 정보 정제 이후 반환처리

소스코드

RC(Resource Credit) 계산

// 해당 계정의 RC 정보를 반환한다
const get_rc = async (authors) =>{
    
    const __MILLISEC = 1000;
    const __CHARGE_PER_SEC = 60 * 60 * 24 * 5;  // 432000, 1초당 충전되는 수치, *5는 하루 20% 1/5을 의미함

    const __parse = (r) =>{
        let curr_mana = parseInt(r.rc_manabar.current_mana);
        let max_mana = parseInt(r.max_rc);
        let per_sec = parseFloat(max_mana / __CHARGE_PER_SEC) ; // 1초당 차오르는 마나, * 5 는 하루 20% 1/5 을 의미함
        let prev_tm = parseInt(r.rc_manabar.last_update_time);
        let now_tm = parseInt(new Date().getTime()/ __MILLISEC);
        let gap = parseInt(now_tm - prev_tm);
        let mod_mana = Math.min(parseInt(per_sec*gap)+parseInt(curr_mana),max_mana);

        return {
            mana : {
                curr : curr_mana,
                max : max_mana,
                mod : mod_mana,
            },
            sec : { // 시간 전환시 x 1000
                last : prev_tm,
                now : now_tm,
                gap : gap
            },
            rate : parseFloat((mod_mana/max_mana).toFixed(4)),
            account : r.account
        };
    }

    if(authors && !Array.isArray(authors)){
        authors = [authors];
    }
    return wrpc.send_rpc('rc_api.find_rc_accounts',{"accounts": authors})
        .then(res=>res.rc_accounts.map(r=>__parse(r)));
}

보팅파워 계산

// 해당 계정의 보팅 파워를 계산해 준다
const get_vp = async (authors)=>{

    const __MAX_VOTING_POWER = 10000;
    const __CHARGE_PER_SEC = 60 * 60 * 24 * 5;  // 432000, 1초당 충전되는 수치, *5는 하루 20% 1/5을 의미함

    const __parse = (r) => {
        let account = r.name;
        let last = r.voting_power; //최근 투표일 기준 보팅파워 , 10000 is max
        let gap = new Date().getTime() - new Date(r.last_vote_time + "Z").getTime();    // 최종 보팅한 이후 흐른 시간, 초
        let vp = Math.min(__MAX_VOTING_POWER, parseInt(last +  ( gap / __CHARGE_PER_SEC ) * __MAX_VOTING_POWER));   // 시간차를 적용한 현재 보팅파워 10000 is max

        return {account, last, gap, vp};
    }

    if(authors && !Array.isArray(authors)){
        authors = [authors];
    }

    return wrpc.send_rpc('condenser_api.get_accounts',[authors])
        .then(res=>res.map(r=>__parse(r)));
}


0
0
0.000
33 comments
avatar

Thank you for your continued support towards JJM. For each 1000 JJM you are holding, you can get an additional 1% of upvote. 10,000JJM would give you a 11% daily voting from the 700K SP virus707 account.

0
0
0.000
avatar

Congratulations @wonsama! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got more than 2250 replies. Your next target is to reach 2500 replies.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
0
0
0.000