github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/capability/module.go (about) 1 package capability 2 3 import ( 4 "encoding/json" 5 "math/rand" 6 7 clientCtx "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 9 types2 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec/types" 10 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 12 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/upgrade" 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/keeper" 14 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/simulation" 15 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/types" 16 simulation2 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/simulation" 17 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/base" 18 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 19 tmtypes "github.com/fibonacci-chain/fbc/libs/tendermint/types" 20 "github.com/gorilla/mux" 21 "github.com/grpc-ecosystem/grpc-gateway/runtime" 22 "github.com/spf13/cobra" 23 ) 24 25 var ( 26 _ module.AppModuleAdapter = AppModule{} 27 _ module.AppModuleBasicAdapter = AppModuleBasic{} 28 _ module.AppModuleSimulation = AppModule{} 29 _ upgrade.UpgradeModule = AppModule{} 30 ) 31 32 // ---------------------------------------------------------------------------- 33 // AppModuleBasic 34 // ---------------------------------------------------------------------------- 35 36 // AppModuleBasic implements the AppModuleBasic interface for the capability module. 37 type AppModuleBasic struct { 38 cdc *codec.CodecProxy 39 } 40 41 func NewAppModuleBasic(cdc *codec.CodecProxy) AppModuleBasic { 42 ret := AppModuleBasic{cdc: cdc} 43 return ret 44 } 45 46 func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} 47 48 // Name returns the capability module's name. 49 func (AppModuleBasic) Name() string { 50 return types.ModuleName 51 } 52 53 // RegisterLegacyAminoCodec does nothing. Capability does not support amino. 54 func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.Codec) {} 55 56 // RegisterInterfaces registers the module's interface types 57 func (a AppModuleBasic) RegisterInterfaces(_ types2.InterfaceRegistry) {} 58 59 // DefaultGenesis returns default genesis state as raw bytes for the ibc 60 // module. 61 func (AppModuleBasic) DefaultGenesis() json.RawMessage { 62 return nil 63 } 64 65 // ValidateGenesis performs genesis state validation for the capability module. 66 func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { 67 return nil 68 } 69 70 // RegisterRESTRoutes registers the capability module's REST service handlers. 71 func (a AppModuleBasic) RegisterRESTRoutes(ctx clientCtx.CLIContext, rtr *mux.Router) {} 72 73 // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module. 74 func (a AppModuleBasic) RegisterGRPCGatewayRoutes(ctx clientCtx.CLIContext, mux *runtime.ServeMux) { 75 } 76 77 // GetTxCmd returns the capability module's root tx command. 78 func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { return nil } 79 80 func (am AppModuleBasic) GetTxCmdV2(cdc *codec.CodecProxy, reg types2.InterfaceRegistry) *cobra.Command { 81 return nil 82 } 83 84 // GetQueryCmd returns the capability module's root query command. 85 func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { return nil } 86 87 func (AppModuleBasic) GetQueryCmdV2(cdc *codec.CodecProxy, reg types2.InterfaceRegistry) *cobra.Command { 88 return nil 89 } 90 91 func (am AppModuleBasic) RegisterRouterForGRPC(cliCtx clientCtx.CLIContext, r *mux.Router) { 92 93 } 94 95 // ---------------------------------------------------------------------------- 96 // AppModule 97 // ---------------------------------------------------------------------------- 98 99 // AppModule implements the AppModule interface for the capability module. 100 type AppModule struct { 101 AppModuleBasic 102 *base.BaseIBCUpgradeModule 103 keeper keeper.Keeper 104 } 105 106 func (am AppModule) NewHandler() sdk.Handler { 107 return nil 108 } 109 110 func (am AppModule) NewQuerierHandler() sdk.Querier { 111 return nil 112 } 113 114 func NewAppModule(cdc *codec.CodecProxy, keeper keeper.Keeper) AppModule { 115 ret := AppModule{ 116 AppModuleBasic: NewAppModuleBasic(cdc), 117 keeper: keeper, 118 } 119 ret.BaseIBCUpgradeModule = base.NewBaseIBCUpgradeModule(ret) 120 return ret 121 } 122 123 // Name returns the capability module's name. 124 func (am AppModule) Name() string { 125 return am.AppModuleBasic.Name() 126 } 127 128 // Route returns the capability module's message routing key. 129 func (AppModule) Route() string { return types.ModuleName } 130 131 // QuerierRoute returns the capability module's query routing key. 132 func (AppModule) QuerierRoute() string { return "" } 133 134 // LegacyQuerierHandler returns the capability module's Querier. 135 func (am AppModule) LegacyQuerierHandler(codec2 *codec.Codec) sdk.Querier { return nil } 136 137 // RegisterServices registers a GRPC query service to respond to the 138 // module-specific GRPC queries. 139 func (am AppModule) RegisterServices(module.Configurator) {} 140 141 // RegisterInvariants registers the capability module's invariants. 142 func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} 143 144 // InitGenesis performs the capability module's genesis initialization It returns 145 // no validator updates. 146 func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 147 return nil 148 } 149 func (am AppModule) initGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 150 var genState types.GenesisState 151 // Initialize global index to index in genesis state 152 ModuleCdc.MustUnmarshalJSON(data, &genState) 153 154 InitGenesis(ctx, am.keeper, genState) 155 156 return []abci.ValidatorUpdate{} 157 } 158 159 // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. 160 func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { 161 return nil 162 } 163 164 func (am AppModule) exportGenesis(ctx sdk.Context) json.RawMessage { 165 genState := ExportGenesis(ctx, am.keeper) 166 return ModuleCdc.MustMarshalJSON(genState) 167 } 168 169 // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. 170 func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { 171 if tmtypes.HigherThanVenus1(ctx.BlockHeight()) { 172 am.keeper.InitMemStore(ctx) 173 } 174 } 175 176 // EndBlock executes all ABCI EndBlock logic respective to the capability module. It 177 // returns no validator updates. 178 func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { 179 return []abci.ValidatorUpdate{} 180 } 181 182 // GenerateGenesisState creates a randomized GenState of the capability module. 183 func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 184 simulation.RandomizedGenState(simState) 185 } 186 187 // ProposalContents performs a no-op 188 func (am AppModule) ProposalContents(simState module.SimulationState) []simulation2.WeightedProposalContent { 189 return nil 190 } 191 192 // RandomizedParams creates randomized capability param changes for the simulator. 193 func (AppModule) RandomizedParams(r *rand.Rand) []simulation2.ParamChange { 194 return nil 195 } 196 197 // RegisterStoreDecoder registers a decoder for capability module's types 198 func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 199 sdr[types.StoreKey] = simulation.NewDecodeStore() 200 } 201 202 // WeightedOperations returns the all the gov module operations with their respective weights. 203 func (am AppModule) WeightedOperations(simState module.SimulationState) []simulation2.WeightedOperation { 204 return nil 205 } 206 207 func (am AppModule) RegisterTask() upgrade.HeightTask { 208 return upgrade.NewHeightTask( 209 0, func(ctx sdk.Context) error { 210 if am.Sealed() { 211 return nil 212 } 213 data := ModuleCdc.MustMarshalJSON(types.DefaultGenesis()) 214 am.initGenesis(ctx, data) 215 return nil 216 }) 217 }