Skip to content

Commit

Permalink
fix(cli): Fix parse error on undefined values in tuples (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzB0t authored Aug 20, 2024
1 parent 7f1a796 commit 3c056d0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/cli/src/commands/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 };
}

Expand Down

0 comments on commit 3c056d0

Please sign in to comment.