Skip to content
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

feat(x/tx): add custom type encoder #17681

Merged
merged 11 commits into from
Sep 13, 2023
1 change: 1 addition & 0 deletions x/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* [#17681](https://github.com/cosmos/cosmos-sdk/pull/17681) Add encoder `DefineTypeEncoding` method for defining custom type encodings.
* [#17600](https://github.com/cosmos/cosmos-sdk/pull/17600) Add encoder `DefineScalarEncoding` method for defining custom scalar encodings.
* [#17600](https://github.com/cosmos/cosmos-sdk/pull/17600) Add indent option to encoder.

Expand Down
6 changes: 3 additions & 3 deletions x/tx/signing/aminojson/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"google.golang.org/protobuf/types/known/anypb"
)

func (enc Encoder) marshalAny(message protoreflect.Message, writer io.Writer) error {
func marshalAny(enc *Encoder, message protoreflect.Message, writer io.Writer) error {
// when a message contains a nested any field, and the top-level message has been unmarshalled into a dyanmicpb,
// the nested any field will also be a dynamicpb. In this case, we must use the dynamicpb API.
_, ok := message.Interface().(*dynamicpb.Message)
if ok {
return enc.marshalDynamic(message, writer)
return marshalDynamic(enc, message, writer)
}

anyMsg, ok := message.Interface().(*anypb.Any)
Expand Down Expand Up @@ -64,7 +64,7 @@ const (
anyValueFieldName = "value"
)

func (enc Encoder) marshalDynamic(message protoreflect.Message, writer io.Writer) error {
func marshalDynamic(enc *Encoder, message protoreflect.Message, writer io.Writer) error {
msgName := message.Get(message.Descriptor().Fields().ByName(anyTypeURLFieldName)).String()[1:]
msgBytes := message.Get(message.Descriptor().Fields().ByName(anyValueFieldName)).Bytes()

Expand Down
5 changes: 5 additions & 0 deletions x/tx/signing/aminojson/internal/testpb/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ message ABitOfEverything {
// google.protobuf.Duration duration = 24;
}

message Duration {
google.protobuf.Duration duration = 1;
google.protobuf.Timestamp timestamp = 2;
}

message NestedMessage {
option (amino.name) = "NestedMessage";

Expand Down
Loading
Loading