The Python Function to Retrieve the Producer Reward for Witness

  • 时间:2020-09-07 13:13:13
  • 分类:网络文摘
  • 阅读:152 次

As you know, the witness is rewarded for produce a block. The TOP 20 gets to produce the blocks more frequently than the backup witnesses, but the reward for each block is different: currently 484 VESTS for TOP 20 while around 2425 VESTS for others on the steem blockchain.

How do we get the reward given a block number? Unfortunately, it is not through the `get_block` api. Instead, we need to use `get_ops_in_block` which is provided by `account_plugin_history`

1
curl -s --data '{"jsonrpc":"2.0", "method":"condenser_api.get_ops_in_block", "params":[43880000,true], "id":1}' https://api.steemit.com
curl -s --data '{"jsonrpc":"2.0", "method":"condenser_api.get_ops_in_block", "params":[43880000,true], "id":1}' https://api.steemit.com

This returns like:

{"jsonrpc":"2.0","result":[{"trx_id":"0000000000000000000000000000000000000000","block":43880000,"trx_in_block":4294967295,"op_in_trx":0,"virtual_op":1,"timestamp":"2020-
06-01T17:49:18","op":["producer_reward",{"producer":"hinomaru-jp","vesting_shares":"481.663694 VESTS"}]}],"id":1}

Then, we can wrap it up in a Python function (please note that we need to scan the transactions array and look for the `producer_reward` ops.

1
2
3
4
5
6
7
8
def getReward(block):
  data={"jsonrpc":"2.0", "method":"condenser_api.get_ops_in_block", "params":[block, True], "id":1}
  result = requests.post(url="https://api.steemit.com", json = data)
  jsonData = result.json()
  for tx in jsonData:
    if tx['op'][0] == 'producer_reward':
      return tx['op'][1]['vesting_shares']
  return None
def getReward(block):
  data={"jsonrpc":"2.0", "method":"condenser_api.get_ops_in_block", "params":[block, True], "id":1}
  result = requests.post(url="https://api.steemit.com", json = data)
  jsonData = result.json()
  for tx in jsonData:
    if tx['op'][0] == 'producer_reward':
      return tx['op'][1]['vesting_shares']
  return None

–EOF (The Ultimate Computing & Technology Blog) —

推荐阅读:
2016年国务院关于修改部分行政法规的决定  居住证暂行条例(国务院令第663号)   国务院关于修改《建设工程勘察设计管理条例》的决定(国务院令第662号)   国务院关于修改《中国公民往来台湾地区管理办法》的决定(国务院令第661号)   存款保险条例(国务院令第660号)   博物馆条例(国务院令第659号)   侵害消费者权益行为处罚办法(工商总局令第73号)  先别想着做什么网站赚钱了 先做好网站建设吧  个人网站站长应了解的基础知识  作为个人站长,何不入驻今日头条 
评论列表
添加评论