From 41ed80646c8ec1df5eb442d33c42a73677896b51 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 21:46:07 -0400 Subject: [PATCH 1/7] Merge InterfaceModule into AppModuleBasic, add missing slashing and staking interface registrations --- simapp/encoding.go | 2 +- types/module/interface_module.go | 24 ------------------------ types/module/module.go | 10 ++++++++++ x/auth/module.go | 5 ++--- x/bank/module.go | 5 ++--- x/capability/module.go | 5 +++++ x/crisis/module.go | 4 ++-- x/distribution/module.go | 5 ++--- x/evidence/module.go | 3 +-- x/evidence/types/codec.go | 3 +++ x/genutil/module.go | 5 +++++ x/gov/module.go | 5 ++--- x/ibc-transfer/module.go | 4 ++-- x/ibc/module.go | 4 ++-- x/mint/module.go | 5 +++++ x/params/module.go | 3 +-- x/slashing/module.go | 7 +++++++ x/slashing/types/codec.go | 7 +++++++ x/staking/module.go | 5 +++++ x/staking/types/codec.go | 12 ++++++++++++ x/upgrade/module.go | 7 +++---- 21 files changed, 79 insertions(+), 51 deletions(-) delete mode 100644 types/module/interface_module.go diff --git a/simapp/encoding.go b/simapp/encoding.go index 7bb939bb777..120d1e74380 100644 --- a/simapp/encoding.go +++ b/simapp/encoding.go @@ -11,6 +11,6 @@ func MakeEncodingConfig() params.EncodingConfig { std.RegisterCodec(encodingConfig.Amino) std.RegisterInterfaces(encodingConfig.InterfaceRegistry) ModuleBasics.RegisterCodec(encodingConfig.Amino) - ModuleBasics.RegisterInterfaceModules(encodingConfig.InterfaceRegistry) + ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } diff --git a/types/module/interface_module.go b/types/module/interface_module.go deleted file mode 100644 index 69524d2d6bb..00000000000 --- a/types/module/interface_module.go +++ /dev/null @@ -1,24 +0,0 @@ -package module - -import ( - "github.com/cosmos/cosmos-sdk/codec/types" -) - -// InterfaceModule is an interface that modules can implement in order to -// register their interfaces and implementations in an InterfaceRegistry -type InterfaceModule interface { - RegisterInterfaceTypes(registry types.InterfaceRegistry) -} - -// RegisterInterfaceModules calls RegisterInterfaceTypes with the registry -// parameter on all of the modules which implement InterfaceModule in the manager -func (bm BasicManager) RegisterInterfaceModules(registry types.InterfaceRegistry) { - for _, m := range bm { - im, ok := m.(InterfaceModule) - if !ok { - continue - } - - im.RegisterInterfaceTypes(registry) - } -} diff --git a/types/module/module.go b/types/module/module.go index a344f7d6b39..5d9700f2469 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -31,6 +31,8 @@ package module import ( "encoding/json" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" @@ -48,6 +50,7 @@ import ( type AppModuleBasic interface { Name() string RegisterCodec(*codec.Codec) + RegisterInterfaces(registry types.InterfaceRegistry) DefaultGenesis(codec.JSONMarshaler) json.RawMessage ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error @@ -77,6 +80,13 @@ func (bm BasicManager) RegisterCodec(cdc *codec.Codec) { } } +// RegisterInterfaces registers all module interface types +func (bm BasicManager) RegisterInterfaces(registry types.InterfaceRegistry) { + for _, m := range bm { + m.RegisterInterfaces(registry) + } +} + // DefaultGenesis provides default genesis information for all modules func (bm BasicManager) DefaultGenesis(cdc codec.JSONMarshaler) map[string]json.RawMessage { genesis := make(map[string]json.RawMessage) diff --git a/x/auth/module.go b/x/auth/module.go index e6bf51f4963..7ca63827ed2 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -28,7 +28,6 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the auth module. @@ -75,8 +74,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } -// RegisterInterfaceTypes registers interfaces and implementations of the auth module. -func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +// RegisterInterfaces registers interfaces and implementations of the auth module. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/bank/module.go b/x/bank/module.go index f15ea158506..cafa7a0f7d3 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -27,7 +27,6 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the bank module. @@ -72,8 +71,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } -// RegisterInterfaceTypes registers interfaces and implementations of the bank module. -func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +// RegisterInterfaces registers interfaces and implementations of the bank module. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/capability/module.go b/x/capability/module.go index 70f7159d46e..06ee437103a 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -49,6 +51,9 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { types.RegisterCodec(cdc) } +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} + // DefaultGenesis returns the capability module's default genesis state. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { return cdc.MustMarshalJSON(types.DefaultGenesis()) diff --git a/x/crisis/module.go b/x/crisis/module.go index 975f2849cf7..40af92e03c7 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -64,9 +64,9 @@ func (b AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns no root query command for the crisis module. func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil } -// RegisterInterfaceTypes registers interfaces and implementations of the crisis +// RegisterInterfaces registers interfaces and implementations of the crisis // module. -func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/distribution/module.go b/x/distribution/module.go index 475d0e46b3b..fe20c76de22 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -29,7 +29,6 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the distribution module. @@ -78,8 +77,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } -// RegisterInterfaceTypes implements InterfaceModule -func (b AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { +// RegisterInterfaces implements InterfaceModule +func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/evidence/module.go b/x/evidence/module.go index d2331dceab4..5ef5bd17d9a 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -30,7 +30,6 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.InterfaceModule = AppModuleBasic{} ) // ---------------------------------------------------------------------------- @@ -101,7 +100,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } -func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index bee5be2cf9d..570c6b8e4fe 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -21,6 +21,9 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterInterface( "cosmos_sdk.evidence.v1.Evidence", (*exported.Evidence)(nil), + ) + registry.RegisterImplementations( + (*exported.Evidence)(nil), &Equivocation{}, ) } diff --git a/x/genutil/module.go b/x/genutil/module.go index dfc2d000736..69fb3208c73 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -32,6 +34,9 @@ func (AppModuleBasic) Name() string { // RegisterCodec registers the genutil module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} +// RegisterInterfaces registers the module's interface types +func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} + // DefaultGenesis returns default genesis state as raw bytes for the genutil // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { diff --git a/x/gov/module.go b/x/gov/module.go index ccc25331783..d0dcde556fe 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -32,7 +32,6 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the gov module. @@ -99,8 +98,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } -// RegisterInterfaceTypes implements InterfaceModule.RegisterInterfaceTypes -func (a AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +// RegisterInterfaces implements InterfaceModule.RegisterInterfaces +func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 0c73c089853..cb1c3629463 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -80,8 +80,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil } -// RegisterInterfaceTypes registers module concrete types into protobuf Any. -func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { +// RegisterInterfaces registers module concrete types into protobuf Any. +func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/ibc/module.go b/x/ibc/module.go index b1920fe3a76..34d16dd0ba0 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -78,8 +78,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } -// RegisterInterfaceTypes registers module concrete types into protobuf Any. -func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { +// RegisterInterfaces registers module concrete types into protobuf Any. +func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/mint/module.go b/x/mint/module.go index ef805706062..5a630f7074c 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -43,6 +45,9 @@ func (AppModuleBasic) Name() string { // RegisterCodec registers the mint module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} +// RegisterInterfaces registers the module's interface types +func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} + // DefaultGenesis returns default genesis state as raw bytes for the mint // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { diff --git a/x/params/module.go b/x/params/module.go index 0ed332c06fa..249e92e794d 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -27,7 +27,6 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the params module. @@ -61,7 +60,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.NewQueryCmd() } -func (am AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +func (am AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { proposal.RegisterInterfaces(registry) } diff --git a/x/slashing/module.go b/x/slashing/module.go index 8fbf4e462ec..08d3a0b2bb2 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" @@ -48,6 +50,11 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { types.RegisterCodec(cdc) } +// RegisterInterfaces registers the module's interface types +func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + // DefaultGenesis returns default genesis state as raw bytes for the slashing // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 5d52f7cb262..256e39f5aa7 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) // RegisterCodec registers concrete types on codec @@ -11,6 +12,12 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUnjail{}, + ) +} + var ( amino = codec.New() diff --git a/x/staking/module.go b/x/staking/module.go index bde3165f24f..0ff4b45bb48 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" @@ -46,6 +48,9 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { types.RegisterCodec(cdc) } +// RegisterInterfaces registers the module's interface types +func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} + // DefaultGenesis returns default genesis state as raw bytes for the staking // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 3f402945d6e..2e64a857d58 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) // RegisterCodec registers the necessary x/staking interfaces and concrete types @@ -16,6 +17,17 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) } +// RegisterInterfaces registers the x/staking interfaces types with the interface registry +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((sdk.Msg)(nil), + &MsgCreateValidator{}, + &MsgEditValidator{}, + &MsgDelegate{}, + &MsgUndelegate{}, + &MsgBeginRedelegate{}, + ) +} + var ( amino = codec.New() diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 015d780bc7c..c1ef30f73a4 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -29,9 +29,8 @@ func init() { } var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} - _ module.InterfaceModule = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} ) // AppModuleBasic implements the sdk.AppModuleBasic interface @@ -62,7 +61,7 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd() } -func (b AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { +func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } From f8dbde02b8d4da19695bf45bd0fa47400a492a83 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 21:52:33 -0400 Subject: [PATCH 2/7] Cleanup --- types/module/module.go | 7 +++---- x/evidence/types/codec.go | 3 --- x/genutil/module.go | 3 +-- x/mint/module.go | 3 +-- x/slashing/module.go | 3 +-- x/staking/module.go | 3 +-- 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 5d9700f2469..7f754ef9f17 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -31,8 +31,6 @@ package module import ( "encoding/json" - "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" @@ -41,6 +39,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -50,7 +49,7 @@ import ( type AppModuleBasic interface { Name() string RegisterCodec(*codec.Codec) - RegisterInterfaces(registry types.InterfaceRegistry) + RegisterInterfaces(registry codectypes.InterfaceRegistry) DefaultGenesis(codec.JSONMarshaler) json.RawMessage ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error @@ -81,7 +80,7 @@ func (bm BasicManager) RegisterCodec(cdc *codec.Codec) { } // RegisterInterfaces registers all module interface types -func (bm BasicManager) RegisterInterfaces(registry types.InterfaceRegistry) { +func (bm BasicManager) RegisterInterfaces(registry codectypes.InterfaceRegistry) { for _, m := range bm { m.RegisterInterfaces(registry) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 570c6b8e4fe..bee5be2cf9d 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -21,9 +21,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterInterface( "cosmos_sdk.evidence.v1.Evidence", (*exported.Evidence)(nil), - ) - registry.RegisterImplementations( - (*exported.Evidence)(nil), &Equivocation{}, ) } diff --git a/x/genutil/module.go b/x/genutil/module.go index 69fb3208c73..06f16c93d2e 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -13,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/types" diff --git a/x/mint/module.go b/x/mint/module.go index 5a630f7074c..e88ab00fc40 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -5,8 +5,6 @@ import ( "fmt" "math/rand" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -14,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" diff --git a/x/slashing/module.go b/x/slashing/module.go index 08d3a0b2bb2..c24f28bd9d1 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -5,8 +5,6 @@ import ( "fmt" "math/rand" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" @@ -16,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" diff --git a/x/staking/module.go b/x/staking/module.go index 0ff4b45bb48..25acd509ba8 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -5,8 +5,6 @@ import ( "fmt" "math/rand" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" @@ -15,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" From 57588fb87092df4371ebd4ca60a0ee45886b2ef4 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 21:54:11 -0400 Subject: [PATCH 3/7] Cleanup --- x/staking/module.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x/staking/module.go b/x/staking/module.go index 25acd509ba8..2b58af18ddd 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -48,7 +48,9 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { } // RegisterInterfaces registers the module's interface types -func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} +func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} // DefaultGenesis returns default genesis state as raw bytes for the staking // module. From fadd1b7393a116b05e7c3280f3dd8560895db7ba Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 21:56:36 -0400 Subject: [PATCH 4/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd6b203074..ff4b4cad4d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa * The `SigVerifiableTx` interface now has a `GetSignaturesV2() ([]signing.SignatureV2, error)` method and no longer has the `GetSignBytes` method. * (client/flags) [\#6632](https://github.com/cosmos/cosmos-sdk/pull/6632) Remove NewCompletionCmd(), the function is now available in tendermint. * (crypto) [\#6780](https://github.com/cosmos/cosmos-sdk/issues/6780) Move ledger code to its own package. +* (modules) [\#6834](https://github.com/cosmos/cosmos-sdk/issues/6834) Add `RegisterInterfaces` method to `AppModuleBasic` to support registration of protobuf interface types. ### Features From 14933fd21ade607ab74f7e1816c349a9b395969b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 21:57:33 -0400 Subject: [PATCH 5/7] Cleanup --- types/module/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/module.go b/types/module/module.go index 7f754ef9f17..a56842992b4 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -49,7 +49,7 @@ import ( type AppModuleBasic interface { Name() string RegisterCodec(*codec.Codec) - RegisterInterfaces(registry codectypes.InterfaceRegistry) + RegisterInterfaces(codectypes.InterfaceRegistry) DefaultGenesis(codec.JSONMarshaler) json.RawMessage ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error From cb1d6d4247c02efccf09671b76d151a9eceee143 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 22:22:34 -0400 Subject: [PATCH 6/7] Test fixes --- tests/mocks/tendermint_tm_db_DB.go | 14 +++--- tests/mocks/types_module_module.go | 69 +++++++++++++++++++++++------- x/staking/types/codec.go | 2 +- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/tests/mocks/tendermint_tm_db_DB.go b/tests/mocks/tendermint_tm_db_DB.go index bed59a498d0..cdf5e5ab0a2 100644 --- a/tests/mocks/tendermint_tm_db_DB.go +++ b/tests/mocks/tendermint_tm_db_DB.go @@ -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 } diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index d9ec3980b9a..947b750d942 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -8,12 +8,13 @@ import ( json "encoding/json" client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" - types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/codec/types" + types0 "github.com/cosmos/cosmos-sdk/types" grpc "github.com/gogo/protobuf/grpc" gomock "github.com/golang/mock/gomock" mux "github.com/gorilla/mux" cobra "github.com/spf13/cobra" - types0 "github.com/tendermint/tendermint/abci/types" + types1 "github.com/tendermint/tendermint/abci/types" reflect "reflect" ) @@ -66,6 +67,18 @@ func (mr *MockAppModuleBasicMockRecorder) RegisterCodec(arg0 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterCodec", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterCodec), arg0) } +// RegisterInterfaces mocks base method +func (m *MockAppModuleBasic) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces +func (mr *MockAppModuleBasicMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterInterfaces), arg0) +} + // DefaultGenesis mocks base method func (m *MockAppModuleBasic) DefaultGenesis(arg0 codec.JSONMarshaler) json.RawMessage { m.ctrl.T.Helper() @@ -183,6 +196,18 @@ func (mr *MockAppModuleGenesisMockRecorder) RegisterCodec(arg0 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterCodec", reflect.TypeOf((*MockAppModuleGenesis)(nil).RegisterCodec), arg0) } +// RegisterInterfaces mocks base method +func (m *MockAppModuleGenesis) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces +func (mr *MockAppModuleGenesisMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModuleGenesis)(nil).RegisterInterfaces), arg0) +} + // DefaultGenesis mocks base method func (m *MockAppModuleGenesis) DefaultGenesis(arg0 codec.JSONMarshaler) json.RawMessage { m.ctrl.T.Helper() @@ -252,10 +277,10 @@ func (mr *MockAppModuleGenesisMockRecorder) GetQueryCmd() *gomock.Call { } // InitGenesis mocks base method -func (m *MockAppModuleGenesis) InitGenesis(arg0 types.Context, arg1 codec.JSONMarshaler, arg2 json.RawMessage) []types0.ValidatorUpdate { +func (m *MockAppModuleGenesis) InitGenesis(arg0 types0.Context, arg1 codec.JSONMarshaler, arg2 json.RawMessage) []types1.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) - ret0, _ := ret[0].([]types0.ValidatorUpdate) + ret0, _ := ret[0].([]types1.ValidatorUpdate) return ret0 } @@ -266,7 +291,7 @@ func (mr *MockAppModuleGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interfa } // ExportGenesis mocks base method -func (m *MockAppModuleGenesis) ExportGenesis(arg0 types.Context, arg1 codec.JSONMarshaler) json.RawMessage { +func (m *MockAppModuleGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSONMarshaler) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -328,6 +353,18 @@ func (mr *MockAppModuleMockRecorder) RegisterCodec(arg0 interface{}) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterCodec", reflect.TypeOf((*MockAppModule)(nil).RegisterCodec), arg0) } +// RegisterInterfaces mocks base method +func (m *MockAppModule) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces +func (mr *MockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModule)(nil).RegisterInterfaces), arg0) +} + // DefaultGenesis mocks base method func (m *MockAppModule) DefaultGenesis(arg0 codec.JSONMarshaler) json.RawMessage { m.ctrl.T.Helper() @@ -397,10 +434,10 @@ func (mr *MockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { } // InitGenesis mocks base method -func (m *MockAppModule) InitGenesis(arg0 types.Context, arg1 codec.JSONMarshaler, arg2 json.RawMessage) []types0.ValidatorUpdate { +func (m *MockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONMarshaler, arg2 json.RawMessage) []types1.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) - ret0, _ := ret[0].([]types0.ValidatorUpdate) + ret0, _ := ret[0].([]types1.ValidatorUpdate) return ret0 } @@ -411,7 +448,7 @@ func (mr *MockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) * } // ExportGenesis mocks base method -func (m *MockAppModule) ExportGenesis(arg0 types.Context, arg1 codec.JSONMarshaler) json.RawMessage { +func (m *MockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONMarshaler) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -425,7 +462,7 @@ func (mr *MockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomo } // RegisterInvariants mocks base method -func (m *MockAppModule) RegisterInvariants(arg0 types.InvariantRegistry) { +func (m *MockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInvariants", arg0) } @@ -437,10 +474,10 @@ func (mr *MockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomoc } // Route mocks base method -func (m *MockAppModule) Route() types.Route { +func (m *MockAppModule) Route() types0.Route { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Route") - ret0, _ := ret[0].(types.Route) + ret0, _ := ret[0].(types0.Route) return ret0 } @@ -465,10 +502,10 @@ func (mr *MockAppModuleMockRecorder) QuerierRoute() *gomock.Call { } // NewQuerierHandler mocks base method -func (m *MockAppModule) NewQuerierHandler() types.Querier { +func (m *MockAppModule) NewQuerierHandler() types0.Querier { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NewQuerierHandler") - ret0, _ := ret[0].(types.Querier) + ret0, _ := ret[0].(types0.Querier) return ret0 } @@ -491,7 +528,7 @@ func (mr *MockAppModuleMockRecorder) RegisterQueryService(arg0 interface{}) *gom } // BeginBlock mocks base method -func (m *MockAppModule) BeginBlock(arg0 types.Context, arg1 types0.RequestBeginBlock) { +func (m *MockAppModule) BeginBlock(arg0 types0.Context, arg1 types1.RequestBeginBlock) { m.ctrl.T.Helper() m.ctrl.Call(m, "BeginBlock", arg0, arg1) } @@ -503,10 +540,10 @@ func (mr *MockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock. } // EndBlock mocks base method -func (m *MockAppModule) EndBlock(arg0 types.Context, arg1 types0.RequestEndBlock) []types0.ValidatorUpdate { +func (m *MockAppModule) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) - ret0, _ := ret[0].([]types0.ValidatorUpdate) + ret0, _ := ret[0].([]types1.ValidatorUpdate) return ret0 } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 2e64a857d58..57d77e15d17 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -19,7 +19,7 @@ func RegisterCodec(cdc *codec.Codec) { // RegisterInterfaces registers the x/staking interfaces types with the interface registry func RegisterInterfaces(registry types.InterfaceRegistry) { - registry.RegisterImplementations((sdk.Msg)(nil), + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgCreateValidator{}, &MsgEditValidator{}, &MsgDelegate{}, From 9f01d0e09e133e17e14c05af7733b5498e5e2e65 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 22:38:10 -0400 Subject: [PATCH 7/7] Add test --- types/module/module_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/module/module_test.go b/types/module/module_test.go index 91ad8d8596d..cc4fc9af326 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -5,6 +5,8 @@ import ( "errors" "testing" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/golang/mock/gomock" "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -24,6 +26,7 @@ func TestBasicManager(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) cdc := codec.New() + interfaceRegistry := types.NewInterfaceRegistry() clientCtx := client.Context{} clientCtx = clientCtx.WithCodec(cdc) wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)} @@ -35,6 +38,7 @@ func TestBasicManager(t *testing.T) { mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(wantDefaultGenesis["mockAppModuleBasic1"])).Times(1).Return(errFoo) mockAppModuleBasic1.EXPECT().RegisterRESTRoutes(gomock.Eq(client.Context{}), gomock.Eq(&mux.Router{})).Times(1) mockAppModuleBasic1.EXPECT().RegisterCodec(gomock.Eq(cdc)).Times(1) + mockAppModuleBasic1.EXPECT().RegisterInterfaces(gomock.Eq(interfaceRegistry)).Times(1) mockAppModuleBasic1.EXPECT().GetTxCmd().Times(1).Return(nil) mockAppModuleBasic1.EXPECT().GetQueryCmd().Times(1).Return(nil) @@ -42,6 +46,7 @@ func TestBasicManager(t *testing.T) { require.Equal(t, mm["mockAppModuleBasic1"], mockAppModuleBasic1) mm.RegisterCodec(cdc) + mm.RegisterInterfaces(interfaceRegistry) require.Equal(t, wantDefaultGenesis, mm.DefaultGenesis(cdc))