Skip to content

Commit

Permalink
feat(types/module): add deprecation panics on unsupported apis (#21512)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 3, 2024
1 parent e3d8378 commit 50b2254
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
storetypes "cosmossdk.io/store/types"

"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"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -293,7 +295,11 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) {

// RegisterLegacyAminoCodec registers all module codecs
func (m *Manager) RegisterLegacyAminoCodec(cdc legacy.Amino) {
for _, b := range m.Modules {
for name, b := range m.Modules {
if _, ok := b.(interface{ RegisterLegacyAminoCodec(*codec.LegacyAmino) }); ok {
panic(fmt.Sprintf("%s uses a deprecated amino registration api, implement HasAminoCodec instead if necessary", name))
}

if mod, ok := b.(HasAminoCodec); ok {
mod.RegisterLegacyAminoCodec(cdc)
}
Expand All @@ -302,7 +308,13 @@ func (m *Manager) RegisterLegacyAminoCodec(cdc legacy.Amino) {

// RegisterInterfaces registers all module interface types
func (m *Manager) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
for _, b := range m.Modules {
for name, b := range m.Modules {
if _, ok := b.(interface {
RegisterInterfaces(cdctypes.InterfaceRegistry)
}); ok {
panic(fmt.Sprintf("%s uses a deprecated interface registration api, implement appmodule.HasRegisterInterfaces instead", name))
}

if mod, ok := b.(appmodule.HasRegisterInterfaces); ok {
mod.RegisterInterfaces(registrar)
}
Expand Down

0 comments on commit 50b2254

Please sign in to comment.