SUBJ. I have geth private network with custom reward progression and looking for a way to calculate circulating supply.
1 Answer
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