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

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