Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: simplify AppModuleBasic interface for CLI #16890

Merged
merged 14 commits into from
Jul 10, 2023
14 changes: 8 additions & 6 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ type AppModuleBasic interface {

// client functionality
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
GetTxCmd() *cobra.Command
GetQueryCmd() *cobra.Command
}

// HasName allows the module to provide its own name for legacy purposes.
Expand Down Expand Up @@ -163,17 +161,21 @@ func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *
// AddTxCommands adds all tx commands to the rootTxCmd.
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
for _, b := range bm {
if cmd := b.GetTxCmd(); cmd != nil {
rootTxCmd.AddCommand(cmd)
if mod, ok := b.(interface {
GetTxCmd() *cobra.Command
Copy link
Member Author

@julienrbrt julienrbrt Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this replicates the behavior from the Core API Adapter:

func (c coreAppModuleBasicAdaptor) GetQueryCmd() *cobra.Command {
if mod, ok := c.module.(interface {
GetQueryCmd() *cobra.Command
}); ok {
return mod.GetQueryCmd()
}
return nil
}

}); ok {
rootTxCmd.AddCommand(mod.GetTxCmd())
}
}
}

// AddQueryCommands adds all query commands to the rootQueryCmd.
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) {
for _, b := range bm {
if cmd := b.GetQueryCmd(); cmd != nil {
rootQueryCmd.AddCommand(cmd)
if mod, ok := b.(interface {
GetQueryCmd() *cobra.Command
}); ok {
rootQueryCmd.AddCommand(mod.GetQueryCmd())
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions x/auth/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd(ab.ac)
}

// GetQueryCmd returns the module's root query command. Currently, this is a no-op.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// AppModule extends the AppModuleBasic implementation by implementing the
// AppModule interface.
type AppModule struct {
Expand Down
11 changes: 0 additions & 11 deletions x/consensus/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"google.golang.org/grpc"

modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
Expand Down Expand Up @@ -67,16 +66,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
}
}

// GetTxCmd returns the root tx command
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return nil
}

// GetQueryCmd returns no root query command
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
Expand Down
3 changes: 0 additions & 3 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ func (b AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// GetQueryCmd returns no root query command for the crisis module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }

// RegisterInterfaces registers interfaces and implementations of the crisis
// module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
Expand Down
5 changes: 0 additions & 5 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd(ab.ac)
}

// GetQueryCmd returns the root query command for the distribution module.
func (ab AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// RegisterInterfaces implements InterfaceModule
func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
Expand Down
5 changes: 0 additions & 5 deletions x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd(evidenceCLIHandlers)
}

// GetQueryCmd returns the evidence module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// RegisterInterfaces registers the evidence module's interface types
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
Expand Down
5 changes: 0 additions & 5 deletions x/feegrant/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd(ab.ac)
}

// GetQueryCmd returns no root query command for the feegrant module.
func (ab AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
Expand Down
7 changes: 0 additions & 7 deletions x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

modulev1 "cosmossdk.io/api/cosmos/genutil/module/v1"
"cosmossdk.io/core/appmodule"
Expand Down Expand Up @@ -68,12 +67,6 @@ func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, txEncodingConfig cl
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {
}

// GetTxCmd returns no root tx command for the genutil module.
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

// GetQueryCmd returns no root query command for the genutil module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }

// AppModule implements an application module for the genutil module.
type AppModule struct {
AppModuleBasic
Expand Down
5 changes: 0 additions & 5 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
// GetTxCmd returns no root tx command for the mint module.
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove as well?

// GetQueryCmd returns the root query command for the mint module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// AppModule implements an application module for the mint module.
type AppModule struct {
AppModuleBasic
Expand Down
3 changes: 0 additions & 3 deletions x/params/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
}
}

// GetTxCmd returns no root tx command for the params module.
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

// GetQueryCmd returns no root query command for the params module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.NewQueryCmd()
Expand Down
5 changes: 0 additions & 5 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// GetQueryCmd returns no root query command for the staking module.
func (ab AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

// AppModule implements an application module for the staking module.
type AppModule struct {
AppModuleBasic
Expand Down