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

Change GetQueryCmd to take client.Context #6326

Merged
merged 5 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa
- TxBuilder.Sign
- TxBuilder.SignStdTx
* (client) [\#6290](https://github.com/cosmos/cosmos-sdk/pull/6290) `CLIContext` is renamed to `Context`. `Context` and all related methods have been moved from package context to client.
* (modules) [\#6326](https://github.com/cosmos/cosmos-sdk/pull/6326) `AppModuleBasic.GetQueryCmd` now takes a single `CLIContext` parameter.

Migration guide:

Expand Down
6 changes: 5 additions & 1 deletion simapp/cmd/simcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ func queryCmd(cdc *codec.Codec) *cobra.Command {
)

// add modules' query commands
simapp.ModuleBasics.AddQueryCommands(queryCmd, cdc)
clientCtx := client.Context{}
clientCtx = clientCtx.
WithJSONMarshaler(appCodec).
WithCodec(cdc)
simapp.ModuleBasics.AddQueryCommands(queryCmd, clientCtx)

return queryCmd
}
Expand Down
14 changes: 7 additions & 7 deletions tests/mocks/tendermint_tm_db_DB.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions tests/mocks/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type AppModuleBasic interface {

// client functionality
RegisterRESTRoutes(client.Context, *mux.Router)
GetTxCmd(client.Context) *cobra.Command
GetQueryCmd(*codec.Codec) *cobra.Command
GetTxCmd(clientCtx client.Context) *cobra.Command
Copy link
Contributor

Choose a reason for hiding this comment

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

nit the package and type suffice for context, no need to add a variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
GetTxCmd(clientCtx client.Context) *cobra.Command
GetTxCmd(client.Context) *cobra.Command

GetQueryCmd(clientCtx client.Context) *cobra.Command
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
GetQueryCmd(clientCtx client.Context) *cobra.Command
GetQueryCmd(client.Context) *cobra.Command

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding the variable name is actually helpful when implementing the method using code completion because we wanted clientCtx rather than ctx. But I can remove it if you prefer

Copy link
Contributor

Choose a reason for hiding this comment

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

Where would one get ctx from? I'd opt to remove it personally. Not blocking though, so proceed at your own discretion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry it would be context. I'd prefer to keep it because it helped my IDE (goland) keep the style conventions from #6290.

}

// BasicManager is a collection of AppModuleBasic
Expand Down Expand Up @@ -113,9 +113,9 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, ctx client.Contex
}

// AddQueryCommands adds all query commands to the rootQueryCmd
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec) {
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, clientCtx client.Context) {
for _, b := range bm {
if cmd := b.GetQueryCmd(cdc); cmd != nil {
if cmd := b.GetQueryCmd(clientCtx); cmd != nil {
rootQueryCmd.AddCommand(cmd)
}
}
Expand Down
4 changes: 2 additions & 2 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestBasicManager(t *testing.T) {
mockAppModuleBasic1.EXPECT().RegisterRESTRoutes(gomock.Eq(client.Context{}), gomock.Eq(&mux.Router{})).Times(1)
mockAppModuleBasic1.EXPECT().RegisterCodec(gomock.Eq(cdc)).Times(1)
mockAppModuleBasic1.EXPECT().GetTxCmd(clientCtx).Times(1).Return(nil)
mockAppModuleBasic1.EXPECT().GetQueryCmd(cdc).Times(1).Return(nil)
mockAppModuleBasic1.EXPECT().GetQueryCmd(clientCtx).Times(1).Return(nil)

mm := module.NewBasicManager(mockAppModuleBasic1)
require.Equal(t, mm["mockAppModuleBasic1"], mockAppModuleBasic1)
Expand All @@ -55,7 +55,7 @@ func TestBasicManager(t *testing.T) {
mockCmd := &cobra.Command{Use: "root"}
mm.AddTxCommands(mockCmd, clientCtx)

mm.AddQueryCommands(mockCmd, cdc)
mm.AddQueryCommands(mockCmd, clientCtx)

// validate genesis returns nil
require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, wantDefaultGenesis))
Expand Down
4 changes: 2 additions & 2 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns the root query command for the auth module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx.Codec)
}

// RegisterInterfaceTypes registers interfaces and implementations of the auth module.
Expand Down
4 changes: 2 additions & 2 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns no root query command for the bank module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx.Codec)
}

// RegisterInterfaceTypes registers interfaces and implementations of the bank module.
Expand Down
2 changes: 1 addition & 1 deletion x/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
func (a AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil }

// GetQueryCmd returns the capability module's root query command.
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { return nil }

// ----------------------------------------------------------------------------
// AppModule
Expand Down
2 changes: 1 addition & 1 deletion x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (b AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns no root query command for the crisis module.
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { return nil }

//____________________________________________________________________________

Expand Down
4 changes: 2 additions & 2 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns the root query command for the distribution module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(StoreKey, clientCtx.Codec)
}

// RegisterInterfaceTypes implements InterfaceModule
Expand Down
4 changes: 2 additions & 2 deletions x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetTxCmd returns the evidence module's root query command.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(StoreKey, clientCtx.Codec)
}

func (AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) {
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil }

// GetQueryCmd returns no root query command for the genutil module.
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { return nil }

//____________________________________________________________________________

Expand Down
4 changes: 2 additions & 2 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns the root query command for the gov module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(StoreKey, clientCtx.Codec)
}

// RegisterInterfaceTypes implements InterfaceModule.RegisterInterfaceTypes
Expand Down
4 changes: 2 additions & 2 deletions x/ibc-transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd implements AppModuleBasic interface
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc, QuerierRoute)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx.Codec, QuerierRoute)
}

// RegisterInterfaceTypes registers module concrete types into protobuf Any.
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns no root query command for the ibc module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(QuerierRoute, cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(QuerierRoute, clientCtx.Codec)
}

// RegisterInterfaceTypes registers module concrete types into protobuf Any.
Expand Down
4 changes: 2 additions & 2 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil }

// GetQueryCmd returns the root query command for the mint module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx.Codec)
}

//____________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion x/params/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil }

// GetQueryCmd returns no root query command for the params module.
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { return nil }

func (am AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) {
proposal.RegisterInterfaces(registry)
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns no root query command for the slashing module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(StoreKey, clientCtx.Codec)
}

//____________________________________________________________________________
Expand Down
4 changes: 2 additions & 2 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
}

// GetQueryCmd returns no root query command for the staking module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(StoreKey, clientCtx.Codec)
}

//_____________________________________
Expand Down
6 changes: 3 additions & 3 deletions x/upgrade/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router
}

// GetQueryCmd returns the cli query commands for this module
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
queryCmd := &cobra.Command{
Use: "upgrade",
Short: "Querying commands for the upgrade module",
}
queryCmd.AddCommand(flags.GetCommands(
cli.GetPlanCmd(StoreKey, cdc),
cli.GetAppliedHeightCmd(StoreKey, cdc),
cli.GetPlanCmd(StoreKey, clientCtx.Codec),
cli.GetAppliedHeightCmd(StoreKey, clientCtx.Codec),
)...)

return queryCmd
Expand Down