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