From b6d3d72feeef16520dda8339e263a91e646ebdfb Mon Sep 17 00:00:00 2001 From: John Letey Date: Mon, 27 Jan 2025 14:01:23 +0000 Subject: [PATCH] feat(x/tx): add an option to encode maps using amino json (#23513) --- x/tx/signing/aminojson/json_marshal.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x/tx/signing/aminojson/json_marshal.go b/x/tx/signing/aminojson/json_marshal.go index 1e5d1b59af..45e08ffc02 100644 --- a/x/tx/signing/aminojson/json_marshal.go +++ b/x/tx/signing/aminojson/json_marshal.go @@ -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. @@ -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 @@ -93,6 +96,7 @@ func NewEncoder(options EncoderOptions) Encoder { indent: options.Indent, enumsAsString: options.EnumAsString, aminoNameAsTypeURL: options.AminoNameAsTypeURL, + marshalMappings: options.MarshalMappings, } return enc } @@ -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: