github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/testing/simapp/adapter/core/module.go (about)

     1  package core
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  	ibc "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core"
     9  	host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host"
    10  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/keeper"
    11  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/types"
    12  	"github.com/fibonacci-chain/fbc/libs/ibc-go/testing/simapp/adapter"
    13  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    14  )
    15  
    16  type CoreModule struct {
    17  	ibc.AppModule
    18  
    19  	tkeeper *keeper.Keeper
    20  
    21  	// create localhost by default
    22  	tcreateLocalhost bool
    23  }
    24  
    25  // NewAppModule creates a new AppModule object
    26  func NewIBCCOreAppModule(k *ibc.Keeper) *CoreModule {
    27  	a := ibc.NewAppModule(k)
    28  	ret := &CoreModule{
    29  		AppModule:        a,
    30  		tkeeper:          k.V2Keeper,
    31  		tcreateLocalhost: false,
    32  	}
    33  	return ret
    34  }
    35  
    36  // DefaultGenesis returns default genesis state as raw bytes for the ibc
    37  // module.
    38  func (CoreModule) DefaultGenesis() json.RawMessage {
    39  	return adapter.ModuleCdc.MustMarshalJSON(ibc.DefaultGenesisState())
    40  }
    41  
    42  // InitGenesis performs genesis initialization for the ibc module. It returns
    43  // no validator updates.
    44  // func (am CoreModule) InitGenesis(ctx sdk.Context, cdc Corec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate {
    45  func (am CoreModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
    46  	return am.initGenesis(ctx, data)
    47  }
    48  
    49  func (am CoreModule) initGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
    50  	var gs types.GenesisState
    51  	err := adapter.ModuleCdc.UnmarshalJSON(data, &gs)
    52  	if err != nil {
    53  		panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", host.ModuleName, err))
    54  	}
    55  	gs.Params.EnableIbc = true
    56  	ibc.InitGenesis(ctx, *am.tkeeper, am.tcreateLocalhost, &gs)
    57  	return []abci.ValidatorUpdate{}
    58  }
    59  
    60  // ExportGenesis returns the exported genesis state as raw bytes for the ibc
    61  // module.
    62  func (am CoreModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
    63  	return am.exportGenesis(ctx)
    64  }
    65  
    66  func (am CoreModule) exportGenesis(ctx sdk.Context) json.RawMessage {
    67  	return adapter.ModuleCdc.MustMarshalJSON(ibc.ExportGenesis(ctx, *am.tkeeper))
    68  }