-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update x/gov to use Any #6147
Merged
Merged
Update x/gov to use Any #6147
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
ce24456
Update x/gov to use Any
aaronc df49ab4
Fixes
aaronc 51240fa
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
aaronc 3e5a787
Remove MsgSubmitProposalLegacy
aaronc 5264182
Update CHANGELOG.md
aaronc b2ca3a4
Add RegisterInterfaces for x/distribution, x/params, & x/upgrade
aaronc 8dcfffb
Fix query JSON issue
aaronc 42092cf
Fix gov tests
aaronc 8ea6a44
Revert custom Any Equals
aaronc 06056b3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
aaronc 7531d14
Re-remove types
aaronc ba6b151
Rename receivers
aaronc eab723e
Fix imports in gov
sahith-narahari 3777926
Sort imports
sahith-narahari 426c04f
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
sahith-narahari bf05676
Make amino JSON signing work with Any
aaronc a4a35df
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
aaronc 519e1b9
Run proto-gen
aaronc 84b4f63
Create full amino wrapper
aaronc 5b2700c
Fix errors
aaronc 06c2d03
Fixes
aaronc ad482e4
Fix tests
aaronc 0ff09a4
Test fixes
aaronc 7b632fa
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
aaronc 33b04ff
Fix tests
aaronc 72a89a1
Linting
aaronc f6fa2ba
Update ADR 019 and CHANGELOG
aaronc f3dbd90
Updated ADR 019
aaronc 8a53536
Extract Marshal/UnmarshalProposal
aaronc 5d63dd6
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
aaronc e5c90d2
fix error
aaronc ccf589a
lint
aaronc ba93a7e
linting
aaronc 065f051
linting
aaronc 3915704
Update client/keys/parse.go
aaronc 83bfba7
linting
aaronc 4836ffb
Merge branch 'master' into aaronc/x-gov-proto-any
alexanderbez fa169dc
Update docs/architecture/adr-019-protobuf-state-encoding.md
aaronc 50d4b36
Update docs/architecture/adr-019-protobuf-state-encoding.md
aaronc 34141d8
Address review feedback
aaronc 63561a8
Add godocs
aaronc 600ac6a
Merge branch 'master' into aaronc/x-gov-proto-any
aaronc 22d8af7
Fix errors
aaronc 5d289e1
Merge remote-tracking branch 'origin/aaronc/x-gov-proto-any' into aar…
aaronc a005332
fix errors
aaronc c1bad36
revert file
aaronc b58c42a
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/x-g…
aaronc c09e298
Address review feedback
aaronc 0e159e7
Address review feedback
aaronc 5ed861d
Stacktrace debug flag
aaronc 2e14d48
Fix tests
aaronc 72ead83
Address review feedback
aaronc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this be deprecated in the future in favor of
AminoCodec
? are there any difference between the 2?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the ADR updates in this PR I noted that we would rename this to
LegacyAmino
. It is more or less deprecated. The difference between the two is thatMarshaler
expects types that implementProtoMarshaler
(i.e. generated by protoc). So any code usingMarshaler
is more or less ensured to be proto compatible. This legacyCodec
is pure amino.