Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ABI decoding should take place instead of random cache being returned #163

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/helpers/functionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,26 @@ 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<BytesSignatureResponse, void>({
method: 'GET',
url,
})
functionSignatures = methods.results.map(result => result.text_signature)
}

const methods = await fetcher<BytesSignatureResponse, void>({
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)) || {}
Expand Down Expand Up @@ -131,9 +138,10 @@ export const decodeData = async (
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,
Expand Down
Loading