From a8bc49bdcf07a51b35f38cf209db27e116cc1a59 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sun, 23 Jul 2023 22:50:49 -0400 Subject: [PATCH] Fix JSON formatting for tuple arrays (#4237). --- src.ts/abi/fragments.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src.ts/abi/fragments.ts b/src.ts/abi/fragments.ts index 30b34deb6..806aa4275 100644 --- a/src.ts/abi/fragments.ts +++ b/src.ts/abi/fragments.ts @@ -612,10 +612,21 @@ export class ParamType { format(format?: FormatType): string { if (format == null) { format = "sighash"; } if (format === "json") { - let result: any = { + const name = this.name || undefined; // @TODO: Make this "" (minor bump) + + if (this.isArray()) { + const result = JSON.parse(this.arrayChildren.format("json")); + result.name = name; + result.type += `[${ (this.arrayLength < 0 ? "": String(this.arrayLength)) }]`; + return JSON.stringify(result); + } + + const result: any = { type: ((this.baseType === "tuple") ? "tuple": this.type), - name: (this.name || undefined) + name }; + + if (typeof(this.indexed) === "boolean") { result.indexed = this.indexed; } if (this.isTuple()) { result.components = this.components.map((c) => JSON.parse(c.format(format)));