验证节点获取排名

获取当前主机运行节点排名信息shell脚本:

#!/bin/bash
###################################################
#Judge判断节点是否参与排名
#get_ranking根据节点的顺序获取排名
#质押合约账户: 0x1000000000000000000000000000000000000002
###################################################
flag=no
rank=0

#获取本节点的ID
nodeid=`platon attach http://localhost:6789 -exec 'admin.nodeInfo.id'|grep -o '\w*'`

#调用6789端口获取全网排名数据
data=`curl -s  -X POST -H "content-type:application/json" -d '{"jsonrpc": "2.0","method": "platon_call", \
    "params": [{"from": "lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzsjx8h7","to": "lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzsjx8h7", \
        "data": "0xc48382044e"},"latest"],"id": 0}' localhost:6789`
hexvalue=`echo $data |grep -o '\w\{10,\}' |cut -c3- |sed 's/\(..\)/\\\\x\1/g'`

#获取所有共识节点的ID
nodelist=`echo -e  $hexvalue |grep -o '\w\{128,\}' |sed -n '1~2p'`

#判断节点是否参数共识
function Judge(){
    for i in ${nodelist[@]}
    do
        if [[ $nodeid == $i ]];then
            flag=yes
        fi
    done
}

#获取排名
function get_ranking(){
    if [ $flag == "yes" ];then
        rank=1
        for j in ${nodelist[@]}
        do
            if [ $j != $nodeid ];then
                ((rank++))
            else
                echo $rank
                break;
            fi
        done
    else
        echo $(($rank+1))
    fi
}
Judge
get_ranking

以上脚本中的两个地址:
"params": [{"from": "lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzsjx8h7","to": "lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzsjx8h7"
from 的地址是发送交易地址[可选],可为任意有效地址
to 的地址是事务指向的地址,填为质押合约地址
(Platon主网的质押合约地址为lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzsjx8h7,
Alaya主网的质押合约地址为atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzfyslg3)
两者地址可一致

1 个赞

学习了!crontab 马上安排

1 个赞