feat: replace all ModuleCdc instances with legacy.Cdc (#11240)

## Description
Replaces all the various `ModuleCdc` instances with the global `legacy.Cdc` to properly support Amino serialization for the `x/authz` module. This is needed in order to correctly support Ledger signing for `MsgExec` and messages.

Closes: #11232



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Riccardo Montagnin 2022-02-23 15:13:36 +01:00 committed by GitHub
parent 433420091a
commit ff31490769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 134 additions and 300 deletions

View File

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

View File

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

View File

@ -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.

View File

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

View File

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

View File

@ -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,
}
}
//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 }
// 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 }
// 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)
}
// 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.IsValid() {
return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String())
}
if !msg.Amount.IsAllPositive() {
return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String())
}
if !msg.Amount.IsAllPositive() {
return sdkerrors.ErrInvalidCoins.Wrap(msg.Amount.String())
}
return nil
}
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))
}
// 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}
}
// 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.

View File

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

View File

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

View File

@ -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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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.

View File

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

View File

@ -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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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.

View File

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

View File

@ -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 {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 {

View File

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

View File

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