---
# System prepended metadata

title: Untitled

---

#### What do we need, to calculate the rewards of a voter of luganodes which are generated in a single epoch (a single round)

1. Votes counted at the end of last round.
2. Votes of the total 127 candidates counted at the end of last round.
3. Total number of blocks generated in the epoch and total number of blocks generated by luganodes in that epoch. 
4. even ranking of luganodes


### How to get the requirements ?

1. Votes

- We can use the API endpoint:`https://api.trongrid.io/wallet/listwitnesses`, to fetch the votes staked on all the witness at the end of previous round.
- We can try to access the database and get the votes. 
- THERE IS NO ENDPOINT THAT GIVES THE VOTES OF A WITNESS WITH RESPECT TO A GIVEN TIME. 

2. Votes of 127 Candidates 

- We can find this if we get 1


3.Blocks generated
- We can use the API `https://api.trongrid.io/wallet/getblockbylimitnext?startNum=42660544&endNum=4266055` to parse the blocks and find the number of the blocks. 

4. Ranking
- if we know 1, we can find this one too.


## My Approaches (After stopping the node on date when luganodes became a witness node)

1. Try to access the db and populate the vote composition staked on all the witnesses and then parse the block chain with this initial state data.

2. A script that does the following:

    1.Fetch the votes of all the witness by using the api at the time when node stopped and save it to db. 
    2.then start an infinite loop
    3. In that loop, we will start the node to sync the data up until a specific timestamp - this would be the timestamp when the current epoch ends. 
    4.Constantly we will be checking if the timestamp reached or not - use setInterval for every 10 mins. 
    5. Once we know that node has reached and stopped the sync process. We will stop the node completely, and configure it to keep its API active without syncing with the blockchain.
    6. Now we will query the API endpoint `/wallet/listwitnesses` to get the votes of the last round and save it.
    7.  Now we will have the votes data that is required after the end of each epoch. 


    1. Now we will start a parser that will start parsing block from the same inital date and keeps counting the blocks
    2. At the end of every epoch, it will fetch the state data of the lugandoes saved by the previous process and then uses the block counts and CALCULATES THE REWARDS for each voter of luganodes for that round and saves it in the database.

    ##### We can include both the processes in a single program and achieve the same output. and it is reliable because we are not dealing with the calculation of the votes. 


- I think these are the only two ways because: 

### REASON:
- We don't have any APIs for querying historical data.
- We cannot get the vote composition for a specific time.
- The rewards API provides the reward of an account as whole, doesn't give the amount of reward provided by the delegators/SRs
- And even the support team of TRON told that for historical data we need to parse the block chain ourselves. 
- Even if we start processing the blocks from the day luganodes started, we won't be able to get the votes of top 127 candidates, ranking of luganodes.



