-
Notifications
You must be signed in to change notification settings - Fork 55
/
genesis.go
42 lines (34 loc) · 1.38 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"
"github.com/crescent-network/crescent/v5/x/liquidstaking/types"
)
// InitGenesis initializes the liquidstaking module's state from a given genesis state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
if err := types.ValidateGenesis(genState); err != nil {
panic(err)
}
// init to prevent nil slice, []types.WhitelistedValidator(nil)
if genState.Params.WhitelistedValidators == nil || len(genState.Params.WhitelistedValidators) == 0 {
genState.Params.WhitelistedValidators = []types.WhitelistedValidator{}
}
k.SetParams(ctx, genState.Params)
for _, lv := range genState.LiquidValidators {
k.SetLiquidValidator(ctx, lv)
}
moduleAcc := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
}
// ExportGenesis returns the liquidstaking module's genesis state.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := k.GetParams(ctx)
// init to prevent nil slice, []types.WhitelistedValidator(nil)
if params.WhitelistedValidators == nil || len(params.WhitelistedValidators) == 0 {
params.WhitelistedValidators = []types.WhitelistedValidator{}
}
liquidValidators := k.GetAllLiquidValidators(ctx)
return types.NewGenesisState(params, liquidValidators)
}