Skip to content

Commit

Permalink
feat(x/tx): add an option to encode maps using amino json
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Nov 5, 2024
1 parent 55f7cfc commit dd3d264
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions x/tx/signing/aminojson/json_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type EncoderOptions struct {
// It is useful when using the Amino JSON encoder for non Amino purposes,
// such as JSON RPC.
AminoNameAsTypeURL bool
// MarshalMappings when set will use the Amino JSON encoder to marshal maps.
MarshalMappings bool
// TypeResolver is used to resolve protobuf message types by TypeURL when marshaling any packed messages.
TypeResolver signing.TypeResolver
// FileResolver is used to resolve protobuf file descriptors TypeURL when TypeResolver fails.
Expand All @@ -57,6 +59,7 @@ type Encoder struct {
indent string
enumsAsString bool
aminoNameAsTypeURL bool
marshalMappings bool
}

// NewEncoder returns a new Encoder capable of serializing protobuf messages to JSON using the Amino JSON encoding
Expand Down Expand Up @@ -93,6 +96,7 @@ func NewEncoder(options EncoderOptions) Encoder {
indent: options.Indent,
enumsAsString: options.EnumAsString,
aminoNameAsTypeURL: options.AminoNameAsTypeURL,
marshalMappings: options.MarshalMappings,
}
return enc
}
Expand Down Expand Up @@ -237,6 +241,9 @@ func (enc Encoder) marshal(value protoreflect.Value, fd protoreflect.FieldDescri
return err

case protoreflect.Map:
if enc.marshalMappings {
return jsonMarshal(writer, value)
}
return errors.New("maps are not supported")

case protoreflect.List:
Expand Down

0 comments on commit dd3d264

Please sign in to comment.