github.com/cosmos/cosmos-sdk@v0.50.10/x/params/module.go (about) 1 package params 2 3 import ( 4 "context" 5 6 gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" 7 8 modulev1 "cosmossdk.io/api/cosmos/params/module/v1" 9 "cosmossdk.io/core/appmodule" 10 "cosmossdk.io/depinject" 11 store "cosmossdk.io/store/types" 12 13 "github.com/cosmos/cosmos-sdk/client" 14 "github.com/cosmos/cosmos-sdk/codec" 15 codectypes "github.com/cosmos/cosmos-sdk/codec/types" 16 "github.com/cosmos/cosmos-sdk/types/module" 17 simtypes "github.com/cosmos/cosmos-sdk/types/simulation" 18 govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" 19 "github.com/cosmos/cosmos-sdk/x/params/keeper" 20 "github.com/cosmos/cosmos-sdk/x/params/types" 21 "github.com/cosmos/cosmos-sdk/x/params/types/proposal" 22 ) 23 24 var ( 25 _ module.AppModuleBasic = AppModule{} 26 _ module.AppModuleSimulation = AppModule{} 27 _ module.HasServices = AppModule{} 28 29 _ appmodule.AppModule = AppModule{} 30 ) 31 32 // ConsensusVersion defines the current x/params module consensus version. 33 const ConsensusVersion = 1 34 35 // AppModuleBasic defines the basic application module used by the params module. 36 type AppModuleBasic struct{} 37 38 // Name returns the params module's name. 39 func (AppModuleBasic) Name() string { 40 return proposal.ModuleName 41 } 42 43 // RegisterLegacyAminoCodec registers the params module's types on the given LegacyAmino codec. 44 func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { 45 proposal.RegisterLegacyAminoCodec(cdc) 46 } 47 48 // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the params module. 49 func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { 50 if err := proposal.RegisterQueryHandlerClient(context.Background(), mux, proposal.NewQueryClient(clientCtx)); err != nil { 51 panic(err) 52 } 53 } 54 55 func (am AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { 56 proposal.RegisterInterfaces(registry) 57 } 58 59 // AppModule implements an application module for the distribution module. 60 type AppModule struct { 61 AppModuleBasic 62 63 keeper keeper.Keeper 64 } 65 66 // NewAppModule creates a new AppModule object 67 func NewAppModule(k keeper.Keeper) AppModule { 68 return AppModule{ 69 AppModuleBasic: AppModuleBasic{}, 70 keeper: k, 71 } 72 } 73 74 // IsOnePerModuleType implements the depinject.OnePerModuleType interface. 75 func (am AppModule) IsOnePerModuleType() {} 76 77 // IsAppModule implements the appmodule.AppModule interface. 78 func (am AppModule) IsAppModule() {} 79 80 // GenerateGenesisState performs a no-op. 81 func (AppModule) GenerateGenesisState(simState *module.SimulationState) {} 82 83 // RegisterServices registers a gRPC query service to respond to the 84 // module-specific gRPC queries. 85 func (am AppModule) RegisterServices(cfg module.Configurator) { 86 proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper) 87 } 88 89 // RegisterStoreDecoder doesn't register any type. 90 func (AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {} 91 92 // WeightedOperations returns the all the gov module operations with their respective weights. 93 func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { 94 return nil 95 } 96 97 // ConsensusVersion implements AppModule/ConsensusVersion. 98 func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } 99 100 // 101 // App Wiring Setup 102 // 103 104 func init() { 105 appmodule.Register(&modulev1.Module{}, 106 appmodule.Provide( 107 ProvideModule, 108 ProvideSubspace, 109 )) 110 } 111 112 type ModuleInputs struct { 113 depinject.In 114 115 KvStoreKey *store.KVStoreKey 116 TransientStoreKey *store.TransientStoreKey 117 Cdc codec.Codec 118 LegacyAmino *codec.LegacyAmino 119 } 120 121 type ModuleOutputs struct { 122 depinject.Out 123 124 ParamsKeeper keeper.Keeper 125 Module appmodule.AppModule 126 GovHandler govv1beta1.HandlerRoute 127 } 128 129 func ProvideModule(in ModuleInputs) ModuleOutputs { 130 k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.KvStoreKey, in.TransientStoreKey) 131 132 m := NewAppModule(k) 133 govHandler := govv1beta1.HandlerRoute{RouteKey: proposal.RouterKey, Handler: NewParamChangeProposalHandler(k)} 134 135 return ModuleOutputs{ParamsKeeper: k, Module: m, GovHandler: govHandler} 136 } 137 138 type SubspaceInputs struct { 139 depinject.In 140 141 Key depinject.ModuleKey 142 Keeper keeper.Keeper 143 KeyTables map[string]types.KeyTable 144 } 145 146 func ProvideSubspace(in SubspaceInputs) types.Subspace { 147 moduleName := in.Key.Name() 148 kt, exists := in.KeyTables[moduleName] 149 if !exists { 150 return in.Keeper.Subspace(moduleName) 151 } 152 return in.Keeper.Subspace(moduleName).WithKeyTable(kt) 153 }