-
Notifications
You must be signed in to change notification settings - Fork 12
/
genesis.go
42 lines (34 loc) · 1.06 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
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
fxtypes "github.com/functionx/fx-core/v7/types"
"github.com/functionx/fx-core/v7/x/erc20/types"
)
// InitGenesis import module genesis
func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
if err := k.SetParams(ctx, &data.Params); err != nil {
panic(err)
}
// ensure erc20 module account is set on genesis
if acc := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName); acc == nil {
// NOTE: shouldn't occur
panic("the erc20 module account has not been set")
}
for _, pair := range data.TokenPairs {
k.AddTokenPair(ctx, pair)
}
if _, found := k.GetTokenPair(ctx, fxtypes.DefaultDenom); !found {
_, err := k.RegisterNativeCoin(ctx, fxtypes.GetFXMetaData())
if err != nil {
panic(fmt.Sprintf("register default denom error %s", err.Error()))
}
}
}
// ExportGenesis export module status
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
TokenPairs: k.GetAllTokenPairs(ctx),
}
}