forked from babylonlabs-io/babylon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenesis.go
37 lines (33 loc) · 1.16 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
package zoneconcierge
import (
"context"
"github.com/babylonlabs-io/babylon/x/zoneconcierge/keeper"
"github.com/babylonlabs-io/babylon/x/zoneconcierge/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx context.Context, k keeper.Keeper, genState types.GenesisState) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
// set params for this module
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
}
k.SetPort(ctx, genState.PortId)
// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !k.IsBound(sdkCtx, genState.PortId) {
// module binds to the port on InitChain
// and claims the returned capability
err := k.BindPort(sdkCtx, genState.PortId)
if err != nil {
panic("could not claim port capability: " + err.Error())
}
}
}
// ExportGenesis returns the module's exported genesis
func ExportGenesis(ctx context.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.PortId = k.GetPort(ctx)
return genesis
}