Move codec.RegisterCrypto and codec.Cdc to new packages (#6330)

* Move codec.Cdc to legacy_global.Cdc

* Update CHANGELOG.md

* Updates

* nit

* Fix imports

* Updates

* Use cosmos multisig instead of tendermint multisig everywhere

* Fix tests

* Rename legacy_global -> legacy

* Add doc.go

* Linting, move all RegisterCrypto calls to crypto/codec

* Update crypto/codec/amino.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Aaron Craelius 2020-06-04 06:38:24 -04:00 committed by GitHub
parent dcbf152ae5
commit 81d647e505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 216 additions and 133 deletions

View File

@ -129,6 +129,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa
* (client/rpc) [\#6290](https://github.com/cosmos/cosmos-sdk/pull/6290) `RegisterRoutes` of rpc is moved from package client to client/rpc and client/rpc.RegisterRPCRoutes is removed.
* (client/lcd) [\#6290](https://github.com/cosmos/cosmos-sdk/pull/6290) `CliCtx` of struct `RestServer` in package client/lcd has been renamed to `ClientCtx`.
* (types) [\#6327](https://github.com/cosmos/cosmos-sdk/pull/6327) `sdk.Msg` now inherits `proto.Message`, as a result all `sdk.Msg` types now use pointer semantics.
* (codec) [\#6330](https://github.com/cosmos/cosmos-sdk/pull/6330) `codec.RegisterCrypto` has been moved to the `crypto/codec` package and the global `codec.Cdc` Amino instance has been deprecated and moved to the `codec/legacy_global` package.
### Features

View File

@ -14,13 +14,13 @@ import (
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/libs/cli"
)

View File

@ -2,6 +2,7 @@ package keys
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// KeysCdc defines codec to be used with key operations
@ -9,7 +10,7 @@ var KeysCdc *codec.Codec
func init() {
KeysCdc = codec.New()
codec.RegisterCrypto(KeysCdc)
cryptocodec.RegisterCrypto(KeysCdc)
KeysCdc.Seal()
}

View File

@ -8,12 +8,12 @@ import (
"github.com/spf13/viper"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
)

View File

@ -7,12 +7,12 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
)

View File

@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/types/rest"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
@ -65,10 +65,10 @@ func getBlock(clientCtx client.Context, height *int64) ([]byte, error) {
}
if clientCtx.Indent {
return codec.Cdc.MarshalJSONIndent(res, "", " ")
return legacy.Cdc.MarshalJSONIndent(res, "", " ")
}
return codec.Cdc.MarshalJSON(res)
return legacy.Cdc.MarshalJSON(res)
}
// get the current blockchain height

View File

@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/version"
@ -55,9 +55,9 @@ func printNodeStatus(_ *cobra.Command, _ []string) error {
var output []byte
if clientCtx.Indent {
output, err = codec.Cdc.MarshalJSONIndent(status, "", " ")
output, err = legacy.Cdc.MarshalJSONIndent(status, "", " ")
} else {
output, err = codec.Cdc.MarshalJSON(status)
output, err = legacy.Cdc.MarshalJSON(status)
}
if err != nil {
return err

View File

@ -4,27 +4,14 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
amino "github.com/tendermint/go-amino"
cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec/types"
)
// Cdc defines a global generic sealed Amino codec to be used throughout sdk. It
// has all Tendermint crypto and evidence types registered.
//
// TODO: Consider removing this global.
var Cdc *Codec
func init() {
Cdc = New()
RegisterCrypto(Cdc)
RegisterEvidences(Cdc)
Cdc.Seal()
}
// deprecated: Codec defines a wrapper for an Amino codec that properly handles protobuf
// types with Any's
type Codec struct {
@ -41,12 +28,6 @@ func New() *Codec {
return &Codec{amino.NewCodec()}
}
// RegisterCrypto registers all crypto dependency types with the provided Amino
// codec.
func RegisterCrypto(cdc *Codec) {
cryptoamino.RegisterAmino(cdc.Amino)
}
// RegisterEvidences registers Tendermint evidence types with the provided Amino
// codec.
func RegisterEvidences(cdc *Codec) {
@ -208,3 +189,7 @@ func (cdc *Codec) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byt
}
return cdc.Amino.MarshalJSONIndent(o, prefix, indent)
}
func (cdc *Codec) PrintTypes(out io.Writer) error {
return cdc.Amino.PrintTypes(out)
}

19
codec/legacy/codec.go Normal file
View File

@ -0,0 +1,19 @@
package legacy
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// Deprecated: Cdc defines a global generic sealed Amino codec to be used throughout sdk. It
// has all Tendermint crypto and evidence types registered.
//
// TODO: remove this global.
var Cdc *codec.Codec
func init() {
Cdc = codec.New()
cryptocodec.RegisterCrypto(Cdc)
codec.RegisterEvidences(Cdc)
Cdc.Seal()
}

4
codec/legacy/doc.go Normal file
View File

@ -0,0 +1,4 @@
// Package legacy contains a global amino Cdc which is deprecated but
// still used in several places within the SDK. This package is intended
// to be removed at some point in the future when the global Cdc is removed.
package legacy

View File

@ -1,19 +1,19 @@
package crypto
import (
amino "github.com/tendermint/go-amino"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/cosmos/cosmos-sdk/codec"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
)
var cdc = amino.NewCodec()
var cdc = codec.New()
func init() {
RegisterAmino(cdc)
cryptoAmino.RegisterAmino(cdc)
cryptoAmino.RegisterCrypto(cdc)
}
// RegisterAmino registers all go-crypto related types in the given (amino) codec.
func RegisterAmino(cdc *amino.Codec) {
func RegisterAmino(cdc *codec.Codec) {
cdc.RegisterConcrete(PrivKeyLedgerSecp256k1{},
"tendermint/PrivKeyLedgerSecp256k1", nil)
}

View File

@ -5,12 +5,11 @@ import (
"fmt"
"github.com/tendermint/crypto/bcrypt"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/armor"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/tendermint/tendermint/crypto/xsalsa20symmetric"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

View File

@ -11,13 +11,12 @@ import (
"github.com/tendermint/crypto/bcrypt"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/armor"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/xsalsa20symmetric"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types"
)

52
crypto/codec/amino.go Normal file
View File

@ -0,0 +1,52 @@
package codec
import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/sr25519"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
)
var amino *codec.Codec
func init() {
amino = codec.New()
RegisterCrypto(amino)
}
// RegisterCrypto registers all crypto dependency types with the provided Amino
// codec.
func RegisterCrypto(cdc *codec.Codec) {
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
ed25519.PubKeyAminoName, nil)
cdc.RegisterConcrete(sr25519.PubKeySr25519{},
sr25519.PubKeyAminoName, nil)
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
secp256k1.PubKeyAminoName, nil)
cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{},
multisig.PubKeyAminoRoute, nil)
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
ed25519.PrivKeyAminoName, nil)
cdc.RegisterConcrete(sr25519.PrivKeySr25519{},
sr25519.PrivKeyAminoName, nil)
cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
secp256k1.PrivKeyAminoName, nil)
}
// PrivKeyFromBytes unmarshals private key bytes and returns a PrivKey
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
err = amino.UnmarshalBinaryBare(privKeyBytes, &privKey)
return
}
// PubKeyFromBytes unmarshals public key bytes and returns a PubKey
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
err = amino.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
return
}

View File

@ -1,9 +1,8 @@
package keyring
import (
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
)
@ -12,7 +11,7 @@ var CryptoCdc *codec.Codec
func init() {
CryptoCdc = codec.New()
cryptoAmino.RegisterAmino(CryptoCdc.Amino)
cryptocodec.RegisterCrypto(CryptoCdc)
RegisterCodec(CryptoCdc)
CryptoCdc.Seal()
}

View File

@ -4,9 +4,9 @@ import (
"fmt"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/types"
)

View File

@ -14,12 +14,13 @@ import (
"github.com/99designs/keyring"
"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/tendermint/crypto/bcrypt"
tmcrypto "github.com/tendermint/tendermint/crypto"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

View File

@ -10,11 +10,11 @@ import (
"github.com/stretchr/testify/require"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
)

View File

@ -5,9 +5,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
)

View File

@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/require"
tmcrypto "github.com/tendermint/tendermint/crypto"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -19,7 +19,7 @@ var cdc = amino.NewCodec()
func init() {
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterConcrete(PubKey{},
cdc.RegisterConcrete(PubKeyMultisigThreshold{},
PubKeyAminoRoute, nil)
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
ed25519.PubKeyAminoName, nil)

View File

@ -4,13 +4,13 @@ import (
"github.com/tendermint/tendermint/crypto"
)
// PubKey implements a K of N threshold multisig.
type PubKey struct {
// PubKeyMultisigThreshold implements a K of N threshold multisig.
type PubKeyMultisigThreshold struct {
K uint `json:"threshold"`
PubKeys []crypto.PubKey `json:"pubkeys"`
}
var _ crypto.PubKey = PubKey{}
var _ crypto.PubKey = PubKeyMultisigThreshold{}
// NewPubKeyMultisigThreshold returns a new PubKeyMultisigThreshold.
// Panics if len(pubkeys) < k or 0 >= k.
@ -26,7 +26,7 @@ func NewPubKeyMultisigThreshold(k int, pubkeys []crypto.PubKey) crypto.PubKey {
panic("nil pubkey")
}
}
return PubKey{uint(k), pubkeys}
return PubKeyMultisigThreshold{uint(k), pubkeys}
}
// VerifyBytes expects sig to be an amino encoded version of a MultiSignature.
@ -35,7 +35,7 @@ func NewPubKeyMultisigThreshold(k int, pubkeys []crypto.PubKey) crypto.PubKey {
// and all signatures are valid. (Not just k of the signatures)
// The multisig uses a bitarray, so multiple signatures for the same key is not
// a concern.
func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool {
func (pk PubKeyMultisigThreshold) VerifyBytes(msg []byte, marshalledSig []byte) bool {
var sig Multisignature
err := cdc.UnmarshalBinaryBare(marshalledSig, &sig)
if err != nil {
@ -67,20 +67,20 @@ func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool {
return true
}
// Bytes returns the amino encoded version of the PubKey
func (pk PubKey) Bytes() []byte {
// Bytes returns the amino encoded version of the PubKeyMultisigThreshold
func (pk PubKeyMultisigThreshold) Bytes() []byte {
return cdc.MustMarshalBinaryBare(pk)
}
// Address returns tmhash(PubKey.Bytes())
func (pk PubKey) Address() crypto.Address {
func (pk PubKeyMultisigThreshold) Address() crypto.Address {
return crypto.AddressHash(pk.Bytes())
}
// Equals returns true iff pk and other both have the same number of keys, and
// all constituent keys are the same, and in the same order.
func (pk PubKey) Equals(other crypto.PubKey) bool {
otherKey, sameType := other.(PubKey)
func (pk PubKeyMultisigThreshold) Equals(other crypto.PubKey) bool {
otherKey, sameType := other.(PubKeyMultisigThreshold)
if !sameType {
return false
}

View File

@ -130,7 +130,7 @@ func TestMultiSigPubKeyEquality(t *testing.T) {
msg := []byte{1, 2, 3, 4}
pubkeys, _ := generatePubKeysAndSignatures(5, msg)
multisigKey := NewPubKeyMultisigThreshold(2, pubkeys)
var unmarshalledMultisig PubKey
var unmarshalledMultisig PubKeyMultisigThreshold
cdc.MustUnmarshalBinaryBare(multisigKey.Bytes(), &unmarshalledMultisig)
require.True(t, multisigKey.Equals(unmarshalledMultisig))

View File

@ -16,6 +16,7 @@ import (
tversion "github.com/tendermint/tendermint/version"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -127,7 +128,7 @@ against which this app has been compiled.
func printlnJSON(v interface{}) error {
cdc := codec.New()
codec.RegisterCrypto(cdc)
cryptocodec.RegisterCrypto(cdc)
marshalled, err := cdc.MarshalJSON(v)
if err != nil {
return err

View File

@ -3,6 +3,7 @@ package std
import (
"github.com/cosmos/cosmos-sdk/codec"
"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/module"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
@ -36,7 +37,7 @@ func MakeCodec(bm module.BasicManager) *codec.Codec {
bm.RegisterCodec(cdc)
vesting.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
cryptocodec.RegisterCrypto(cdc)
return cdc
}

View File

@ -9,9 +9,9 @@ import (
"strings"
"github.com/tendermint/tendermint/crypto"
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
yaml "gopkg.in/yaml.v2"
tmamino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/types/bech32"
)

View File

@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -180,7 +181,7 @@ func CheckNotFoundError(w http.ResponseWriter, err error) bool {
func WriteErrorResponse(w http.ResponseWriter, status int, err string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_, _ = w.Write(codec.Cdc.MustMarshalJSON(NewErrorResponse(0, err)))
_, _ = w.Write(legacy.Cdc.MustMarshalJSON(NewErrorResponse(0, err)))
}
// WriteSimulationResponse prepares and writes an HTTP

View File

@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
)
@ -199,7 +200,7 @@ func TestProcessPostResponse(t *testing.T) {
acc := mockAccount{addr, coins, pubKey, accNumber, sequence}
cdc := codec.New()
codec.RegisterCrypto(cdc)
cryptocodec.RegisterCrypto(cdc)
cdc.RegisterConcrete(&mockAccount{}, "cosmos-sdk/mockAccount", nil)
ctx = ctx.WithCodec(cdc)

View File

@ -9,10 +9,10 @@ import (
yaml "gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
)
func (gi GasInfo) String() string {
@ -58,7 +58,7 @@ func NewABCIMessageLog(i uint16, log string, events Events) ABCIMessageLog {
// String implements the fmt.Stringer interface for the ABCIMessageLogs type.
func (logs ABCIMessageLogs) String() (str string) {
if logs != nil {
raw, err := codec.Cdc.MarshalJSON(logs)
raw, err := legacy.Cdc.MarshalJSON(logs)
if err == nil {
str = string(raw)
}

View File

@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -31,7 +31,7 @@ func TestABCIMessageLog(t *testing.T) {
msgLog := sdk.NewABCIMessageLog(0, "", events)
msgLogs := sdk.ABCIMessageLogs{msgLog}
bz, err := codec.Cdc.MarshalJSON(msgLogs)
bz, err := legacy.Cdc.MarshalJSON(msgLogs)
require.NoError(t, err)
require.Equal(t, string(bz), msgLogs.String())
}

View File

@ -11,9 +11,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"

View File

@ -1,13 +1,12 @@
package ante
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
@ -131,7 +130,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
PubKey: pubkey.Bytes(),
}
sigBz := codec.Cdc.MustMarshalBinaryBare(simSig)
sigBz := legacy.Cdc.MustMarshalBinaryBare(simSig)
cost := sdk.Gas(len(sigBz) + 6)
// If the pubkey is a multi-signature pubkey, then we estimate for the maximum

View File

@ -6,10 +6,10 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/types"
@ -305,7 +305,7 @@ func DefaultSigVerificationGasConsumer(
case multisig.PubKeyMultisigThreshold:
var multisignature multisig.Multisignature
codec.Cdc.MustUnmarshalBinaryBare(sig, &multisignature)
legacy.Cdc.MustUnmarshalBinaryBare(sig, &multisignature)
ConsumeMultisignatureVerificationGas(meter, multisignature, pubkey, params)
return nil

View File

@ -7,9 +7,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/types"

View File

@ -10,12 +10,11 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"

View File

@ -6,11 +6,11 @@ import (
"strings"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/types"

View File

@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
@ -158,7 +159,7 @@ func writeToNewTempFile(t *testing.T, data string) *os.File {
func makeCodec() *codec.Codec {
var cdc = codec.New()
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
cryptocodec.RegisterCrypto(cdc)
authtypes.RegisterCodec(cdc)
cdc.RegisterConcrete(sdk.TestMsg{}, "cosmos-sdk/Test", nil)
return cdc

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
@ -14,7 +15,7 @@ import (
func TestMigrate(t *testing.T) {
v039Codec := codec.New()
codec.RegisterCrypto(v039Codec)
cryptocodec.RegisterCrypto(v039Codec)
v038auth.RegisterCodec(v039Codec)
coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// RegisterCodec registers the account interfaces and concrete types on the
@ -41,5 +42,5 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
}

View File

@ -5,11 +5,12 @@ import (
"fmt"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
yaml "gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -49,7 +50,7 @@ func (fee StdFee) Bytes() []byte {
fee.Amount = sdk.NewCoins()
}
bz, err := codec.Cdc.MarshalJSON(fee)
bz, err := legacy.Cdc.MarshalJSON(fee)
if err != nil {
panic(err)
}
@ -295,7 +296,7 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms
msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes()))
}
bz, err := codec.Cdc.MarshalJSON(StdSignDoc{
bz, err := legacy.Cdc.MarshalJSON(StdSignDoc{
AccountNumber: accnum,
ChainID: chainID,
Fee: json.RawMessage(fee.Bytes()),

View File

@ -4,7 +4,7 @@ import (
"errors"
"time"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
@ -241,13 +241,13 @@ func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) {
EndTime: bva.EndTime,
}
return codec.Cdc.MarshalJSON(alias)
return legacy.Cdc.MarshalJSON(alias)
}
// UnmarshalJSON unmarshals raw JSON bytes into a BaseVestingAccount.
func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error {
var alias vestingAccountJSON
if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil {
if err := legacy.Cdc.UnmarshalJSON(bz, &alias); err != nil {
return err
}
@ -398,13 +398,13 @@ func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) {
StartTime: cva.StartTime,
}
return codec.Cdc.MarshalJSON(alias)
return legacy.Cdc.MarshalJSON(alias)
}
// UnmarshalJSON unmarshals raw JSON bytes into a ContinuousVestingAccount.
func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error {
var alias vestingAccountJSON
if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil {
if err := legacy.Cdc.UnmarshalJSON(bz, &alias); err != nil {
return err
}
@ -589,13 +589,13 @@ func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) {
VestingPeriods: pva.VestingPeriods,
}
return codec.Cdc.MarshalJSON(alias)
return legacy.Cdc.MarshalJSON(alias)
}
// UnmarshalJSON unmarshals raw JSON bytes into a PeriodicVestingAccount.
func (pva *PeriodicVestingAccount) UnmarshalJSON(bz []byte) error {
var alias vestingAccountJSON
if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil {
if err := legacy.Cdc.UnmarshalJSON(bz, &alias); err != nil {
return err
}
@ -692,13 +692,13 @@ func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) {
EndTime: dva.EndTime,
}
return codec.Cdc.MarshalJSON(alias)
return legacy.Cdc.MarshalJSON(alias)
}
// UnmarshalJSON unmarshals raw JSON bytes into a DelayedVestingAccount.
func (dva *DelayedVestingAccount) UnmarshalJSON(bz []byte) error {
var alias vestingAccountJSON
if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil {
if err := legacy.Cdc.UnmarshalJSON(bz, &alias); err != nil {
return err
}

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38"
@ -14,7 +15,7 @@ import (
func TestMigrate(t *testing.T) {
v039Codec := codec.New()
codec.RegisterCrypto(v039Codec)
cryptocodec.RegisterCrypto(v039Codec)
v038auth.RegisterCodec(v039Codec)
coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
)
@ -43,6 +44,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// RegisterCodec registers the necessary x/crisis interfaces and concrete types
@ -25,6 +26,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov"
)
@ -44,6 +45,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
)
@ -38,6 +39,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/mock"
"github.com/cosmos/cosmos-sdk/tests"
@ -141,6 +142,6 @@ func TestInitNodeValidatorFiles(t *testing.T) {
func makeCodec() *codec.Codec {
var cdc = codec.New()
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
cryptocodec.RegisterCrypto(cdc)
return cdc
}

View File

@ -2,6 +2,7 @@ package v036
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v036bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_36"
@ -19,11 +20,11 @@ import (
// Migrate migrates exported state from v0.34 to a v0.36 genesis state.
func Migrate(appState genutil.AppMap) genutil.AppMap {
v034Codec := codec.New()
codec.RegisterCrypto(v034Codec)
cryptocodec.RegisterCrypto(v034Codec)
v034gov.RegisterCodec(v034Codec)
v036Codec := codec.New()
codec.RegisterCrypto(v036Codec)
cryptocodec.RegisterCrypto(v036Codec)
v036gov.RegisterCodec(v036Codec)
// migrate genesis accounts state

View File

@ -2,6 +2,7 @@ package v038
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
@ -15,10 +16,10 @@ import (
// Migrate migrates exported state from v0.36/v0.37 to a v0.38 genesis state.
func Migrate(appState genutil.AppMap) genutil.AppMap {
v036Codec := codec.New()
codec.RegisterCrypto(v036Codec)
cryptocodec.RegisterCrypto(v036Codec)
v038Codec := codec.New()
codec.RegisterCrypto(v038Codec)
cryptocodec.RegisterCrypto(v038Codec)
v038auth.RegisterCodec(v038Codec)
if appState[v036genaccounts.ModuleName] != nil {

View File

@ -2,6 +2,7 @@ package v039
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38"
@ -11,11 +12,11 @@ import (
func Migrate(appState genutil.AppMap) genutil.AppMap {
v038Codec := codec.New()
codec.RegisterCrypto(v038Codec)
cryptocodec.RegisterCrypto(v038Codec)
v038auth.RegisterCodec(v038Codec)
v039Codec := codec.New()
codec.RegisterCrypto(v039Codec)
cryptocodec.RegisterCrypto(v039Codec)
v038auth.RegisterCodec(v039Codec)
// remove balances from existing accounts

View File

@ -2,6 +2,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
@ -17,6 +18,6 @@ func init() {
stakingtypes.RegisterCodec(ModuleCdc)
authtypes.RegisterCodec(ModuleCdc)
sdk.RegisterCodec(ModuleCdc)
codec.RegisterCrypto(ModuleCdc)
cryptocodec.RegisterCrypto(ModuleCdc)
ModuleCdc.Seal()
}

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -53,5 +54,5 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
}

View File

@ -9,6 +9,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
@ -35,7 +36,7 @@ type TendermintTestSuite struct {
func (suite *TendermintTestSuite) SetupTest() {
suite.cdc = codec.New()
codec.RegisterCrypto(suite.cdc)
cryptocodec.RegisterCrypto(suite.cdc)
ibctmtypes.RegisterCodec(suite.cdc)
commitmenttypes.RegisterCodec(suite.cdc)

View File

@ -2,6 +2,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
var (
@ -9,6 +10,6 @@ var (
)
func init() {
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -4,6 +4,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/params/types"
@ -26,7 +27,7 @@ func NewQuerier(k Keeper) sdk.Querier {
func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var params types.QuerySubspaceParams
if err := codec.Cdc.UnmarshalJSON(req.Data, &params); err != nil {
if err := legacy.Cdc.UnmarshalJSON(req.Data, &params); err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
@ -38,7 +39,7 @@ func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, erro
rawValue := ss.GetRaw(ctx, []byte(params.Key))
resp := types.NewSubspaceParamsResponse(params.Subspace, params.Key, string(rawValue))
bz, err := codec.MarshalJSONIndent(codec.Cdc, resp)
bz, err := codec.MarshalJSONIndent(legacy.Cdc, resp)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// RegisterCodec registers concrete types on codec
@ -24,6 +25,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -131,7 +131,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
return nil, err
}
return codec.Cdc.MarshalJSON(bechValidator{
return legacy.Cdc.MarshalJSON(bechValidator{
OperatorAddress: v.OperatorAddress,
ConsPubKey: bechConsPubKey,
Jailed: v.Jailed,
@ -149,7 +149,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
// UnmarshalJSON unmarshals the validator from JSON using Bech32
func (v *Validator) UnmarshalJSON(data []byte) error {
bv := &bechValidator{}
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
if err := legacy.Cdc.UnmarshalJSON(data, bv); err != nil {
return err
}
consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey)

View File

@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
)
@ -94,7 +94,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
return nil, err
}
return codec.Cdc.MarshalJSON(bechValidator{
return legacy.Cdc.MarshalJSON(bechValidator{
OperatorAddress: v.OperatorAddress,
ConsPubKey: bechConsPubKey,
Jailed: v.Jailed,
@ -111,7 +111,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
func (v *Validator) UnmarshalJSON(data []byte) error {
bv := &bechValidator{}
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
if err := legacy.Cdc.UnmarshalJSON(data, bv); err != nil {
return err
}
consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey)

View File

@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
@ -105,7 +105,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
return nil, err
}
return codec.Cdc.MarshalJSON(bechValidator{
return legacy.Cdc.MarshalJSON(bechValidator{
OperatorAddress: v.OperatorAddress,
ConsPubKey: bechConsPubKey,
Jailed: v.Jailed,
@ -123,7 +123,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
// UnmarshalJSON unmarshals the validator from JSON using Bech32
func (v *Validator) UnmarshalJSON(data []byte) error {
bv := &bechValidator{}
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
if err := legacy.Cdc.UnmarshalJSON(data, bv); err != nil {
return err
}
consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey)

View File

@ -11,6 +11,7 @@ import (
tmkv "github.com/tendermint/tendermint/libs/kv"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/simulation"
@ -26,7 +27,7 @@ var (
func makeTestCodec() (cdc *codec.Codec) {
cdc = codec.New()
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
cryptocodec.RegisterCrypto(cdc)
types.RegisterCodec(cdc)
return
}

View File

@ -3,6 +3,7 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// RegisterCodec registers the necessary x/staking interfaces and concrete types
@ -29,6 +30,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -11,7 +11,7 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -230,12 +230,12 @@ func TestPossibleOverflow(t *testing.T) {
func TestValidatorMarshalUnmarshalJSON(t *testing.T) {
validator := NewValidator(valAddr1, pk1, Description{})
js, err := codec.Cdc.MarshalJSON(validator)
js, err := legacy.Cdc.MarshalJSON(validator)
require.NoError(t, err)
require.NotEmpty(t, js)
require.Contains(t, string(js), "\"consensus_pubkey\":\"cosmosvalconspu")
got := &Validator{}
err = codec.Cdc.UnmarshalJSON(js, got)
err = legacy.Cdc.UnmarshalJSON(js, got)
assert.NoError(t, err)
assert.Equal(t, validator, *got)
}