2

SUBJ. I have geth private network with custom reward progression and looking for a way to calculate circulating supply.

closed as unclear what you're asking by goodvibration, flygoing, Achala Dissanayake, shane, niksmac May 17 at 14:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

You would have to go through the block number ranges in which you expect the reward to change, and their respective block rewards in order to calculate the circulating supply.

Here is a golang example, supposing you have an ordered slice consisting in the last block number of each range and its respective block reward, you could do something like this:

package main

import (
    "fmt"
    "math/big"
)

type BlockRange struct {
    lastBlockNumber *big.Int
    reward          *big.Int
}

func main() {

    blockRanges := []BlockRange{
        BlockRange{
            lastBlockNumber: big.NewInt(500),
            reward:          big.NewInt(2e+18),
        },
        BlockRange{
            lastBlockNumber: big.NewInt(1000),
            reward:          big.NewInt(1e+18),
        },
        BlockRange{
            lastBlockNumber: big.NewInt(1500),
            reward:          big.NewInt(5e+17),
        },
    }

    currentBlockNumber := big.NewInt(1357)
    circulatingSupply := big.NewInt(0)

    for i, blockRange := range blockRanges {

        lastBlockNumber := blockRange.lastBlockNumber
        addReward := big.NewInt(0)
        multiplier := big.NewInt(0)

        if i == 0 {
            multiplier = lastBlockNumber
        } else if currentBlockNumber.Cmp(lastBlockNumber) >= 0 {
            multiplier.Sub(lastBlockNumber, blockRanges[i-1].lastBlockNumber)
        } else {
            multiplier.Sub(lastBlockNumber, currentBlockNumber)
        }

        addReward.Mul(multiplier, blockRange.reward)
        circulatingSupply.Add(circulatingSupply, addReward)
    }

    fmt.Println("Circulating supply: ", circulatingSupply)
}

Modify the BlockReward slice initialization with your private network values.

Try this example in the Go Playground

  • 1
    You would have to take into consideration uncle blocks they have a small reward and modify the block's reward. – Ismael May 12 at 3:40
  • Thanks. Figured it a while ago. Made a python script that calculates all rewards including uncles. – Alexandr May 24 at 10:14

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