From 9f0d0adf03081e363e14f670a61e7fa04ba3fd92 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:01:09 +0300 Subject: [PATCH] fix: amino messages registration --- x/bet/module.go | 7 +++---- x/bet/types/codec.go | 21 +++++++++++++++------ x/house/types/codec.go | 18 +++++++++++++----- x/market/module.go | 7 +------ x/market/types/codec.go | 25 +++++++++++++++++-------- x/mint/module.go | 7 +++---- x/mint/types/codec.go | 19 ++++++++++++++----- x/orderbook/module.go | 7 +++---- x/orderbook/types/codec.go | 20 +++++++++++++++----- x/ovm/module.go | 7 +++---- x/ovm/types/codec.go | 27 ++++++++++++++++----------- 11 files changed, 103 insertions(+), 62 deletions(-) diff --git a/x/bet/module.go b/x/bet/module.go index caf98dbc..420b2ef4 100644 --- a/x/bet/module.go +++ b/x/bet/module.go @@ -41,11 +41,10 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { return AppModuleB // Name returns the module's name. func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterCodec registers the codec for the app module basic -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } - // RegisterLegacyAminoCodec registers the legacy amino codec for the app module basic -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // RegisterInterfaces registers the module's interface types func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { diff --git a/x/bet/types/codec.go b/x/bet/types/codec.go index b09f7fac..41bd2245 100644 --- a/x/bet/types/codec.go +++ b/x/bet/types/codec.go @@ -2,15 +2,18 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) -// RegisterCodec registers module codec to the app codec -func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgWager{}, "bet/Wager", nil) +// RegisterLegacyAminoCodec registers the necessary x/bet interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgWager{}, "bet/Wager") } // RegisterInterfaces registers the module interface types @@ -23,8 +26,14 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - // Amino is the legacy amino codec - Amino = codec.NewLegacyAmino() + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() // ModuleCdc is the codec of the module - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewAminoCodec(amino) ) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/house/types/codec.go b/x/house/types/codec.go index 39be4517..d986bdc5 100644 --- a/x/house/types/codec.go +++ b/x/house/types/codec.go @@ -2,7 +2,9 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" @@ -12,8 +14,8 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/house interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgDeposit{}, "house/Deposit", nil) - cdc.RegisterConcrete(&MsgWithdraw{}, "house/Withdraw", nil) + legacy.RegisterAminoMsg(cdc, &MsgDeposit{}, "house/Deposit") + legacy.RegisterAminoMsg(cdc, &MsgWithdraw{}, "house/Withdraw") } // RegisterInterfaces registers the x/house interfaces types with the interface registry @@ -32,8 +34,14 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - // Amino is the legacy amino codec - Amino = codec.NewLegacyAmino() + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() // ModuleCdc is the codec of the module - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewAminoCodec(amino) ) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/market/module.go b/x/market/module.go index d1d1f2ba..e6f273e9 100644 --- a/x/market/module.go +++ b/x/market/module.go @@ -45,14 +45,9 @@ func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterCodec registers the codec for the app module basic -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} - // RegisterLegacyAminoCodec registers the legacy amino codec for the app module basic func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) + types.RegisterLegacyAminoCodec(cdc) } // RegisterInterfaces registers the module's interface types diff --git a/x/market/types/codec.go b/x/market/types/codec.go index bcee1258..85b30c9e 100644 --- a/x/market/types/codec.go +++ b/x/market/types/codec.go @@ -2,17 +2,20 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) -// RegisterCodec registers module codec to the app codec -func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgAdd{}, "market/Add", nil) - cdc.RegisterConcrete(&MsgResolve{}, "market/Resolve", nil) - cdc.RegisterConcrete(&MsgUpdate{}, "market/Update", nil) +// RegisterLegacyAminoCodec registers the necessary x/market interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgAdd{}, "market/Add") + legacy.RegisterAminoMsg(cdc, &MsgResolve{}, "market/Resolve") + legacy.RegisterAminoMsg(cdc, &MsgUpdate{}, "market/Update") } // RegisterInterfaces registers the module interface types @@ -32,8 +35,14 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - // Amino is the legacy amino codec - Amino = codec.NewLegacyAmino() + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() // ModuleCdc is the codec of the module - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewAminoCodec(amino) ) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/mint/module.go b/x/mint/module.go index 03291a48..1791116e 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -43,11 +43,10 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { // Name returns the module's name. func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterCodec registers the codec for the app module basic -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } - // RegisterLegacyAminoCodec registers the lagacy amino codec for the app module basic -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // RegisterInterfaces registers the module's interface types func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go index 5ff89ac6..e0313e08 100644 --- a/x/mint/types/codec.go +++ b/x/mint/types/codec.go @@ -3,11 +3,14 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) -// RegisterCodec registers module codec to the app codec -func RegisterCodec(_ *codec.LegacyAmino) { +// RegisterLegacyAminoCodec registers the necessary x/mint interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { // left empty because no message is available in this module } @@ -17,8 +20,14 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - // Amino is the legacy amino codec - Amino = codec.NewLegacyAmino() + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() // ModuleCdc is the codec of the module - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewAminoCodec(amino) ) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/orderbook/module.go b/x/orderbook/module.go index df3349e0..4c8324f6 100644 --- a/x/orderbook/module.go +++ b/x/orderbook/module.go @@ -41,11 +41,10 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { return AppModuleB // Name returns the orderbook module's name. func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterCodec registers the codec for the app module basic -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } - // RegisterLegacyAminoCodec registers the legacy amino codec for the app module basic -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // RegisterInterfaces registers the module's interface types func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { diff --git a/x/orderbook/types/codec.go b/x/orderbook/types/codec.go index 8d7c9841..5fb3ee9f 100644 --- a/x/orderbook/types/codec.go +++ b/x/orderbook/types/codec.go @@ -3,11 +3,15 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) -// RegisterCodec registers module codec to the app codec -func RegisterCodec(_ *codec.LegacyAmino) {} +// RegisterLegacyAminoCodec registers the necessary x/orderbook interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { + // left empty because no message is available in this module +} // RegisterInterfaces registers the module interface types func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -15,8 +19,14 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - // Amino is the legacy amino codec - Amino = codec.NewLegacyAmino() + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() // ModuleCdc is the codec of the module - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewAminoCodec(amino) ) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/ovm/module.go b/x/ovm/module.go index 91e29601..9c2c4110 100644 --- a/x/ovm/module.go +++ b/x/ovm/module.go @@ -39,11 +39,10 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { return AppModuleB // Name returns the module's name. func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterCodec registers the codec for the app module basic -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } - // RegisterLegacyAminoCodec registers the lagacy amino codec for the app module basic -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // RegisterInterfaces registers the module's interface types func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { diff --git a/x/ovm/types/codec.go b/x/ovm/types/codec.go index fd6118c8..f7578b24 100644 --- a/x/ovm/types/codec.go +++ b/x/ovm/types/codec.go @@ -2,19 +2,18 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) -// RegisterCodec registers module codec to the app codec -func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete( - &MsgSubmitPubkeysChangeProposalRequest{}, - "ovm/SubmitPubkeysChangeProposal", - nil, - ) - cdc.RegisterConcrete(&MsgVotePubkeysChangeRequest{}, "ovm/VotePubkeysChange", nil) +// RegisterLegacyAminoCodec registers the necessary x/ovm interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgSubmitPubkeysChangeProposalRequest{}, "ovm/SubmitPubkeysChangeProposal") + legacy.RegisterAminoMsg(cdc, &MsgVotePubkeysChangeRequest{}, "ovm/VotePubkeysChange") } // RegisterInterfaces registers the module interface types @@ -27,8 +26,14 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - // Amino is the legacy amino codec - Amino = codec.NewLegacyAmino() + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() // ModuleCdc is the codec of the module - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewAminoCodec(amino) ) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +}