github.com/Finschia/finschia-sdk@v0.49.1/x/feegrant/module/module.go (about) 1 package module 2 3 import ( 4 "context" 5 "encoding/json" 6 "math/rand" 7 8 "github.com/grpc-ecosystem/grpc-gateway/runtime" 9 "github.com/spf13/cobra" 10 abci "github.com/tendermint/tendermint/abci/types" 11 12 sdkclient "github.com/Finschia/finschia-sdk/client" 13 "github.com/Finschia/finschia-sdk/codec" 14 cdctypes "github.com/Finschia/finschia-sdk/codec/types" 15 sdk "github.com/Finschia/finschia-sdk/types" 16 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 17 "github.com/Finschia/finschia-sdk/types/module" 18 simtypes "github.com/Finschia/finschia-sdk/types/simulation" 19 "github.com/Finschia/finschia-sdk/x/feegrant" 20 "github.com/Finschia/finschia-sdk/x/feegrant/client/cli" 21 "github.com/Finschia/finschia-sdk/x/feegrant/keeper" 22 "github.com/Finschia/finschia-sdk/x/feegrant/simulation" 23 ) 24 25 var ( 26 _ module.AppModule = AppModule{} 27 _ module.AppModuleBasic = AppModuleBasic{} 28 _ module.AppModuleSimulation = AppModule{} 29 ) 30 31 // ---------------------------------------------------------------------------- 32 // AppModuleBasic 33 // ---------------------------------------------------------------------------- 34 35 // AppModuleBasic defines the basic application module used by the feegrant module. 36 type AppModuleBasic struct { 37 cdc codec.Codec 38 } 39 40 // Name returns the feegrant module's name. 41 func (AppModuleBasic) Name() string { 42 return feegrant.ModuleName 43 } 44 45 // RegisterServices registers a gRPC query service to respond to the 46 // module-specific gRPC queries. 47 func (am AppModule) RegisterServices(cfg module.Configurator) { 48 feegrant.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) 49 feegrant.RegisterQueryServer(cfg.QueryServer(), am.keeper) 50 } 51 52 // RegisterLegacyAminoCodec registers the feegrant module's types for the given codec. 53 func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { 54 feegrant.RegisterLegacyAminoCodec(cdc) 55 } 56 57 // RegisterInterfaces registers the feegrant module's interface types 58 func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { 59 feegrant.RegisterInterfaces(registry) 60 } 61 62 // LegacyQuerierHandler returns the feegrant module sdk.Querier. 63 func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { 64 return nil 65 } 66 67 // DefaultGenesis returns default genesis state as raw bytes for the feegrant 68 // module. 69 func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { 70 return cdc.MustMarshalJSON(feegrant.DefaultGenesisState()) 71 } 72 73 // ValidateGenesis performs genesis state validation for the feegrant module. 74 func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { 75 var data feegrant.GenesisState 76 if err := cdc.UnmarshalJSON(bz, &data); err != nil { 77 return sdkerrors.Wrapf(err, "failed to unmarshal %s genesis state", feegrant.ModuleName) 78 } 79 80 return feegrant.ValidateGenesis(data) 81 } 82 83 // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the feegrant module. 84 func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { 85 if err := feegrant.RegisterQueryHandlerClient(context.Background(), mux, feegrant.NewQueryClient(clientCtx)); err != nil { 86 panic(err) 87 } 88 } 89 90 // GetTxCmd returns the root tx command for the feegrant module. 91 func (AppModuleBasic) GetTxCmd() *cobra.Command { 92 return cli.GetTxCmd() 93 } 94 95 // GetQueryCmd returns no root query command for the feegrant module. 96 func (AppModuleBasic) GetQueryCmd() *cobra.Command { 97 return cli.GetQueryCmd() 98 } 99 100 // ---------------------------------------------------------------------------- 101 // AppModule 102 // ---------------------------------------------------------------------------- 103 104 // AppModule implements an application module for the feegrant module. 105 type AppModule struct { 106 AppModuleBasic 107 keeper keeper.Keeper 108 accountKeeper feegrant.AccountKeeper 109 bankKeeper feegrant.BankKeeper 110 registry cdctypes.InterfaceRegistry 111 } 112 113 // NewAppModule creates a new AppModule object 114 func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule { 115 return AppModule{ 116 AppModuleBasic: AppModuleBasic{cdc: cdc}, 117 keeper: keeper, 118 accountKeeper: ak, 119 bankKeeper: bk, 120 registry: registry, 121 } 122 } 123 124 // Name returns the feegrant module's name. 125 func (AppModule) Name() string { 126 return feegrant.ModuleName 127 } 128 129 // RegisterInvariants registers the feegrant module invariants. 130 func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} 131 132 // Deprecated: Route returns the message routing key for the feegrant module. 133 func (am AppModule) Route() sdk.Route { 134 return sdk.Route{} 135 } 136 137 // NewHandler returns an sdk.Handler for the feegrant module. 138 func (am AppModule) NewHandler() sdk.Handler { 139 return nil 140 } 141 142 // QuerierRoute returns the feegrant module's querier route name. 143 func (AppModule) QuerierRoute() string { 144 return "" 145 } 146 147 // InitGenesis performs genesis initialization for the feegrant module. It returns 148 // no validator updates. 149 func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { 150 var gs feegrant.GenesisState 151 cdc.MustUnmarshalJSON(bz, &gs) 152 153 err := am.keeper.InitGenesis(ctx, &gs) 154 if err != nil { 155 panic(err) 156 } 157 return []abci.ValidatorUpdate{} 158 } 159 160 // ExportGenesis returns the exported genesis state as raw bytes for the feegrant 161 // module. 162 func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { 163 gs, err := am.keeper.ExportGenesis(ctx) 164 if err != nil { 165 panic(err) 166 } 167 168 return cdc.MustMarshalJSON(gs) 169 } 170 171 // ConsensusVersion implements AppModule/ConsensusVersion. 172 func (AppModule) ConsensusVersion() uint64 { return 1 } 173 174 // AppModuleSimulation functions 175 176 // GenerateGenesisState creates a randomized GenState of the feegrant module. 177 func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 178 simulation.RandomizedGenState(simState) 179 } 180 181 // ProposalContents returns all the feegrant content functions used to 182 // simulate governance proposals. 183 func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { 184 return nil 185 } 186 187 // RandomizedParams creates randomized feegrant param changes for the simulator. 188 func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { 189 return nil 190 } 191 192 // RegisterStoreDecoder registers a decoder for feegrant module's types 193 func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 194 sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) 195 } 196 197 // WeightedOperations returns all the feegrant module operations with their respective weights. 198 func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { 199 return simulation.WeightedOperations( 200 simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, 201 ) 202 }