celo-org / celo-blockchain

Official repository for the golang Celo Blockchain
https://celo.org
GNU Lesser General Public License v3.0
554 stars 199 forks source link

Get epoch rewards for a block from node. #2255

Closed shaswatsaloni closed 6 months ago

shaswatsaloni commented 6 months ago

Hi Team,

I have a rosetta as well as archival Celo Node. There i am getting the normal transactions with the query:

{ "method": "eth_getBlockByNumber", "params": [ "0x556E00", //blocknumber true ], "id": 1, "jsonrpc": "2.0" }

But here the epoch transactions are not present, by which i want to have the voting rewards.

But if i want to query the rosetta or archival node for this epoch transactions/rewards, how would i get that?

@eelanagaraj could you please help us here.

Thanks, Saloni

carterqw2 commented 6 months ago

Hey @shaswatsaloni, could you please check out this repo for an explainer on how epoch transactions work and how to fetch them.

shaswatsaloni commented 6 months ago

Hey @carterqw2 , that repo was really helpful, thanks.

One more query here, i want to get the epoch rewards for the address : 0x9efecf85d7e668c0c3c7a778a1164b064234f96d

So, here i can see it has epoch transactions in block: [5598720]

the explorer link : https://explorer.celo.org/mainnet/address/0x9efeCf85d7E668c0C3c7a778A1164b064234f96d/epoch-transactions

image

When i am calling the POST method for this particular block:

{ "method": "eth_getLogs", "params": [ { "fromBlock": "0x556E00", "toBlock": "0x556E00" } ], "id": 1, "jsonrpc": "2.0" }

I am not able to find the particular address (0x9efecf85d7e668c0c3c7a778a1164b064234f96d) in the response JSON.

how would i calculate and get the epoch rewards here?

Thanks, Saloni

carterqw2 commented 6 months ago

Hi @shaswatsaloni! You're trying to get individual voter rewards, please refer to this section of the explainer for more details. Celo Explorer has to perform additional calculations to be able to display individual voter rewards that are not directly available through logs. I hope that helps.

shaswatsaloni commented 6 months ago

Okay, understood.

So, there is no simple way that we an fetch epoch transactions/ voting rewards for a celo address.

And, is there any way we can get the epoch transactions for an address instead of a block.

Thanks, Saloni

carterqw2 commented 6 months ago

We provide an RPC API in Celo Explorer, if that works for you (search for getvoterrewards).

https://explorer.celo.org/mainnet/api?module=epoch&action=getvoterrewards&voterAddress=0x9efecf85d7e668c0c3c7a778a1164b064234f96d

curl -X GET "https://explorer.celo.org/mainnet/api?module=epoch&action=getvoterrewards&voterAddress=0x9efecf85d7e668c0c3c7a778a1164b064234f96d" -H "accept: application/json"
shaswatsaloni commented 6 months ago

Yes, this i have. I just wanted to query my node if its at all possible?

carterqw2 commented 6 months ago

Yeah, unfortunately, there is no easy way, you'd have to fetch epoch blocks and perform calculations described in the explainer manually.