-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
genesis.go
45 lines (37 loc) · 1.37 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
package ununifidist
import (
"fmt"
"github.com/UnUniFi/chain/x/ununifidist/keeper"
"github.com/UnUniFi/chain/x/ununifidist/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the store state from a genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, accountKeeper types.AccountKeeper, gs types.GenesisState) {
if err := gs.Validate(); err != nil {
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
}
k.SetParams(ctx, gs.Params)
// only set the previous block time if it's different than default
if !gs.PreviousBlockTime.Equal(types.DefaultPreviousBlockTime) {
k.SetPreviousBlockTime(ctx, gs.PreviousBlockTime)
}
// check if the module account exists
moduleAcc := accountKeeper.GetModuleAccount(ctx, types.UnunifidistMacc)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.UnunifidistMacc))
}
k.SetGovDenom(ctx, gs.GovDenom)
}
// ExportGenesis export genesis state for cdp module
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
params := k.GetParams(ctx)
previousBlockTime, found := k.GetPreviousBlockTime(ctx)
if !found {
previousBlockTime = types.DefaultPreviousBlockTime
}
govDenom, found := k.GetGovDenom(ctx)
if !found {
govDenom = types.DefaultGovDenom
}
return types.NewGenesisState(params, previousBlockTime, govDenom)
}