Skip to content

Commit dd3d264

Browse files
committed
feat(x/tx): add an option to encode maps using amino json
1 parent 55f7cfc commit dd3d264

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

x/tx/signing/aminojson/json_marshal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type EncoderOptions struct {
3838
// It is useful when using the Amino JSON encoder for non Amino purposes,
3939
// such as JSON RPC.
4040
AminoNameAsTypeURL bool
41+
// MarshalMappings when set will use the Amino JSON encoder to marshal maps.
42+
MarshalMappings bool
4143
// TypeResolver is used to resolve protobuf message types by TypeURL when marshaling any packed messages.
4244
TypeResolver signing.TypeResolver
4345
// FileResolver is used to resolve protobuf file descriptors TypeURL when TypeResolver fails.
@@ -57,6 +59,7 @@ type Encoder struct {
5759
indent string
5860
enumsAsString bool
5961
aminoNameAsTypeURL bool
62+
marshalMappings bool
6063
}
6164

6265
// 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 {
9396
indent: options.Indent,
9497
enumsAsString: options.EnumAsString,
9598
aminoNameAsTypeURL: options.AminoNameAsTypeURL,
99+
marshalMappings: options.MarshalMappings,
96100
}
97101
return enc
98102
}
@@ -237,6 +241,9 @@ func (enc Encoder) marshal(value protoreflect.Value, fd protoreflect.FieldDescri
237241
return err
238242

239243
case protoreflect.Map:
244+
if enc.marshalMappings {
245+
return jsonMarshal(writer, value)
246+
}
240247
return errors.New("maps are not supported")
241248

242249
case protoreflect.List:

0 commit comments

Comments
 (0)