2

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

| improve this 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

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

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