-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
genesis.go
37 lines (31 loc) · 1.07 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 transfer
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
)
// InitGenesis binds to portid from genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state types.GenesisState) {
// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !keeper.IsBound(ctx, state.PortID) {
// transfer module binds to the transfer port on InitChain
// and claims the returned capability
err := keeper.BindPort(ctx, state.PortID)
if err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
// check if the module account exists
moduleAcc := keeper.GetTransferAccount(ctx)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.GetModuleAccountName()))
}
}
// ExportGenesis exports transfer module's portID into its geneis state
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
portID := keeper.GetPort(ctx)
return types.GenesisState{
PortID: portID,
}
}