github.com/KiraCore/sekai@v0.3.43/x/gov/module.go (about)

     1  package gov
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  
     7  	"github.com/grpc-ecosystem/grpc-gateway/runtime"
     8  
     9  	"github.com/KiraCore/sekai/x/gov/client/cli"
    10  	"github.com/KiraCore/sekai/x/gov/keeper"
    11  	"github.com/KiraCore/sekai/x/gov/types"
    12  	abci "github.com/cometbft/cometbft/abci/types"
    13  	"github.com/cosmos/cosmos-sdk/client"
    14  	"github.com/cosmos/cosmos-sdk/codec"
    15  	codectypes "github.com/cosmos/cosmos-sdk/codec/types"
    16  	sdk "github.com/cosmos/cosmos-sdk/types"
    17  	"github.com/cosmos/cosmos-sdk/types/module"
    18  	"github.com/gorilla/mux"
    19  	"github.com/spf13/cobra"
    20  )
    21  
    22  var (
    23  	_ module.AppModule      = AppModule{}
    24  	_ module.AppModuleBasic = AppModuleBasic{}
    25  )
    26  
    27  type AppModuleBasic struct{}
    28  
    29  // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the staking module.
    30  func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
    31  }
    32  
    33  func (b AppModuleBasic) Name() string {
    34  	return types.ModuleName
    35  }
    36  
    37  func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
    38  	types.RegisterInterfaces(registry)
    39  }
    40  
    41  func (b AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
    42  	return cdc.MustMarshalJSON(types.DefaultGenesis())
    43  }
    44  
    45  func (b AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error {
    46  	return nil
    47  }
    48  
    49  func (b AppModuleBasic) RegisterRESTRoutes(context client.Context, router *mux.Router) {}
    50  
    51  func (b AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, serveMux *runtime.ServeMux) {
    52  	types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(clientCtx))
    53  }
    54  
    55  func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {}
    56  
    57  func (b AppModuleBasic) GetTxCmd() *cobra.Command {
    58  	return cli.NewTxCmd()
    59  }
    60  
    61  // GetQueryCmd implement query commands for this module
    62  func (b AppModuleBasic) GetQueryCmd() *cobra.Command {
    63  	return cli.NewQueryCmd()
    64  }
    65  
    66  // AppModule extends the cosmos SDK gov.
    67  type AppModule struct {
    68  	AppModuleBasic
    69  	customGovKeeper keeper.Keeper
    70  }
    71  
    72  // RegisterServices registers a GRPC query service to respond to the
    73  // module-specific GRPC queries.
    74  func (am AppModule) RegisterServices(cfg module.Configurator) {
    75  	types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.customGovKeeper))
    76  	types.RegisterQueryServer(cfg.QueryServer(), am.customGovKeeper)
    77  }
    78  
    79  func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
    80  	types.RegisterInterfaces(registry)
    81  }
    82  
    83  func (am AppModule) InitGenesis(
    84  	ctx sdk.Context,
    85  	cdc codec.JSONCodec,
    86  	data json.RawMessage,
    87  ) []abci.ValidatorUpdate {
    88  	var genesisState types.GenesisState
    89  	cdc.MustUnmarshalJSON(data, &genesisState)
    90  
    91  	InitGenesis(ctx, am.customGovKeeper, genesisState)
    92  	return nil
    93  }
    94  
    95  func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
    96  	gs := ExportGenesis(ctx, am.customGovKeeper)
    97  	return cdc.MustMarshalJSON(gs)
    98  }
    99  
   100  // ConsensusVersion implements AppModule/ConsensusVersion.
   101  func (AppModule) ConsensusVersion() uint64 { return 1 }
   102  
   103  func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {}
   104  
   105  func (am AppModule) QuerierRoute() string {
   106  	return types.QuerierRoute
   107  }
   108  
   109  func (am AppModule) BeginBlock(context sdk.Context, block abci.RequestBeginBlock) {}
   110  
   111  func (am AppModule) EndBlock(ctx sdk.Context, block abci.RequestEndBlock) []abci.ValidatorUpdate {
   112  	EndBlocker(ctx, am.customGovKeeper)
   113  
   114  	return []abci.ValidatorUpdate{}
   115  }
   116  
   117  func (am AppModule) Name() string {
   118  	return types.ModuleName
   119  }
   120  
   121  // NewAppModule returns a new Custom Staking module.
   122  func NewAppModule(
   123  	keeper keeper.Keeper,
   124  ) AppModule {
   125  	return AppModule{
   126  		customGovKeeper: keeper,
   127  	}
   128  }