Rename *codec.Codec to *codec.LegacyAmino (#6991)
* Rename *codec.Codec to *codec.LegacyAmino * Implement requested changes Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
+27
-27
@@ -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)
|
||||
}
|
||||
|
||||
+11
-11
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 "+
|
||||
|
||||
Reference in New Issue
Block a user