-
Notifications
You must be signed in to change notification settings - Fork 127
/
genesis.go
54 lines (42 loc) · 993 Bytes
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package types
import (
"fmt"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewGenesisState(
params Params,
maxSupply sdk.Coin,
) GenesisState {
return GenesisState{
Params: params,
PrevBlockTs: math.NewInt(0),
MaxSupply: maxSupply,
}
}
func DefaultGenesisState() *GenesisState {
params := DefaultParams()
maxSupply := math.NewIntWithDecimal(100_000_000_000, 18)
return &GenesisState{
Params: params,
PrevBlockTs: math.NewInt(0),
MaxSupply: sdk.NewCoin(params.MintDenom, maxSupply),
}
}
// Validate genesis state
func (gs GenesisState) Validate() error {
if err := validateMaxSupply(gs.MaxSupply); err != nil {
return err
}
return gs.Params.Validate()
}
func validateMaxSupply(i interface{}) error {
totalTargetSupply, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("max supply: invalid genesis state type: %T", i)
}
if totalTargetSupply.IsNil() {
return fmt.Errorf("max supply: can't be nil")
}
return nil
}