Created
May 11, 2019 15:32
-
-
Save CodeFuentes/34046c69245c662b798e15df2801f0a0 to your computer and use it in GitHub Desktop.
Example: Calculate circulating supply for geth private network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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