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

Fix module interface registration #6834

Merged
merged 7 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -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

Expand Down
2 changes: 1 addition & 1 deletion simapp/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 0 additions & 24 deletions types/module/interface_module.go

This file was deleted.

9 changes: 9 additions & 0 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,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"
)

Expand All @@ -48,6 +49,7 @@ import (
type AppModuleBasic interface {
Name() string
RegisterCodec(*codec.Codec)
RegisterInterfaces(codectypes.InterfaceRegistry)

DefaultGenesis(codec.JSONMarshaler) json.RawMessage
ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error
Expand Down Expand Up @@ -77,6 +79,13 @@ func (bm BasicManager) RegisterCodec(cdc *codec.Codec) {
}
}

// RegisterInterfaces registers all module interface types
func (bm BasicManager) RegisterInterfaces(registry codectypes.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)
Expand Down
5 changes: 2 additions & 3 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 2 additions & 3 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions x/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 2 additions & 3 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ module.InterfaceModule = AppModuleBasic{}
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,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"
Expand All @@ -32,6 +33,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 {
Expand Down
5 changes: 2 additions & 3 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

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

Expand Down
4 changes: 2 additions & 2 deletions x/ibc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,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"
Expand Down Expand Up @@ -43,6 +44,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 {
Expand Down
3 changes: 1 addition & 2 deletions x/params/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions x/slashing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,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"
Expand Down Expand Up @@ -48,6 +49,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 {
Expand Down
7 changes: 7 additions & 0 deletions x/slashing/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ 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
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()

Expand Down
6 changes: 6 additions & 0 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,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"
Expand Down Expand Up @@ -46,6 +47,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 staking
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
Expand Down
12 changes: 12 additions & 0 deletions x/staking/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
7 changes: 3 additions & 4 deletions x/upgrade/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down