Skip to content

Instantly share code, notes, and snippets.

@CodeFuentes
Created May 11, 2019 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeFuentes/34046c69245c662b798e15df2801f0a0 to your computer and use it in GitHub Desktop.
Save CodeFuentes/34046c69245c662b798e15df2801f0a0 to your computer and use it in GitHub Desktop.
Example: Calculate circulating supply for geth private network
/**
* Go playground: https://play.golang.org/p/DaCCAm2KGZ6
*/
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment