diff --git a/CHANGELOG.md b/CHANGELOG.md index eb6f9151ac6e..74d8a9a80452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#11006](https://github.com/cosmos/cosmos-sdk/pull/11006) Add `debug pubkey-raw` command to allow inspecting of pubkeys in legacy bech32 format * (x/authz) [\#10714](https://github.com/cosmos/cosmos-sdk/pull/10714) Add support for pruning expired authorizations * [\#10015](https://github.com/cosmos/cosmos-sdk/pull/10015) ADR-040: ICS-23 proofs for SMT store +* [\#11240](https://github.com/cosmos/cosmos-sdk/pull/11240) Replace various modules `ModuleCdc` with the global `legacy.Cdc` ### API Breaking Changes diff --git a/codec/legacy/codec.go b/codec/legacy/codec.go index d5d9a686c576..0bc2e74993b8 100644 --- a/codec/legacy/codec.go +++ b/codec/legacy/codec.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // Cdc defines a global generic sealed Amino codec to be used throughout sdk. It @@ -15,6 +16,7 @@ var Cdc = codec.NewLegacyAmino() func init() { cryptocodec.RegisterCrypto(Cdc) codec.RegisterEvidences(Cdc) + sdk.RegisterLegacyAminoCodec(Cdc) } // PrivKeyFromBytes unmarshals private key bytes and returns a PrivKey diff --git a/x/auth/middleware/sigverify_test.go b/x/auth/middleware/sigverify_test.go index 01e8898336c7..a0c68062a968 100644 --- a/x/auth/middleware/sigverify_test.go +++ b/x/auth/middleware/sigverify_test.go @@ -207,7 +207,6 @@ func (s *MWTestSuite) TestSigVerification_ExplicitAmino() { // Set up TxConfig. aminoCdc := legacy.Cdc - aminoCdc.RegisterInterface((*sdk.Msg)(nil), nil) aminoCdc.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) // We're using TestMsg amino encoding in some tests, so register it here. diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 1f1603fc752c..fa8f0589fcfb 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) @@ -38,16 +37,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { ) } -var ( - amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 6cd11a27b566..616978cb0aaf 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -61,9 +62,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var amino = codec.NewLegacyAmino() - func init() { - RegisterLegacyAminoCodec(amino) - amino.Seal() + RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index 8f7150014c33..0948daac702b 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -67,7 +68,7 @@ func (msg MsgCreateVestingAccount) ValidateBasic() error { // GetSignBytes returns the bytes all expected signers must sign over for a // MsgCreateVestingAccount. func (msg MsgCreateVestingAccount) GetSignBytes() []byte { - return sdk.MustSortJSON(amino.MustMarshalJSON(&msg)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } // GetSigners returns the expected signers for a MsgCreateVestingAccount. @@ -77,52 +78,52 @@ func (msg MsgCreateVestingAccount) GetSigners() []sdk.AccAddress { } // NewMsgCreatePermanentLockedAccount returns a reference to a new MsgCreatePermanentLockedAccount. - //nolint:interfacer - func NewMsgCreatePermanentLockedAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgCreatePermanentLockedAccount { - return &MsgCreatePermanentLockedAccount{ - FromAddress: fromAddr.String(), - ToAddress: toAddr.String(), - Amount: amount, - } - } - - // Route returns the message route for a MsgCreatePermanentLockedAccount. - func (msg MsgCreatePermanentLockedAccount) Route() string { return RouterKey } - - // Type returns the message type for a MsgCreatePermanentLockedAccount. - func (msg MsgCreatePermanentLockedAccount) Type() string { return TypeMsgCreatePermanentLockedAccount } - - // ValidateBasic Implements Msg. - func (msg MsgCreatePermanentLockedAccount) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err) - } - if _, err := sdk.AccAddressFromBech32(msg.ToAddress); err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid recipient address: %s", err) - } - - if !msg.Amount.IsValid() { - return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String()) - } - - if !msg.Amount.IsAllPositive() { - return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String()) - } - - return nil - } - - // GetSignBytes returns the bytes all expected signers must sign over for a - // MsgCreatePermanentLockedAccount. - func (msg MsgCreatePermanentLockedAccount) GetSignBytes() []byte { - return sdk.MustSortJSON(amino.MustMarshalJSON(&msg)) - } - - // GetSigners returns the expected signers for a MsgCreatePermanentLockedAccount. - func (msg MsgCreatePermanentLockedAccount) GetSigners() []sdk.AccAddress { - from, _ := sdk.AccAddressFromBech32(msg.FromAddress) - return []sdk.AccAddress{from} - } +//nolint:interfacer +func NewMsgCreatePermanentLockedAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgCreatePermanentLockedAccount { + return &MsgCreatePermanentLockedAccount{ + FromAddress: fromAddr.String(), + ToAddress: toAddr.String(), + Amount: amount, + } +} + +// Route returns the message route for a MsgCreatePermanentLockedAccount. +func (msg MsgCreatePermanentLockedAccount) Route() string { return RouterKey } + +// Type returns the message type for a MsgCreatePermanentLockedAccount. +func (msg MsgCreatePermanentLockedAccount) Type() string { return TypeMsgCreatePermanentLockedAccount } + +// ValidateBasic Implements Msg. +func (msg MsgCreatePermanentLockedAccount) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err) + } + if _, err := sdk.AccAddressFromBech32(msg.ToAddress); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid recipient address: %s", err) + } + + if !msg.Amount.IsValid() { + return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String()) + } + + if !msg.Amount.IsAllPositive() { + return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String()) + } + + return nil +} + +// GetSignBytes returns the bytes all expected signers must sign over for a +// MsgCreatePermanentLockedAccount. +func (msg MsgCreatePermanentLockedAccount) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) +} + +// GetSigners returns the expected signers for a MsgCreatePermanentLockedAccount. +func (msg MsgCreatePermanentLockedAccount) GetSigners() []sdk.AccAddress { + from, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{from} +} // NewMsgCreatePeriodicVestingAccount returns a reference to a new MsgCreatePeriodicVestingAccount. //nolint:interfacer @@ -153,7 +154,7 @@ func (msg MsgCreatePeriodicVestingAccount) GetSigners() []sdk.AccAddress { // GetSignBytes returns the bytes all expected signers must sign over for a // MsgCreatePeriodicVestingAccount. func (msg MsgCreatePeriodicVestingAccount) GetSignBytes() []byte { - return sdk.MustSortJSON(amino.MustMarshalJSON(&msg)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } // ValidateBasic Implements Msg. diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index f50c2b944885..77ad02ff2c76 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -1,6 +1,7 @@ package simulation_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/rand" "testing" @@ -80,7 +81,7 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { suite.Require().NoError(err) var msg types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("65337742stake", msg.Amount.String()) @@ -109,7 +110,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require.NoError(err) var msg types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Len(msg.Inputs, 3) @@ -146,7 +147,7 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { suite.Require().Error(err) var msg types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") @@ -175,7 +176,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { suite.Require().Error(err) var msg types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail suite.Require().Equal(operationMsg.Comment, "invalid transfers") diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 62e6b4fe1568..c25d3cebaecd 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "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" "github.com/cosmos/cosmos-sdk/x/authz" @@ -31,24 +30,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/bank module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/staking and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - amino.Seal() - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 8030e04519f3..f04433a6bb14 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -48,7 +49,7 @@ func (msg MsgSend) ValidateBasic() error { // GetSignBytes Implements Msg. func (msg MsgSend) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } // GetSigners Implements Msg. @@ -87,7 +88,7 @@ func (msg MsgMultiSend) ValidateBasic() error { // GetSignBytes Implements Msg. func (msg MsgMultiSend) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } // GetSigners Implements Msg. diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 67e32f4cee53..56b8c1cfa7cb 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "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" ) @@ -23,24 +22,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/crisis module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/crisis and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - amino.Seal() - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index a5450b010e7f..bd9c60e936d9 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -29,7 +30,7 @@ func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress { // GetSignBytes gets the sign bytes for the msg MsgVerifyInvariant func (msg MsgVerifyInvariant) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/distribution/client/common/common_test.go b/x/distribution/client/common/common_test.go index 6b3ecdd5cdfb..3a6cf8c9b547 100644 --- a/x/distribution/client/common/common_test.go +++ b/x/distribution/client/common/common_test.go @@ -1,16 +1,16 @@ package common import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" "testing" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/x/distribution/types" ) func TestQueryDelegationRewardsAddrValidation(t *testing.T) { - clientCtx := client.Context{}.WithLegacyAmino(types.ModuleCdc.LegacyAmino) + clientCtx := client.Context{}.WithLegacyAmino(legacy.Cdc) type args struct { delAddr string diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 4d70aab2eacf..bc902a0f1f6b 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -1,6 +1,7 @@ package simulation_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/rand" "testing" @@ -73,7 +74,7 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { suite.Require().NoError(err) var msg types.MsgSetWithdrawAddress - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) @@ -114,7 +115,7 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { suite.Require().NoError(err) var msg types.MsgWithdrawDelegatorReward - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) @@ -175,7 +176,7 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName suite.Require().NoError(err) var msg types.MsgWithdrawValidatorCommission - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) @@ -202,7 +203,7 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { suite.Require().NoError(err) var msg types.MsgFundCommunityPool - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index bf82ebcf0d3b..c528ba539b19 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "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" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -36,24 +35,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/distribution module codec. Note, the codec - // should ONLY be used in certain instances of tests and for JSON encoding as Amino - // is still used for that purpose. - // - // The actual codec used for serialization should be provided to x/distribution and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - amino.Seal() - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index 2071ca0282e8..5f7b9b371075 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -34,7 +35,7 @@ func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { // get the bytes for the message signer to sign on func (msg MsgSetWithdrawAddress) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -68,7 +69,7 @@ func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress { // get the bytes for the message signer to sign on func (msg MsgWithdrawDelegatorReward) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -100,7 +101,7 @@ func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress { // get the bytes for the message signer to sign on func (msg MsgWithdrawValidatorCommission) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -137,7 +138,7 @@ func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress { // GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that // the expected signer needs to sign. func (msg MsgFundCommunityPool) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/distribution/types/proposal.go b/x/distribution/types/proposal.go index b903014a8255..a60291b9eb24 100644 --- a/x/distribution/types/proposal.go +++ b/x/distribution/types/proposal.go @@ -18,7 +18,6 @@ var _ govtypes.Content = &CommunityPoolSpendProposal{} func init() { govtypes.RegisterProposalType(ProposalTypeCommunityPoolSpend) - govtypes.RegisterProposalTypeCodec(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal") } // NewCommunityPoolSpendProposal creates a new community pool spend proposal. diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 45644588b43b..915b1f101af6 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "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" "github.com/cosmos/cosmos-sdk/x/evidence/exported" @@ -29,24 +28,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/evidence module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/evidence and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - amino.Seal() - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index 89b0d414d05d..6227040fd4e9 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/gogo/protobuf/proto" @@ -62,7 +63,7 @@ func (m MsgSubmitEvidence) ValidateBasic() error { // GetSignBytes returns the raw bytes a signer is expected to sign when submitting // a MsgSubmitEvidence message. func (m MsgSubmitEvidence) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the single expected signer for a MsgSubmitEvidence. diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index fa0c4b4dcce4..19cba5221cdf 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -2,6 +2,7 @@ package simulation_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/rand" "testing" "time" @@ -116,7 +117,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.NoError(t, err) var msg v1beta2.MsgSubmitProposal - err = types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -163,7 +164,7 @@ func TestSimulateMsgDeposit(t *testing.T) { require.NoError(t, err) var msg v1beta2.MsgDeposit - err = types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -209,7 +210,7 @@ func TestSimulateMsgVote(t *testing.T) { require.NoError(t, err) var msg v1beta2.MsgVote - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) @@ -252,7 +253,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { require.NoError(t, err) var msg v1beta2.MsgVoteWeighted - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) diff --git a/x/gov/types/codec.go b/x/gov/types/codec.go deleted file mode 100644 index 2aec985558be..000000000000 --- a/x/gov/types/codec.go +++ /dev/null @@ -1,27 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/gov module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/gov and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - -func init() { - cryptocodec.RegisterCrypto(amino) - sdk.RegisterLegacyAminoCodec(amino) - - // v1beta1 and v1beta2 will each add their own Amino registrations inside - // their init() functions. -} diff --git a/x/gov/types/v1beta1/codec.go b/x/gov/types/v1beta1/codec.go index 721daecaa7f0..fabc3482f97e 100644 --- a/x/gov/types/v1beta1/codec.go +++ b/x/gov/types/v1beta1/codec.go @@ -6,7 +6,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/cosmos-sdk/x/gov/types" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -36,20 +35,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -// RegisterProposalTypeCodec registers an external proposal content type defined -// in another module for the internal ModuleCdc. This allows the MsgSubmitProposal -// to be correctly Amino encoded and decoded. -// -// NOTE: This should only be used for applications that are still using a concrete -// Amino codec for serialization. -func RegisterProposalTypeCodec(o interface{}, name string) { - types.ModuleCdc.LegacyAmino.RegisterConcrete(o, name, nil) -} - func init() { - RegisterLegacyAminoCodec(types.ModuleCdc.LegacyAmino) - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index d111e5bc6bd0..3fc309577b3c 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -2,6 +2,7 @@ package v1beta1 import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/gogo/protobuf/proto" "sigs.k8s.io/yaml" @@ -109,7 +110,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { // GetSignBytes implements Msg func (m MsgSubmitProposal) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&m) + bz := legacy.Cdc.MustMarshalJSON(&m) return sdk.MustSortJSON(bz) } @@ -166,7 +167,7 @@ func (msg MsgDeposit) String() string { // GetSignBytes implements Msg func (msg MsgDeposit) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -208,7 +209,7 @@ func (msg MsgVote) String() string { // GetSignBytes implements Msg func (msg MsgVote) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -271,7 +272,7 @@ func (msg MsgVoteWeighted) String() string { // GetSignBytes implements Msg func (msg MsgVoteWeighted) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/gov/types/v1beta2/codec.go b/x/gov/types/v1beta2/codec.go index a2403f8e5428..ca315e87cae9 100644 --- a/x/gov/types/v1beta2/codec.go +++ b/x/gov/types/v1beta2/codec.go @@ -6,7 +6,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/cosmos-sdk/x/gov/types" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -32,9 +31,5 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { } func init() { - RegisterLegacyAminoCodec(types.ModuleCdc.LegacyAmino) - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/gov/types/v1beta2/msgs.go b/x/gov/types/v1beta2/msgs.go index 3da6965e02bc..2929d339e4f2 100644 --- a/x/gov/types/v1beta2/msgs.go +++ b/x/gov/types/v1beta2/msgs.go @@ -2,6 +2,7 @@ package v1beta2 import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -81,7 +82,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { // GetSignBytes implements Msg func (m MsgSubmitProposal) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&m) + bz := legacy.Cdc.MustMarshalJSON(&m) return sdk.MustSortJSON(bz) } @@ -126,7 +127,7 @@ func (msg MsgDeposit) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgDeposit) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -162,7 +163,7 @@ func (msg MsgVote) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgVote) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -223,7 +224,7 @@ func (msg MsgVoteWeighted) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgVoteWeighted) GetSignBytes() []byte { - bz := types.ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/group/codec.go b/x/group/codec.go index 2c1f36ba141c..ab588e3d3a83 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -57,15 +57,6 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { ) } -var ( - amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/group/msgs.go b/x/group/msgs.go index d97340f2ff0c..38982d847210 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -3,6 +3,8 @@ package group import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy" + proto "github.com/gogo/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec/types" @@ -23,7 +25,7 @@ func (m MsgCreateGroup) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgCreateGroup) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgCreateGroup. @@ -79,7 +81,7 @@ func (m MsgUpdateGroupAdmin) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupAdmin. @@ -129,7 +131,7 @@ func (m MsgUpdateGroupMetadata) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupMetadata. @@ -171,7 +173,7 @@ func (m MsgUpdateGroupMembers) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupMembers) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } var _ sdk.Msg = &MsgUpdateGroupMembers{} @@ -268,7 +270,7 @@ func (m MsgCreateGroupWithPolicy) Type() string { // GetSignBytes Implements Msg. func (m MsgCreateGroupWithPolicy) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgCreateGroupWithPolicy. @@ -318,7 +320,7 @@ func (m MsgCreateGroupPolicy) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgCreateGroupPolicy) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgCreateGroupPolicy. @@ -363,7 +365,7 @@ func (m MsgUpdateGroupPolicyAdmin) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyAdmin) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupPolicyAdmin. @@ -438,7 +440,7 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) Type() string { // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyDecisionPolicy) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupPolicyDecisionPolicy. @@ -500,7 +502,7 @@ func (m MsgUpdateGroupPolicyMetadata) Type() string { return sdk.MsgTypeURL(&m) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyMetadata) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupPolicyMetadata. @@ -610,7 +612,7 @@ func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgSubmitProposal) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgSubmitProposal. @@ -691,7 +693,7 @@ func (m MsgWithdrawProposal) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgWithdrawProposal) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgWithdrawProposal. @@ -729,7 +731,7 @@ func (m MsgVote) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgVote) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgVote. @@ -771,7 +773,7 @@ func (m MsgExec) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgExec) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgExec. diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 48aea7d51933..b84fff53379c 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -1,6 +1,7 @@ package simulation_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/rand" "testing" "time" @@ -114,7 +115,7 @@ func (suite *SimTestSuite) TestSimulateCreateGroup() { suite.Require().NoError(err) var msg group.MsgCreateGroup - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -143,7 +144,7 @@ func (suite *SimTestSuite) TestSimulateCreateGroupWithPolicy() { suite.Require().NoError(err) var msg group.MsgCreateGroupWithPolicy - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -185,7 +186,7 @@ func (suite *SimTestSuite) TestSimulateCreateGroupPolicy() { suite.Require().NoError(err) var msg group.MsgCreateGroupPolicy - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -239,7 +240,7 @@ func (suite *SimTestSuite) TestSimulateSubmitProposal() { suite.Require().NoError(err) var msg group.MsgSubmitProposal - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.Address) @@ -306,7 +307,7 @@ func (suite *SimTestSuite) TestWithdrawProposal() { suite.Require().NoError(err) var msg group.MsgWithdrawProposal - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(addr, msg.Address) @@ -373,7 +374,7 @@ func (suite *SimTestSuite) TestSimulateVote() { suite.Require().NoError(err) var msg group.MsgVote - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(addr, msg.Voter) @@ -448,7 +449,7 @@ func (suite *SimTestSuite) TestSimulateExec() { suite.Require().NoError(err) var msg group.MsgExec - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(addr, msg.Signer) @@ -490,7 +491,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupAdmin() { suite.Require().NoError(err) var msg group.MsgUpdateGroupAdmin - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -532,7 +533,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupMetadata() { suite.Require().NoError(err) var msg group.MsgUpdateGroupMetadata - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -574,7 +575,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupMembers() { suite.Require().NoError(err) var msg group.MsgUpdateGroupMembers - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -628,7 +629,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyAdmin() { suite.Require().NoError(err) var msg group.MsgUpdateGroupPolicyAdmin - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.Address) @@ -682,7 +683,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyDecisionPolicy() { suite.Require().NoError(err) var msg group.MsgUpdateGroupPolicyDecisionPolicy - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.Address) @@ -736,7 +737,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyMetadata() { suite.Require().NoError(err) var msg group.MsgUpdateGroupPolicyMetadata - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.Address) diff --git a/x/params/types/proposal/proposal.go b/x/params/types/proposal/proposal.go index f25ab0ed0b1b..55c65afa4e4b 100644 --- a/x/params/types/proposal/proposal.go +++ b/x/params/types/proposal/proposal.go @@ -19,7 +19,6 @@ var _ govtypes.Content = &ParameterChangeProposal{} func init() { govtypes.RegisterProposalType(ProposalTypeChange) - govtypes.RegisterProposalTypeCodec(&ParameterChangeProposal{}, "cosmos-sdk/ParameterChangeProposal") } func NewParameterChangeProposal(title, description string, changes []ParamChange) *ParameterChangeProposal { diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index a0dbffb1f360..25b1473e4b1b 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -1,6 +1,7 @@ package simulation_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/rand" "testing" "time" @@ -99,7 +100,7 @@ func TestSimulateMsgUnjail(t *testing.T) { require.NoError(t, err) var msg types.MsgUnjail - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, types.TypeMsgUnjail, msg.Type()) diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index d56869d38088..7ac9b8643c48 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "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" ) @@ -22,24 +21,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/slashing module codec. Note, the codec - // should ONLY be used in certain instances of tests and for JSON encoding as Amino - // is still used for that purpose. - // - // The actual codec used for serialization should be provided to x/slashing and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - amino.Seal() - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 91a15f72dbd4..374f0c3dd32c 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -30,7 +31,7 @@ func (msg MsgUnjail) GetSigners() []sdk.AccAddress { // GetSignBytes gets the bytes for the message signer to sign on func (msg MsgUnjail) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 8c1ee9ec152e..ae93cf79008a 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -1,6 +1,7 @@ package simulation_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/big" "math/rand" "testing" @@ -80,7 +81,7 @@ func TestSimulateMsgCreateValidator(t *testing.T) { require.NoError(t, err) var msg types.MsgCreateValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, "0.080000000000000000", msg.Commission.MaxChangeRate.String()) @@ -117,7 +118,7 @@ func TestSimulateMsgEditValidator(t *testing.T) { require.NoError(t, err) var msg types.MsgEditValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, "0.280623462081924936", msg.CommissionRate.String()) @@ -146,7 +147,7 @@ func TestSimulateMsgDelegate(t *testing.T) { require.NoError(t, err) var msg types.MsgDelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) @@ -192,7 +193,7 @@ func TestSimulateMsgUndelegate(t *testing.T) { require.NoError(t, err) var msg types.MsgUndelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) @@ -241,7 +242,7 @@ func TestSimulateMsgBeginRedelegate(t *testing.T) { require.NoError(t, err) var msg types.MsgBeginRedelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, "cosmos1092v0qgulpejj8y8hs6dmlw82x9gv8f7jfc7jl", msg.DelegatorAddress) diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 5b95b543650e..ef8527512c83 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "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" "github.com/cosmos/cosmos-sdk/x/authz" @@ -42,24 +41,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/staking module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/staking and - // defined at the application level. - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - amino.Seal() - - // Register all Amino interfaces and concrete types on the global Amino codec so that this can later be - // used to properly serialize x/authz MsgExec instances RegisterLegacyAminoCodec(legacy.Cdc) } diff --git a/x/staking/types/historical_info_test.go b/x/staking/types/historical_info_test.go index 45305de91c56..66d3105897e1 100644 --- a/x/staking/types/historical_info_test.go +++ b/x/staking/types/historical_info_test.go @@ -1,6 +1,8 @@ package types_test import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" "math/rand" "sort" "testing" @@ -32,11 +34,11 @@ func TestHistoricalInfo(t *testing.T) { var value []byte require.NotPanics(t, func() { - value = types.ModuleCdc.MustMarshal(&hi) + value = legacy.Cdc.MustMarshal(&hi) }) require.NotNil(t, value, "Marshalled HistoricalInfo is nil") - recv, err := types.UnmarshalHistoricalInfo(types.ModuleCdc, value) + recv, err := types.UnmarshalHistoricalInfo(codec.NewAminoCodec(legacy.Cdc), value) require.Nil(t, err, "Unmarshalling HistoricalInfo failed") require.Equal(t, hi.Header, recv.Header) for i := range hi.Valset { diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 77eaf668befc..d755070e326f 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -76,7 +77,7 @@ func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress { // GetSignBytes returns the message bytes to sign over. func (msg MsgCreateValidator) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -160,7 +161,7 @@ func (msg MsgEditValidator) GetSigners() []sdk.AccAddress { // GetSignBytes implements the sdk.Msg interface. func (msg MsgEditValidator) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -214,7 +215,7 @@ func (msg MsgDelegate) GetSigners() []sdk.AccAddress { // GetSignBytes implements the sdk.Msg interface. func (msg MsgDelegate) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -264,7 +265,7 @@ func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress { // GetSignBytes implements the sdk.Msg interface. func (msg MsgBeginRedelegate) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -314,7 +315,7 @@ func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { // GetSignBytes implements the sdk.Msg interface. func (msg MsgUndelegate) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := legacy.Cdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/upgrade/types/proposal.go b/x/upgrade/types/proposal.go index 1729139f79c5..987ccf978824 100644 --- a/x/upgrade/types/proposal.go +++ b/x/upgrade/types/proposal.go @@ -20,9 +20,7 @@ var _ gov.Content = &SoftwareUpgradeProposal{} func init() { gov.RegisterProposalType(ProposalTypeSoftwareUpgrade) - gov.RegisterProposalTypeCodec(&SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal") gov.RegisterProposalType(ProposalTypeCancelSoftwareUpgrade) - gov.RegisterProposalTypeCodec(&CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal") } func (sup *SoftwareUpgradeProposal) GetTitle() string { return sup.Title }