diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bed0902b3..d87cbd427a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,8 +107,8 @@ information on how to implement the new `Keyring` interface. * [\#5858](https://github.com/cosmos/cosmos-sdk/pull/5858) Make Keyring store keys by name and address's hexbytes representation. * (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Remove APIs for getting and setting `x/evidence` parameters. `BaseApp` now uses a `ParamStore` to manage Tendermint consensus parameters which is managed via the `x/params` `Substore` type. * (export) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) `AppExporter` now returns ABCI consensus parameters to be included in marshaled exported state. These parameters must be returned from the application via the `BaseApp`. -* (codec) `*codec.Codec` is now a wrapper around Amino which provides backwards compatibility with protobuf `Any`. -ALL legacy code should use `*codec.Codec` instead of `*amino.Codec` directly +* (codec) `*codec.LegacyAmino` is now a wrapper around Amino which provides backwards compatibility with protobuf `Any`. +ALL legacy code should use `*codec.LegacyAmino` instead of `*amino.Codec` directly * (x/gov) [\#6147](https://github.com/cosmos/cosmos-sdk/pull/6147) The `Content` field on `Proposal` and `MsgSubmitProposal` is now `Any` in concordance with [ADR 019](docs/architecture/adr-019-protobuf-state-encoding.md) and `GetContent` should now be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposal` constructor now may return an `error` diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 3dcef1600b..569bcb4401 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -80,7 +80,7 @@ func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp { return NewBaseApp(name, logger, db, testTxDecoder(codec), options...) } -func registerTestCodec(cdc *codec.Codec) { +func registerTestCodec(cdc *codec.LegacyAmino) { // register Tx, Msg sdk.RegisterCodec(cdc) @@ -631,7 +631,7 @@ func (msg msgCounter2) ValidateBasic() error { } // amino decode -func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { +func testTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var tx txTest if len(txBytes) == 0 { diff --git a/client/context.go b/client/context.go index 21e5a29ac7..74f791e621 100644 --- a/client/context.go +++ b/client/context.go @@ -43,7 +43,7 @@ type Context struct { NodeURI string // TODO: Deprecated (remove). - Codec *codec.Codec + LegacyAmino *codec.LegacyAmino } // WithKeyring returns a copy of the context with an updated keyring. @@ -66,8 +66,8 @@ func (ctx Context) WithJSONMarshaler(m codec.JSONMarshaler) Context { // WithCodec returns a copy of the context with an updated codec. // TODO: Deprecated (remove). -func (ctx Context) WithCodec(cdc *codec.Codec) Context { - ctx.Codec = cdc +func (ctx Context) WithLegacyAmino(cdc *codec.LegacyAmino) Context { + ctx.LegacyAmino = cdc return ctx } diff --git a/client/context_test.go b/client/context_test.go index accca7dcff..7d879e1b4e 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -71,7 +71,7 @@ x: "10" // amino // amino := testdata.NewTestAmino() - ctx = ctx.WithJSONMarshaler(codec.NewAminoCodec(&codec.Codec{Amino: amino})) + ctx = ctx.WithJSONMarshaler(codec.NewAminoCodec(&codec.LegacyAmino{Amino: amino})) // json buf = &bytes.Buffer{} diff --git a/client/keys/codec.go b/client/keys/codec.go index 1d1e6d8790..02d8389ada 100644 --- a/client/keys/codec.go +++ b/client/keys/codec.go @@ -6,7 +6,7 @@ import ( ) // KeysCdc defines codec to be used with key operations -var KeysCdc *codec.Codec +var KeysCdc *codec.LegacyAmino func init() { KeysCdc = codec.New() diff --git a/client/query.go b/client/query.go index 4173b916c6..a485210c03 100644 --- a/client/query.go +++ b/client/query.go @@ -60,7 +60,7 @@ func (ctx Context) QuerySubspace(subspace []byte, storeName string) (res []sdk.K return res, height, err } - ctx.Codec.MustUnmarshalBinaryBare(resRaw, &res) + ctx.LegacyAmino.MustUnmarshalBinaryBare(resRaw, &res) return } diff --git a/client/tx/legacy.go b/client/tx/legacy.go index b32fb5165c..80f9e4ef8c 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -11,7 +11,8 @@ import ( ) // ConvertTxToStdTx converts a transaction to the legacy StdTx format -func ConvertTxToStdTx(codec *codec.Codec, tx signing.Tx) (types.StdTx, error) { +func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (types.StdTx, error) { + if stdTx, ok := tx.(types.StdTx); ok { return stdTx, nil } diff --git a/client/tx/tx.go b/client/tx/tx.go index 14a4bcce18..bcffbc321e 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -178,7 +178,7 @@ func WriteGeneratedTxResponse( txf = txf.WithGas(adjusted) if br.Simulate { - rest.WriteSimulationResponse(w, ctx.Codec, txf.Gas()) + rest.WriteSimulationResponse(w, ctx.LegacyAmino, txf.Gas()) return } } @@ -188,12 +188,12 @@ func WriteGeneratedTxResponse( return } - stdTx, err := ConvertTxToStdTx(ctx.Codec, tx.GetTx()) + stdTx, err := ConvertTxToStdTx(ctx.LegacyAmino, tx.GetTx()) if rest.CheckInternalServerError(w, err) { return } - output, err := ctx.Codec.MarshalJSON(stdTx) + output, err := ctx.LegacyAmino.MarshalJSON(stdTx) if rest.CheckInternalServerError(w, err) { return } diff --git a/codec/amino.go b/codec/amino.go index a7348ee4b8..058f2fa238 100644 --- a/codec/amino.go +++ b/codec/amino.go @@ -15,23 +15,23 @@ import ( // deprecated: Codec defines a wrapper for an Amino codec that properly handles protobuf // types with Any's -type Codec struct { +type LegacyAmino struct { Amino *amino.Codec } -var _ JSONMarshaler = &Codec{} +var _ JSONMarshaler = &LegacyAmino{} -func (cdc *Codec) Seal() { +func (cdc *LegacyAmino) Seal() { cdc.Amino.Seal() } -func New() *Codec { - return &Codec{amino.NewCodec()} +func New() *LegacyAmino { + return &LegacyAmino{amino.NewCodec()} } // RegisterEvidences registers Tendermint evidence types with the provided Amino // codec. -func RegisterEvidences(cdc *Codec) { +func RegisterEvidences(cdc *LegacyAmino) { tmtypes.RegisterEvidences(cdc.Amino) } @@ -62,23 +62,23 @@ func MustMarshalJSONIndent(m JSONMarshaler, obj interface{}) []byte { return bz } -func (cdc *Codec) marshalAnys(o interface{}) error { +func (cdc *LegacyAmino) marshalAnys(o interface{}) error { return types.UnpackInterfaces(o, types.AminoPacker{Cdc: cdc.Amino}) } -func (cdc *Codec) unmarshalAnys(o interface{}) error { +func (cdc *LegacyAmino) unmarshalAnys(o interface{}) error { return types.UnpackInterfaces(o, types.AminoUnpacker{Cdc: cdc.Amino}) } -func (cdc *Codec) jsonMarshalAnys(o interface{}) error { +func (cdc *LegacyAmino) jsonMarshalAnys(o interface{}) error { return types.UnpackInterfaces(o, types.AminoJSONPacker{Cdc: cdc.Amino}) } -func (cdc *Codec) jsonUnmarshalAnys(o interface{}) error { +func (cdc *LegacyAmino) jsonUnmarshalAnys(o interface{}) error { return types.UnpackInterfaces(o, types.AminoJSONUnpacker{Cdc: cdc.Amino}) } -func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { +func (cdc *LegacyAmino) MarshalBinaryBare(o interface{}) ([]byte, error) { err := cdc.marshalAnys(o) if err != nil { return nil, err @@ -86,7 +86,7 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { return cdc.Amino.MarshalBinaryBare(o) } -func (cdc *Codec) MustMarshalBinaryBare(o interface{}) []byte { +func (cdc *LegacyAmino) MustMarshalBinaryBare(o interface{}) []byte { bz, err := cdc.MarshalBinaryBare(o) if err != nil { panic(err) @@ -94,7 +94,7 @@ func (cdc *Codec) MustMarshalBinaryBare(o interface{}) []byte { return bz } -func (cdc *Codec) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error) { +func (cdc *LegacyAmino) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error) { err := cdc.marshalAnys(o) if err != nil { return nil, err @@ -102,7 +102,7 @@ func (cdc *Codec) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error) { return cdc.Amino.MarshalBinaryLengthPrefixed(o) } -func (cdc *Codec) MustMarshalBinaryLengthPrefixed(o interface{}) []byte { +func (cdc *LegacyAmino) MustMarshalBinaryLengthPrefixed(o interface{}) []byte { bz, err := cdc.MarshalBinaryLengthPrefixed(o) if err != nil { panic(err) @@ -110,7 +110,7 @@ func (cdc *Codec) MustMarshalBinaryLengthPrefixed(o interface{}) []byte { return bz } -func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { +func (cdc *LegacyAmino) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { err := cdc.Amino.UnmarshalBinaryBare(bz, ptr) if err != nil { return err @@ -118,14 +118,14 @@ func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { return cdc.unmarshalAnys(ptr) } -func (cdc *Codec) MustUnmarshalBinaryBare(bz []byte, ptr interface{}) { +func (cdc *LegacyAmino) MustUnmarshalBinaryBare(bz []byte, ptr interface{}) { err := cdc.UnmarshalBinaryBare(bz, ptr) if err != nil { panic(err) } } -func (cdc *Codec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error { +func (cdc *LegacyAmino) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error { err := cdc.Amino.UnmarshalBinaryLengthPrefixed(bz, ptr) if err != nil { return err @@ -133,14 +133,14 @@ func (cdc *Codec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) erro return cdc.unmarshalAnys(ptr) } -func (cdc *Codec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) { +func (cdc *LegacyAmino) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) { err := cdc.UnmarshalBinaryLengthPrefixed(bz, ptr) if err != nil { panic(err) } } -func (cdc *Codec) MarshalJSON(o interface{}) ([]byte, error) { +func (cdc *LegacyAmino) MarshalJSON(o interface{}) ([]byte, error) { err := cdc.jsonMarshalAnys(o) if err != nil { return nil, err @@ -148,7 +148,7 @@ func (cdc *Codec) MarshalJSON(o interface{}) ([]byte, error) { return cdc.Amino.MarshalJSON(o) } -func (cdc *Codec) MustMarshalJSON(o interface{}) []byte { +func (cdc *LegacyAmino) MustMarshalJSON(o interface{}) []byte { bz, err := cdc.MarshalJSON(o) if err != nil { panic(err) @@ -156,7 +156,7 @@ func (cdc *Codec) MustMarshalJSON(o interface{}) []byte { return bz } -func (cdc *Codec) UnmarshalJSON(bz []byte, ptr interface{}) error { +func (cdc *LegacyAmino) UnmarshalJSON(bz []byte, ptr interface{}) error { err := cdc.Amino.UnmarshalJSON(bz, ptr) if err != nil { return err @@ -164,26 +164,26 @@ func (cdc *Codec) UnmarshalJSON(bz []byte, ptr interface{}) error { return cdc.jsonUnmarshalAnys(ptr) } -func (cdc *Codec) MustUnmarshalJSON(bz []byte, ptr interface{}) { +func (cdc *LegacyAmino) MustUnmarshalJSON(bz []byte, ptr interface{}) { err := cdc.UnmarshalJSON(bz, ptr) if err != nil { panic(err) } } -func (*Codec) UnpackAny(*types.Any, interface{}) error { +func (*LegacyAmino) UnpackAny(*types.Any, interface{}) error { return errors.New("AminoCodec can't handle unpack protobuf Any's") } -func (cdc *Codec) RegisterInterface(ptr interface{}, iopts *amino.InterfaceOptions) { +func (cdc *LegacyAmino) RegisterInterface(ptr interface{}, iopts *amino.InterfaceOptions) { cdc.Amino.RegisterInterface(ptr, iopts) } -func (cdc *Codec) RegisterConcrete(o interface{}, name string, copts *amino.ConcreteOptions) { +func (cdc *LegacyAmino) RegisterConcrete(o interface{}, name string, copts *amino.ConcreteOptions) { cdc.Amino.RegisterConcrete(o, name, copts) } -func (cdc *Codec) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error) { +func (cdc *LegacyAmino) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error) { err := cdc.jsonMarshalAnys(o) if err != nil { panic(err) @@ -191,6 +191,6 @@ 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 { +func (cdc *LegacyAmino) PrintTypes(out io.Writer) error { return cdc.Amino.PrintTypes(out) } diff --git a/codec/amino_codec.go b/codec/amino_codec.go index a7cf476bae..79b58fa816 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -3,43 +3,43 @@ package codec // AminoCodec defines a codec that utilizes Codec for both binary and JSON // encoding. type AminoCodec struct { - *Codec + *LegacyAmino } var _ Marshaler = &AminoCodec{} -func NewAminoCodec(codec *Codec) *AminoCodec { - return &AminoCodec{Codec: codec} +func NewAminoCodec(codec *LegacyAmino) *AminoCodec { + return &AminoCodec{LegacyAmino: codec} } func (ac *AminoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) { - return ac.Codec.MarshalBinaryBare(o) + return ac.LegacyAmino.MarshalBinaryBare(o) } func (ac *AminoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte { - return ac.Codec.MustMarshalBinaryBare(o) + return ac.LegacyAmino.MustMarshalBinaryBare(o) } func (ac *AminoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error) { - return ac.Codec.MarshalBinaryLengthPrefixed(o) + return ac.LegacyAmino.MarshalBinaryLengthPrefixed(o) } func (ac *AminoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte { - return ac.Codec.MustMarshalBinaryLengthPrefixed(o) + return ac.LegacyAmino.MustMarshalBinaryLengthPrefixed(o) } func (ac *AminoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error { - return ac.Codec.UnmarshalBinaryBare(bz, ptr) + return ac.LegacyAmino.UnmarshalBinaryBare(bz, ptr) } func (ac *AminoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) { - ac.Codec.MustUnmarshalBinaryBare(bz, ptr) + ac.LegacyAmino.MustUnmarshalBinaryBare(bz, ptr) } func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error { - return ac.Codec.UnmarshalBinaryLengthPrefixed(bz, ptr) + return ac.LegacyAmino.UnmarshalBinaryLengthPrefixed(bz, ptr) } func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) { - ac.Codec.MustUnmarshalBinaryLengthPrefixed(bz, ptr) + ac.LegacyAmino.MustUnmarshalBinaryLengthPrefixed(bz, ptr) } diff --git a/codec/amino_codec_test.go b/codec/amino_codec_test.go index 937d2799ff..cc8e0fac14 100644 --- a/codec/amino_codec_test.go +++ b/codec/amino_codec_test.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" ) -func createTestCodec() *codec.Codec { +func createTestCodec() *codec.LegacyAmino { cdc := codec.New() cdc.RegisterInterface((*testdata.Animal)(nil), nil) diff --git a/codec/hybrid_codec.go b/codec/hybrid_codec.go index 7fbd109a3d..5e9667c708 100644 --- a/codec/hybrid_codec.go +++ b/codec/hybrid_codec.go @@ -9,7 +9,7 @@ type HybridCodec struct { amino Marshaler } -func NewHybridCodec(amino *Codec, unpacker types.AnyUnpacker) Marshaler { +func NewHybridCodec(amino *LegacyAmino, unpacker types.AnyUnpacker) Marshaler { return &HybridCodec{ proto: NewProtoCodec(unpacker), amino: NewAminoCodec(amino), diff --git a/codec/legacy/codec.go b/codec/legacy/codec.go index f4e0e5be3f..4298668e0b 100644 --- a/codec/legacy/codec.go +++ b/codec/legacy/codec.go @@ -9,7 +9,7 @@ import ( // has all Tendermint crypto and evidence types registered. // // TODO: Deprecated - remove this global. -var Cdc *codec.Codec +var Cdc *codec.LegacyAmino func init() { Cdc = codec.New() diff --git a/codec/types/compat.go b/codec/types/compat.go index c9c24cdcf0..3e42067763 100644 --- a/codec/types/compat.go +++ b/codec/types/compat.go @@ -25,7 +25,7 @@ func anyCompatError(errType string, x interface{}) error { } return fmt.Errorf( "%s marshaling error for %+v, this is likely because "+ - "amino is being used directly (instead of codec.Codec which is preferred) "+ + "amino is being used directly (instead of codec.LegacyAmino which is preferred) "+ "or UnpackInterfacesMessage is not defined for some type which contains "+ "a protobuf Any either directly or via one of its members. To see a "+ "stacktrace of where the error is coming from, set the var Debug = true "+ diff --git a/crypto/codec/amino.go b/crypto/codec/amino.go index 9ef14fe93d..017498717a 100644 --- a/crypto/codec/amino.go +++ b/crypto/codec/amino.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/types/multisig" ) -var amino *codec.Codec +var amino *codec.LegacyAmino func init() { amino = codec.New() @@ -19,7 +19,7 @@ func init() { // RegisterCrypto registers all crypto dependency types with the provided Amino // codec. -func RegisterCrypto(cdc *codec.Codec) { +func RegisterCrypto(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, ed25519.PubKeyAminoName, nil) diff --git a/crypto/keyring/codec.go b/crypto/keyring/codec.go index 6187ce5982..a71006228f 100644 --- a/crypto/keyring/codec.go +++ b/crypto/keyring/codec.go @@ -7,7 +7,7 @@ import ( ) // CryptoCdc defines the codec required for keys and info -var CryptoCdc *codec.Codec +var CryptoCdc *codec.LegacyAmino func init() { CryptoCdc = codec.New() @@ -17,7 +17,7 @@ func init() { } // RegisterCodec registers concrete types and interfaces on the given codec. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*Info)(nil), nil) cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil) cdc.RegisterConcrete(localInfo{}, "crypto/keys/localInfo", nil) diff --git a/crypto/ledger/amino.go b/crypto/ledger/amino.go index dd9ba8769f..24345226a8 100644 --- a/crypto/ledger/amino.go +++ b/crypto/ledger/amino.go @@ -13,7 +13,7 @@ func init() { } // RegisterAmino registers all go-crypto related types in the given (amino) codec. -func RegisterAmino(cdc *codec.Codec) { +func RegisterAmino(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(PrivKeyLedgerSecp256k1{}, "tendermint/PrivKeyLedgerSecp256k1", nil) } diff --git a/docs/architecture/adr-011-generalize-genesis-accounts.md b/docs/architecture/adr-011-generalize-genesis-accounts.md index 94e1dd1447..a8d528d1f0 100644 --- a/docs/architecture/adr-011-generalize-genesis-accounts.md +++ b/docs/architecture/adr-011-generalize-genesis-accounts.md @@ -77,7 +77,7 @@ type ModuleAccount struct { The `auth` codec definition: ```go -var ModuleCdc *codec.Codec +var ModuleCdc *codec.LegacyAmino func init() { ModuleCdc = codec.New() diff --git a/docs/architecture/adr-012-state-accessors.md b/docs/architecture/adr-012-state-accessors.md index 61cdbc94fa..b66e23eb67 100644 --- a/docs/architecture/adr-012-state-accessors.md +++ b/docs/architecture/adr-012-state-accessors.md @@ -41,7 +41,7 @@ We will define a type named `Mapping`: ```go type Mapping struct { storeKey sdk.StoreKey - cdc *codec.Codec + cdc *codec.LegacyAmino prefix []byte } ``` diff --git a/docs/architecture/adr-019-protobuf-state-encoding.md b/docs/architecture/adr-019-protobuf-state-encoding.md index 3abddd7921..aae56e7814 100644 --- a/docs/architecture/adr-019-protobuf-state-encoding.md +++ b/docs/architecture/adr-019-protobuf-state-encoding.md @@ -203,7 +203,7 @@ type InterfaceUnpacker interface { ``` Note that `InterfaceRegistry` usage does not deviate from standard protobuf -usage of `Any`, it just introduces a security and introspection layer for +usage of `Any`, it just introduces a security and introspection layer for golang usage. `InterfaceRegistry` will be a member of `ProtoCodec` and `HybridCodec` as @@ -270,6 +270,7 @@ interfaces before they're needed. To implement the `UnpackInterfaces` phase of deserialization which unpacks interfaces wrapped in `Any` before they're needed, we create an interface that `sdk.Msg`s and other types can implement: + ```go type UnpackInterfacesMessage interface { UnpackInterfaces(InterfaceUnpacker) error @@ -291,7 +292,7 @@ correct interface type. This has the added benefit that unmarshaling of `Any` values only happens once during initial deserialization rather than every time the value is read. Also, when `Any` values are first packed (for instance in a call to -`NewMsgSubmitEvidence`), the original interface value is cached so that +`NewMsgSubmitEvidence`), the original interface value is cached so that unmarshaling isn't needed to read it again. `MsgSubmitEvidence` could implement `UnpackInterfaces`, plus a convenience getter @@ -316,12 +317,12 @@ with the proper codec instance. What this means is that interfaces packed within have been registered properly with Amino). In order for this functionality to work: -* **all legacy code must use `*codec.Codec` instead of `*amino.Codec` which is -now a wrapper which properly handles `Any`** -* **all new code should use `Marshaler` which is compatible with both amino and -protobuf** -Also, before v0.39, `codec.Codec` will be renamed to `codec.LegacyAmino`. +- **all legacy code must use `*codec.LegacyAmino` instead of `*amino.Codec` which is + now a wrapper which properly handles `Any`** +- **all new code should use `Marshaler` which is compatible with both amino and + protobuf** +- Also, before v0.39, `codec.LegacyAmino` will be renamed to `codec.LegacyAmino`. ### Why Wasn't X Chosen Instead @@ -366,7 +367,7 @@ seamless. - Learning curve required to understand and implement Protobuf messages. - Slightly larger message size due to use of `Any`, although this could be offset -by a compression layer in the future + by a compression layer in the future ### Neutral @@ -374,3 +375,4 @@ by a compression layer in the future 1. https://github.com/cosmos/cosmos-sdk/issues/4977 2. https://github.com/cosmos/cosmos-sdk/issues/5444 + diff --git a/docs/building-modules/module-interfaces.md b/docs/building-modules/module-interfaces.md index 444c877bc2..d2761248d9 100644 --- a/docs/building-modules/module-interfaces.md +++ b/docs/building-modules/module-interfaces.md @@ -8,15 +8,15 @@ This document details how to build CLI and REST interfaces for a module. Example ## Pre-requisite Readings -* [Building Modules Intro](./intro.md) {prereq} +- [Building Modules Intro](./intro.md) {prereq} ## CLI -One of the main interfaces for an application is the [command-line interface](../interfaces/cli.md). This entrypoint adds commands from the application's modules to let end-users create [**messages**](./messages-and-queries.md#messages) and [**queries**](./messages-and-queries.md#queries). The CLI files are typically found in the `./x/moduleName/client/cli` folder. +One of the main interfaces for an application is the [command-line interface](../interfaces/cli.md). This entrypoint adds commands from the application's modules to let end-users create [**messages**](./messages-and-queries.md#messages) and [**queries**](./messages-and-queries.md#queries). The CLI files are typically found in the `./x/moduleName/client/cli` folder. ### Transaction Commands -[Transactions](../core/transactions.md) are created by users to wrap messages that trigger state changes when they get included in a valid block. Transaction commands typically have their own `tx.go` file in the module `./x/moduleName/client/cli` folder. The commands are specified in getter functions prefixed with `GetCmd` and include the name of the command. +[Transactions](../core/transactions.md) are created by users to wrap messages that trigger state changes when they get included in a valid block. Transaction commands typically have their own `tx.go` file in the module `./x/moduleName/client/cli` folder. The commands are specified in getter functions prefixed with `GetCmd` and include the name of the command. Here is an example from the `nameservice` module: @@ -25,19 +25,19 @@ Here is an example from the `nameservice` module: This getter function creates the command for the Buy Name transaction. It does the following: - **Construct the command:** Read the [Cobra Documentation](https://github.com/spf13/cobra) for details on how to create commands. - + **Use:** Specifies the format of a command-line entry users should type in order to invoke this command. In this case, the user uses `buy-name` as the name of the transaction command and provides the `name` the user wishes to buy and the `amount` the user is willing to pay. - + **Args:** The number of arguments the user provides, in this case exactly two: `name` and `amount`. - + **Short and Long:** A description for the function is provided here. A `Short` description is expected, and `Long` can be used to provide a more detailed description when a user uses the `--help` flag to ask for more information. - + **RunE:** Defines a function that can return an error, called when the command is executed. Using `Run` would do the same thing, but would not allow for errors to be returned. + - **Use:** Specifies the format of a command-line entry users should type in order to invoke this command. In this case, the user uses `buy-name` as the name of the transaction command and provides the `name` the user wishes to buy and the `amount` the user is willing to pay. + - **Args:** The number of arguments the user provides, in this case exactly two: `name` and `amount`. + - **Short and Long:** A description for the function is provided here. A `Short` description is expected, and `Long` can be used to provide a more detailed description when a user uses the `--help` flag to ask for more information. + - **RunE:** Defines a function that can return an error, called when the command is executed. Using `Run` would do the same thing, but would not allow for errors to be returned. - **`RunE` Function Body:** The function should be specified as a `RunE` to allow for errors to be returned. This function encapsulates all of the logic to create a new transaction that is ready to be relayed to nodes. - + The function should first initialize a [`TxBuilder`](../core/transactions.md#txbuilder) with the application `codec`'s `TxEncoder`, as well as a new [`Context`](../interfaces/query-lifecycle.md#context) with the `codec` and `AccountDecoder`. These contexts contain all the information provided by the user and will be used to transfer this user-specific information between processes. To learn more about how contexts are used in a transaction, click [here](../core/transactions.md#transaction-generation). - + If applicable, the command's arguments are parsed. Here, the `amount` given by the user is parsed into a denomination of `coins`. - + If applicable, the `Context` is used to retrieve any parameters such as the transaction originator's address to be used in the transaction. Here, the `from` address is retrieved by calling `cliCtx.getFromAddress()`. - + A [message](./messages-and-queries.md) is created using all parameters parsed from the command arguments and `Context`. The constructor function of the specific message type is called directly. It is good practice to call `ValidateBasic()` on the newly created message to run a sanity check and check for invalid arguments. - + Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `GenerateOrBroadcastMsgs()`. -- **Flags.** Add any [flags](#flags) to the command. No flags were specified here, but all transaction commands have flags to provide additional information from the user (e.g. amount of fees they are willing to pay). These *persistent* [transaction flags](../interfaces/cli.md#flags) can be added to a higher-level command so that they apply to all transaction commands. + - The function should first initialize a [`TxBuilder`](../core/transactions.md#txbuilder) with the application `codec`'s `TxEncoder`, as well as a new [`Context`](../interfaces/query-lifecycle.md#context) with the `codec` and `AccountDecoder`. These contexts contain all the information provided by the user and will be used to transfer this user-specific information between processes. To learn more about how contexts are used in a transaction, click [here](../core/transactions.md#transaction-generation). + - If applicable, the command's arguments are parsed. Here, the `amount` given by the user is parsed into a denomination of `coins`. + - If applicable, the `Context` is used to retrieve any parameters such as the transaction originator's address to be used in the transaction. Here, the `from` address is retrieved by calling `cliCtx.getFromAddress()`. + - A [message](./messages-and-queries.md) is created using all parameters parsed from the command arguments and `Context`. The constructor function of the specific message type is called directly. It is good practice to call `ValidateBasic()` on the newly created message to run a sanity check and check for invalid arguments. + - Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `GenerateOrBroadcastMsgs()`. +- **Flags.** Add any [flags](#flags) to the command. No flags were specified here, but all transaction commands have flags to provide additional information from the user (e.g. amount of fees they are willing to pay). These _persistent_ [transaction flags](../interfaces/cli.md#flags) can be added to a higher-level command so that they apply to all transaction commands. -Finally, the module needs to have a `GetTxCmd()`, which aggregates all of the transaction commands of the module. Often, each command getter function has its own file in the module's `cli` folder, and a separate `tx.go` file contains `GetTxCmd()`. Application developers wishing to include the module's transactions will call this function to add them as subcommands in their CLI. Here is the `auth` `GetTxCmd()` function, which adds the `Sign` and `MultiSign` commands. +Finally, the module needs to have a `GetTxCmd()`, which aggregates all of the transaction commands of the module. Often, each command getter function has its own file in the module's `cli` folder, and a separate `tx.go` file contains `GetTxCmd()`. Application developers wishing to include the module's transactions will call this function to add them as subcommands in their CLI. Here is the `auth` `GetTxCmd()` function, which adds the `Sign` and `MultiSign` commands. +++ https://github.com/cosmos/cosmos-sdk/blob/67f6b021180c7ef0bcf25b6597a629aca27766b8/x/auth/client/cli/tx.go#L11-L25 @@ -54,25 +54,24 @@ This query returns the address that owns a particular name. The getter function - **`codec` and `queryRoute`.** In addition to taking in the application `codec`, query command getters also take a `queryRoute` used to construct a path [Baseapp](../core/baseapp.md#query-routing) uses to route the query in the application. - **Construct the command.** Read the [Cobra Documentation](https://github.com/spf13/cobra) and the [transaction command](#transaction-commands) example above for more information. The user must type `whois` and provide the `name` they are querying for as the only argument. - **`RunE`.** The function should be specified as a `RunE` to allow for errors to be returned. This function encapsulates all of the logic to create a new query that is ready to be relayed to nodes. - + The function should first initialize a new [`Context`](../interfaces/query-lifecycle.md#context) with the application `codec`. - + If applicable, the `Context` is used to retrieve any parameters (e.g. the query originator's address to be used in the query) and marshal them with the query parameter type, in preparation to be relayed to a node. There are no `Context` parameters in this case because the query does not involve any information about the user. - + The `queryRoute` is used to construct a `path` [`baseapp`](../core/baseapp.md) will use to route the query to the appropriate [querier](./querier.md). The expected format for a query `path` is "queryCategory/queryRoute/queryType/arg1/arg2/...", where `queryCategory` can be `p2p`, `store`, `app`, or `custom`, `queryRoute` is the name of the module, and `queryType` is the name of the query type defined within the module. [`baseapp`](../core/baseapp.md) can handle each type of `queryCategory` by routing it to a module querier or retrieving results directly from stores and functions for querying peer nodes. Module queries are `custom` type queries (some SDK modules have exceptions, such as `auth` and `gov` module queries). - + The `Context` `QueryWithData()` function is used to relay the query to a node and retrieve the response. It requires the `path`. It returns the result and height of the query upon success or an error if the query fails. - + The `codec` is used to nmarshal the response and the `Context` is used to print the output back to the user. + - The function should first initialize a new [`Context`](../interfaces/query-lifecycle.md#context) with the application `codec`. + - If applicable, the `Context` is used to retrieve any parameters (e.g. the query originator's address to be used in the query) and marshal them with the query parameter type, in preparation to be relayed to a node. There are no `Context` parameters in this case because the query does not involve any information about the user. + - The `queryRoute` is used to construct a `path` [`baseapp`](../core/baseapp.md) will use to route the query to the appropriate [querier](./querier.md). The expected format for a query `path` is "queryCategory/queryRoute/queryType/arg1/arg2/...", where `queryCategory` can be `p2p`, `store`, `app`, or `custom`, `queryRoute` is the name of the module, and `queryType` is the name of the query type defined within the module. [`baseapp`](../core/baseapp.md) can handle each type of `queryCategory` by routing it to a module querier or retrieving results directly from stores and functions for querying peer nodes. Module queries are `custom` type queries (some SDK modules have exceptions, such as `auth` and `gov` module queries). + - The `Context` `QueryWithData()` function is used to relay the query to a node and retrieve the response. It requires the `path`. It returns the result and height of the query upon success or an error if the query fails. + - The `codec` is used to nmarshal the response and the `Context` is used to print the output back to the user. - **Flags.** Add any [flags](#flags) to the command. - Finally, the module also needs a `GetQueryCmd`, which aggregates all of the query commands of the module. Application developers wishing to include the module's queries will call this function to add them as subcommands in their CLI. Its structure is identical to the `GetTxCmd` command shown above. ### Flags [Flags](../interfaces/cli.md#flags) are entered by the user and allow for command customizations. Examples include the [fees](../basics/gas-fees.md) or gas prices users are willing to pay for their transactions. -The flags for a module are typically found in a `flags.go` file in the `./x/moduleName/client/cli` folder. Module developers can create a list of possible flags including the value type, default value, and a description displayed if the user uses a `help` command. In each transaction getter function, they can add flags to the commands and, optionally, mark flags as *required* so that an error is thrown if the user does not provide values for them. +The flags for a module are typically found in a `flags.go` file in the `./x/moduleName/client/cli` folder. Module developers can create a list of possible flags including the value type, default value, and a description displayed if the user uses a `help` command. In each transaction getter function, they can add flags to the commands and, optionally, mark flags as _required_ so that an error is thrown if the user does not provide values for them. For full details on flags, visit the [Cobra Documentation](https://github.com/spf13/cobra). -For example, the SDK `./client/flags` package includes a `PostCommands()` function that adds necessary flags to transaction commands, such as the `from` flag to indicate which address the transaction originates from. +For example, the SDK `./client/flags` package includes a `PostCommands()` function that adds necessary flags to transaction commands, such as the `from` flag to indicate which address the transaction originates from. +++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/client/flags/flags.go#L85-L116 @@ -84,7 +83,7 @@ cmd.Flags().String(FlagFrom, "", "Name or address of private key with which to s The input provided for this flag - called `FlagFrom` is a string with the default value of `""` if none is provided. If the user asks for a description of this flag, the description will be printed. -A flag can be marked as *required* so that an error is automatically thrown if the user does not provide a value: +A flag can be marked as _required_ so that an error is automatically thrown if the user does not provide a value: ```go cmd.MarkFlagRequired(FlagFrom) @@ -100,7 +99,7 @@ To support HTTP requests, the module developer needs to define possible request ### Request Types -Request types, which define structured interactions from users, must be defined for all *transaction* requests. Users using this method to interact with an application will send HTTP Requests with the required fields in order to trigger state changes in the application. Conventionally, each request is named with the suffix `Req`, e.g. `SendReq` for a Send transaction. Each struct should include a base request [`baseReq`](../interfaces/rest.md#basereq), the name of the transaction, and all the arguments the user must provide for the transaction. +Request types, which define structured interactions from users, must be defined for all _transaction_ requests. Users using this method to interact with an application will send HTTP Requests with the required fields in order to trigger state changes in the application. Conventionally, each request is named with the suffix `Req`, e.g. `SendReq` for a Send transaction. Each struct should include a base request [`baseReq`](../interfaces/rest.md#basereq), the name of the transaction, and all the arguments the user must provide for the transaction. Here is an example of a request to buy a name from the `nameservice` module: @@ -112,16 +111,16 @@ The `BaseReq` includes basic information that every request needs to have, simil `BaseReq` is a type defined in the SDK that encapsulates much of the transaction configurations similar to CLI command flags. Users must provide the information in the body of their requests. -* `From` indicates which [account](../basics/accounts.md) the transaction originates from. This account is used to sign the transaction. -* `Memo` sends a memo along with the transaction. -* `ChainID` specifies the unique identifier of the blockchain the transaction pertains to. -* `AccountNumber` is an identifier for the account. -* `Sequence`is the value of a counter measuring how many transactions have been sent from the account. It is used to prevent replay attacks. -* `Gas` refers to how much [gas](../basics/gas-fees.md), which represents computational resources, Tx consumes. Gas is dependent on the transaction and is not precisely calculated until execution, but can be estimated by providing auto as the value for `Gas`. -* `GasAdjustment` can be used to scale gas up in order to avoid underestimating. For example, users can specify their gas adjustment as 1.5 to use 1.5 times the estimated gas. -* `GasPrices` specifies how much the user is willing pay per unit of gas, which can be one or multiple denominations of tokens. For example, --gas-prices=0.025uatom, 0.025upho means the user is willing to pay 0.025uatom AND 0.025upho per unit of gas. -* `Fees` specifies how much in [fees](../basics/gas-fees.md) the user is willing to pay in total. Note that the user only needs to provide either `gas-prices` or `fees`, but not both, because they can be derived from each other. -* `Simulate` instructs the application to ignore gas and simulate the transaction running without broadcasting. +- `From` indicates which [account](../basics/accounts.md) the transaction originates from. This account is used to sign the transaction. +- `Memo` sends a memo along with the transaction. +- `ChainID` specifies the unique identifier of the blockchain the transaction pertains to. +- `AccountNumber` is an identifier for the account. +- `Sequence`is the value of a counter measuring how many transactions have been sent from the account. It is used to prevent replay attacks. +- `Gas` refers to how much [gas](../basics/gas-fees.md), which represents computational resources, Tx consumes. Gas is dependent on the transaction and is not precisely calculated until execution, but can be estimated by providing auto as the value for `Gas`. +- `GasAdjustment` can be used to scale gas up in order to avoid underestimating. For example, users can specify their gas adjustment as 1.5 to use 1.5 times the estimated gas. +- `GasPrices` specifies how much the user is willing pay per unit of gas, which can be one or multiple denominations of tokens. For example, --gas-prices=0.025uatom, 0.025upho means the user is willing to pay 0.025uatom AND 0.025upho per unit of gas. +- `Fees` specifies how much in [fees](../basics/gas-fees.md) the user is willing to pay in total. Note that the user only needs to provide either `gas-prices` or `fees`, but not both, because they can be derived from each other. +- `Simulate` instructs the application to ignore gas and simulate the transaction running without broadcasting. ### Request Handlers @@ -133,13 +132,12 @@ Here is an example of a request handler for the nameservice module `buyNameReq` The request handler can be broken down as follows: -* **Parse Request:** The request handler first attempts to parse the request, and then run `Sanitize` and `ValidateBasic` on the underlying `BaseReq` to check the validity of the request. Next, it attempts to parse the arguments `Buyer` and `Amount` to the types `AccountAddress` and `Coins` respectively. -* **Message:** Then, a [message](./messages-and-queries.md) of the type `MsgBuyName` (defined by the module developer to trigger the state changes for this transaction) is created from the values and another sanity check, `ValidateBasic` is run on it. -* **Generate Transaction:** Finally, the HTTP `ResponseWriter`, application [`codec`](../core/encoding.md), [`Context`](../interfaces/query-lifecycle.md#context), request [`BaseReq`](../interfaces/rest.md#basereq), and message is passed to `WriteGenerateStdTxResponse` to further process the request. +- **Parse Request:** The request handler first attempts to parse the request, and then run `Sanitize` and `ValidateBasic` on the underlying `BaseReq` to check the validity of the request. Next, it attempts to parse the arguments `Buyer` and `Amount` to the types `AccountAddress` and `Coins` respectively. +- **Message:** Then, a [message](./messages-and-queries.md) of the type `MsgBuyName` (defined by the module developer to trigger the state changes for this transaction) is created from the values and another sanity check, `ValidateBasic` is run on it. +- **Generate Transaction:** Finally, the HTTP `ResponseWriter`, application [`codec`](../core/encoding.md), [`Context`](../interfaces/query-lifecycle.md#context), request [`BaseReq`](../interfaces/rest.md#basereq), and message is passed to `WriteGenerateStdTxResponse` to further process the request. To read more about how a transaction is generated, visit the transactions documentation [here](../core/transactions.md#transaction-generation). - ### Register Routes The application CLI entrypoint will have a `RegisterRoutes` function in its `main.go` file, which calls the `registerRoutes` functions of each module utilized by the application. Module developers need to implement `registerRoutes` for their modules so that applications are able to route messages and queries to their corresponding handlers and queriers. @@ -148,8 +146,8 @@ The router used by the SDK is [Gorilla Mux](https://github.com/gorilla/mux). The Here is a `registerRoutes` function with one query route example from the [nameservice tutorial](https://cosmos.network/docs/tutorial/rest.html): -``` go -func RegisterRoutes(cliCtx client.Context, r *mux.Router, cdc *codec.Codec, storeName string) { +```go +func RegisterRoutes(cliCtx client.Context, r *mux.Router, cdc *codec.LegacyAmino, storeName string) { // ResolveName Query r.HandleFunc(fmt.Sprintf("/%s/names/{%s}", storeName, restName), resolveNameHandler(cdc, cliCtx, storeName)).Methods("GET") } @@ -157,11 +155,10 @@ func RegisterRoutes(cliCtx client.Context, r *mux.Router, cdc *codec.Codec, stor A few things to note: -* The router `r` has already been initialized by the application and is passed in here as an argument - this function is able to add on the nameservice module's routes onto any application's router. The application must also provide a [`Context`](../interfaces/query-lifecycle.md#context) that the querier will need to process user requests and the application [`codec`](../core/encoding.md) for encoding and decoding application-specific types. -* `"/%s/names/{%s}", storeName, restName` is the url for the HTTP request. `storeName` is the name of the module, `restName` is a variable provided by the user to specify what kind of query they are making. -* `resolveNameHandler` is the query request handler defined by the module developer. It also takes the application `codec` and `Context` passed in from the user side, as well as the `storeName`. -* `"GET"` is the HTTP Request method. As to be expected, queries are typically GET requests. Transactions are typically POST and PUT requests. - +- The router `r` has already been initialized by the application and is passed in here as an argument - this function is able to add on the nameservice module's routes onto any application's router. The application must also provide a [`Context`](../interfaces/query-lifecycle.md#context) that the querier will need to process user requests and the application [`codec`](../core/encoding.md) for encoding and decoding application-specific types. +- `"/%s/names/{%s}", storeName, restName` is the url for the HTTP request. `storeName` is the name of the module, `restName` is a variable provided by the user to specify what kind of query they are making. +- `resolveNameHandler` is the query request handler defined by the module developer. It also takes the application `codec` and `Context` passed in from the user side, as well as the `storeName`. +- `"GET"` is the HTTP Request method. As to be expected, queries are typically GET requests. Transactions are typically POST and PUT requests. ## Next {hide} diff --git a/docs/building-modules/module-manager.md b/docs/building-modules/module-manager.md index 8d8abf668c..17bf12a036 100644 --- a/docs/building-modules/module-manager.md +++ b/docs/building-modules/module-manager.md @@ -12,7 +12,7 @@ Cosmos SDK modules need to implement the [`AppModule` interfaces](#application-m ## Application Module Interfaces -Application module interfaces exist to facilitate the composition of modules together to form a functional SDK application. There are 3 main application module interfaces: +Application module interfaces exist to facilitate the composition of modules together to form a functional SDK application. There are 3 main application module interfaces: - [`AppModuleBasic`](#appmodulebasic) for independent module functionalities. - [`AppModule`](#appmodule) for inter-dependent module functionalities (except genesis-related functionalities). @@ -20,28 +20,28 @@ Application module interfaces exist to facilitate the composition of modules tog The `AppModuleBasic` interface exists to define independent methods of the module, i.e. those that do not depend on other modules in the application. This allows for the construction of the basic application structure early in the application definition, generally in the `init()` function of the [main application file](../basics/app-anatomy.md#core-application-file). -The `AppModule` interface exists to define inter-dependent module methods. Many modules need to interract with other modules, typically through [`keeper`s](./keeper.md), which means there is a need for an interface where modules list their `keeper`s and other methods that require a reference to another module's object. `AppModule` interface also enables the module manager to set the order of execution between module's methods like `BeginBlock` and `EndBlock`, which is important in cases where the order of execution between modules matters in the context of the application. +The `AppModule` interface exists to define inter-dependent module methods. Many modules need to interract with other modules, typically through [`keeper`s](./keeper.md), which means there is a need for an interface where modules list their `keeper`s and other methods that require a reference to another module's object. `AppModule` interface also enables the module manager to set the order of execution between module's methods like `BeginBlock` and `EndBlock`, which is important in cases where the order of execution between modules matters in the context of the application. Lastly the interface for genesis functionality `AppModuleGenesis` is separated out from full module functionality `AppModule` so that modules which -are only used for genesis can take advantage of the `Module` patterns without having to define many placeholder functions. +are only used for genesis can take advantage of the `Module` patterns without having to define many placeholder functions. ### `AppModuleBasic` -The `AppModuleBasic` interface defines the independent methods modules need to implement. +The `AppModuleBasic` interface defines the independent methods modules need to implement. +++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/module/module.go#L46-L59 Let us go through the methods: - `Name()`: Returns the name of the module as a `string`. -- `RegisterCodec(*codec.Codec)`: Registers the `codec` for the module, which is used to marhsal and unmarshal structs to/from `[]byte` in order to persist them in the moduel's `KVStore`. -- `DefaultGenesis()`: Returns a default [`GenesisState`](./genesis.md#genesisstate) for the module, marshalled to `json.RawMessage`. The default `GenesisState` need to be defined by the module developer and is primarily used for testing. -- `ValidateGenesis(json.RawMessage)`: Used to validate the `GenesisState` defined by a module, given in its `json.RawMessage` form. It will usually unmarshall the `json` before running a custom [`ValidateGenesis`](./genesis.md#validategenesis) function defined by the module developer. +- `RegisterCodec(*codec.LegacyAmino)`: Registers the `amino` codec for the module, which is used to marhsal and unmarshal structs to/from `[]byte` in order to persist them in the moduel's `KVStore`. +- `DefaultGenesis()`: Returns a default [`GenesisState`](./genesis.md#genesisstate) for the module, marshalled to `json.RawMessage`. The default `GenesisState` need to be defined by the module developer and is primarily used for testing. +- `ValidateGenesis(json.RawMessage)`: Used to validate the `GenesisState` defined by a module, given in its `json.RawMessage` form. It will usually unmarshall the `json` before running a custom [`ValidateGenesis`](./genesis.md#validategenesis) function defined by the module developer. - `RegisterRESTRoutes(client.Context, *mux.Router)`: Registers the REST routes for the module. These routes will be used to map REST request to the module in order to process them. See [../interfaces/rest.md] for more. -- `GetTxCmd(*codec.Codec)`: Returns the root [`Tx` command](./module-interfaces.md#tx) for the module. The subcommands of this root command are used by end-users to generate new transactions containing [`message`s](./messages-and-queries.md#queries) defined in the module. -- `GetQueryCmd(*codec.Codec)`: Return the root [`query` command](./module-interfaces.md#query) for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module. +- `GetTxCmd()`: Returns the root [`Tx` command](./module-interfaces.md#tx) for the module. The subcommands of this root command are used by end-users to generate new transactions containing [`message`s](./messages-and-queries.md#queries) defined in the module. +- `GetQueryCmd()`: Return the root [`query` command](./module-interfaces.md#query) for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module. -All the `AppModuleBasic` of an application are managed by the [`BasicManager`](#basicmanager). +All the `AppModuleBasic` of an application are managed by the [`BasicManager`](#basicmanager). ### `AppModuleGenesis` @@ -52,32 +52,32 @@ The `AppModuleGenesis` interface is a simple embedding of the `AppModuleBasic` i Let us go through the two added methods: - `InitGenesis(sdk.Context, json.RawMessage)`: Initializes the subset of the state managed by the module. It is called at genesis (i.e. when the chain is first started). -- `ExportGenesis(sdk.Context)`: Exports the latest subset of the state managed by the module to be used in a new genesis file. `ExportGenesis` is called for each module when a new chain is started from the state of an existing chain. +- `ExportGenesis(sdk.Context)`: Exports the latest subset of the state managed by the module to be used in a new genesis file. `ExportGenesis` is called for each module when a new chain is started from the state of an existing chain. -It does not have its own manager, and exists separately from [`AppModule`](#appmodule) only for modules that exist only to implement genesis functionalities, so that they can be managed without having to implement all of `AppModule`'s methods. If the module is not only used during genesis, `InitGenesis(sdk.Context, json.RawMessage)` and `ExportGenesis(sdk.Context)` will generally be defined as methods of the concrete type implementing hte `AppModule` interface. +It does not have its own manager, and exists separately from [`AppModule`](#appmodule) only for modules that exist only to implement genesis functionalities, so that they can be managed without having to implement all of `AppModule`'s methods. If the module is not only used during genesis, `InitGenesis(sdk.Context, json.RawMessage)` and `ExportGenesis(sdk.Context)` will generally be defined as methods of the concrete type implementing hte `AppModule` interface. ### `AppModule` -The `AppModule` interface defines the inter-dependent methods modules need to implement. +The `AppModule` interface defines the inter-dependent methods modules need to implement. +++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/module/module.go#L133-L149 -`AppModule`s are managed by the [module manager](#manager). This interface embeds the `AppModuleGenesis` interface so that the manager can access all the independent and genesis inter-dependent methods of the module. This means that a concrete type implementing the `AppModule` interface must either implement all the methods of `AppModuleGenesis` (and by extension `AppModuleBasic`), or include a concrete type that does as parameter. +`AppModule`s are managed by the [module manager](#manager). This interface embeds the `AppModuleGenesis` interface so that the manager can access all the independent and genesis inter-dependent methods of the module. This means that a concrete type implementing the `AppModule` interface must either implement all the methods of `AppModuleGenesis` (and by extension `AppModuleBasic`), or include a concrete type that does as parameter. Let us go through the methods of `AppModule`: -- `RegisterInvariants(sdk.InvariantRegistry)`: Registers the [`invariants`](./invariants.md) of the module. If the invariants deviates from its predicted value, the [`InvariantRegistry`](./invariants.md#registry) triggers appropriate logic (most often the chain will be halted). +- `RegisterInvariants(sdk.InvariantRegistry)`: Registers the [`invariants`](./invariants.md) of the module. If the invariants deviates from its predicted value, the [`InvariantRegistry`](./invariants.md#registry) triggers appropriate logic (most often the chain will be halted). - `Route()`: Returns the route for [`message`s](./messages-and-queries.md#messages) to be routed to the module by [`baseapp`](../core/baseapp.md#message-routing). -- `QuerierRoute()`: Returns the name of the module's query route, for [`queries`](./messages-and-queries.md#queries) to be routes to the module by [`baseapp`](../core/baseapp.md#query-routing). -- `NewQuerierHandler()`: Returns a [`querier`](./querier.md) given the query `path`, in order to process the `query`. -- `BeginBlock(sdk.Context, abci.RequestBeginBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the beginning of each block. Implement empty if no logic needs to be triggered at the beginning of each block for this module. -- `EndBlock(sdk.Context, abci.RequestEndBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the beginning of each block. This is also where the module can inform the underlying consensus engine of validator set changes (e.g. the `staking` module). Implement empty if no logic needs to be triggered at the beginning of each block for this module. +- `QuerierRoute()`: Returns the name of the module's query route, for [`queries`](./messages-and-queries.md#queries) to be routes to the module by [`baseapp`](../core/baseapp.md#query-routing). +- `NewQuerierHandler()`: Returns a [`querier`](./querier.md) given the query `path`, in order to process the `query`. +- `BeginBlock(sdk.Context, abci.RequestBeginBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the beginning of each block. Implement empty if no logic needs to be triggered at the beginning of each block for this module. +- `EndBlock(sdk.Context, abci.RequestEndBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the beginning of each block. This is also where the module can inform the underlying consensus engine of validator set changes (e.g. the `staking` module). Implement empty if no logic needs to be triggered at the beginning of each block for this module. ### Implementing the Application Module Interfaces -Typically, the various application module interfaces are implemented in a file called `module.go`, located in the module's folder (e.g. `./x/module/module.go`). +Typically, the various application module interfaces are implemented in a file called `module.go`, located in the module's folder (e.g. `./x/module/module.go`). -Almost every module need to implement the `AppModuleBasic` and `AppModule` interfaces. If the module is only used for genesis, it will implement `AppModuleGenesis` instead of `AppModule`. The concrete type that implements the interface can add parameters that are required for the implementation of the various methods of the interface. For example, the `Route()` function often calls a `NewHandler(k keeper)` function defined in [`handler.go`](./handler.md) and therefore needs to pass the module's [`keeper`](./keeper.md) as parameter. +Almost every module need to implement the `AppModuleBasic` and `AppModule` interfaces. If the module is only used for genesis, it will implement `AppModuleGenesis` instead of `AppModule`. The concrete type that implements the interface can add parameters that are required for the implementation of the various methods of the interface. For example, the `Route()` function often calls a `NewHandler(k keeper)` function defined in [`handler.go`](./handler.md) and therefore needs to pass the module's [`keeper`](./keeper.md) as parameter. ```go // example @@ -87,7 +87,7 @@ type AppModule struct { } ``` -In the example above, you can see that the `AppModule` concrete type references an `AppModuleBasic`, and not an `AppModuleGenesis`. That is because `AppModuleGenesis` only needs to be implemented in modules that focus on genesis-related functionalities. In most modules, the concrete `AppModule` type will have a reference to an `AppModuleBasic` and implement the two added methods of `AppModuleGenesis` directly in the `AppModule` type. +In the example above, you can see that the `AppModule` concrete type references an `AppModuleBasic`, and not an `AppModuleGenesis`. That is because `AppModuleGenesis` only needs to be implemented in modules that focus on genesis-related functionalities. In most modules, the concrete `AppModule` type will have a reference to an `AppModuleBasic` and implement the two added methods of `AppModuleGenesis` directly in the `AppModule` type. If no parameter is required (which is often the case for `AppModuleBasic`), just declare an empty concrete type like so: @@ -97,24 +97,23 @@ type AppModuleBasic struct{} ## Module Managers -Module managers are used to manage collections of `AppModuleBasic` and `AppModule`. +Module managers are used to manage collections of `AppModuleBasic` and `AppModule`. ### `BasicManager` -The `BasicManager` is a structure that lists all the `AppModuleBasic` of an application: +The `BasicManager` is a structure that lists all the `AppModuleBasic` of an application: +++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/module/module.go#L61-L63 It implements the following methods: - `NewBasicManager(modules ...AppModuleBasic)`: Constructor function. It takes a list of the application's `AppModuleBasic` and builds a new `BasicManager`. This function is generally called in the `init()` function of [`app.go`](../basics/app-anatomy.md#core-application-file) to quickly initialize the independent elements of the application's modules (click [here](https://github.com/cosmos/gaia/blob/master/app/app.go#L59-L74) to see an example). -- `RegisterCodec(cdc *codec.Codec)`: Registers the [`codec`s](../core/encoding.md) of each of the application's `AppModuleBasic`. This function is usually called early on in the [application's construction](../basics/app-anatomy.md#constructor). +- `RegisterCodec(cdc *codec.LegacyAmino)`: Registers the [`codec`s](../core/encoding.md) of each of the application's `AppModuleBasic`. This function is usually called early on in the [application's construction](../basics/app-anatomy.md#constructor). - `DefaultGenesis()`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis()`](./genesis.md#defaultgenesis) function of each module. It is used to construct a default genesis file for the application. - `ValidateGenesis(genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis()`](./genesis.md#validategenesis) function of each module. - `RegisterRESTRoutes(ctx client.Context, rtr *mux.Router)`: Registers REST routes for modules by calling the [`RegisterRESTRoutes`](./module-interfaces.md#register-routes) function of each module. This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md). -- `AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec)`: Adds modules' transaction commands to the application's [`rootTxCommand`](../interfaces/cli.md#transaction-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md). -- `AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec)`: Adds modules' query commands to the application's [`rootQueryCommand`](../interfaces/cli.md#query-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md). - +- `AddTxCommands(rootTxCmd *cobra.Command)`: Adds modules' transaction commands to the application's [`rootTxCommand`](../interfaces/cli.md#transaction-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md). +- `AddQueryCommands(rootQueryCmd *cobra.Command)`: Adds modules' query commands to the application's [`rootQueryCommand`](../interfaces/cli.md#query-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md). ### `Manager` @@ -131,9 +130,9 @@ The module manager is used throughout the application whenever an action on a co - `SetOrderEndBlockers(moduleNames ...string)`: Sets the order in which the `EndBlock()` function of each module will be called at the beginning of each block. This function is generally called from the application's main [constructor function](../basics/app-anatomy.md#constructor-function). - `RegisterInvariants(ir sdk.InvariantRegistry)`: Registers the [invariants](./invariants.md) of each module. - `RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter)`: Registers module routes to the application's `router`, in order to route [`message`s](./messages-and-queries.md#messages) to the appropriate [`handler`](./handler.md), and module query routes to the application's `queryRouter`, in order to route [`queries`](./messages-and-queries.md#queries) to the appropriate [`querier`](./querier.md). -- `InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage)`: Calls the [`InitGenesis`](./genesis.md#initgenesis) function of each module when the application is first started, in the order defined in `OrderInitGenesis`. Returns an `abci.ResponseInitChain` to the underlying consensus engine, which can contain validator updates. -- `ExportGenesis(ctx sdk.Context)`: Calls the [`ExportGenesis`](./genesis.md#exportgenesis) function of each module, in the order defined in `OrderExportGenesis`. The export constructs a genesis file from a previously existing state, and is mainly used when a hard-fork upgrade of the chain is required. -- `BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)`: At the beginning of each block, this function is called from [`baseapp`](../core/baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./beginblock-endblock.md) function of each module, in the order defined in `OrderBeginBlockers`. It creates a child [context](../core/context.md) with an event manager to aggregate [events](../core/events.md) emitted from all modules. The function returns an `abci.ResponseBeginBlock` which contains the aforementioned events. +- `InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage)`: Calls the [`InitGenesis`](./genesis.md#initgenesis) function of each module when the application is first started, in the order defined in `OrderInitGenesis`. Returns an `abci.ResponseInitChain` to the underlying consensus engine, which can contain validator updates. +- `ExportGenesis(ctx sdk.Context)`: Calls the [`ExportGenesis`](./genesis.md#exportgenesis) function of each module, in the order defined in `OrderExportGenesis`. The export constructs a genesis file from a previously existing state, and is mainly used when a hard-fork upgrade of the chain is required. +- `BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)`: At the beginning of each block, this function is called from [`baseapp`](../core/baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./beginblock-endblock.md) function of each module, in the order defined in `OrderBeginBlockers`. It creates a child [context](../core/context.md) with an event manager to aggregate [events](../core/events.md) emitted from all modules. The function returns an `abci.ResponseBeginBlock` which contains the aforementioned events. - `EndBlock(ctx sdk.Context, req abci.RequestEndBlock)`: At the end of each block, this function is called from [`baseapp`](../core/baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./beginblock-endblock.md) function of each module, in the order defined in `OrderEndBlockers`. It creates a child [context](../core/context.md) with an event manager to aggregate [events](../core/events.md) emitted from all modules. The function returns an `abci.ResponseEndBlock` which contains the aforementioned events, as well as validator set updates (if any). ## Next {hide} diff --git a/server/export_test.go b/server/export_test.go index a65163dec6..7b1df33fec 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -41,9 +41,9 @@ func TestExportCmd_ConsensusParams(t *testing.T) { serverCtx := NewDefaultContext() serverCtx.Config.RootDir = tempDir - clientCtx := client.Context{}.WithJSONMarshaler(app.Codec()) + clientCtx := client.Context{}.WithJSONMarshaler(app.LegacyAmino()) - genDoc := newDefaultGenesisDoc(app.Codec()) + genDoc := newDefaultGenesisDoc(app.LegacyAmino()) err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile()) app.InitChain( @@ -71,7 +71,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) { require.NoError(t, cmd.ExecuteContext(ctx)) var exportedGenDoc tmtypes.GenesisDoc - err = app.Codec().UnmarshalJSON(output.Bytes(), &exportedGenDoc) + err = app.LegacyAmino().UnmarshalJSON(output.Bytes(), &exportedGenDoc) if err != nil { t.Fatalf("error unmarshaling exported genesis doc: %s", err) } @@ -90,7 +90,7 @@ func createConfigFolder(dir string) error { return os.Mkdir(path.Join(dir, "config"), 0700) } -func newDefaultGenesisDoc(cdc *codec.Codec) *tmtypes.GenesisDoc { +func newDefaultGenesisDoc(cdc *codec.LegacyAmino) *tmtypes.GenesisDoc { genesisState := simapp.NewDefaultGenesisState() stateBytes, err := codec.MarshalJSONIndent(cdc, genesisState) diff --git a/server/mock/app.go b/server/mock/app.go index 51a50efc72..e3fdd2c914 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -103,7 +103,7 @@ func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci // AppGenState can be passed into InitCmd, returns a static string of a few // key-values that can be parsed by InitChainer -func AppGenState(_ *codec.Codec, _ types.GenesisDoc, _ []json.RawMessage) (appState json. +func AppGenState(_ *codec.LegacyAmino, _ types.GenesisDoc, _ []json.RawMessage) (appState json. RawMessage, err error) { appState = json.RawMessage(`{ "values": [ @@ -121,7 +121,7 @@ func AppGenState(_ *codec.Codec, _ types.GenesisDoc, _ []json.RawMessage) (appSt } // AppGenStateEmpty returns an empty transaction state for mocking. -func AppGenStateEmpty(_ *codec.Codec, _ types.GenesisDoc, _ []json.RawMessage) ( +func AppGenStateEmpty(_ *codec.LegacyAmino, _ types.GenesisDoc, _ []json.RawMessage) ( appState json.RawMessage, err error) { appState = json.RawMessage(``) return diff --git a/simapp/app.go b/simapp/app.go index 992725a077..72894458f8 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -128,7 +128,7 @@ var _ App = (*SimApp)(nil) // capabilities aren't needed for testing. type SimApp struct { *baseapp.BaseApp - cdc *codec.Codec + cdc *codec.LegacyAmino appCodec codec.Marshaler interfaceRegistry types.InterfaceRegistry @@ -392,10 +392,10 @@ func NewSimApp( return app } -// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by +// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by // simapp. It is useful for tests and clients who do not want to construct the // full simapp -func MakeCodecs() (codec.Marshaler, *codec.Codec) { +func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) { config := MakeEncodingConfig() return config.Marshaler, config.Amino } @@ -450,7 +450,7 @@ func (app *SimApp) BlockedAddrs() map[string]bool { // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. -func (app *SimApp) Codec() *codec.Codec { +func (app *SimApp) LegacyAmino() *codec.LegacyAmino { return app.cdc } diff --git a/simapp/app_test.go b/simapp/app_test.go index 3cfd7579b6..7481c5e363 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -18,7 +18,7 @@ func TestSimAppExport(t *testing.T) { app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) genesisState := NewDefaultGenesisState() - stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) require.NoError(t, err) // Initialize the chain diff --git a/simapp/params/encoding.go b/simapp/params/encoding.go index a5fe0eaea8..698408dafd 100644 --- a/simapp/params/encoding.go +++ b/simapp/params/encoding.go @@ -12,5 +12,5 @@ type EncodingConfig struct { InterfaceRegistry types.InterfaceRegistry Marshaler codec.Marshaler TxConfig client.TxConfig - Amino *codec.Codec + Amino *codec.LegacyAmino } diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index 6d8ee05dbf..d60dc5265d 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -30,8 +30,8 @@ func BenchmarkFullAppSimulation(b *testing.B) { // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( - b, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(app, app.Codec(), config), + b, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(app, app.LegacyAmino(), config), app.ModuleAccountAddrs(), config, ) @@ -69,8 +69,8 @@ func BenchmarkInvariants(b *testing.B) { // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( - b, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(app, app.Codec(), config), + b, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(app, app.LegacyAmino(), config), app.ModuleAccountAddrs(), config, ) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 83acd4a24f..7d84072f8a 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -72,8 +72,8 @@ func TestFullAppSimulation(t *testing.T) { // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( - t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(app, app.Codec(), config), + t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(app, app.LegacyAmino(), config), app.ModuleAccountAddrs(), config, ) @@ -104,8 +104,8 @@ func TestAppImportExport(t *testing.T) { // Run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( - t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(app, app.Codec(), config), + t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(app, app.LegacyAmino(), config), app.ModuleAccountAddrs(), config, ) @@ -137,12 +137,12 @@ func TestAppImportExport(t *testing.T) { require.Equal(t, "SimApp", newApp.Name()) var genesisState GenesisState - err = app.Codec().UnmarshalJSON(appState, &genesisState) + err = app.LegacyAmino().UnmarshalJSON(appState, &genesisState) require.NoError(t, err) ctxA := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) - newApp.mm.InitGenesis(ctxB, app.Codec(), genesisState) + newApp.mm.InitGenesis(ctxB, app.LegacyAmino(), genesisState) newApp.StoreConsensusParams(ctxB, consensusParams) fmt.Printf("comparing stores...\n") @@ -195,8 +195,8 @@ func TestAppSimulationAfterImport(t *testing.T) { // Run randomized simulation stopEarly, simParams, simErr := simulation.SimulateFromSeed( - t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(app, app.Codec(), config), + t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(app, app.LegacyAmino(), config), app.ModuleAccountAddrs(), config, ) @@ -237,8 +237,8 @@ func TestAppSimulationAfterImport(t *testing.T) { }) _, _, err = simulation.SimulateFromSeed( - t, os.Stdout, newApp.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(newApp, newApp.Codec(), config), + t, os.Stdout, newApp.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(newApp, newApp.LegacyAmino(), config), newApp.ModuleAccountAddrs(), config, ) require.NoError(t, err) @@ -282,8 +282,8 @@ func TestAppStateDeterminism(t *testing.T) { ) _, _, err := simulation.SimulateFromSeed( - t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()), - SimulationOperations(app, app.Codec(), config), + t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()), + SimulationOperations(app, app.LegacyAmino(), config), app.ModuleAccountAddrs(), config, ) require.NoError(t, err) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index efb5ca6484..22d45cb389 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -50,7 +50,7 @@ var ( WithJSONMarshaler(encodingConfig.Marshaler). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). - WithCodec(encodingConfig.Amino). + WithLegacyAmino(encodingConfig.Amino). WithInput(os.Stdin). WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). WithBroadcastMode(flags.BroadcastBlock). diff --git a/simapp/state.go b/simapp/state.go index 24d15f4514..1411fcc9ec 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -21,7 +21,7 @@ import ( // AppStateFn returns the initial application state using a genesis or the simulation parameters. // It panics if the user provides files for both of them. // If a file is not given for the genesis or the sim params, it creates a randomized one. -func AppStateFn(cdc *codec.Codec, simManager *module.SimulationManager) simtypes.AppStateFn { +func AppStateFn(cdc *codec.LegacyAmino, simManager *module.SimulationManager) simtypes.AppStateFn { return func(r *rand.Rand, accs []simtypes.Account, config simtypes.Config, ) (appState json.RawMessage, simAccs []simtypes.Account, chainID string, genesisTimestamp time.Time) { @@ -71,7 +71,7 @@ func AppStateFn(cdc *codec.Codec, simManager *module.SimulationManager) simtypes // AppStateRandomizedFn creates calls each module's GenesisState generator function // and creates the simulation params func AppStateRandomizedFn( - simManager *module.SimulationManager, r *rand.Rand, cdc *codec.Codec, + simManager *module.SimulationManager, r *rand.Rand, cdc *codec.LegacyAmino, accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, ) (json.RawMessage, []simtypes.Account) { numAccs := int64(len(accs)) @@ -125,7 +125,7 @@ func AppStateRandomizedFn( // AppStateFromGenesisFileFn util function to generate the genesis AppState // from a genesis.json file. -func AppStateFromGenesisFileFn(r io.Reader, cdc *codec.Codec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) { +func AppStateFromGenesisFileFn(r io.Reader, cdc *codec.LegacyAmino, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) { bytes, err := ioutil.ReadFile(genesisFile) if err != nil { panic(err) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 4901eb8cc4..2f12ccaafc 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -52,7 +52,7 @@ func Setup(isCheckTx bool) *SimApp { if !isCheckTx { // init chain must be called to stop deliverState from being nil genesisState := NewDefaultGenesisState() - stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) if err != nil { panic(err) } @@ -82,7 +82,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs // set genesis accounts authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) - genesisState[authtypes.ModuleName] = app.Codec().MustMarshalJSON(authGenesis) + genesisState[authtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(authGenesis) validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators)) @@ -110,7 +110,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs // set validators and delegations stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) - genesisState[stakingtypes.ModuleName] = app.Codec().MustMarshalJSON(stakingGenesis) + genesisState[stakingtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(stakingGenesis) totalSupply := sdk.NewCoins() for _, b := range balances { @@ -120,9 +120,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs // update total supply bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) - genesisState[banktypes.ModuleName] = app.Codec().MustMarshalJSON(bankGenesis) + genesisState[banktypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(bankGenesis) - stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) require.NoError(t, err) // init chain will set the validator set and initialize the genesis accounts @@ -156,7 +156,7 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba genesisState := NewDefaultGenesisState() authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) - genesisState[authtypes.ModuleName] = app.Codec().MustMarshalJSON(authGenesis) + genesisState[authtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(authGenesis) totalSupply := sdk.NewCoins() for _, b := range balances { @@ -164,9 +164,9 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba } bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) - genesisState[banktypes.ModuleName] = app.Codec().MustMarshalJSON(bankGenesis) + genesisState[banktypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(bankGenesis) - stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) if err != nil { panic(err) } diff --git a/simapp/types.go b/simapp/types.go index 64c1fe53f3..94fac5b77d 100644 --- a/simapp/types.go +++ b/simapp/types.go @@ -19,7 +19,7 @@ type App interface { // The application types codec. // NOTE: This shoult be sealed before being returned. - Codec() *codec.Codec + LegacyAmino() *codec.LegacyAmino // Application updates every begin block. BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock diff --git a/simapp/utils.go b/simapp/utils.go index c5add05647..7591010ae9 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -49,7 +49,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, // SimulationOperations retrieves the simulation params from the provided file path // and returns all the modules weighted operations -func SimulationOperations(app App, cdc *codec.Codec, config simtypes.Config) []simtypes.WeightedOperation { +func SimulationOperations(app App, cdc *codec.LegacyAmino, config simtypes.Config) []simtypes.WeightedOperation { simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, @@ -61,7 +61,7 @@ func SimulationOperations(app App, cdc *codec.Codec, config simtypes.Config) []s panic(err) } - app.Codec().MustUnmarshalJSON(bz, &simState.AppParams) + app.LegacyAmino().MustUnmarshalJSON(bz, &simState.AppParams) } simState.ParamChanges = app.SimulationManager().GenerateParamChanges(config.Seed) diff --git a/std/codec.go b/std/codec.go index 09686dc00d..664d1a8280 100644 --- a/std/codec.go +++ b/std/codec.go @@ -15,7 +15,7 @@ import ( // // NOTE: This codec will be deprecated in favor of AppCodec once all modules are // migrated. -func MakeCodec(bm module.BasicManager) *codec.Codec { +func MakeCodec(bm module.BasicManager) *codec.LegacyAmino { cdc := codec.New() bm.RegisterCodec(cdc) @@ -24,7 +24,7 @@ func MakeCodec(bm module.BasicManager) *codec.Codec { return cdc } -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { vesting.RegisterCodec(cdc) sdk.RegisterCodec(cdc) cryptocodec.RegisterCrypto(cdc) diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 737959ae02..cf32937f80 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -57,7 +57,7 @@ func (mr *MockAppModuleBasicMockRecorder) Name() *gomock.Call { } // RegisterCodec mocks base method -func (m *MockAppModuleBasic) RegisterCodec(arg0 *codec.Codec) { +func (m *MockAppModuleBasic) RegisterCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterCodec", arg0) } @@ -186,7 +186,7 @@ func (mr *MockAppModuleGenesisMockRecorder) Name() *gomock.Call { } // RegisterCodec mocks base method -func (m *MockAppModuleGenesis) RegisterCodec(arg0 *codec.Codec) { +func (m *MockAppModuleGenesis) RegisterCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterCodec", arg0) } @@ -343,7 +343,7 @@ func (mr *MockAppModuleMockRecorder) Name() *gomock.Call { } // RegisterCodec mocks base method -func (m *MockAppModule) RegisterCodec(arg0 *codec.Codec) { +func (m *MockAppModule) RegisterCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterCodec", arg0) } diff --git a/testutil/network/network.go b/testutil/network/network.go index 5e6c2f5d87..71a7bc7d50 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -62,7 +62,7 @@ func NewSimApp(val Validator) servertypes.Application { // in-process local testing network. type Config struct { Codec codec.Marshaler - LegacyAmino *codec.Codec + LegacyAmino *codec.LegacyAmino TxConfig client.TxConfig AccountRetriever client.AccountRetriever AppConstructor AppConstructor // the ABCI application constructor @@ -315,7 +315,7 @@ func New(t *testing.T, cfg Config) *Network { WithHomeDir(tmCfg.RootDir). WithChainID(cfg.ChainID). WithJSONMarshaler(cfg.Codec). - WithCodec(cfg.LegacyAmino). + WithLegacyAmino(cfg.LegacyAmino). WithTxConfig(cfg.TxConfig). WithAccountRetriever(cfg.AccountRetriever) diff --git a/types/codec.go b/types/codec.go index f2bd9b22c8..66ab0b32ed 100644 --- a/types/codec.go +++ b/types/codec.go @@ -7,7 +7,7 @@ import ( ) // Register the sdk message type -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*Msg)(nil), nil) cdc.RegisterInterface((*Tx)(nil), nil) } diff --git a/types/module/module.go b/types/module/module.go index 98ebc0bfa5..797c29cdb6 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -48,7 +48,7 @@ import ( // AppModuleBasic is the standard form for basic non-dependant elements of an application module. type AppModuleBasic interface { Name() string - RegisterCodec(*codec.Codec) + RegisterCodec(*codec.LegacyAmino) RegisterInterfaces(codectypes.InterfaceRegistry) DefaultGenesis(codec.JSONMarshaler) json.RawMessage @@ -73,7 +73,7 @@ func NewBasicManager(modules ...AppModuleBasic) BasicManager { } // RegisterCodec registers all module codecs -func (bm BasicManager) RegisterCodec(cdc *codec.Codec) { +func (bm BasicManager) RegisterCodec(cdc *codec.LegacyAmino) { for _, b := range bm { b.RegisterCodec(cdc) } diff --git a/types/module/module_test.go b/types/module/module_test.go index 1c1ab3d4d9..0826a76bb2 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -28,7 +28,7 @@ func TestBasicManager(t *testing.T) { cdc := codec.New() interfaceRegistry := types.NewInterfaceRegistry() clientCtx := client.Context{} - clientCtx = clientCtx.WithCodec(cdc) + clientCtx = clientCtx.WithLegacyAmino(cdc) wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)} mockAppModuleBasic1 := mocks.NewMockAppModuleBasic(mockCtrl) diff --git a/types/module/simulation.go b/types/module/simulation.go index 2efcb669a4..c3e01066e4 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -99,7 +99,7 @@ func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simu // GenesisState generator function type SimulationState struct { AppParams simulation.AppParams - Cdc *codec.Codec // application codec + Cdc *codec.LegacyAmino // application codec Rand *rand.Rand // random number GenState map[string]json.RawMessage // genesis state Accounts []simulation.Account // simulation accounts diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index bd33f5dc0d..a6eb24c20a 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -170,7 +170,7 @@ func ExamplePaginate() { accountStore := prefix.NewStore(balancesStore, addr1.Bytes()) pageRes, err := query.Paginate(accountStore, request.Pagination, func(key []byte, value []byte) error { var tempRes sdk.Coin - err := app.Codec().UnmarshalBinaryBare(value, &tempRes) + err := app.LegacyAmino().UnmarshalBinaryBare(value, &tempRes) if err != nil { return err } diff --git a/types/rest/rest.go b/types/rest/rest.go index c1aebd44b3..7eb29e36b9 100644 --- a/types/rest/rest.go +++ b/types/rest/rest.go @@ -310,7 +310,7 @@ func PostProcessResponse(w http.ResponseWriter, ctx client.Context, resp interfa if ctx.JSONMarshaler != nil { marshaler = ctx.JSONMarshaler } else { - marshaler = ctx.Codec + marshaler = ctx.LegacyAmino } switch res := resp.(type) { diff --git a/types/rest/rest_test.go b/types/rest/rest_test.go index 1cd0b10ea5..3a57caa472 100644 --- a/types/rest/rest_test.go +++ b/types/rest/rest_test.go @@ -203,14 +203,14 @@ func TestProcessPostResponse(t *testing.T) { cdc := codec.New() cryptocodec.RegisterCrypto(cdc) cdc.RegisterConcrete(&mockAccount{}, "cosmos-sdk/mockAccount", nil) - ctx = ctx.WithCodec(cdc) + ctx = ctx.WithLegacyAmino(cdc) // setup expected results - jsonNoIndent, err := ctx.Codec.MarshalJSON(acc) + jsonNoIndent, err := ctx.LegacyAmino.MarshalJSON(acc) require.Nil(t, err) respNoIndent := rest.NewResponseWithHeight(height, jsonNoIndent) - expectedNoIndent, err := ctx.Codec.MarshalJSON(respNoIndent) + expectedNoIndent, err := ctx.LegacyAmino.MarshalJSON(respNoIndent) require.Nil(t, err) // check that negative height writes an error @@ -402,7 +402,7 @@ func runPostProcessResponse(t *testing.T, ctx client.Context, obj interface{}, e require.Nil(t, err) require.Equal(t, expectedBody, body) - marshalled, err := ctx.Codec.MarshalJSON(obj) + marshalled, err := ctx.LegacyAmino.MarshalJSON(obj) require.NoError(t, err) // test using marshalled struct diff --git a/types/simulation/types.go b/types/simulation/types.go index 1ede0c0554..be4027c9fa 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -135,7 +135,7 @@ type AppParams map[string]json.RawMessage // object. If it exists, it'll be decoded and returned. Otherwise, the provided // ParamSimulator is used to generate a random value or default value (eg: in the // case of operation weights where Rand is not used). -func (sp AppParams) GetOrGenerate(cdc *codec.Codec, key string, ptr interface{}, r *rand.Rand, ps ParamSimulator) { +func (sp AppParams) GetOrGenerate(cdc *codec.LegacyAmino, key string, ptr interface{}, r *rand.Rand, ps ParamSimulator) { if v, ok := sp[key]; ok && v != nil { cdc.MustUnmarshalJSON(v, ptr) return diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 876ab3a746..dd879de6ad 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -325,7 +325,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() { codec := codec2.New() sdk.RegisterCodec(codec) banktypes.RegisterCodec(codec) - val1.ClientCtx.Codec = codec + val1.ClientCtx.LegacyAmino = codec // Generate 2 accounts and a multisig. account1, err := val1.ClientCtx.Keyring.Key("newAccount1") @@ -436,7 +436,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() { codec := codec2.New() sdk.RegisterCodec(codec) banktypes.RegisterCodec(codec) - val1.ClientCtx.Codec = codec + val1.ClientCtx.LegacyAmino = codec // Generate 2 accounts and a multisig. account1, err := val1.ClientCtx.Keyring.Key("newAccount1") @@ -537,7 +537,7 @@ func (s *IntegrationTestSuite) TestCLIMultisign() { codec := codec2.New() sdk.RegisterCodec(codec) banktypes.RegisterCodec(codec) - val1.ClientCtx.Codec = codec + val1.ClientCtx.LegacyAmino = codec // Generate 2 accounts and a multisig. account1, err := val1.ClientCtx.Keyring.Key("newAccount1") diff --git a/x/auth/client/query.go b/x/auth/client/query.go index ed8ecacd7a..5bd4cacd38 100644 --- a/x/auth/client/query.go +++ b/x/auth/client/query.go @@ -53,7 +53,7 @@ func QueryTxsByEvents(clientCtx client.Context, events []string, page, limit int return nil, err } - txs, err := formatTxResults(clientCtx.Codec, resTxs.Txs, resBlocks) + txs, err := formatTxResults(clientCtx.LegacyAmino, resTxs.Txs, resBlocks) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func QueryTx(clientCtx client.Context, hashHexStr string) (*sdk.TxResponse, erro return nil, err } - out, err := formatTxResult(clientCtx.Codec, resTx, resBlocks[resTx.Height]) + out, err := formatTxResult(clientCtx.LegacyAmino, resTx, resBlocks[resTx.Height]) if err != nil { return out, err } @@ -97,7 +97,7 @@ func QueryTx(clientCtx client.Context, hashHexStr string) (*sdk.TxResponse, erro } // formatTxResults parses the indexed txs into a slice of TxResponse objects. -func formatTxResults(cdc *codec.Codec, resTxs []*ctypes.ResultTx, resBlocks map[int64]*ctypes.ResultBlock) ([]*sdk.TxResponse, error) { +func formatTxResults(cdc *codec.LegacyAmino, resTxs []*ctypes.ResultTx, resBlocks map[int64]*ctypes.ResultBlock) ([]*sdk.TxResponse, error) { var err error out := make([]*sdk.TxResponse, len(resTxs)) for i := range resTxs { @@ -132,7 +132,7 @@ func getBlocksForTxResults(clientCtx client.Context, resTxs []*ctypes.ResultTx) return resBlocks, nil } -func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.ResultBlock) (*sdk.TxResponse, error) { +func formatTxResult(cdc *codec.LegacyAmino, resTx *ctypes.ResultTx, resBlock *ctypes.ResultBlock) (*sdk.TxResponse, error) { tx, err := parseTx(cdc, resTx.Tx) if err != nil { return nil, err @@ -141,7 +141,7 @@ func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.R return sdk.NewResponseResultTx(resTx, tx, resBlock.Block.Time.Format(time.RFC3339)), nil } -func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { +func parseTx(cdc *codec.LegacyAmino, txBytes []byte) (sdk.Tx, error) { var tx types.StdTx err := cdc.UnmarshalBinaryBare(txBytes, &tx) diff --git a/x/auth/client/rest/broadcast.go b/x/auth/client/rest/broadcast.go index d689e7c69c..632c10c3a4 100644 --- a/x/auth/client/rest/broadcast.go +++ b/x/auth/client/rest/broadcast.go @@ -30,7 +30,7 @@ func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { } // NOTE: amino is used intentionally here, don't migrate it! - if err := clientCtx.Codec.UnmarshalJSON(body, &req); rest.CheckBadRequestError(w, err) { + if err := clientCtx.LegacyAmino.UnmarshalJSON(body, &req); rest.CheckBadRequestError(w, err) { return } @@ -47,7 +47,7 @@ func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { } // NOTE: amino is set intentionally here, don't migrate it! - clientCtx = clientCtx.WithJSONMarshaler(clientCtx.Codec) + clientCtx = clientCtx.WithJSONMarshaler(clientCtx.LegacyAmino) rest.PostProcessResponseBare(w, clientCtx, res) } } diff --git a/x/auth/client/rest/decode.go b/x/auth/client/rest/decode.go index 81346fc5c8..5081412b6a 100644 --- a/x/auth/client/rest/decode.go +++ b/x/auth/client/rest/decode.go @@ -37,7 +37,7 @@ func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { } // NOTE: amino is used intentionally here, don't migrate it - err = clientCtx.Codec.UnmarshalJSON(body, &req) + err = clientCtx.LegacyAmino.UnmarshalJSON(body, &req) if rest.CheckBadRequestError(w, err) { return } @@ -58,7 +58,7 @@ func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return } - stdTx, err := clienttx.ConvertTxToStdTx(clientCtx.Codec, tx) + stdTx, err := clienttx.ConvertTxToStdTx(clientCtx.LegacyAmino, tx) if rest.CheckBadRequestError(w, err) { return } @@ -66,7 +66,7 @@ func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { response := DecodeResp(stdTx) // NOTE: amino is set intentionally here, don't migrate it - clientCtx = clientCtx.WithJSONMarshaler(clientCtx.Codec) + clientCtx = clientCtx.WithJSONMarshaler(clientCtx.LegacyAmino) rest.PostProcessResponse(w, clientCtx, response) } } diff --git a/x/auth/client/rest/encode.go b/x/auth/client/rest/encode.go index 7512237943..e3930a1f8f 100644 --- a/x/auth/client/rest/encode.go +++ b/x/auth/client/rest/encode.go @@ -30,7 +30,7 @@ func EncodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { } // NOTE: amino is used intentionally here, don't migrate it - err = clientCtx.Codec.UnmarshalJSON(body, &req) + err = clientCtx.LegacyAmino.UnmarshalJSON(body, &req) if rest.CheckBadRequestError(w, err) { return } diff --git a/x/auth/client/rest/rest_test.go b/x/auth/client/rest/rest_test.go index fa1ceca6fb..6979801501 100644 --- a/x/auth/client/rest/rest_test.go +++ b/x/auth/client/rest/rest_test.go @@ -55,7 +55,7 @@ func (s *IntegrationTestSuite) TestEncodeDecode() { } // NOTE: this uses amino explicitly, don't migrate it! - cdc := val.ClientCtx.Codec + cdc := val.ClientCtx.LegacyAmino bz, err := cdc.MarshalJSON(stdTx) s.Require().NoError(err) @@ -107,7 +107,7 @@ func (s *IntegrationTestSuite) broadcastReq(stdTx authtypes.StdTx, mode string) val := s.network.Validators[0] // NOTE: this uses amino explicitly, don't migrate it! - cdc := val.ClientCtx.Codec + cdc := val.ClientCtx.LegacyAmino req := rest2.BroadcastReq{ Tx: stdTx, diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 7f7fde8526..e3af34132a 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -153,7 +153,7 @@ func populateAccountFromState( // GetTxEncoder return tx encoder from global sdk configuration if ones is defined. // Otherwise returns encoder with default logic. -func GetTxEncoder(cdc *codec.Codec) (encoder sdk.TxEncoder) { +func GetTxEncoder(cdc *codec.LegacyAmino) (encoder sdk.TxEncoder) { encoder = sdk.GetConfig().GetTxEncoder() if encoder == nil { encoder = authtypes.DefaultTxEncoder(cdc) diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 13b5743cf2..1a5847d424 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -150,7 +150,7 @@ func compareEncoders(t *testing.T, expected sdk.TxEncoder, actual sdk.TxEncoder) require.Equal(t, defaultEncoderBytes, encoderBytes) } -func makeCodec() *codec.Codec { +func makeCodec() *codec.LegacyAmino { var cdc = codec.New() sdk.RegisterCodec(cdc) cryptocodec.RegisterCrypto(cdc) diff --git a/x/auth/keeper/querier_test.go b/x/auth/keeper/querier_test.go index b39d58afd0..470ebb8261 100644 --- a/x/auth/keeper/querier_test.go +++ b/x/auth/keeper/querier_test.go @@ -17,7 +17,7 @@ import ( func TestQueryAccount(t *testing.T) { app, ctx := createTestApp(true) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) req := abci.RequestQuery{ Path: "", diff --git a/x/auth/legacy/v0_38/types.go b/x/auth/legacy/v0_38/types.go index b7004a4081..077fd1cc06 100644 --- a/x/auth/legacy/v0_38/types.go +++ b/x/auth/legacy/v0_38/types.go @@ -521,7 +521,7 @@ func ValidateGenAccounts(genAccounts GenesisAccounts) error { return nil } -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*GenesisAccount)(nil), nil) cdc.RegisterInterface((*Account)(nil), nil) cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil) diff --git a/x/auth/legacy/v0_39/types.go b/x/auth/legacy/v0_39/types.go index 9de38e6d6f..3cb6956003 100644 --- a/x/auth/legacy/v0_39/types.go +++ b/x/auth/legacy/v0_39/types.go @@ -419,7 +419,7 @@ func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error { return nil } -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*v038auth.GenesisAccount)(nil), nil) cdc.RegisterInterface((*v038auth.Account)(nil), nil) cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil) diff --git a/x/auth/module.go b/x/auth/module.go index 6f6bdceab3..96b096ae59 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -39,7 +39,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the auth module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 59a2502dfd..ec7c61d312 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -18,7 +18,7 @@ import ( // and will not work for protobuf transactions. type StdTxBuilder struct { StdTx - cdc *codec.Codec + cdc *codec.LegacyAmino } var _ client.TxBuilder = &StdTxBuilder{} @@ -77,7 +77,7 @@ func (s *StdTxBuilder) SetTimeoutHeight(height uint64) { // StdTxConfig is a context.TxConfig for StdTx type StdTxConfig struct { - Cdc *codec.Codec + Cdc *codec.LegacyAmino } var _ client.TxConfig = StdTxConfig{} diff --git a/x/auth/types/client_tx_test.go b/x/auth/types/client_tx_test.go index 26684ac202..683487c70b 100644 --- a/x/auth/types/client_tx_test.go +++ b/x/auth/types/client_tx_test.go @@ -16,7 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func testCodec() *codec.Codec { +func testCodec() *codec.LegacyAmino { cdc := codec.New() sdk.RegisterCodec(cdc) cryptoAmino.RegisterCrypto(cdc) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 30ebf84a04..d7374da6ab 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -8,7 +8,7 @@ import ( // RegisterCodec registers the account interfaces and concrete types on the // provided Amino codec. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*ModuleAccountI)(nil), nil) cdc.RegisterInterface((*GenesisAccount)(nil), nil) cdc.RegisterInterface((*AccountI)(nil), nil) diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index e15c17c0a4..5f52b492cf 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -321,7 +321,7 @@ type StdSignature struct { } // DefaultTxDecoder logic for standard transaction decoding -func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { +func DefaultTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var tx = StdTx{} @@ -340,7 +340,7 @@ func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { } } -func DefaultJSONTxDecoder(cdc *codec.Codec) sdk.TxDecoder { +func DefaultJSONTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var tx = StdTx{} @@ -360,7 +360,7 @@ func DefaultJSONTxDecoder(cdc *codec.Codec) sdk.TxDecoder { } // DefaultTxEncoder logic for standard transaction encoding -func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder { +func DefaultTxEncoder(cdc *codec.LegacyAmino) sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { return cdc.MarshalBinaryBare(tx) } @@ -379,7 +379,7 @@ func (tx StdTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { } // StdSignatureToSignatureV2 converts a StdSignature to a SignatureV2 -func StdSignatureToSignatureV2(cdc *codec.Codec, sig StdSignature) (signing.SignatureV2, error) { +func StdSignatureToSignatureV2(cdc *codec.LegacyAmino, sig StdSignature) (signing.SignatureV2, error) { pk := sig.GetPubKey() data, err := pubKeySigToSigData(cdc, pk, sig.Signature) if err != nil { @@ -393,7 +393,7 @@ func StdSignatureToSignatureV2(cdc *codec.Codec, sig StdSignature) (signing.Sign } // SignatureV2ToStdSignature converts a SignatureV2 to a StdSignature -func SignatureV2ToStdSignature(cdc *codec.Codec, sig signing.SignatureV2) (StdSignature, error) { +func SignatureV2ToStdSignature(cdc *codec.LegacyAmino, sig signing.SignatureV2) (StdSignature, error) { var ( sigBz []byte err error @@ -412,7 +412,7 @@ func SignatureV2ToStdSignature(cdc *codec.Codec, sig signing.SignatureV2) (StdSi }, nil } -func pubKeySigToSigData(cdc *codec.Codec, key crypto.PubKey, sig []byte) (signing.SignatureData, error) { +func pubKeySigToSigData(cdc *codec.LegacyAmino, key crypto.PubKey, sig []byte) (signing.SignatureData, error) { multiPK, ok := key.(multisig.PubKey) if !ok { return &signing.SingleSignatureData{ @@ -451,7 +451,7 @@ func pubKeySigToSigData(cdc *codec.Codec, key crypto.PubKey, sig []byte) (signin // MultiSignatureDataToAminoMultisignature converts a MultiSignatureData to an AminoMultisignature. // Only SIGN_MODE_LEGACY_AMINO_JSON is supported. -func MultiSignatureDataToAminoMultisignature(cdc *codec.Codec, mSig *signing.MultiSignatureData) (multisig.AminoMultisignature, error) { +func MultiSignatureDataToAminoMultisignature(cdc *codec.LegacyAmino, mSig *signing.MultiSignatureData) (multisig.AminoMultisignature, error) { n := len(mSig.Signatures) sigs := make([][]byte, n) @@ -471,7 +471,7 @@ func MultiSignatureDataToAminoMultisignature(cdc *codec.Codec, mSig *signing.Mul // SignatureDataToAminoSignature converts a SignatureData to amino-encoded signature bytes. // Only SIGN_MODE_LEGACY_AMINO_JSON is supported. -func SignatureDataToAminoSignature(cdc *codec.Codec, data signing.SignatureData) ([]byte, error) { +func SignatureDataToAminoSignature(cdc *codec.LegacyAmino, data signing.SignatureData) ([]byte, error) { switch data := data.(type) { case *signing.SingleSignatureData: if data.SignMode != signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON { diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index ac94ba2b67..2889f48fef 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -9,7 +9,7 @@ import ( // RegisterCodec registers the vesting interfaces and concrete types on the // provided Amino codec. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.VestingAccount)(nil), nil) cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil) cdc.RegisterConcrete(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount", nil) diff --git a/x/bank/client/rest/tx_test.go b/x/bank/client/rest/tx_test.go index 2bc2cd4b4d..9d8bf43e0c 100644 --- a/x/bank/client/rest/tx_test.go +++ b/x/bank/client/rest/tx_test.go @@ -45,7 +45,7 @@ func submitSendReq(val *network.Validator, req bankrest.SendReq) (authtypes.StdT url := fmt.Sprintf("%s/bank/accounts/%s/transfers", val.APIAddress, val.Address) // NOTE: this uses amino explicitly, don't migrate it! - bz, err := val.ClientCtx.Codec.MarshalJSON(req) + bz, err := val.ClientCtx.LegacyAmino.MarshalJSON(req) if err != nil { return authtypes.StdTx{}, errors.Wrap(err, "error encoding SendReq to json") } @@ -57,7 +57,7 @@ func submitSendReq(val *network.Validator, req bankrest.SendReq) (authtypes.StdT var tx authtypes.StdTx // NOTE: this uses amino explicitly, don't migrate it! - err = val.ClientCtx.Codec.UnmarshalJSON(res, &tx) + err = val.ClientCtx.LegacyAmino.UnmarshalJSON(res, &tx) if err != nil { return authtypes.StdTx{}, errors.Wrap(err, "error unmarshaling to StdTx SendReq response") } diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index 791ffc0ce9..0e1ba93d09 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -15,7 +15,7 @@ import ( func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { app, ctx := suite.app, suite.ctx - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) _, _, addr := testdata.KeyTestPubAddr() req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryBalance), @@ -28,13 +28,13 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { suite.Require().NotNil(err) suite.Require().Nil(res) - req.Data = app.Codec().MustMarshalJSON(types.NewQueryBalanceRequest(addr, fooDenom)) + req.Data = app.LegacyAmino().MustMarshalJSON(types.NewQueryBalanceRequest(addr, fooDenom)) res, err = querier(ctx, []string{types.QueryBalance}, req) suite.Require().NoError(err) suite.Require().NotNil(res) var balance sdk.Coin - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balance)) + suite.Require().NoError(app.LegacyAmino().UnmarshalJSON(res, &balance)) suite.True(balance.IsZero()) origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30)) @@ -46,13 +46,13 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { res, err = querier(ctx, []string{types.QueryBalance}, req) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balance)) + suite.Require().NoError(app.LegacyAmino().UnmarshalJSON(res, &balance)) suite.True(balance.IsEqual(newFooCoin(50))) } func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { app, ctx := suite.app, suite.ctx - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) _, _, addr := testdata.KeyTestPubAddr() req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryAllBalances), @@ -65,13 +65,13 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { suite.Require().NotNil(err) suite.Require().Nil(res) - req.Data = app.Codec().MustMarshalJSON(types.NewQueryAllBalancesRequest(addr, nil)) + req.Data = app.LegacyAmino().MustMarshalJSON(types.NewQueryAllBalancesRequest(addr, nil)) res, err = querier(ctx, []string{types.QueryAllBalances}, req) suite.Require().NoError(err) suite.Require().NotNil(res) var balances sdk.Coins - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balances)) + suite.Require().NoError(app.LegacyAmino().UnmarshalJSON(res, &balances)) suite.True(balances.IsZero()) origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30)) @@ -83,13 +83,13 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { res, err = querier(ctx, []string{types.QueryAllBalances}, req) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balances)) + suite.Require().NoError(app.LegacyAmino().UnmarshalJSON(res, &balances)) suite.True(balances.IsEqual(origCoins)) } func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { app, ctx := suite.app, suite.ctx - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) expectedTotalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin("test", 400000000))) app.BankKeeper.SetSupply(ctx, expectedTotalSupply) @@ -104,19 +104,19 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { suite.Require().NotNil(err) suite.Require().Nil(res) - req.Data = app.Codec().MustMarshalJSON(types.NewQueryTotalSupplyParams(1, 100)) + req.Data = app.LegacyAmino().MustMarshalJSON(types.NewQueryTotalSupplyParams(1, 100)) res, err = querier(ctx, []string{types.QueryTotalSupply}, req) suite.Require().NoError(err) suite.Require().NotNil(res) var resp sdk.Coins - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &resp)) + suite.Require().NoError(app.LegacyAmino().UnmarshalJSON(res, &resp)) suite.Require().Equal(expectedTotalSupply.Total, resp) } func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { app, ctx := suite.app, suite.ctx - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) test1Supply := sdk.NewInt64Coin("test1", 4000000) test2Supply := sdk.NewInt64Coin("test2", 700000000) @@ -134,19 +134,19 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { suite.Require().NotNil(err) suite.Require().Nil(res) - req.Data = app.Codec().MustMarshalJSON(types.NewQuerySupplyOfParams(test1Supply.Denom)) + req.Data = app.LegacyAmino().MustMarshalJSON(types.NewQuerySupplyOfParams(test1Supply.Denom)) res, err = querier(ctx, []string{types.QuerySupplyOf}, req) suite.Require().NoError(err) suite.Require().NotNil(res) var resp sdk.Coin - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &resp)) + suite.Require().NoError(app.LegacyAmino().UnmarshalJSON(res, &resp)) suite.Require().Equal(test1Supply, resp) } func (suite *IntegrationTestSuite) TestQuerierRouteNotFound() { app, ctx := suite.app, suite.ctx - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/invalid", types.ModuleName), Data: []byte{}, diff --git a/x/bank/module.go b/x/bank/module.go index c8a1985988..21726cf86a 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -38,7 +38,7 @@ type AppModuleBasic struct { func (AppModuleBasic) Name() string { return types.ModuleName } // RegisterCodec registers the bank module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { types.RegisterCodec(cdc) } +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the bank // module. diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 7cd73e2342..13d23d5338 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -24,7 +24,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc *codec.Codec, ak types.AccountKeeper, bk keeper.Keeper, + appParams simtypes.AppParams, cdc *codec.LegacyAmino, ak types.AccountKeeper, bk keeper.Keeper, ) simulation.WeightedOperations { var weightMsgSend, weightMsgMultiSend int diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 2718dde500..948912ec95 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -31,7 +31,7 @@ func (suite *SimTestSuite) SetupTest() { // TestWeightedOperations tests the weights of the operations. func (suite *SimTestSuite) TestWeightedOperations() { - cdc := suite.app.Codec() + cdc := suite.app.LegacyAmino() appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, suite.app.BankKeeper) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index ce5c483880..cb703fee77 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -10,7 +10,7 @@ import ( // RegisterCodec registers the necessary x/bank interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.SupplyI)(nil), nil) cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) cdc.RegisterConcrete(&MsgSend{}, "cosmos-sdk/MsgSend", nil) diff --git a/x/capability/module.go b/x/capability/module.go index 76dd16d526..b4aa43f021 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -47,7 +47,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the capability module's types to the provided codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/capability/types/codec.go b/x/capability/types/codec.go index 887a68655e..57f1312cc5 100644 --- a/x/capability/types/codec.go +++ b/x/capability/types/codec.go @@ -6,7 +6,7 @@ import ( // RegisterCodec registers all the necessary types and interfaces for the // capability module. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&Capability{}, "cosmos-sdk/Capability", nil) cdc.RegisterConcrete(Owner{}, "cosmos-sdk/Owner", nil) cdc.RegisterConcrete(&CapabilityOwners{}, "cosmos-sdk/CapabilityOwners", nil) diff --git a/x/crisis/module.go b/x/crisis/module.go index cc0922b37a..fc48a078fe 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -33,7 +33,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the crisis module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index b35dd6d9a3..c87b55e8eb 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -9,7 +9,7 @@ import ( // RegisterCodec registers the necessary x/crisis interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil) } diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index 917907871f..0269e92611 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -30,7 +30,7 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req CommunityPoolSpendProposalReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index 9d437f9469..675be4af1a 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -64,7 +64,7 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req withdrawRewardsReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -91,7 +91,7 @@ func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.Handler func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req withdrawRewardsReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -123,7 +123,7 @@ func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.Handle func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req setWithdrawalAddrReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -150,7 +150,7 @@ func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.Handl func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req withdrawRewardsReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -178,7 +178,7 @@ func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.Handler func newFundCommunityPoolHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req fundCommunityPoolReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 5934af6a1b..154c61b561 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -19,7 +19,7 @@ import ( const custom = "custom" -func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) types.Params { +func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier) types.Params { var params types.Params bz, err := querier(ctx, []string{types.QueryParams}, abci.RequestQuery{}) @@ -29,7 +29,7 @@ func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier s return params } -func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress) sdk.DecCoins { +func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, validatorAddr sdk.ValAddress) sdk.DecCoins { query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryValidatorOutstandingRewards}, "/"), Data: cdc.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr)), @@ -43,7 +43,7 @@ func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *c return outstandingRewards.GetRewards() } -func getQueriedValidatorCommission(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress) sdk.DecCoins { +func getQueriedValidatorCommission(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, validatorAddr sdk.ValAddress) sdk.DecCoins { query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryValidatorCommission}, "/"), Data: cdc.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)), @@ -57,7 +57,7 @@ func getQueriedValidatorCommission(t *testing.T, ctx sdk.Context, cdc *codec.Cod return validatorCommission.GetCommission() } -func getQueriedValidatorSlashes(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress, startHeight uint64, endHeight uint64) (slashes []types.ValidatorSlashEvent) { +func getQueriedValidatorSlashes(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, validatorAddr sdk.ValAddress, startHeight uint64, endHeight uint64) (slashes []types.ValidatorSlashEvent) { query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryValidatorSlashes}, "/"), Data: cdc.MustMarshalJSON(types.NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight)), @@ -70,7 +70,7 @@ func getQueriedValidatorSlashes(t *testing.T, ctx sdk.Context, cdc *codec.Codec, return } -func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) (rewards sdk.DecCoins) { +func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) (rewards sdk.DecCoins) { query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryDelegationRewards}, "/"), Data: cdc.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)), @@ -83,7 +83,7 @@ func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec return } -func getQueriedDelegatorTotalRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, delegatorAddr sdk.AccAddress) (response types.QueryDelegatorTotalRewardsResponse) { +func getQueriedDelegatorTotalRewards(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, delegatorAddr sdk.AccAddress) (response types.QueryDelegatorTotalRewardsResponse) { query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryDelegatorTotalRewards}, "/"), Data: cdc.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)), @@ -96,7 +96,7 @@ func getQueriedDelegatorTotalRewards(t *testing.T, ctx sdk.Context, cdc *codec.C return } -func getQueriedCommunityPool(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (ptr []byte) { +func getQueriedCommunityPool(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier) (ptr []byte) { query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryCommunityPool}, ""), Data: []byte{}, diff --git a/x/distribution/module.go b/x/distribution/module.go index cd91fad11c..196c2ae2d8 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -42,7 +42,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the distribution module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index f33329b5f3..92b744a96a 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -26,7 +26,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc *codec.Codec, ak types.AccountKeeper, + appParams simtypes.AppParams, cdc *codec.LegacyAmino, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper, ) simulation.WeightedOperations { diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index f7aa170197..99c92f2f4b 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -20,7 +20,7 @@ import ( // TestWeightedOperations tests the weights of the operations. func (suite *SimTestSuite) TestWeightedOperations() { - cdc := suite.app.Codec() + cdc := suite.app.LegacyAmino() appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index f3aa03d102..4a1d3ab3c9 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -10,7 +10,7 @@ import ( // RegisterCodec registers the necessary x/distribution interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil) cdc.RegisterConcrete(&MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission", nil) cdc.RegisterConcrete(&MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil) diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 1aaaca5f38..b52334b45e 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -83,7 +83,7 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) // recreate keeper in order to use custom testing types evidenceKeeper := keeper.NewKeeper( diff --git a/x/evidence/module.go b/x/evidence/module.go index 01009b5a34..b3aebb1f64 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -54,7 +54,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the evidence module's types to the provided codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index bee5be2cf9..2363d1ca3a 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -10,7 +10,7 @@ import ( // RegisterCodec registers all the necessary types and interfaces for the // evidence module. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.Evidence)(nil), nil) cdc.RegisterConcrete(&MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence", nil) cdc.RegisterConcrete(&Equivocation{}, "cosmos-sdk/Equivocation", nil) diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index cc5446cf7c..a0e2bc5f13 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -200,7 +200,7 @@ func TestInitNodeValidatorFiles(t *testing.T) { } // custom tx codec -func makeCodec() *codec.Codec { +func makeCodec() *codec.LegacyAmino { var cdc = codec.New() sdk.RegisterCodec(cdc) cryptocodec.RegisterCrypto(cdc) diff --git a/x/genutil/client/rest/query.go b/x/genutil/client/rest/query.go index 62fe405462..a53de65fdb 100644 --- a/x/genutil/client/rest/query.go +++ b/x/genutil/client/rest/query.go @@ -22,7 +22,7 @@ func QueryGenesisTxs(clientCtx client.Context, w http.ResponseWriter) { return } - appState, err := types.GenesisStateFromGenDoc(clientCtx.Codec, *resultGenesis.Genesis) + appState, err := types.GenesisStateFromGenDoc(clientCtx.LegacyAmino, *resultGenesis.Genesis) if err != nil { rest.WriteErrorResponse( w, http.StatusInternalServerError, @@ -31,7 +31,7 @@ func QueryGenesisTxs(clientCtx client.Context, w http.ResponseWriter) { return } - genState := types.GetGenesisStateFromAppState(clientCtx.Codec, appState) + genState := types.GetGenesisStateFromAppState(clientCtx.LegacyAmino, appState) genTxs := make([]sdk.Tx, len(genState.GenTxs)) for i, tx := range genState.GenTxs { err := clientCtx.JSONMarshaler.UnmarshalJSON(tx, &genTxs[i]) diff --git a/x/genutil/module.go b/x/genutil/module.go index dc7bd72e57..c4a2b073b4 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -31,7 +31,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the genutil module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers the module's interface types func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} diff --git a/x/genutil/types/expected_keepers.go b/x/genutil/types/expected_keepers.go index e6404e0e9d..62d8d48f15 100644 --- a/x/genutil/types/expected_keepers.go +++ b/x/genutil/types/expected_keepers.go @@ -26,7 +26,7 @@ type AccountKeeper interface { // GenesisAccountsIterator defines the expected iterating genesis accounts object (noalias) type GenesisAccountsIterator interface { IterateGenesisAccounts( - cdc *codec.Codec, + cdc *codec.LegacyAmino, appGenesis map[string]json.RawMessage, cb func(auth.AccountI) (stop bool), ) diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index 30d1afd2fd..284c671481 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -27,7 +27,7 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalR func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req PostProposalReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -67,7 +67,7 @@ func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { } var req DepositReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -102,7 +102,7 @@ func newVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { } var req VoteReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index 85f0983fa3..8985b4d91d 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -39,7 +39,7 @@ func (mock TxSearchMock) Block(height *int64) (*ctypes.ResultBlock, error) { return &ctypes.ResultBlock{Block: &tmtypes.Block{}}, nil } -func newTestCodec() *codec.Codec { +func newTestCodec() *codec.LegacyAmino { cdc := codec.New() sdk.RegisterCodec(cdc) types.RegisterCodec(cdc) @@ -147,7 +147,7 @@ func TestGetPaginatedVotes(t *testing.T) { cli := TxSearchMock{txs: marshalled} clientCtx := client.Context{}. WithJSONMarshaler(cdc). - WithCodec(cdc). + WithLegacyAmino(cdc). WithClient(cli) params := types.NewQueryProposalVotesParams(0, tc.page, tc.limit) diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index 0d1a0d5a9a..5708bd3fbb 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -61,7 +61,7 @@ func TestImportExportQueues(t *testing.T) { genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState) genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) - stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) if err != nil { panic(err) } diff --git a/x/gov/keeper/querier_test.go b/x/gov/keeper/querier_test.go index db86e89679..95e6e8dca2 100644 --- a/x/gov/keeper/querier_test.go +++ b/x/gov/keeper/querier_test.go @@ -147,7 +147,7 @@ func TestQueries(t *testing.T) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) appCodec := app.AppCodec() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.GovKeeper, legacyQuerierCdc) TestAddrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(20000001)) @@ -317,7 +317,7 @@ func TestPaginatedVotesQuery(t *testing.T) { app.GovKeeper.SetVote(ctx, vote) } - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.GovKeeper, legacyQuerierCdc) // keeper preserves consistent order for each query, but this is not the insertion order diff --git a/x/gov/legacy/v0_34/types.go b/x/gov/legacy/v0_34/types.go index 23e5eebc5e..349206f232 100644 --- a/x/gov/legacy/v0_34/types.go +++ b/x/gov/legacy/v0_34/types.go @@ -326,7 +326,7 @@ func (pt ProposalKind) String() string { } } -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*ProposalContent)(nil), nil) cdc.RegisterConcrete(TextProposal{}, "gov/TextProposal", nil) } diff --git a/x/gov/legacy/v0_36/types.go b/x/gov/legacy/v0_36/types.go index faaaa4e321..0c874a9205 100644 --- a/x/gov/legacy/v0_36/types.go +++ b/x/gov/legacy/v0_36/types.go @@ -127,7 +127,7 @@ func ValidateAbstract(c Content) error { return nil } -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*Content)(nil), nil) cdc.RegisterConcrete(TextProposal{}, "cosmos-sdk/TextProposal", nil) } diff --git a/x/gov/module.go b/x/gov/module.go index 17c9265dc5..a2bf1ddb63 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -53,7 +53,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the gov module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 93f8af8a9e..9534e47d3c 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -26,7 +26,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc *codec.Codec, ak types.AccountKeeper, + appParams simtypes.AppParams, cdc *codec.LegacyAmino, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, wContents []simtypes.WeightedProposalContent, ) simulation.WeightedOperations { diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index c412bd46f1..e42e2a75af 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -58,7 +58,7 @@ func TestWeightedOperations(t *testing.T) { app, ctx := createTestApp(false) ctx.WithChainID("test-chain") - cdc := app.Codec() + cdc := app.LegacyAmino() appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, cdc, app.AccountKeeper, diff --git a/x/gov/types/codec.go b/x/gov/types/codec.go index 6fdb458218..c2509dc34c 100644 --- a/x/gov/types/codec.go +++ b/x/gov/types/codec.go @@ -9,7 +9,7 @@ import ( // RegisterCodec registers all the necessary types and interfaces for the // governance module. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*Content)(nil), nil) cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil) cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil) diff --git a/x/ibc-transfer/client/rest/tx.go b/x/ibc-transfer/client/rest/tx.go index dce5358181..2a64acbccf 100644 --- a/x/ibc-transfer/client/rest/tx.go +++ b/x/ibc-transfer/client/rest/tx.go @@ -37,7 +37,7 @@ func transferHandlerFn(clientCtx client.Context) http.HandlerFunc { channelID := vars[restChannelID] var req TransferTxReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 132ba89f88..2119c2dbc5 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -45,7 +45,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec implements AppModuleBasic interface -func (AppModuleBasic) RegisterCodec(*codec.Codec) {} +func (AppModuleBasic) RegisterCodec(*codec.LegacyAmino) {} // DefaultGenesis returns default genesis state as raw bytes for the ibc // transfer module. diff --git a/x/ibc/02-client/abci_test.go b/x/ibc/02-client/abci_test.go index b949ad7b91..f0f8da205d 100644 --- a/x/ibc/02-client/abci_test.go +++ b/x/ibc/02-client/abci_test.go @@ -14,7 +14,7 @@ import ( type ClientTestSuite struct { suite.Suite - cdc *codec.Codec + cdc *codec.LegacyAmino ctx sdk.Context app *simapp.SimApp } @@ -23,7 +23,7 @@ func (suite *ClientTestSuite) SetupTest() { isCheckTx := false suite.app = simapp.Setup(isCheckTx) - suite.cdc = suite.app.Codec() + suite.cdc = suite.app.LegacyAmino() suite.ctx = suite.app.BaseApp.NewContext(isCheckTx, abci.Header{Height: 0, ChainID: "localhost_chain"}) } diff --git a/x/ibc/02-client/client/utils/utils.go b/x/ibc/02-client/client/utils/utils.go index dbd11ac222..2a3507f4a1 100644 --- a/x/ibc/02-client/client/utils/utils.go +++ b/x/ibc/02-client/client/utils/utils.go @@ -54,7 +54,7 @@ func QueryClientState( } var clientState exported.ClientState - if err := clientCtx.Codec.UnmarshalBinaryBare(res.Value, &clientState); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &clientState); err != nil { return types.StateResponse{}, err } @@ -82,7 +82,7 @@ func QueryConsensusState( } var cs exported.ConsensusState - if err := clientCtx.Codec.UnmarshalBinaryBare(res.Value, &cs); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &cs); err != nil { return conStateRes, err } diff --git a/x/ibc/02-client/types/codec.go b/x/ibc/02-client/types/codec.go index 7450a775ae..d6e58b3000 100644 --- a/x/ibc/02-client/types/codec.go +++ b/x/ibc/02-client/types/codec.go @@ -3,14 +3,15 @@ package types import ( "fmt" + proto "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" - proto "github.com/gogo/protobuf/proto" ) // RegisterCodec registers the IBC client interfaces and types -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.ClientState)(nil), nil) // remove after genesis migration cdc.RegisterInterface((*exported.MsgCreateClient)(nil), nil) cdc.RegisterInterface((*exported.MsgUpdateClient)(nil), nil) diff --git a/x/ibc/03-connection/client/cli/tx.go b/x/ibc/03-connection/client/cli/tx.go index 64dc4db973..c69e382887 100644 --- a/x/ibc/03-connection/client/cli/tx.go +++ b/x/ibc/03-connection/client/cli/tx.go @@ -39,7 +39,7 @@ func NewConnectionOpenInitCmd() *cobra.Command { counterpartyConnectionID := args[2] counterpartyClientID := args[3] - counterpartyPrefix, err := utils.ParsePrefix(clientCtx.Codec, args[4]) + counterpartyPrefix, err := utils.ParsePrefix(clientCtx.LegacyAmino, args[4]) if err != nil { return err } @@ -90,7 +90,7 @@ func NewConnectionOpenTryCmd() *cobra.Command { counterpartyConnectionID := args[2] counterpartyClientID := args[3] - counterpartyPrefix, err := utils.ParsePrefix(clientCtx.Codec, args[4]) + counterpartyPrefix, err := utils.ParsePrefix(clientCtx.LegacyAmino, args[4]) if err != nil { return err } @@ -98,12 +98,12 @@ func NewConnectionOpenTryCmd() *cobra.Command { // TODO: parse strings? counterpartyVersions := args[5] - proofInit, err := utils.ParseProof(clientCtx.Codec, args[6]) + proofInit, err := utils.ParseProof(clientCtx.LegacyAmino, args[6]) if err != nil { return err } - proofConsensus, err := utils.ParseProof(clientCtx.Codec, args[7]) + proofConsensus, err := utils.ParseProof(clientCtx.LegacyAmino, args[7]) if err != nil { return err } @@ -154,12 +154,12 @@ func NewConnectionOpenAckCmd() *cobra.Command { connectionID := args[0] - proofTry, err := utils.ParseProof(clientCtx.Codec, args[1]) + proofTry, err := utils.ParseProof(clientCtx.LegacyAmino, args[1]) if err != nil { return err } - proofConsensus, err := utils.ParseProof(clientCtx.Codec, args[2]) + proofConsensus, err := utils.ParseProof(clientCtx.LegacyAmino, args[2]) if err != nil { return err } @@ -211,7 +211,7 @@ func NewConnectionOpenConfirmCmd() *cobra.Command { connectionID := args[0] - proofAck, err := utils.ParseProof(clientCtx.Codec, args[1]) + proofAck, err := utils.ParseProof(clientCtx.LegacyAmino, args[1]) if err != nil { return err } diff --git a/x/ibc/03-connection/client/rest/tx.go b/x/ibc/03-connection/client/rest/tx.go index e4d2088de9..09f1f5433c 100644 --- a/x/ibc/03-connection/client/rest/tx.go +++ b/x/ibc/03-connection/client/rest/tx.go @@ -33,7 +33,7 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func connectionOpenInitHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req ConnectionOpenInitReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -76,7 +76,7 @@ func connectionOpenInitHandlerFn(clientCtx client.Context) http.HandlerFunc { func connectionOpenTryHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req ConnectionOpenTryReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -126,7 +126,7 @@ func connectionOpenAckHandlerFn(clientCtx client.Context) http.HandlerFunc { connectionID := vars[RestConnectionID] var req ConnectionOpenAckReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -174,7 +174,7 @@ func connectionOpenConfirmHandlerFn(clientCtx client.Context) http.HandlerFunc { connectionID := vars[RestConnectionID] var req ConnectionOpenConfirmReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/ibc/03-connection/client/utils/utils.go b/x/ibc/03-connection/client/utils/utils.go index 81fc8e22d4..2dbc18a32c 100644 --- a/x/ibc/03-connection/client/utils/utils.go +++ b/x/ibc/03-connection/client/utils/utils.go @@ -47,11 +47,11 @@ func queryConnectionABCI(clientCtx client.Context, connectionID string) (*types. } var connection types.ConnectionEnd - if err := clientCtx.Codec.UnmarshalBinaryBare(res.Value, &connection); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &connection); err != nil { return nil, err } - proofBz, err := clientCtx.Codec.MarshalBinaryBare(res.Proof) + proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.Proof) if err != nil { return nil, err } @@ -90,11 +90,11 @@ func queryClientConnectionsABCI(clientCtx client.Context, clientID string) (*typ } var paths []string - if err := clientCtx.Codec.UnmarshalBinaryBare(res.Value, &paths); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &paths); err != nil { return nil, err } - proofBz, err := clientCtx.Codec.MarshalBinaryBare(res.Proof) + proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.Proof) if err != nil { return nil, err } @@ -104,7 +104,7 @@ func queryClientConnectionsABCI(clientCtx client.Context, clientID string) (*typ // ParsePrefix unmarshals an cmd input argument from a JSON string to a commitment // Prefix. If the input is not a JSON, it looks for a path to the JSON file. -func ParsePrefix(cdc *codec.Codec, arg string) (commitmenttypes.MerklePrefix, error) { +func ParsePrefix(cdc *codec.LegacyAmino, arg string) (commitmenttypes.MerklePrefix, error) { var prefix commitmenttypes.MerklePrefix if err := cdc.UnmarshalJSON([]byte(arg), &prefix); err != nil { // check for file path if JSON input is not provided @@ -122,7 +122,7 @@ func ParsePrefix(cdc *codec.Codec, arg string) (commitmenttypes.MerklePrefix, er // ParseProof unmarshals a cmd input argument from a JSON string to a commitment // Proof. If the input is not a JSON, it looks for a path to the JSON file. It // then marshals the commitment proof into a proto encoded byte array. -func ParseProof(cdc *codec.Codec, arg string) ([]byte, error) { +func ParseProof(cdc *codec.LegacyAmino, arg string) ([]byte, error) { var merkleProof commitmenttypes.MerkleProof if err := cdc.UnmarshalJSON([]byte(arg), &merkleProof); err != nil { // check for file path if JSON input is not provided diff --git a/x/ibc/04-channel/client/cli/tx.go b/x/ibc/04-channel/client/cli/tx.go index 3ffaa0a3f3..af00a4d375 100644 --- a/x/ibc/04-channel/client/cli/tx.go +++ b/x/ibc/04-channel/client/cli/tx.go @@ -84,7 +84,7 @@ func NewChannelOpenTryCmd() *cobra.Command { // TODO: Differentiate between channel and counterparty versions. version, _ := cmd.Flags().GetString(FlagIBCVersion) - proofInit, err := connectionutils.ParseProof(clientCtx.Codec, args[5]) + proofInit, err := connectionutils.ParseProof(clientCtx.LegacyAmino, args[5]) if err != nil { return err } @@ -133,7 +133,7 @@ func NewChannelOpenAckCmd() *cobra.Command { // TODO: Differentiate between channel and counterparty versions. version, _ := cmd.Flags().GetString(FlagIBCVersion) - proofTry, err := connectionutils.ParseProof(clientCtx.Codec, args[5]) + proofTry, err := connectionutils.ParseProof(clientCtx.LegacyAmino, args[5]) if err != nil { return err } @@ -175,7 +175,7 @@ func NewChannelOpenConfirmCmd() *cobra.Command { portID := args[0] channelID := args[1] - proofAck, err := connectionutils.ParseProof(clientCtx.Codec, args[5]) + proofAck, err := connectionutils.ParseProof(clientCtx.LegacyAmino, args[5]) if err != nil { return err } @@ -247,7 +247,7 @@ func NewChannelCloseConfirmCmd() *cobra.Command { portID := args[0] channelID := args[1] - proofInit, err := connectionutils.ParseProof(clientCtx.Codec, args[5]) + proofInit, err := connectionutils.ParseProof(clientCtx.LegacyAmino, args[5]) if err != nil { return err } diff --git a/x/ibc/04-channel/client/rest/tx.go b/x/ibc/04-channel/client/rest/tx.go index 8367299a60..cde4abc8dd 100644 --- a/x/ibc/04-channel/client/rest/tx.go +++ b/x/ibc/04-channel/client/rest/tx.go @@ -37,7 +37,7 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func channelOpenInitHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req ChannelOpenInitReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -86,7 +86,7 @@ func channelOpenInitHandlerFn(clientCtx client.Context) http.HandlerFunc { func channelOpenTryHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req ChannelOpenTryReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -145,7 +145,7 @@ func channelOpenAckHandlerFn(clientCtx client.Context) http.HandlerFunc { channelID := vars[RestChannelID] var req ChannelOpenAckReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -199,7 +199,7 @@ func channelOpenConfirmHandlerFn(clientCtx client.Context) http.HandlerFunc { channelID := vars[RestChannelID] var req ChannelOpenConfirmReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -252,7 +252,7 @@ func channelCloseInitHandlerFn(clientCtx client.Context) http.HandlerFunc { channelID := vars[RestChannelID] var req ChannelCloseInitReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -303,7 +303,7 @@ func channelCloseConfirmHandlerFn(clientCtx client.Context) http.HandlerFunc { channelID := vars[RestChannelID] var req ChannelCloseConfirmReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -349,7 +349,7 @@ func channelCloseConfirmHandlerFn(clientCtx client.Context) http.HandlerFunc { func recvPacketHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req RecvPacketReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/ibc/04-channel/client/utils/utils.go b/x/ibc/04-channel/client/utils/utils.go index b36cc2eb98..511cf40da1 100644 --- a/x/ibc/04-channel/client/utils/utils.go +++ b/x/ibc/04-channel/client/utils/utils.go @@ -48,7 +48,7 @@ func queryPacketCommitmentABCI( return nil, err } - proofBz, err := clientCtx.Codec.MarshalBinaryBare(res.Proof) + proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.Proof) if err != nil { return nil, err } @@ -89,11 +89,11 @@ func queryChannelABCI(clientCtx client.Context, portID, channelID string) (*type } var channel types.Channel - if err := clientCtx.Codec.UnmarshalBinaryBare(res.Value, &channel); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &channel); err != nil { return nil, err } - proofBz, err := clientCtx.Codec.MarshalBinaryBare(res.Proof) + proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.Proof) if err != nil { return nil, err } @@ -195,7 +195,7 @@ func queryNextSequenceRecvABCI(clientCtx client.Context, portID, channelID strin return nil, err } - proofBz, err := clientCtx.Codec.MarshalBinaryBare(res.Proof) + proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.Proof) if err != nil { return nil, err } diff --git a/x/ibc/07-tendermint/client/cli/tx.go b/x/ibc/07-tendermint/client/cli/tx.go index 39950d062d..69c7ec153a 100644 --- a/x/ibc/07-tendermint/client/cli/tx.go +++ b/x/ibc/07-tendermint/client/cli/tx.go @@ -49,13 +49,13 @@ func NewCreateClientCmd() *cobra.Command { clientID := args[0] var header ibctmtypes.Header - if err := clientCtx.Codec.UnmarshalJSON([]byte(args[1]), &header); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(args[1]), &header); err != nil { // check for file path if JSON input is not provided contents, err := ioutil.ReadFile(args[1]) if err != nil { return errors.New("neither JSON input nor path to .json file were provided for consensus header") } - if err := clientCtx.Codec.UnmarshalJSON(contents, &header); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &header); err != nil { return errors.Wrap(err, "error unmarshalling consensus header file") } } @@ -94,13 +94,13 @@ func NewCreateClientCmd() *cobra.Command { spc, _ := cmd.Flags().GetString(flagProofSpecs) if spc == "default" { specs = commitmenttypes.GetSDKSpecs() - } else if err := clientCtx.Codec.UnmarshalJSON([]byte(spc), &specs); err != nil { + } else if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(spc), &specs); err != nil { // check for file path if JSON input not provided contents, err := ioutil.ReadFile(spc) if err != nil { return errors.New("neither JSON input nor path to .json file was provided for proof specs flag") } - if err := clientCtx.Codec.UnmarshalJSON(contents, &specs); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &specs); err != nil { return errors.Wrap(err, "error unmarshalling proof specs file") } } @@ -146,13 +146,13 @@ func NewUpdateClientCmd() *cobra.Command { clientID := args[0] var header ibctmtypes.Header - if err := clientCtx.Codec.UnmarshalJSON([]byte(args[1]), &header); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(args[1]), &header); err != nil { // check for file path if JSON input is not provided contents, err := ioutil.ReadFile(args[1]) if err != nil { return errors.New("neither JSON input nor path to .json file were provided") } - if err := clientCtx.Codec.UnmarshalJSON(contents, &header); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &header); err != nil { return errors.Wrap(err, "error unmarshalling header file") } } @@ -192,13 +192,13 @@ func NewSubmitMisbehaviourCmd() *cobra.Command { } var ev evidenceexported.Evidence - if err := clientCtx.Codec.UnmarshalJSON([]byte(args[0]), &ev); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(args[0]), &ev); err != nil { // check for file path if JSON input is not provided contents, err := ioutil.ReadFile(args[0]) if err != nil { return errors.New("neither JSON input nor path to .json file were provided") } - if err := clientCtx.Codec.UnmarshalJSON(contents, &ev); err != nil { + if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &ev); err != nil { return errors.Wrap(err, "error unmarshalling evidence file") } } diff --git a/x/ibc/07-tendermint/client/rest/tx.go b/x/ibc/07-tendermint/client/rest/tx.go index 5d02db931b..c57834acfb 100644 --- a/x/ibc/07-tendermint/client/rest/tx.go +++ b/x/ibc/07-tendermint/client/rest/tx.go @@ -33,7 +33,7 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func createClientHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req CreateClientReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -82,7 +82,7 @@ func updateClientHandlerFn(clientCtx client.Context) http.HandlerFunc { clientID := vars[RestClientID] var req UpdateClientReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -127,7 +127,7 @@ func updateClientHandlerFn(clientCtx client.Context) http.HandlerFunc { func submitMisbehaviourHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req SubmitMisbehaviourReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/ibc/07-tendermint/tendermint_test.go b/x/ibc/07-tendermint/tendermint_test.go index d6e7e1bb17..8d16de4562 100644 --- a/x/ibc/07-tendermint/tendermint_test.go +++ b/x/ibc/07-tendermint/tendermint_test.go @@ -26,7 +26,7 @@ const ( type TendermintTestSuite struct { suite.Suite - cdc *codec.Codec + cdc *codec.LegacyAmino signers []tmtypes.PrivValidator privVal tmtypes.PrivValidator valSet *tmtypes.ValidatorSet diff --git a/x/ibc/07-tendermint/types/codec.go b/x/ibc/07-tendermint/types/codec.go index 06b75aa40c..eb262c1d6a 100644 --- a/x/ibc/07-tendermint/types/codec.go +++ b/x/ibc/07-tendermint/types/codec.go @@ -9,7 +9,7 @@ import ( // RegisterCodec registers the necessary x/ibc/07-tendermint interfaces and conrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(ClientState{}, "ibc/client/tendermint/ClientState", nil) cdc.RegisterConcrete(ConsensusState{}, "ibc/client/tendermint/ConsensusState", nil) cdc.RegisterConcrete(Header{}, "ibc/client/tendermint/Header", nil) diff --git a/x/ibc/07-tendermint/types/tendermint_test.go b/x/ibc/07-tendermint/types/tendermint_test.go index ea0e7ce7f1..82b381bc61 100644 --- a/x/ibc/07-tendermint/types/tendermint_test.go +++ b/x/ibc/07-tendermint/types/tendermint_test.go @@ -28,7 +28,7 @@ type TendermintTestSuite struct { suite.Suite ctx sdk.Context - aminoCdc *codec.Codec + aminoCdc *codec.LegacyAmino cdc codec.Marshaler privVal tmtypes.PrivValidator valSet *tmtypes.ValidatorSet @@ -41,7 +41,7 @@ func (suite *TendermintTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) - suite.aminoCdc = app.Codec() + suite.aminoCdc = app.LegacyAmino() suite.cdc = app.AppCodec() suite.now = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC) diff --git a/x/ibc/09-localhost/client/rest/tx.go b/x/ibc/09-localhost/client/rest/tx.go index e959aa5982..418e7181e2 100644 --- a/x/ibc/09-localhost/client/rest/tx.go +++ b/x/ibc/09-localhost/client/rest/tx.go @@ -30,7 +30,7 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func createClientHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req CreateClientReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/ibc/09-localhost/types/codec.go b/x/ibc/09-localhost/types/codec.go index 3db64cf7cb..684e40be00 100644 --- a/x/ibc/09-localhost/types/codec.go +++ b/x/ibc/09-localhost/types/codec.go @@ -8,7 +8,7 @@ import ( ) // REMOVE: once simapp uses proto -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(ClientState{}, "ibc/client/localhost/ClientState", nil) } diff --git a/x/ibc/23-commitment/types/codec.go b/x/ibc/23-commitment/types/codec.go index 412daf58fd..d7e4bbdc8b 100644 --- a/x/ibc/23-commitment/types/codec.go +++ b/x/ibc/23-commitment/types/codec.go @@ -45,7 +45,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { // RegisterCodec registers the necessary x/ibc/23-commitment interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.Root)(nil), nil) cdc.RegisterInterface((*exported.Prefix)(nil), nil) cdc.RegisterInterface((*exported.Path)(nil), nil) diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index 0b97ef6698..f31281a932 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -43,7 +43,7 @@ const ( type IBCTestSuite struct { suite.Suite - cdc *codec.Codec + cdc *codec.LegacyAmino ctx sdk.Context app *simapp.SimApp header ibctmtypes.Header @@ -64,7 +64,7 @@ func (suite *IBCTestSuite) SetupTest() { suite.header = ibctmtypes.CreateTestHeader(chainID, height, height-1, now, valSet, valSet, []tmtypes.PrivValidator{privVal}) - suite.cdc = suite.app.Codec() + suite.cdc = suite.app.LegacyAmino() suite.ctx = suite.app.BaseApp.NewContext(isCheckTx, abci.Header{}) } diff --git a/x/ibc/keeper/keeper_test.go b/x/ibc/keeper/keeper_test.go index 941b20eb78..b6b97af745 100644 --- a/x/ibc/keeper/keeper_test.go +++ b/x/ibc/keeper/keeper_test.go @@ -16,7 +16,7 @@ import ( type KeeperTestSuite struct { suite.Suite - cdc *codec.Codec + cdc *codec.LegacyAmino ctx sdk.Context keeper *keeper.Keeper querier sdk.Querier @@ -25,9 +25,9 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { isCheckTx := false app := simapp.Setup(isCheckTx) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) - suite.cdc = app.Codec() + suite.cdc = app.LegacyAmino() suite.ctx = app.BaseApp.NewContext(isCheckTx, abci.Header{}) suite.keeper = app.IBCKeeper suite.querier = keeper.NewQuerier(*app.IBCKeeper, legacyQuerierCdc) diff --git a/x/ibc/module.go b/x/ibc/module.go index a7e85c7c7d..4858bedf04 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -43,7 +43,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the ibc module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 51e4fe6711..55d5e425d9 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -114,7 +114,7 @@ func NewTestChain(t *testing.T, chainID string) *TestChain { } app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) // create current header and call begin block header := abci.Header{ diff --git a/x/ibc/types/codec.go b/x/ibc/types/codec.go index 661e7b18b2..115a6f1516 100644 --- a/x/ibc/types/codec.go +++ b/x/ibc/types/codec.go @@ -13,7 +13,7 @@ import ( // RegisterCodec registers the necessary x/ibc interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { clienttypes.RegisterCodec(cdc) ibctmtypes.RegisterCodec(cdc) localhosttypes.RegisterCodec(cdc) diff --git a/x/mint/keeper/querier_test.go b/x/mint/keeper/querier_test.go index 7ed3841780..d2f1b223a7 100644 --- a/x/mint/keeper/querier_test.go +++ b/x/mint/keeper/querier_test.go @@ -16,7 +16,7 @@ import ( func TestNewQuerier(t *testing.T) { app, ctx := createTestApp(true) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) query := abci.RequestQuery{ @@ -39,7 +39,7 @@ func TestNewQuerier(t *testing.T) { func TestQueryParams(t *testing.T) { app, ctx := createTestApp(true) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) var params types.Params @@ -47,7 +47,7 @@ func TestQueryParams(t *testing.T) { res, sdkErr := querier(ctx, []string{types.QueryParameters}, abci.RequestQuery{}) require.NoError(t, sdkErr) - err := app.Codec().UnmarshalJSON(res, ¶ms) + err := app.LegacyAmino().UnmarshalJSON(res, ¶ms) require.NoError(t, err) require.Equal(t, app.MintKeeper.GetParams(ctx), params) @@ -55,7 +55,7 @@ func TestQueryParams(t *testing.T) { func TestQueryInflation(t *testing.T) { app, ctx := createTestApp(true) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) var inflation sdk.Dec @@ -63,7 +63,7 @@ func TestQueryInflation(t *testing.T) { res, sdkErr := querier(ctx, []string{types.QueryInflation}, abci.RequestQuery{}) require.NoError(t, sdkErr) - err := app.Codec().UnmarshalJSON(res, &inflation) + err := app.LegacyAmino().UnmarshalJSON(res, &inflation) require.NoError(t, err) require.Equal(t, app.MintKeeper.GetMinter(ctx).Inflation, inflation) @@ -71,7 +71,7 @@ func TestQueryInflation(t *testing.T) { func TestQueryAnnualProvisions(t *testing.T) { app, ctx := createTestApp(true) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) var annualProvisions sdk.Dec @@ -79,7 +79,7 @@ func TestQueryAnnualProvisions(t *testing.T) { res, sdkErr := querier(ctx, []string{types.QueryAnnualProvisions}, abci.RequestQuery{}) require.NoError(t, sdkErr) - err := app.Codec().UnmarshalJSON(res, &annualProvisions) + err := app.LegacyAmino().UnmarshalJSON(res, &annualProvisions) require.NoError(t, err) require.Equal(t, app.MintKeeper.GetMinter(ctx).AnnualProvisions, annualProvisions) diff --git a/x/mint/module.go b/x/mint/module.go index 99375854da..2548e32ec5 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -42,7 +42,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the mint module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers the module's interface types func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} diff --git a/x/params/client/rest/rest.go b/x/params/client/rest/rest.go index a822f609c2..70d90236e0 100644 --- a/x/params/client/rest/rest.go +++ b/x/params/client/rest/rest.go @@ -24,7 +24,7 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req paramscutils.ParamChangeProposalReq - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/params/module.go b/x/params/module.go index 49fc15a980..bc12ca60a9 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -38,7 +38,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the params module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { proposal.RegisterCodec(cdc) } diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index ddbb81fb7c..1ee0cd3426 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -22,7 +22,7 @@ func validateNoOp(_ interface{}) error { return nil } type testInput struct { ctx sdk.Context - cdc *codec.Codec + cdc *codec.LegacyAmino keeper keeper.Keeper } diff --git a/x/params/types/proposal/codec.go b/x/params/types/proposal/codec.go index a6bae4968e..94e3b6f932 100644 --- a/x/params/types/proposal/codec.go +++ b/x/params/types/proposal/codec.go @@ -11,10 +11,10 @@ type Codec struct { // Keep reference to the amino codec to allow backwards compatibility along // with type, and interface registration. - amino *codec.Codec + amino *codec.LegacyAmino } -func NewCodec(amino *codec.Codec) *Codec { +func NewCodec(amino *codec.LegacyAmino) *Codec { return &Codec{Marshaler: codec.NewHybridCodec(amino, types.NewInterfaceRegistry()), amino: amino} } @@ -29,7 +29,7 @@ func init() { } // RegisterCodec registers all necessary param module types with a given codec. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&ParameterChangeProposal{}, "cosmos-sdk/ParameterChangeProposal", nil) } diff --git a/x/slashing/keeper/querier_test.go b/x/slashing/keeper/querier_test.go index 1721fe7670..b26260007e 100644 --- a/x/slashing/keeper/querier_test.go +++ b/x/slashing/keeper/querier_test.go @@ -17,7 +17,7 @@ func TestNewQuerier(t *testing.T) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) app.SlashingKeeper.SetParams(ctx, keeper.TestParams()) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc) query := abci.RequestQuery{ diff --git a/x/slashing/module.go b/x/slashing/module.go index 038416ffa9..3000016136 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -45,7 +45,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the slashing module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index f8ea2845a3..e6f01e2abf 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -23,7 +23,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc *codec.Codec, ak types.AccountKeeper, + appParams simtypes.AppParams, cdc *codec.LegacyAmino, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper, ) simulation.WeightedOperations { diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 0987daadb2..2487084d6e 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -24,7 +24,7 @@ func TestWeightedOperations(t *testing.T) { app, ctx := createTestApp(false) ctx.WithChainID("test-chain") - cdc := app.Codec() + cdc := app.LegacyAmino() appParams := make(simtypes.AppParams) s := rand.NewSource(1) diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 256e39f5aa..c274beda37 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -8,7 +8,7 @@ import ( ) // RegisterCodec registers concrete types on codec -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index 1db24506ea..26e859c41a 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -58,7 +58,7 @@ type ( func newPostDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req DelegateRequest - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -89,7 +89,7 @@ func newPostDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { func newPostRedelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req RedelegateRequest - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -120,7 +120,7 @@ func newPostRedelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { func newPostUnbondingDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req UndelegateRequest - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/staking/common_test.go b/x/staking/common_test.go index a19969df7e..10b4f900f5 100644 --- a/x/staking/common_test.go +++ b/x/staking/common_test.go @@ -37,7 +37,7 @@ func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk. // getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper // to avoid messing with the hooks. -func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context) { +func getBaseSimappWithCustomKeeper() (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) diff --git a/x/staking/keeper/common_test.go b/x/staking/keeper/common_test.go index b4c98a011c..9ddd24da0b 100644 --- a/x/staking/keeper/common_test.go +++ b/x/staking/keeper/common_test.go @@ -18,7 +18,7 @@ var ( // createTestInput Returns a simapp with custom StakingKeeper // to avoid messing with the hooks. -func createTestInput() (*codec.Codec, *simapp.SimApp, sdk.Context) { +func createTestInput() (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index 1655892246..ae9d2e8078 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -45,7 +45,7 @@ func TestNewQuerier(t *testing.T) { Data: []byte{}, } - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) bz, err := querier(ctx, []string{"other"}, query) @@ -110,7 +110,7 @@ func TestNewQuerier(t *testing.T) { func TestQueryParametersPool(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) bondDenom := sdk.DefaultBondDenom @@ -137,7 +137,7 @@ func TestQueryParametersPool(t *testing.T) { func TestQueryValidators(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000)) @@ -205,7 +205,7 @@ func TestQueryValidators(t *testing.T) { func TestQueryDelegation(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) @@ -454,7 +454,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { } cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 100, sdk.TokensFromConsensusPower(10000)) @@ -539,7 +539,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { func TestQueryRedelegations(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) @@ -611,7 +611,7 @@ func TestQueryRedelegations(t *testing.T) { func TestQueryUnbondingDelegation(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) @@ -707,7 +707,7 @@ func TestQueryUnbondingDelegation(t *testing.T) { func TestQueryHistoricalInfo(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) diff --git a/x/staking/module.go b/x/staking/module.go index dffecd95ed..7be852331e 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -43,7 +43,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the staking module's types for the given codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 214da41d91..674d8f2e85 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -23,7 +23,7 @@ var ( valAddr1 = sdk.ValAddress(delPk1.Address()) ) -func makeTestCodec() (cdc *codec.Codec) { +func makeTestCodec() (cdc *codec.LegacyAmino) { cdc = codec.New() sdk.RegisterCodec(cdc) cryptocodec.RegisterCrypto(cdc) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index fe5e341aa5..116abe0443 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -26,7 +26,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc *codec.Codec, ak types.AccountKeeper, + appParams simtypes.AppParams, cdc *codec.LegacyAmino, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, ) simulation.WeightedOperations { var ( diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 8d2afdfa59..f1ae877c94 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -25,7 +25,7 @@ func TestWeightedOperations(t *testing.T) { ctx.WithChainID("test-chain") - cdc := app.Codec() + cdc := app.LegacyAmino() appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, cdc, app.AccountKeeper, diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 57d77e15d1..8e080e99e2 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -9,7 +9,7 @@ import ( // RegisterCodec registers the necessary x/staking interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) cdc.RegisterConcrete(&MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) cdc.RegisterConcrete(&MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) diff --git a/x/staking/types/genesis.go b/x/staking/types/genesis.go index 2e1a3a15f4..5da7713684 100644 --- a/x/staking/types/genesis.go +++ b/x/staking/types/genesis.go @@ -24,7 +24,7 @@ func DefaultGenesisState() GenesisState { // GetGenesisStateFromAppState returns x/staking GenesisState given raw application // genesis state. -func GetGenesisStateFromAppState(cdc *codec.Codec, appState map[string]json.RawMessage) GenesisState { +func GetGenesisStateFromAppState(cdc *codec.LegacyAmino, appState map[string]json.RawMessage) GenesisState { var genesisState GenesisState if appState[ModuleName] != nil { diff --git a/x/staking/types/params.go b/x/staking/types/params.go index c2bf32c657..a4f71802e8 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -87,7 +87,7 @@ func (p Params) String() string { } // unmarshal the current staking params value from store key or panic -func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params { +func MustUnmarshalParams(cdc *codec.LegacyAmino, value []byte) Params { params, err := UnmarshalParams(cdc, value) if err != nil { panic(err) @@ -97,7 +97,7 @@ func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params { } // unmarshal the current staking params value from store key -func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error) { +func UnmarshalParams(cdc *codec.LegacyAmino, value []byte) (params Params, err error) { err = cdc.UnmarshalBinaryBare(value, ¶ms) if err != nil { return diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 2f7cbdf3a7..98c66890a7 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -40,7 +40,7 @@ func setupTest(height int64, skip map[int64]bool) TestSuite { db := dbm.NewMemDB() app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, skip, simapp.DefaultNodeHome, 0) genesisState := simapp.NewDefaultGenesisState() - stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) if err != nil { panic(err) } @@ -55,7 +55,7 @@ func setupTest(height int64, skip map[int64]bool) TestSuite { s.ctx = app.BaseApp.NewContext(false, abci.Header{Height: height, Time: time.Now()}) s.module = upgrade.NewAppModule(s.keeper) - s.querier = s.module.LegacyQuerierHandler(codec.NewAminoCodec(app.Codec())) + s.querier = s.module.LegacyQuerierHandler(codec.NewAminoCodec(app.LegacyAmino())) s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper) return s } diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index a555cfc900..bb7a12ad14 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -101,7 +101,7 @@ func GetAppliedPlanCmd() *cobra.Command { } // always output json as Header is unreable in toml ([]byte is a long list of numbers) - bz, err := clientCtx.Codec.MarshalJSONIndent(headers.BlockMetas[0], "", " ") + bz, err := clientCtx.LegacyAmino.MarshalJSONIndent(headers.BlockMetas[0], "", " ") if err != nil { return err } diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index a5bb499cca..2df7b86b9c 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -34,7 +34,7 @@ func getCurrentPlanHandler(clientCtx client.Context) func(http.ResponseWriter, * } var plan types.Plan - err = clientCtx.Codec.UnmarshalBinaryBare(res, &plan) + err = clientCtx.LegacyAmino.UnmarshalBinaryBare(res, &plan) if rest.CheckInternalServerError(w, err) { return } diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index fc05ff2c70..51bdb8f923 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -62,7 +62,7 @@ func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req PlanRequest - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } @@ -102,7 +102,7 @@ func newCancelPlanHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req CancelRequest - if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) { + if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index f5f2ab22d4..e13cdadbd6 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -42,7 +42,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the upgrade types on the amino codec -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterCodec(cdc) } diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index 5531085a27..6b274e467d 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -7,7 +7,7 @@ import ( ) // RegisterCodec registers concrete types on the Amino codec -func RegisterCodec(cdc *codec.Codec) { +func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(Plan{}, "cosmos-sdk/Plan", nil) cdc.RegisterConcrete(&SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal", nil) cdc.RegisterConcrete(&CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal", nil)