Change GetQueryCmd to take client.Context (#6326)

* Change GetQueryCmd to take a client.Context

* Update CHANGELOG

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Aaron Craelius 2020-06-03 16:15:11 -04:00 committed by GitHub
parent 2e11c81668
commit fed0c2317d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 70 additions and 65 deletions

View File

@ -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:

View File

@ -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
}

View File

@ -6,7 +6,7 @@ package mocks
import (
gomock "github.com/golang/mock/gomock"
tm_db "github.com/tendermint/tm-db"
db "github.com/tendermint/tm-db"
reflect "reflect"
)
@ -106,10 +106,10 @@ func (mr *MockDBMockRecorder) Has(arg0 interface{}) *gomock.Call {
}
// Iterator mocks base method
func (m *MockDB) Iterator(arg0, arg1 []byte) (tm_db.Iterator, error) {
func (m *MockDB) Iterator(arg0, arg1 []byte) (db.Iterator, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Iterator", arg0, arg1)
ret0, _ := ret[0].(tm_db.Iterator)
ret0, _ := ret[0].(db.Iterator)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -121,10 +121,10 @@ func (mr *MockDBMockRecorder) Iterator(arg0, arg1 interface{}) *gomock.Call {
}
// NewBatch mocks base method
func (m *MockDB) NewBatch() tm_db.Batch {
func (m *MockDB) NewBatch() db.Batch {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewBatch")
ret0, _ := ret[0].(tm_db.Batch)
ret0, _ := ret[0].(db.Batch)
return ret0
}
@ -149,10 +149,10 @@ func (mr *MockDBMockRecorder) Print() *gomock.Call {
}
// ReverseIterator mocks base method
func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (tm_db.Iterator, error) {
func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (db.Iterator, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ReverseIterator", arg0, arg1)
ret0, _ := ret[0].(tm_db.Iterator)
ret0, _ := ret[0].(db.Iterator)
ret1, _ := ret[1].(error)
return ret0, ret1
}

View File

@ -106,31 +106,31 @@ func (mr *MockAppModuleBasicMockRecorder) RegisterRESTRoutes(arg0, arg1 interfac
}
// GetTxCmd mocks base method
func (m *MockAppModuleBasic) GetTxCmd(arg0 client.Context) *cobra.Command {
func (m *MockAppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTxCmd", arg0)
ret := m.ctrl.Call(m, "GetTxCmd", clientCtx)
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetTxCmd indicates an expected call of GetTxCmd
func (mr *MockAppModuleBasicMockRecorder) GetTxCmd(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleBasicMockRecorder) GetTxCmd(clientCtx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleBasic)(nil).GetTxCmd), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleBasic)(nil).GetTxCmd), clientCtx)
}
// GetQueryCmd mocks base method
func (m *MockAppModuleBasic) GetQueryCmd(arg0 *codec.Codec) *cobra.Command {
func (m *MockAppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetQueryCmd", arg0)
ret := m.ctrl.Call(m, "GetQueryCmd", clientCtx)
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetQueryCmd indicates an expected call of GetQueryCmd
func (mr *MockAppModuleBasicMockRecorder) GetQueryCmd(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleBasicMockRecorder) GetQueryCmd(clientCtx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleBasic)(nil).GetQueryCmd), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleBasic)(nil).GetQueryCmd), clientCtx)
}
// MockAppModuleGenesis is a mock of AppModuleGenesis interface
@ -223,31 +223,31 @@ func (mr *MockAppModuleGenesisMockRecorder) RegisterRESTRoutes(arg0, arg1 interf
}
// GetTxCmd mocks base method
func (m *MockAppModuleGenesis) GetTxCmd(arg0 client.Context) *cobra.Command {
func (m *MockAppModuleGenesis) GetTxCmd(clientCtx client.Context) *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTxCmd", arg0)
ret := m.ctrl.Call(m, "GetTxCmd", clientCtx)
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetTxCmd indicates an expected call of GetTxCmd
func (mr *MockAppModuleGenesisMockRecorder) GetTxCmd(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleGenesisMockRecorder) GetTxCmd(clientCtx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleGenesis)(nil).GetTxCmd), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleGenesis)(nil).GetTxCmd), clientCtx)
}
// GetQueryCmd mocks base method
func (m *MockAppModuleGenesis) GetQueryCmd(arg0 *codec.Codec) *cobra.Command {
func (m *MockAppModuleGenesis) GetQueryCmd(clientCtx client.Context) *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetQueryCmd", arg0)
ret := m.ctrl.Call(m, "GetQueryCmd", clientCtx)
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetQueryCmd indicates an expected call of GetQueryCmd
func (mr *MockAppModuleGenesisMockRecorder) GetQueryCmd(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleGenesisMockRecorder) GetQueryCmd(clientCtx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleGenesis)(nil).GetQueryCmd), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleGenesis)(nil).GetQueryCmd), clientCtx)
}
// InitGenesis mocks base method
@ -368,31 +368,31 @@ func (mr *MockAppModuleMockRecorder) RegisterRESTRoutes(arg0, arg1 interface{})
}
// GetTxCmd mocks base method
func (m *MockAppModule) GetTxCmd(arg0 client.Context) *cobra.Command {
func (m *MockAppModule) GetTxCmd(clientCtx client.Context) *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTxCmd", arg0)
ret := m.ctrl.Call(m, "GetTxCmd", clientCtx)
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetTxCmd indicates an expected call of GetTxCmd
func (mr *MockAppModuleMockRecorder) GetTxCmd(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleMockRecorder) GetTxCmd(clientCtx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModule)(nil).GetTxCmd), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModule)(nil).GetTxCmd), clientCtx)
}
// GetQueryCmd mocks base method
func (m *MockAppModule) GetQueryCmd(arg0 *codec.Codec) *cobra.Command {
func (m *MockAppModule) GetQueryCmd(clientCtx client.Context) *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetQueryCmd", arg0)
ret := m.ctrl.Call(m, "GetQueryCmd", clientCtx)
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetQueryCmd indicates an expected call of GetQueryCmd
func (mr *MockAppModuleMockRecorder) GetQueryCmd(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleMockRecorder) GetQueryCmd(clientCtx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModule)(nil).GetQueryCmd), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModule)(nil).GetQueryCmd), clientCtx)
}
// InitGenesis mocks base method

View File

@ -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
GetQueryCmd(clientCtx client.Context) *cobra.Command
}
// BasicManager is a collection of AppModuleBasic
@ -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)
}
}

View File

@ -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)
@ -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))

View File

@ -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.

View File

@ -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.

View File

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

View File

@ -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 }
//____________________________________________________________________________

View File

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

View File

@ -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) {

View File

@ -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 }
//____________________________________________________________________________

View File

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

View File

@ -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.

View File

@ -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.

View File

@ -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)
}
//____________________________________________________________________________

View File

@ -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)

View File

@ -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)
}
//____________________________________________________________________________

View File

@ -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)
}
//_____________________________________

View File

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