From d39570d58d56c55f9979c1b9d5d18177a026fa8a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Jun 2023 17:27:33 +0200 Subject: [PATCH] remove app mobule basic --- go.mod | 2 +- module/module.go | 89 +++++++++++++++++------------------------------- 2 files changed, 32 insertions(+), 59 deletions(-) diff --git a/go.mod b/go.mod index 12c947d..1e166d6 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/cosmos/gogoproto v1.4.10 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 google.golang.org/genproto/googleapis/api v0.0.0-20230525234020-1aefcd67740a google.golang.org/grpc v1.56.1 @@ -123,6 +122,7 @@ require ( github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.16.0 // indirect diff --git a/module/module.go b/module/module.go index 1247f30..2b2bc55 100644 --- a/module/module.go +++ b/module/module.go @@ -7,7 +7,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -22,81 +21,40 @@ import ( // ConsensusVersion defines the current module consensus version. const ConsensusVersion = 1 -var ( - _ module.AppModuleGenesis = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} -) - -// AppModuleBasic defines the basic application module used by the module. -type AppModuleBasic struct { - cdc codec.Codec +type AppModule struct { + cdc codec.Codec + keeper keeper.Keeper } -// Name returns the module name. -func (AppModuleBasic) Name() string { return example.ModuleName } - -// RegisterLegacyAminoCodec registers the circuit module's types on the LegacyAmino codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - example.RegisterLegacyAminoCodec(cdc) +// NewAppModule creates a new AppModule object +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + cdc: cdc, + keeper: keeper, + } } -// DefaultGenesis returns default genesis state as raw bytes for the module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(example.NewGenesisState()) +func NewAppModuleBasic(m AppModule) module.AppModuleBasic { + return module.CoreAppModuleBasicAdaptor(example.ModuleName, m) } -// ValidateGenesis performs genesis state validation for the circuit module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { - var data example.GenesisState - if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", example.ModuleName, err) - } - - return data.Validate() +// RegisterLegacyAminoCodec registers the circuit module's types on the LegacyAmino codec. +func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + example.RegisterLegacyAminoCodec(cdc) } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the circuit module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { +func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { if err := example.RegisterQueryHandlerClient(context.Background(), mux, example.NewQueryClient(clientCtx)); err != nil { panic(err) } } -// GetTxCmd returns the root tx command for the module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - // Here we return nil to fulfill the interface, - // However, CLI commands will be created by AutoCLI - // Learn more about AutoCLI here: https://docs.cosmos.network/main/building-modules/autocli - return nil -} - -// GetQueryCmd returns no root query command for the circuit module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - // Here we return nil to fulfill the interface, - // However, CLI commands will be created by AutoCLI - // Learn more about AutoCLI here: https://docs.cosmos.network/main/building-modules/autocli - return nil -} - // RegisterInterfaces registers interfaces and implementations of the circuit module. -func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { +func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { example.RegisterInterfaces(registry) } -type AppModule struct { - AppModuleBasic - - keeper keeper.Keeper -} - -// NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { - return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, - keeper: keeper, - } -} - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } @@ -112,6 +70,21 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // } } +// DefaultGenesis returns default genesis state as raw bytes for the module. +func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(example.NewGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the circuit module. +func (AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data example.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", example.ModuleName, err) + } + + return data.Validate() +} + // InitGenesis performs genesis initialization for the example module. // It returns no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {