* Make JSONMarshaler require proto.Message * Use &msg with MarshalJSON * Use *LegacyAmino in queriers instead of JSONMarshaler * Revert ABCIMessageLogs String() and coins tests * Use LegacyAmino in client/debug and fix subspace tests * Use LegacyAmino in all legacy queriers and adapt simulation * Make AminoCodec implement Marshaler and some godoc fixes * Test fixes * Remove unrelevant comment * Use TxConfig.TxJSONEncoder * Use encoding/json in genutil cli migrate/validate genesis cmds * Address simulation related comments * Use JSONMarshaler in cli tests * Use proto.Message as respType in cli tests * Use tmjson for tm GenesisDoc * Update types/module/simulation.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update types/module/module_test.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Add godoc comments * Remove unused InsertKeyJSON * Fix tests Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
81 lines
3.1 KiB
Go
81 lines
3.1 KiB
Go
package codec
|
|
|
|
import "github.com/gogo/protobuf/proto"
|
|
|
|
// AminoCodec defines a codec that utilizes Codec for both binary and JSON
|
|
// encoding.
|
|
type AminoCodec struct {
|
|
*LegacyAmino
|
|
}
|
|
|
|
var _ Marshaler = &AminoCodec{}
|
|
|
|
// NewAminoCodec returns a reference to a new AminoCodec
|
|
func NewAminoCodec(codec *LegacyAmino) *AminoCodec {
|
|
return &AminoCodec{LegacyAmino: codec}
|
|
}
|
|
|
|
// MarshalBinaryBare implements BinaryMarshaler.MarshalBinaryBare method.
|
|
func (ac *AminoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) {
|
|
return ac.LegacyAmino.MarshalBinaryBare(o)
|
|
}
|
|
|
|
// MustMarshalBinaryBare implements BinaryMarshaler.MustMarshalBinaryBare method.
|
|
func (ac *AminoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte {
|
|
return ac.LegacyAmino.MustMarshalBinaryBare(o)
|
|
}
|
|
|
|
// MarshalBinaryLengthPrefixed implements BinaryMarshaler.MarshalBinaryLengthPrefixed method.
|
|
func (ac *AminoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error) {
|
|
return ac.LegacyAmino.MarshalBinaryLengthPrefixed(o)
|
|
}
|
|
|
|
// MustMarshalBinaryLengthPrefixed implements BinaryMarshaler.MustMarshalBinaryLengthPrefixed method.
|
|
func (ac *AminoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte {
|
|
return ac.LegacyAmino.MustMarshalBinaryLengthPrefixed(o)
|
|
}
|
|
|
|
// UnmarshalBinaryBare implements BinaryMarshaler.UnmarshalBinaryBare method.
|
|
func (ac *AminoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error {
|
|
return ac.LegacyAmino.UnmarshalBinaryBare(bz, ptr)
|
|
}
|
|
|
|
// MustUnmarshalBinaryBare implements BinaryMarshaler.MustUnmarshalBinaryBare method.
|
|
func (ac *AminoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) {
|
|
ac.LegacyAmino.MustUnmarshalBinaryBare(bz, ptr)
|
|
}
|
|
|
|
// UnmarshalBinaryLengthPrefixed implements BinaryMarshaler.UnmarshalBinaryLengthPrefixed method.
|
|
func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error {
|
|
return ac.LegacyAmino.UnmarshalBinaryLengthPrefixed(bz, ptr)
|
|
}
|
|
|
|
// MustUnmarshalBinaryLengthPrefixed implements BinaryMarshaler.MustUnmarshalBinaryLengthPrefixed method.
|
|
func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) {
|
|
ac.LegacyAmino.MustUnmarshalBinaryLengthPrefixed(bz, ptr)
|
|
}
|
|
|
|
// MarshalJSON implements JSONMarshaler.MarshalJSON method,
|
|
// it marshals to JSON using legacy amino codec.
|
|
func (ac *AminoCodec) MarshalJSON(o proto.Message) ([]byte, error) {
|
|
return ac.LegacyAmino.MarshalJSON(o)
|
|
}
|
|
|
|
// MustMarshalJSON implements JSONMarshaler.MustMarshalJSON method,
|
|
// it executes MarshalJSON except it panics upon failure.
|
|
func (ac *AminoCodec) MustMarshalJSON(o proto.Message) []byte {
|
|
return ac.LegacyAmino.MustMarshalJSON(o)
|
|
}
|
|
|
|
// UnmarshalJSON implements JSONMarshaler.UnmarshalJSON method,
|
|
// it unmarshals from JSON using legacy amino codec.
|
|
func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error {
|
|
return ac.LegacyAmino.UnmarshalJSON(bz, ptr)
|
|
}
|
|
|
|
// MustUnmarshalJSON implements JSONMarshaler.MustUnmarshalJSON method,
|
|
// it executes UnmarshalJSON except it panics upon failure.
|
|
func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message) {
|
|
ac.LegacyAmino.MustUnmarshalJSON(bz, ptr)
|
|
}
|