eos离线签名获取ref_block_prefix和ref_block_num最简单方式

只需要请求/v1/chain/get_info

从eos源代码得知head_block_id是由ref_block_prefix和ref_block_num经过hash拼接而成

请求 https://mainnet-eos…/v1/chain/get_info

返回

    {
    	server_version: "b312faa4",
    	chain_id: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
    	head_block_num: 65476388,
    	last_irreversible_block_num: 65476059,
    	last_irreversible_block_id: "03e715db8e46880c00ce7a03725380dc085736361ede1a72b44c53ed333aedf0",
    	head_block_id: "03e71724eff1698cf8b381ae8f97964536f147e1e83205ca67cade1bc8ce53b0",
    	head_block_time: "2019-06-26T05:36:20.000",
    	head_block_producer: "atticlabeosb",
    	virtual_block_cpu_limit: 200000000,
    	virtual_block_net_limit: 1048576000,
    	block_cpu_limit: 43827,
    	block_net_limit: 1040264,
    	server_version_string: "mainnet-1.5.1-dirty"
    }

解析head_block_id

       AsciiToHex((u8 *) head_block_id.substr(0, 8).c_str(), block_num, 8);
        AsciiToHex((u8 *) head_block_id.substr(16, 24).c_str(), block_prefix, 8);
    
        ref_block_num = ((block_num[0] & 0xFF) << 24) |
                        ((block_num[1] & 0xFF) << 16) |
                        ((block_num[2] & 0xFF) << 8) |
                        ((block_num[3] & 0xFF) << 0);
    
        ref_block_prefix =
                (u32((block_prefix[0] & 0xFF))) |
                (u32((block_prefix[1] & 0xFF) << 8)) |
                (u32((block_prefix[2] & 0xFF) << 16)) |
                (u32((block_prefix[3] & 0xFF) << 24));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值