Skip to content

Commit

Permalink
Rename *codec.Codec to *codec.LegacyAmino (#6991)
Browse files Browse the repository at this point in the history
* Rename *codec.Codec to *codec.LegacyAmino

* Implement requested changes

Co-authored-by: Aaron Craelius <[email protected]>
  • Loading branch information
dauTT and aaronc authored Aug 10, 2020
1 parent 769387b commit 20c80cf
Show file tree
Hide file tree
Showing 148 changed files with 422 additions and 422 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion client/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion client/keys/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion client/tx/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
Expand Down
54 changes: 27 additions & 27 deletions codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -62,135 +62,135 @@ 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
}
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)
}
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
}
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)
}
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
}
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
}
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
}
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)
}
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
}
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)
}
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)
}
22 changes: 11 additions & 11 deletions codec/amino_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion codec/hybrid_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion codec/legacy/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion codec/types/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "+
Expand Down
Loading

0 comments on commit 20c80cf

Please sign in to comment.