forked from Finschia/finschia-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update x/gov to use Any * Fixes * Remove MsgSubmitProposalLegacy * Update CHANGELOG.md * Add RegisterInterfaces for x/distribution, x/params, & x/upgrade * Fix query JSON issue * Fix gov tests * Revert custom Any Equals * Re-remove types * Rename receivers * Fix imports in gov * Sort imports * Make amino JSON signing work with Any * Run proto-gen * Create full amino wrapper * Fix errors * Fixes * Fix tests * Test fixes * Fix tests * Linting * Update ADR 019 and CHANGELOG * Updated ADR 019 * Extract Marshal/UnmarshalProposal * fix error * lint * linting * linting * Update client/keys/parse.go Co-authored-by: Marko <marbar3778@yahoo.com> * linting * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Address review feedback * Add godocs * Fix errors * fix errors * revert file * Address review feedback * Address review feedback * Stacktrace debug flag * Fix tests * Address review feedback Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
- Loading branch information
1 parent
d7677e0
commit 70767c8
Showing
58 changed files
with
1,432 additions
and
2,568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,45 @@ | ||
package codec | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
) | ||
|
||
// AminoCodec defines a codec that utilizes Amino for both binary and JSON | ||
// AminoCodec defines a codec that utilizes Codec for both binary and JSON | ||
// encoding. | ||
type AminoCodec struct { | ||
amino *Codec | ||
} | ||
|
||
func NewAminoCodec(amino *Codec) Marshaler { | ||
return &AminoCodec{amino} | ||
} | ||
|
||
func (ac *AminoCodec) marshalAnys(o ProtoMarshaler) error { | ||
return types.UnpackInterfaces(o, types.AminoPacker{Cdc: ac.amino}) | ||
*Codec | ||
} | ||
|
||
func (ac *AminoCodec) unmarshalAnys(o ProtoMarshaler) error { | ||
return types.UnpackInterfaces(o, types.AminoUnpacker{Cdc: ac.amino}) | ||
} | ||
var _ Marshaler = &AminoCodec{} | ||
|
||
func (ac *AminoCodec) jsonMarshalAnys(o interface{}) error { | ||
return types.UnpackInterfaces(o, types.AminoJSONPacker{Cdc: ac.amino}) | ||
} | ||
|
||
func (ac *AminoCodec) jsonUnmarshalAnys(o interface{}) error { | ||
return types.UnpackInterfaces(o, types.AminoJSONUnpacker{Cdc: ac.amino}) | ||
func NewAminoCodec(codec *Codec) *AminoCodec { | ||
return &AminoCodec{Codec: codec} | ||
} | ||
|
||
func (ac *AminoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) { | ||
err := ac.marshalAnys(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ac.amino.MarshalBinaryBare(o) | ||
return ac.Codec.MarshalBinaryBare(o) | ||
} | ||
|
||
func (ac *AminoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte { | ||
err := ac.marshalAnys(o) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ac.amino.MustMarshalBinaryBare(o) | ||
return ac.Codec.MustMarshalBinaryBare(o) | ||
} | ||
|
||
func (ac *AminoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error) { | ||
err := ac.marshalAnys(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ac.amino.MarshalBinaryLengthPrefixed(o) | ||
return ac.Codec.MarshalBinaryLengthPrefixed(o) | ||
} | ||
|
||
func (ac *AminoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte { | ||
err := ac.marshalAnys(o) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ac.amino.MustMarshalBinaryLengthPrefixed(o) | ||
return ac.Codec.MustMarshalBinaryLengthPrefixed(o) | ||
} | ||
|
||
func (ac *AminoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error { | ||
err := ac.amino.UnmarshalBinaryBare(bz, ptr) | ||
if err != nil { | ||
return err | ||
} | ||
return ac.unmarshalAnys(ptr) | ||
return ac.Codec.UnmarshalBinaryBare(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) { | ||
ac.amino.MustUnmarshalBinaryBare(bz, ptr) | ||
err := ac.unmarshalAnys(ptr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ac.Codec.MustUnmarshalBinaryBare(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error { | ||
err := ac.amino.UnmarshalBinaryLengthPrefixed(bz, ptr) | ||
if err != nil { | ||
return err | ||
} | ||
return ac.unmarshalAnys(ptr) | ||
return ac.Codec.UnmarshalBinaryLengthPrefixed(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) { | ||
ac.amino.MustUnmarshalBinaryLengthPrefixed(bz, ptr) | ||
err := ac.unmarshalAnys(ptr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (ac *AminoCodec) MarshalJSON(o interface{}) ([]byte, error) { | ||
err := ac.jsonMarshalAnys(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ac.amino.MarshalJSON(o) | ||
} | ||
|
||
func (ac *AminoCodec) MustMarshalJSON(o interface{}) []byte { | ||
err := ac.jsonMarshalAnys(o) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ac.amino.MustMarshalJSON(o) | ||
} | ||
|
||
func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error { | ||
err := ac.amino.UnmarshalJSON(bz, ptr) | ||
if err != nil { | ||
return err | ||
} | ||
return ac.jsonUnmarshalAnys(ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) { | ||
ac.amino.MustUnmarshalJSON(bz, ptr) | ||
err := ac.jsonUnmarshalAnys(ptr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (*AminoCodec) UnpackAny(*types.Any, interface{}) error { | ||
return fmt.Errorf("AminoCodec can't handle unpack protobuf Any's") | ||
ac.Codec.MustUnmarshalBinaryLengthPrefixed(bz, ptr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.