2020-08-14 14:46:26 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-10-01 08:32:53 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
|
2020-08-14 14:46:26 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// InitGenesis initializes the ibc-transfer state and binds to PortID.
|
|
|
|
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
|
|
|
|
k.SetPort(ctx, state.PortId)
|
|
|
|
|
|
|
|
for _, trace := range state.DenomTraces {
|
|
|
|
k.SetDenomTrace(ctx, trace)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(ctx, state.PortId) {
|
|
|
|
// transfer module binds to the transfer port on InitChain
|
|
|
|
// and claims the returned capability
|
|
|
|
err := k.BindPort(ctx, state.PortId)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("could not claim port capability: %v", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-16 23:24:14 -07:00
|
|
|
k.SetParams(ctx, state.Params)
|
|
|
|
|
2020-08-14 14:46:26 -07:00
|
|
|
// check if the module account exists
|
|
|
|
moduleAcc := k.GetTransferAccount(ctx)
|
|
|
|
if moduleAcc == nil {
|
|
|
|
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis exports ibc-transfer module's portID and denom trace info into its genesis state.
|
|
|
|
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
|
|
|
|
return &types.GenesisState{
|
|
|
|
PortId: k.GetPort(ctx),
|
|
|
|
DenomTraces: k.GetAllDenomTraces(ctx),
|
2020-08-16 23:24:14 -07:00
|
|
|
Params: k.GetParams(ctx),
|
2020-08-14 14:46:26 -07:00
|
|
|
}
|
|
|
|
}
|