Skip to content

Commit

Permalink
remove app mobule basic
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jun 29, 2023
1 parent 2e4876d commit d39570d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 59 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
89 changes: 31 additions & 58 deletions module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }

Expand All @@ -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 {
Expand Down

0 comments on commit d39570d

Please sign in to comment.