diff --git a/CHANGELOG.md b/CHANGELOG.md index d96f9a5eec8a..de9bd67deffe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (codec) [#13196](https://github.com/cosmos/cosmos-sdk/pull/13196) Register all modules' `Msg`s with gov's ModuleCdc so that Amino sign bytes are correctly generated. * (x/distribution) [#12852](https://github.com/cosmos/cosmos-sdk/pull/12852) Deprecate `CommunityPoolSpendProposal`. Please execute a `MsgCommunityPoolSpend` message via the new v1 `x/gov` module instead. This message can be used to directly fund the `x/gov` module account. * (x/bank) [#12610](https://github.com/cosmos/cosmos-sdk/pull/12610) `MsgMultiSend` now allows only a single input. * (x/bank) [#12630](https://github.com/cosmos/cosmos-sdk/pull/12630) Migrate `x/bank` to self-managed parameters and deprecate its usage of `x/params`. diff --git a/docs/core/encoding.md b/docs/core/encoding.md index be6a1491d7cd..25497d4bc530 100644 --- a/docs/core/encoding.md +++ b/docs/core/encoding.md @@ -67,18 +67,22 @@ Note, there are length-prefixed variants of the above functionality and this is typically used for when the data needs to be streamed or grouped together (e.g. `ResponseDeliverTx.Data`) -#### Authz authorizations +#### Authz authorizations and Gov proposals -Since the `MsgExec` message type can contain different messages instances, it is important that developers +Since authz's `MsgExec` and `MsgGrant` message types, as well as gov's `MsgSubmitProposal`, can contain different messages instances, it is important that developers add the following code inside the `init` method of their module's `codec.go` file: ```go -import authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" +import ( + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" +) init() { - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } ``` diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 020fa7c0d9c3..29fda99e090f 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the account interfaces and concrete types on the @@ -57,7 +58,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 270116671e91..8e14ce6aa1a1 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -10,6 +10,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the vesting interfaces and concrete types on the @@ -74,7 +75,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/authz/codec.go b/x/authz/codec.go index 77a6fa24e4f9..ddad1b45d700 100644 --- a/x/authz/codec.go +++ b/x/authz/codec.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types @@ -38,7 +39,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { } func init() { - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 7ad20f741608..2f85d785d595 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/x/authz" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types @@ -46,7 +47,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 8df1ab46762e..bce0c3800fca 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types @@ -36,7 +37,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 7016de77db46..574b02f4a319 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the necessary x/distribution interfaces @@ -48,8 +49,9 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec + // Register all Amino interfaces and concrete types on the authz and gov Amino codec // so that this can later be used to properly serialize MsgGrant and MsgExec // instances. RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 19dcd12cbee9..170764a83bec 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" "github.com/cosmos/cosmos-sdk/x/evidence/exported" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -40,7 +41,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/feegrant/codec.go b/x/feegrant/codec.go index 0fd6eaeb9e7f..421435f34ebb 100644 --- a/x/feegrant/codec.go +++ b/x/feegrant/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the necessary x/feegrant interfaces and concrete types @@ -57,7 +58,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/gov/codec/cdc.go b/x/gov/codec/cdc.go new file mode 100644 index 000000000000..520e435afd69 --- /dev/null +++ b/x/gov/codec/cdc.go @@ -0,0 +1,18 @@ +package codec + +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 = codec.NewAminoCodec(Amino) +) + +func init() { + cryptocodec.RegisterCrypto(Amino) + codec.RegisterEvidences(Amino) + sdk.RegisterLegacyAminoCodec(Amino) +} diff --git a/x/gov/codec/doc.go b/x/gov/codec/doc.go new file mode 100644 index 000000000000..574a18d57c9d --- /dev/null +++ b/x/gov/codec/doc.go @@ -0,0 +1,18 @@ +/* +Package codec provides a singleton instance of Amino codec that should be used to register +any concrete type that can later be referenced inside a MsgSubmitProposal instance so that they +can be (de)serialized properly. + +Amino types should be ideally registered inside this codec within the init function of each module's +codec.go file as follows: + + func init() { + // ... + + RegisterLegacyAminoCodec(govcodec.Amino) + + } + +The codec instance is put inside this package and not the x/gov/types package in order to avoid any dependency cycle. +*/ +package codec diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 267934307206..5caf94f50a20 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -22,6 +22,7 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/testutil" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/simulation" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -128,7 +129,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.NoError(t, err) var msg v1.MsgSubmitProposal - err = v1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -176,7 +177,7 @@ func TestSimulateMsgDeposit(t *testing.T) { require.NoError(t, err) var msg v1.MsgDeposit - err = v1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -223,7 +224,7 @@ func TestSimulateMsgVote(t *testing.T) { require.NoError(t, err) var msg v1.MsgVote - v1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) @@ -267,7 +268,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { require.NoError(t, err) var msg v1.MsgVoteWeighted - v1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) diff --git a/x/gov/types/v1/codec.go b/x/gov/types/v1/codec.go index 8b45b2098346..35310cc5f0a3 100644 --- a/x/gov/types/v1/codec.go +++ b/x/gov/types/v1/codec.go @@ -4,11 +4,10 @@ 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" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -35,18 +34,9 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - v1beta1.RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - sdk.RegisterLegacyAminoCodec(amino) - - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index ed1aa7820966..763c7294401e 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdktx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) @@ -84,7 +85,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { // GetSignBytes implements Msg func (m MsgSubmitProposal) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&m) + bz := codec.ModuleCdc.MustMarshalJSON(&m) return sdk.MustSortJSON(bz) } @@ -130,7 +131,7 @@ func (msg MsgDeposit) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgDeposit) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -167,7 +168,7 @@ func (msg MsgVote) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgVote) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -229,7 +230,7 @@ func (msg MsgVoteWeighted) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgVoteWeighted) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -283,7 +284,7 @@ func (msg MsgUpdateParams) ValidateBasic() error { // GetSignBytes implements Msg func (msg MsgUpdateParams) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/gov/types/v1/msgs_test.go b/x/gov/types/v1/msgs_test.go index efd614bc9b81..6d0d8ed7f040 100644 --- a/x/gov/types/v1/msgs_test.go +++ b/x/gov/types/v1/msgs_test.go @@ -1,12 +1,14 @@ package v1_test import ( + "fmt" "testing" "cosmossdk.io/math" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) @@ -170,13 +172,30 @@ func TestMsgSubmitProposal_ValidateBasic(t *testing.T) { // this tests that Amino JSON MsgSubmitProposal.GetSignBytes() still works with Content as Any using the ModuleCdc func TestMsgSubmitProposal_GetSignBytes(t *testing.T) { - proposal := []sdk.Msg{v1.NewMsgVote(addrs[0], 1, v1.OptionYes, "")} - msg, err := v1.NewMsgSubmitProposal(proposal, sdk.NewCoins(), sdk.AccAddress{}.String(), "") - require.NoError(t, err) - var bz []byte - require.NotPanics(t, func() { - bz = msg.GetSignBytes() - }) - require.Equal(t, "{\"type\":\"cosmos-sdk/v1/MsgSubmitProposal\",\"value\":{\"initial_deposit\":[],\"messages\":[{\"type\":\"cosmos-sdk/v1/MsgVote\",\"value\":{\"option\":1,\"proposal_id\":\"1\",\"voter\":\"cosmos1w3jhxap3gempvr\"}}]}}", - string(bz)) + testcases := []struct { + name string + proposal []sdk.Msg + expSignBz string + }{ + { + "MsgVote", []sdk.Msg{v1.NewMsgVote(addrs[0], 1, v1.OptionYes, "")}, + `{"type":"cosmos-sdk/v1/MsgSubmitProposal","value":{"initial_deposit":[],"messages":[{"type":"cosmos-sdk/v1/MsgVote","value":{"option":1,"proposal_id":"1","voter":"cosmos1w3jhxap3gempvr"}}]}}`, + }, + { + "MsgSend", []sdk.Msg{banktypes.NewMsgSend(addrs[0], addrs[0], sdk.NewCoins())}, + fmt.Sprintf(`{"type":"cosmos-sdk/v1/MsgSubmitProposal","value":{"initial_deposit":[],"messages":[{"type":"cosmos-sdk/MsgSend","value":{"amount":[],"from_address":"%s","to_address":"%s"}}]}}`, addrs[0], addrs[0]), + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + msg, err := v1.NewMsgSubmitProposal(tc.proposal, sdk.NewCoins(), sdk.AccAddress{}.String(), "") + require.NoError(t, err) + var bz []byte + require.NotPanics(t, func() { + bz = msg.GetSignBytes() + }) + require.Equal(t, tc.expSignBz, string(bz)) + }) + } } diff --git a/x/gov/types/v1beta1/codec.go b/x/gov/types/v1beta1/codec.go index f73f1082c5cd..fa9c9f05591a 100644 --- a/x/gov/types/v1beta1/codec.go +++ b/x/gov/types/v1beta1/codec.go @@ -4,10 +4,10 @@ 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" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -37,17 +37,9 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var ( - amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - sdk.RegisterLegacyAminoCodec(amino) - - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 85ef0c66eb7d..d2f8a5b66452 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -10,6 +10,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -111,7 +112,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { // GetSignBytes implements Msg func (m MsgSubmitProposal) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&m) + bz := codec.ModuleCdc.MustMarshalJSON(&m) return sdk.MustSortJSON(bz) } @@ -169,7 +170,7 @@ func (msg MsgDeposit) String() string { // GetSignBytes implements Msg func (msg MsgDeposit) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -212,7 +213,7 @@ func (msg MsgVote) String() string { // GetSignBytes implements Msg func (msg MsgVote) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -276,7 +277,7 @@ func (msg MsgVoteWeighted) String() string { // GetSignBytes implements Msg func (msg MsgVoteWeighted) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) + bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } diff --git a/x/group/codec.go b/x/group/codec.go index 32e1ec15c7cb..437f81460eeb 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers all the necessary group module concrete @@ -72,7 +73,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go index 748889553560..967b3f18106b 100644 --- a/x/mint/types/codec.go +++ b/x/mint/types/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) var ( @@ -20,10 +21,11 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec + // Register all Amino interfaces and concrete types on the authz and gov Amino codec // so that this can later be used to properly serialize MsgGrant and MsgExec // instances. RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } // RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 35af62c22632..6a7252b17ee3 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers concrete types on LegacyAmino codec @@ -36,7 +37,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 2eaece370201..0ac238e972c4 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/x/authz" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" ) // RegisterLegacyAminoCodec registers the necessary x/staking interfaces and concrete types @@ -58,7 +59,8 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) } diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index 91f9531a1320..4e058d218000 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) @@ -45,8 +46,9 @@ func init() { cryptocodec.RegisterCrypto(amino) sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec + // Register all Amino interfaces and concrete types on the authz and gov Amino codec // so that this can later be used to properly serialize MsgGrant and MsgExec // instances. RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) }