@@ -11,14 +11,15 @@ import (
1111)
1212
1313// NewParams returns Params instance with the given values.
14- func NewParams (mintDenom string , inflationRateChange , inflationMax , inflationMin , goalBonded math.LegacyDec , blocksPerYear uint64 ) Params {
14+ func NewParams (mintDenom string , inflationRateChange , inflationMax , inflationMin , goalBonded math.LegacyDec , blocksPerYear uint64 , maxSupply math. Int ) Params {
1515 return Params {
1616 MintDenom : mintDenom ,
1717 InflationRateChange : inflationRateChange ,
1818 InflationMax : inflationMax ,
1919 InflationMin : inflationMin ,
2020 GoalBonded : goalBonded ,
2121 BlocksPerYear : blocksPerYear ,
22+ MaxSupply : maxSupply ,
2223 }
2324}
2425
@@ -31,6 +32,7 @@ func DefaultParams() Params {
3132 InflationMin : math .LegacyNewDecWithPrec (7 , 2 ),
3233 GoalBonded : math .LegacyNewDecWithPrec (67 , 2 ),
3334 BlocksPerYear : uint64 (60 * 60 * 8766 / 5 ), // assuming 5 second block times
35+ MaxSupply : math .ZeroInt (), // assuming zero is infinite
3436 }
3537}
3638
@@ -54,6 +56,9 @@ func (p Params) Validate() error {
5456 if err := validateBlocksPerYear (p .BlocksPerYear ); err != nil {
5557 return err
5658 }
59+ if err := validateMaxSupply (p .MaxSupply ); err != nil {
60+ return err
61+ }
5762 if p .InflationMax .LT (p .InflationMin ) {
5863 return fmt .Errorf (
5964 "max inflation (%s) must be greater than or equal to min inflation (%s)" ,
@@ -168,3 +173,16 @@ func validateBlocksPerYear(i interface{}) error {
168173
169174 return nil
170175}
176+
177+ func validateMaxSupply (i interface {}) error {
178+ v , ok := i .(math.Int )
179+ if ! ok {
180+ return fmt .Errorf ("invalid parameter type: %T" , i )
181+ }
182+
183+ if v .IsNegative () {
184+ return fmt .Errorf ("max supply must be positive: %d" , v )
185+ }
186+
187+ return nil
188+ }
0 commit comments