From f4abc9c46377015f63c3d86d1b49fecf391ecc99 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Tue, 24 Sep 2024 17:04:11 +0300 Subject: [PATCH 1/2] fix: ABI decoding should take place instead of random cache being returned --- src/helpers/functionUtils.ts | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/helpers/functionUtils.ts b/src/helpers/functionUtils.ts index c4fb809a..e82c76d4 100644 --- a/src/helpers/functionUtils.ts +++ b/src/helpers/functionUtils.ts @@ -91,22 +91,30 @@ export const decodeData = async ( } catch {} const url = getSelectorLookupURL(selector) const functionSignatureResponse = await signatureCache?.match(url) + + let functionSignatures: string[] = [] if (functionSignatureResponse) { - return await functionSignatureResponse.json() + const response = await functionSignatureResponse.json() + if (response.functionSignature) { + functionSignatures.push(response.functionSignature) + } + } + if (functionSignatures.length === 0) { + const methods = await fetcher({ + method: 'GET', + url, + }) + functionSignatures = methods.results.map(result => result.text_signature) } - const methods = await fetcher({ - method: 'GET', - url, - }) - - if (methods && methods.results.length > 0) { - for (const result of methods.results.reverse()) { + if (functionSignatures.length > 0) { + for (const functionSignature of functionSignatures.reverse()) { try { - const params: string[] = result.text_signature + const params: string[] = functionSignature .replace(/^[^(]*\(|\)[^)]*$/g, '') .split(',') const args = eth.abi.decodeParameters(params, data.substring(8)) || {} + console.log('decodeData args/params', args, params) const encodeArgs = Array(params.length) .fill(null) .map((_val, index) => { @@ -126,14 +134,16 @@ export const decodeData = async ( throw new Error('Invalid address value') } } + console.log('value at', index, args[`${index}`]) return args[`${index}`] ?? '0x' }) const newData = eth.abi.encodeParameters(params, encodeArgs).substring(2) || '0x' if (data.substring(8) === newData) { - const call = result.text_signature.replace(/\(.*$/, '') + const call = functionSignature.replace(/\(.*$/, '') const item = { - label: `Decoded ${result.text_signature.replace(/\(.*$/, '')}`, + label: `Decoded ${functionSignature}`, + functionSignature: functionSignature, call, inputs: params.map((type, index) => ({ type, From fb09500baaf6a6e7a5eb6f8c096a90178c6a270c Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:25:31 +0300 Subject: [PATCH 2/2] chore: removed test console.log --- src/helpers/functionUtils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/helpers/functionUtils.ts b/src/helpers/functionUtils.ts index e82c76d4..49f3e6d9 100644 --- a/src/helpers/functionUtils.ts +++ b/src/helpers/functionUtils.ts @@ -114,7 +114,6 @@ export const decodeData = async ( .replace(/^[^(]*\(|\)[^)]*$/g, '') .split(',') const args = eth.abi.decodeParameters(params, data.substring(8)) || {} - console.log('decodeData args/params', args, params) const encodeArgs = Array(params.length) .fill(null) .map((_val, index) => { @@ -134,7 +133,6 @@ export const decodeData = async ( throw new Error('Invalid address value') } } - console.log('value at', index, args[`${index}`]) return args[`${index}`] ?? '0x' }) const newData =