github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/27-interchain-accounts/host/keeper/genesis.go (about)

     1  package keeper
     2  
     3  import (
     4  	"fmt"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  	icatypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types"
     8  	host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host"
     9  )
    10  
    11  // InitGenesis initializes the interchain accounts host application state from a provided genesis state
    12  func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.HostGenesisState) {
    13  	if !keeper.IsBound(ctx, state.Port) {
    14  		cap := keeper.BindPort(ctx, state.Port)
    15  		if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.Port)); err != nil {
    16  			panic(fmt.Sprintf("could not claim port capability: %v", err))
    17  		}
    18  	}
    19  
    20  	for _, ch := range state.ActiveChannels {
    21  		keeper.SetActiveChannelID(ctx, ch.ConnectionId, ch.PortId, ch.ChannelId)
    22  	}
    23  
    24  	for _, acc := range state.InterchainAccounts {
    25  		keeper.SetInterchainAccountAddress(ctx, acc.ConnectionId, acc.PortId, acc.AccountAddress)
    26  	}
    27  
    28  	keeper.SetParams(ctx, state.Params)
    29  }
    30  
    31  // ExportGenesis returns the interchain accounts host exported genesis
    32  func ExportGenesis(ctx sdk.Context, keeper Keeper) icatypes.HostGenesisState {
    33  	return icatypes.NewHostGenesisState(
    34  		keeper.GetAllActiveChannels(ctx),
    35  		keeper.GetAllInterchainAccounts(ctx),
    36  		icatypes.PortID,
    37  		keeper.GetParams(ctx),
    38  	)
    39  }