-
Notifications
You must be signed in to change notification settings - Fork 3
/
genesis.go
50 lines (42 loc) · 1.21 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
package fantoken
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bitsongofficial/chainmodules/x/fantoken/keeper"
"github.com/bitsongofficial/chainmodules/x/fantoken/types"
)
// InitGenesis stores the genesis state
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
if err := types.ValidateGenesis(data); err != nil {
panic(err.Error())
}
k.SetParamSet(ctx, data.Params)
// init tokens
for _, token := range data.Tokens {
if err := k.AddFanToken(ctx, token); err != nil {
panic(err.Error())
}
}
for _, coin := range data.BurnedCoins {
k.AddBurnCoin(ctx, coin)
}
}
// ExportGenesis outputs the genesis state
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
var tokens []types.FanToken
for _, token := range k.GetFanTokens(ctx, nil) {
t := token.(*types.FanToken)
tokens = append(tokens, *t)
}
return &types.GenesisState{
Params: k.GetParamSet(ctx),
Tokens: tokens,
BurnedCoins: k.GetAllBurnCoin(ctx),
}
}
// DefaultGenesisState returns the default genesis state for testing
func DefaultGenesisState() *types.GenesisState {
return &types.GenesisState{
Params: types.DefaultParams(),
Tokens: []types.FanToken{},
}
}