github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/transfer/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  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/transfer/types"
     8  )
     9  
    10  // InitGenesis initializes the ibc-transfer state and binds to PortID.
    11  func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
    12  	k.SetPort(ctx, state.PortId)
    13  
    14  	for _, trace := range state.DenomTraces {
    15  		k.SetDenomTrace(ctx, trace)
    16  	}
    17  
    18  	// Only try to bind to port if it is not already bound, since we may already own
    19  	// port capability from capability InitGenesis
    20  	if !k.IsBound(ctx, state.PortId) {
    21  		// transfer module binds to the transfer port on InitChain
    22  		// and claims the returned capability
    23  		err := k.BindPort(ctx, state.PortId)
    24  		if err != nil {
    25  			panic(fmt.Sprintf("could not claim port capability: %v", err))
    26  		}
    27  	}
    28  
    29  	k.SetParams(ctx, state.Params)
    30  
    31  	// check if the module account exists
    32  	moduleAcc := k.GetTransferAccount(ctx)
    33  	if moduleAcc == nil {
    34  		panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
    35  	}
    36  }
    37  
    38  // ExportGenesis exports ibc-transfer module's portID and denom trace info into its genesis state.
    39  func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
    40  	return &types.GenesisState{
    41  		PortId:      k.GetPort(ctx),
    42  		DenomTraces: k.GetAllDenomTraces(ctx),
    43  		Params:      k.GetParams(ctx),
    44  	}
    45  }