github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/27-interchain-accounts/module.go (about) 1 package ica 2 3 import ( 4 "context" 5 "encoding/json" 6 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/upgrade" 8 9 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/common" 10 11 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/client/cli" 12 13 controllertypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/controller/types" 14 hosttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/host/types" 15 16 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 17 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/host" 18 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types" 19 20 cliCtx "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 21 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 22 anytypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec/types" 23 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 24 porttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/05-port/types" 25 "github.com/gorilla/mux" 26 "github.com/grpc-ecosystem/grpc-gateway/runtime" 27 "github.com/spf13/cobra" 28 29 controllerkeeper "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/controller/keeper" 30 hostkeeper "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/host/keeper" 31 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 32 ) 33 34 var ( 35 _ module.AppModuleAdapter = AppModule{} 36 _ module.AppModuleBasicAdapter = AppModuleBasic{} 37 38 _ porttypes.IBCModule = host.IBCModule{} 39 ) 40 41 // AppModuleBasic is the IBC interchain accounts AppModuleBasic 42 type AppModuleBasic struct{} 43 44 func (b AppModuleBasic) RegisterCodec(codec *codec.Codec) { 45 types.RegisterCodec(codec) 46 } 47 48 func (b AppModuleBasic) DefaultGenesis() json.RawMessage { 49 return nil 50 } 51 52 func (b AppModuleBasic) ValidateGenesis(message json.RawMessage) error { 53 return nil 54 } 55 56 func (b AppModuleBasic) RegisterRESTRoutes(context cliCtx.CLIContext, router *mux.Router) {} 57 58 func (b AppModuleBasic) GetTxCmd(codec *codec.Codec) *cobra.Command { 59 return nil 60 } 61 62 func (b AppModuleBasic) GetQueryCmd(codec *codec.Codec) *cobra.Command { 63 return nil 64 } 65 66 func (b AppModuleBasic) RegisterInterfaces(registry anytypes.InterfaceRegistry) { 67 types.RegisterInterfaces(registry) 68 } 69 70 func (b AppModuleBasic) RegisterGRPCGatewayRoutes(ctx cliCtx.CLIContext, mux *runtime.ServeMux) { 71 controllertypes.RegisterQueryHandlerClient(context.Background(), mux, controllertypes.NewQueryClient(ctx)) 72 hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(ctx)) 73 } 74 75 func (b AppModuleBasic) GetTxCmdV2(cdc *codec.CodecProxy, reg anytypes.InterfaceRegistry) *cobra.Command { 76 return nil 77 } 78 79 func (b AppModuleBasic) GetQueryCmdV2(cdc *codec.CodecProxy, reg anytypes.InterfaceRegistry) *cobra.Command { 80 return cli.GetQueryCmd(cdc, reg) 81 } 82 83 func (b AppModuleBasic) RegisterRouterForGRPC(cliCtx cliCtx.CLIContext, r *mux.Router) {} 84 85 // Name implements AppModuleBasic interface 86 func (AppModuleBasic) Name() string { 87 return types.ModuleName 88 } 89 90 // AppModule is the application module for the IBC interchain accounts module 91 type AppModule struct { 92 *common.Veneus3BaseUpgradeModule 93 AppModuleBasic 94 controllerKeeper *controllerkeeper.Keeper 95 hostKeeper *hostkeeper.Keeper 96 } 97 98 // NewAppModule creates a new 20-transfer module 99 func NewAppModule(m *codec.CodecProxy, ck *controllerkeeper.Keeper, hk *hostkeeper.Keeper) AppModule { 100 ret := AppModule{ 101 controllerKeeper: ck, 102 hostKeeper: hk, 103 } 104 ret.Veneus3BaseUpgradeModule = common.NewVeneus3BaseUpgradeModule(ret) 105 return ret 106 } 107 108 func (am AppModule) InitGenesis(s sdk.Context, message json.RawMessage) []abci.ValidatorUpdate { 109 return nil 110 } 111 112 func (a AppModule) ExportGenesis(s sdk.Context) json.RawMessage { 113 return nil 114 } 115 116 func (a AppModule) Route() string { 117 return types.RouterKey 118 } 119 120 func (a AppModule) NewHandler() sdk.Handler { 121 return NewHandler(a.hostKeeper, a.controllerKeeper) 122 } 123 124 func (a AppModule) QuerierRoute() string { 125 return types.QuerierRoute 126 } 127 128 func (a AppModule) NewQuerierHandler() sdk.Querier { 129 return nil 130 } 131 132 func (a AppModule) BeginBlock(s sdk.Context, block abci.RequestBeginBlock) {} 133 134 func (a AppModule) EndBlock(s sdk.Context, block abci.RequestEndBlock) []abci.ValidatorUpdate { 135 return []abci.ValidatorUpdate{} 136 } 137 138 func (a AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {} 139 140 func (a AppModule) RegisterServices(cfg module.Configurator) { 141 controllertypes.RegisterQueryServer(cfg.QueryServer(), a.controllerKeeper) 142 hosttypes.RegisterQueryServer(cfg.QueryServer(), a.hostKeeper) 143 } 144 145 func (a AppModule) RegisterTask() upgrade.HeightTask { 146 return upgrade.NewHeightTask(6, func(ctx sdk.Context) error { 147 ret := types.DefaultGenesis() 148 data := ModuleCdc.MustMarshalJSON(ret) 149 a.initGenesis(ctx, data) 150 return nil 151 }) 152 } 153 154 func (am AppModule) initGenesis(s sdk.Context, message json.RawMessage) []abci.ValidatorUpdate { 155 var genesisState types.GenesisState 156 ModuleCdc.MustUnmarshalJSON(message, &genesisState) 157 158 if am.controllerKeeper != nil { 159 controllerkeeper.InitGenesis(s, *am.controllerKeeper, genesisState.ControllerGenesisState) 160 } 161 162 if am.hostKeeper != nil { 163 hostkeeper.InitGenesis(s, *am.hostKeeper, genesisState.HostGenesisState) 164 } 165 166 return nil 167 }