-
Notifications
You must be signed in to change notification settings - Fork 30
/
genesis.go
60 lines (49 loc) · 1.4 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
package token
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/irisnet/irismod/modules/token/keeper"
v1 "github.com/irisnet/irismod/modules/token/types/v1"
)
// InitGenesis stores the genesis state
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data v1.GenesisState) {
if err := v1.ValidateGenesis(data); err != nil {
panic(err.Error())
}
if err := k.SetParams(ctx, data.Params); err != nil {
panic(err.Error())
}
// init tokens
for _, token := range data.Tokens {
if err := k.AddToken(ctx, token); err != nil {
panic(err.Error())
}
}
for _, coin := range data.BurnedCoins {
k.AddBurnCoin(ctx, coin)
}
// assert the symbol exists
if !k.HasSymbol(ctx, data.Params.IssueTokenBaseFee.Denom) {
panic(fmt.Sprintf("Token %s does not exist", data.Params.IssueTokenBaseFee.Denom))
}
}
// ExportGenesis outputs the genesis state
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *v1.GenesisState {
var tokens []v1.Token
for _, token := range k.GetTokens(ctx, nil) {
t := token.(*v1.Token)
tokens = append(tokens, *t)
}
return &v1.GenesisState{
Params: k.GetParams(ctx),
Tokens: tokens,
BurnedCoins: k.GetAllBurnCoin(ctx),
}
}
// DefaultGenesisState returns the default genesis state for testing
func DefaultGenesisState() *v1.GenesisState {
return &v1.GenesisState{
Params: v1.DefaultParams(),
Tokens: []v1.Token{v1.GetNativeToken()},
}
}