-
Notifications
You must be signed in to change notification settings - Fork 28
/
genesis.go
87 lines (78 loc) · 1.7 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package v1
import (
"github.com/cometbft/cometbft/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
tokentypes "github.com/irisnet/irismod/modules/token/types"
)
var (
nativeToken Token
Initialized bool
)
// NewGenesisState creates a new genesis state.
func NewGenesisState(params Params, tokens []Token) GenesisState {
return GenesisState{
Params: params,
Tokens: tokens,
}
}
// SetNativeToken resets the system's default native token
func SetNativeToken(
symbol string,
name string,
minUnit string,
decimal uint32,
initialSupply,
maxSupply uint64,
mintable bool,
owner sdk.AccAddress,
) {
nativeToken = NewToken(
symbol,
name,
minUnit,
decimal,
initialSupply,
maxSupply,
mintable,
owner,
)
Initialized = true
}
// GetNativeToken returns the system's default native token
func GetNativeToken() Token {
if !Initialized {
nativeToken = Token{
Symbol: sdk.DefaultBondDenom,
Name: "Network staking token",
Scale: 0,
MinUnit: sdk.DefaultBondDenom,
InitialSupply: 2000000000,
MaxSupply: 10000000000,
Mintable: true,
Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).
String(),
}
Initialized = true
}
return nativeToken
}
// ValidateGenesis validates the provided token genesis state to ensure the
// expected invariants holds.
func ValidateGenesis(data GenesisState) error {
if err := data.Params.Validate(); err != nil {
return err
}
// validate token
for _, token := range data.Tokens {
if err := token.Validate(); err != nil {
return err
}
}
// validate token
for _, coin := range data.BurnedCoins {
if err := coin.Validate(); err != nil {
return err
}
}
return nil
}