4

As a baker I want to calculate the rewards to pay the addresses delegating to me (delegatees).

For this, I need the effective contribution from my delegatees, to my baking/endorsing rights in a specified cycle.

How do I get this information from the Tezos Node RPC API?

3

First you have to find out which snapshot was used for cycle X. Use (cycle# * blocksPerCycle + 1) to get the hash of the first block of that cycle. Then you can query:

"/chains/main/blocks/"+blockHash+"/context/raw/json/cycle/"+cycle#

This gets you information about the snapshots for this cycle. From this info, grab the RollSnapShot value. This tells you which of the several snapshots taken during this cycle was used for calculations.

Calculate the block hash for that snapshot: ((cycle - PreservedCycles - 2) * BlocksPerCycle) + (RollSnapShot + 1) * 256

Now that you have that hash, you can get bakers staking balance: "/chains/main/blocks/"+hash+"/context/delegates/"+bakerAddr+"/staking_balance"

And each delegate's balance: "/chains/main/blocks/"hash+"/context/raw/json/contracts/index/"+delegateKT1+ "/frozen_balance/"+cycle+"/"

If you are familiar with Go, check out this library: https://github.com/DefinitelyNotAGoat/go-tezos

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.