github.com/Finschia/finschia-sdk@v0.48.1/x/params/module.go (about)

     1  package params
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"math/rand"
     7  
     8  	"github.com/grpc-ecosystem/grpc-gateway/runtime"
     9  
    10  	"github.com/spf13/cobra"
    11  	abci "github.com/tendermint/tendermint/abci/types"
    12  
    13  	"github.com/Finschia/finschia-sdk/client"
    14  	"github.com/Finschia/finschia-sdk/codec"
    15  	codectypes "github.com/Finschia/finschia-sdk/codec/types"
    16  	sdk "github.com/Finschia/finschia-sdk/types"
    17  	"github.com/Finschia/finschia-sdk/types/module"
    18  	simtypes "github.com/Finschia/finschia-sdk/types/simulation"
    19  	"github.com/Finschia/finschia-sdk/x/params/client/cli"
    20  	"github.com/Finschia/finschia-sdk/x/params/keeper"
    21  	"github.com/Finschia/finschia-sdk/x/params/simulation"
    22  	"github.com/Finschia/finschia-sdk/x/params/types"
    23  	"github.com/Finschia/finschia-sdk/x/params/types/proposal"
    24  )
    25  
    26  var (
    27  	_ module.AppModule           = AppModule{}
    28  	_ module.AppModuleBasic      = AppModuleBasic{}
    29  	_ module.AppModuleSimulation = AppModule{}
    30  )
    31  
    32  // AppModuleBasic defines the basic application module used by the params module.
    33  type AppModuleBasic struct{}
    34  
    35  // Name returns the params module's name.
    36  func (AppModuleBasic) Name() string {
    37  	return proposal.ModuleName
    38  }
    39  
    40  // RegisterLegacyAminoCodec registers the params module's types on the given LegacyAmino codec.
    41  func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
    42  	proposal.RegisterLegacyAminoCodec(cdc)
    43  }
    44  
    45  // DefaultGenesis returns default genesis state as raw bytes for the params
    46  // module.
    47  func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage { return nil }
    48  
    49  // ValidateGenesis performs genesis state validation for the params module.
    50  func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, config client.TxEncodingConfig, _ json.RawMessage) error {
    51  	return nil
    52  }
    53  
    54  // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the params module.
    55  func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
    56  	if err := proposal.RegisterQueryHandlerClient(context.Background(), mux, proposal.NewQueryClient(clientCtx)); err != nil {
    57  		panic(err)
    58  	}
    59  }
    60  
    61  // GetTxCmd returns no root tx command for the params module.
    62  func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
    63  
    64  // GetQueryCmd returns no root query command for the params module.
    65  func (AppModuleBasic) GetQueryCmd() *cobra.Command {
    66  	return cli.NewQueryCmd()
    67  }
    68  
    69  func (am AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
    70  	proposal.RegisterInterfaces(registry)
    71  }
    72  
    73  // AppModule implements an application module for the distribution module.
    74  type AppModule struct {
    75  	AppModuleBasic
    76  
    77  	keeper keeper.Keeper
    78  }
    79  
    80  // NewAppModule creates a new AppModule object
    81  func NewAppModule(k keeper.Keeper) AppModule {
    82  	return AppModule{
    83  		AppModuleBasic: AppModuleBasic{},
    84  		keeper:         k,
    85  	}
    86  }
    87  
    88  func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
    89  
    90  // InitGenesis performs a no-op.
    91  func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate {
    92  	return []abci.ValidatorUpdate{}
    93  }
    94  
    95  func (AppModule) Route() sdk.Route { return sdk.Route{} }
    96  
    97  // GenerateGenesisState performs a no-op.
    98  func (AppModule) GenerateGenesisState(simState *module.SimulationState) {}
    99  
   100  // QuerierRoute returns the x/param module's querier route name.
   101  func (AppModule) QuerierRoute() string { return types.QuerierRoute }
   102  
   103  // LegacyQuerierHandler returns the x/params querier handler.
   104  func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
   105  	return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
   106  }
   107  
   108  // RegisterServices registers a gRPC query service to respond to the
   109  // module-specific gRPC queries.
   110  func (am AppModule) RegisterServices(cfg module.Configurator) {
   111  	proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper)
   112  
   113  	// m := keeper.NewMigrator(am.keeper)
   114  	// if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
   115  	// 	panic(fmt.Sprintf("failed to migrate x/params from version 1 to 2: %v", err))
   116  	// }
   117  }
   118  
   119  // ProposalContents returns all the params content functions used to
   120  // simulate governance proposals.
   121  func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
   122  	return simulation.ProposalContents(simState.ParamChanges)
   123  }
   124  
   125  // RandomizedParams creates randomized distribution param changes for the simulator.
   126  func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
   127  	return nil
   128  }
   129  
   130  // RegisterStoreDecoder doesn't register any type.
   131  func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {}
   132  
   133  // WeightedOperations returns the all the gov module operations with their respective weights.
   134  func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
   135  	return nil
   136  }
   137  
   138  // ExportGenesis performs a no-op.
   139  func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMessage {
   140  	return nil
   141  }
   142  
   143  // ConsensusVersion implements AppModule/ConsensusVersion.
   144  func (AppModule) ConsensusVersion() uint64 { return 1 }