diff --git a/CHANGELOG.md b/CHANGELOG.md index 94baea31454a..08cd61e2c234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/client/keys/add.go b/client/keys/add.go index 4f226d1dd036..1159148edc35 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -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" ) diff --git a/client/keys/codec.go b/client/keys/codec.go index e47d3b231afc..1d1e6d87904d 100644 --- a/client/keys/codec.go +++ b/client/keys/codec.go @@ -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() } diff --git a/client/keys/show.go b/client/keys/show.go index 11473aba4072..465aa0007a89 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -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" ) diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 54746e0207b4..079e56b4a7c5 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -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" ) diff --git a/client/rpc/block.go b/client/rpc/block.go index 766a41fea953..4fabdf3ab7b8 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -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 diff --git a/client/rpc/status.go b/client/rpc/status.go index e8215006a19e..b85a67c1302a 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -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 diff --git a/codec/amino.go b/codec/amino.go index 53587808e65f..b3302609fc4b 100644 --- a/codec/amino.go +++ b/codec/amino.go @@ -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) +} diff --git a/codec/legacy/codec.go b/codec/legacy/codec.go new file mode 100644 index 000000000000..5a9f11e12e27 --- /dev/null +++ b/codec/legacy/codec.go @@ -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() +} diff --git a/codec/legacy/doc.go b/codec/legacy/doc.go new file mode 100644 index 000000000000..d89944f3df42 --- /dev/null +++ b/codec/legacy/doc.go @@ -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 diff --git a/crypto/amino.go b/crypto/amino.go index 553a4723f9db..0b694529e8c0 100644 --- a/crypto/amino.go +++ b/crypto/amino.go @@ -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) } diff --git a/crypto/armor.go b/crypto/armor.go index e95a6f49f7ab..933f2eafc0bc 100644 --- a/crypto/armor.go +++ b/crypto/armor.go @@ -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" ) diff --git a/crypto/armor_test.go b/crypto/armor_test.go index 9ebb7cc8c818..52d2922b54cd 100644 --- a/crypto/armor_test.go +++ b/crypto/armor_test.go @@ -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" ) diff --git a/crypto/codec/amino.go b/crypto/codec/amino.go new file mode 100644 index 000000000000..9ef14fe93d8d --- /dev/null +++ b/crypto/codec/amino.go @@ -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 +} diff --git a/crypto/keyring/codec.go b/crypto/keyring/codec.go index 4dd78c6e8436..6187ce5982aa 100644 --- a/crypto/keyring/codec.go +++ b/crypto/keyring/codec.go @@ -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() } diff --git a/crypto/keyring/info.go b/crypto/keyring/info.go index a391d86a943e..74bb62d774f2 100644 --- a/crypto/keyring/info.go +++ b/crypto/keyring/info.go @@ -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" ) diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index 9458e672fe78..846bd55463cd 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -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" diff --git a/crypto/keyring/keyring_test.go b/crypto/keyring/keyring_test.go index e1b713019685..55646c1e3af6 100644 --- a/crypto/keyring/keyring_test.go +++ b/crypto/keyring/keyring_test.go @@ -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" ) diff --git a/crypto/keyring/output_test.go b/crypto/keyring/output_test.go index 89f2b188fa7e..150a546b589f 100644 --- a/crypto/keyring/output_test.go +++ b/crypto/keyring/output_test.go @@ -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" ) diff --git a/crypto/ledger_test.go b/crypto/ledger_test.go index 7d73a36c9803..7408543b30e4 100644 --- a/crypto/ledger_test.go +++ b/crypto/ledger_test.go @@ -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" diff --git a/crypto/types/multisig/codec.go b/crypto/types/multisig/codec.go index 3c34b6ca0162..9fedd111b1c5 100644 --- a/crypto/types/multisig/codec.go +++ b/crypto/types/multisig/codec.go @@ -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) diff --git a/crypto/types/multisig/threshold_pubkey.go b/crypto/types/multisig/threshold_pubkey.go index 3e0deb83b594..13fa11638cce 100644 --- a/crypto/types/multisig/threshold_pubkey.go +++ b/crypto/types/multisig/threshold_pubkey.go @@ -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 } diff --git a/crypto/types/multisig/threshold_pubkey_test.go b/crypto/types/multisig/threshold_pubkey_test.go index 11ea2f0c4536..cc4aa780b27a 100644 --- a/crypto/types/multisig/threshold_pubkey_test.go +++ b/crypto/types/multisig/threshold_pubkey_test.go @@ -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)) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 2772de40ae5c..443645cdba03 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -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 diff --git a/std/codec.go b/std/codec.go index eeb8f038c9e0..ce9ded25a9c0 100644 --- a/std/codec.go +++ b/std/codec.go @@ -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 } diff --git a/types/address.go b/types/address.go index b7bd4ae64b8f..d59db6b15055 100644 --- a/types/address.go +++ b/types/address.go @@ -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" ) diff --git a/types/rest/rest.go b/types/rest/rest.go index 2ada6d6da586..bee3bbbeaa55 100644 --- a/types/rest/rest.go +++ b/types/rest/rest.go @@ -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 diff --git a/types/rest/rest_test.go b/types/rest/rest_test.go index 465c098c95cd..e428d8e49a61 100644 --- a/types/rest/rest_test.go +++ b/types/rest/rest_test.go @@ -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) diff --git a/types/result.go b/types/result.go index 1c5340819775..156cd340c0f8 100644 --- a/types/result.go +++ b/types/result.go @@ -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) } diff --git a/types/result_test.go b/types/result_test.go index 70f7d98fbbdb..98e8ddca10a4 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -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()) } diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 9278caff2b0d..bff57793df30 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -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" diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 41ba96d8bb73..0f464b491db4 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,13 +1,12 @@ package ante import ( - "github.com/cosmos/cosmos-sdk/codec" - 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/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" ) @@ -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 diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index a217fad06c04..f80f6074eba4 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -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 diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 6d83318c14c5..0c69dba9d3d2 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -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" diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 8b58813adc03..938fc682379f 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -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" diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index c7d565c927bb..7782021a78bf 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -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" diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index ab2ce267ece3..740f87499b30 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -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 diff --git a/x/auth/legacy/v0_39/migrate_test.go b/x/auth/legacy/v0_39/migrate_test.go index 027db2e89602..76eb51e21e61 100644 --- a/x/auth/legacy/v0_39/migrate_test.go +++ b/x/auth/legacy/v0_39/migrate_test.go @@ -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)) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 071ef3249504..30ebf84a043a 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -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) } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 4ef303d21e36..6b6f8ac51030 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -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()), diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index b032499b3492..0f34228a0282 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -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 } diff --git a/x/bank/legacy/v0_39/migrate_test.go b/x/bank/legacy/v0_39/migrate_test.go index ae51134d47c1..1b61ccdcb89e 100644 --- a/x/bank/legacy/v0_39/migrate_test.go +++ b/x/bank/legacy/v0_39/migrate_test.go @@ -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)) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 69a181382453..ce5c48388008 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -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() } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 04802607cbe3..33cf7198249d 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -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() } diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index a154c956e83e..869b8316310e 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -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() } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 3a23356a1f47..bee5be2cf9da 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -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() } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 70b20ccc4068..3fb52fc7fbbd 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -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 } diff --git a/x/genutil/legacy/v0_36/migrate.go b/x/genutil/legacy/v0_36/migrate.go index 59c1c4491e6f..f552fc3cc501 100644 --- a/x/genutil/legacy/v0_36/migrate.go +++ b/x/genutil/legacy/v0_36/migrate.go @@ -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 diff --git a/x/genutil/legacy/v0_38/migrate.go b/x/genutil/legacy/v0_38/migrate.go index 59ba4772705f..0c67a0d341ae 100644 --- a/x/genutil/legacy/v0_38/migrate.go +++ b/x/genutil/legacy/v0_38/migrate.go @@ -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 { diff --git a/x/genutil/legacy/v0_39/migrate.go b/x/genutil/legacy/v0_39/migrate.go index aea5ccd3f91e..13b53a196802 100644 --- a/x/genutil/legacy/v0_39/migrate.go +++ b/x/genutil/legacy/v0_39/migrate.go @@ -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 diff --git a/x/genutil/types/codec.go b/x/genutil/types/codec.go index 624be93d138f..57e2115d072d 100644 --- a/x/genutil/types/codec.go +++ b/x/genutil/types/codec.go @@ -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() } diff --git a/x/gov/types/codec.go b/x/gov/types/codec.go index ee53c71c4582..6fdb45821823 100644 --- a/x/gov/types/codec.go +++ b/x/gov/types/codec.go @@ -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) } diff --git a/x/ibc/07-tendermint/tendermint_test.go b/x/ibc/07-tendermint/tendermint_test.go index 9792d3034bc4..8d05ddaddb75 100644 --- a/x/ibc/07-tendermint/tendermint_test.go +++ b/x/ibc/07-tendermint/tendermint_test.go @@ -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) diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go index 974091a97928..5ee27a45bbe2 100644 --- a/x/mint/types/codec.go +++ b/x/mint/types/codec.go @@ -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() } diff --git a/x/params/keeper/querier.go b/x/params/keeper/querier.go index a898bacc6d42..ac218e05e9a9 100644 --- a/x/params/keeper/querier.go +++ b/x/params/keeper/querier.go @@ -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, ¶ms); err != nil { + if err := legacy.Cdc.UnmarshalJSON(req.Data, ¶ms); 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()) } diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 088c2977c1e1..5d52f7cb2621 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -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() } diff --git a/x/staking/legacy/v0_34/types.go b/x/staking/legacy/v0_34/types.go index 013edb792d9e..062fb3176044 100644 --- a/x/staking/legacy/v0_34/types.go +++ b/x/staking/legacy/v0_34/types.go @@ -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) diff --git a/x/staking/legacy/v0_36/types.go b/x/staking/legacy/v0_36/types.go index 246d6b011821..0f90d1de9678 100644 --- a/x/staking/legacy/v0_36/types.go +++ b/x/staking/legacy/v0_36/types.go @@ -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) diff --git a/x/staking/legacy/v0_38/types.go b/x/staking/legacy/v0_38/types.go index b3c27e8b47cd..86f07d8a7b40 100644 --- a/x/staking/legacy/v0_38/types.go +++ b/x/staking/legacy/v0_38/types.go @@ -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) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 2d98a6615b0d..67e26be1e810 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -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 } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index bc33edd5eee3..3f402945d6ee 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -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() } diff --git a/x/staking/types/validator_test.go b/x/staking/types/validator_test.go index 54e0c7ebb639..e914a87e8792 100644 --- a/x/staking/types/validator_test.go +++ b/x/staking/types/validator_test.go @@ -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) }