Skip to content

Commit

Permalink
feat!: simplify AppModuleBasic interface for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jul 9, 2023
1 parent 864ce72 commit adb03ec
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 60 deletions.
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
}); 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 }

// 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

0 comments on commit adb03ec

Please sign in to comment.