From 3c056d0b84fe49a63ba8cccbe57926c31e6fd688 Mon Sep 17 00:00:00 2001 From: N00b <30664234+FuzzB0t@users.noreply.github.com> Date: Tue, 20 Aug 2024 09:12:13 -0600 Subject: [PATCH] fix(cli): Fix parse error on undefined values in tuples (#1285) --- packages/cli/src/commands/decode.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/decode.ts b/packages/cli/src/commands/decode.ts index c78431e4c..6e33b406d 100644 --- a/packages/cli/src/commands/decode.ts +++ b/packages/cli/src/commands/decode.ts @@ -93,9 +93,9 @@ export async function decode({ renderArgs( { ...components[i], - name: `[${i}]`, + name: `${components[i].name}`, }, - v[i], + v[`${components[i].name}`] ? v[`${components[i].name}`] : v[i], offset.repeat(2) ); } @@ -148,14 +148,21 @@ function _renderValue(type: viem.AbiParameter, value: string | bigint) { return value.toString(); case type.type === 'address': - return viem.getAddress(value); - + return viem.getAddress(value as string); case type.type == 'bool': return typeof value == 'string' && value.startsWith('0x') ? viem.hexToBool(value as viem.Hex) : value; case type.type.startsWith('bytes'): try { - return viem.hexToString(value as viem.Hex, { size: 32 }); + const decodedBytes32 = viem.hexToString(value as viem.Hex, { size: 32 }); + + // Check for characters outside the ASCII range (0-127) + // in case the bytes32 value isnt meant to be converted (e.g an identifier) + if (/[\u0080-\uFFFF]/.test(decodedBytes32)) { + return `${value}`; + } + + return decodedBytes32; } catch (err) { const settings = resolveCliSettings(); if (settings.trace) { @@ -183,7 +190,6 @@ function _parseData(abis: ContractData['abi'][], data: viem.Hash[]) { data: data.length > 1 ? data[data.length - 1] : '0x', }) ); - if (result) return { abi, result }; }