Skip to content

Commit

Permalink
Adds 4byte registry fallback to getMethodData() (#6435)
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm authored and whymarrh committed May 7, 2019
1 parent 50f4638 commit 3f2889b
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions ui/app/helpers/utils/transactions.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ export function getTokenData (data = '') {
return abiDecoder.decodeMethod(data)
}

async function getMethodFrom4Byte (fourBytePrefix) {
const fourByteResponse = (await fetch(`https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`, {
referrerPolicy: 'no-referrer-when-downgrade',
body: null,
method: 'GET',
mode: 'cors',
})).json()

if (fourByteResponse.count === 1) {
return fourByteResponse.results[0].text_signature
} else {
return null
}
}

const registry = new MethodRegistry({ provider: global.ethereumProvider })

/**
Expand All @@ -43,7 +58,16 @@ const registry = new MethodRegistry({ provider: global.ethereumProvider })
const fourBytePrefix = prefixedData.slice(0, 10)

try {
const sig = await registry.lookup(fourBytePrefix)
const fourByteSig = getMethodFrom4Byte(fourBytePrefix).catch((e) => {
log.error(e)
return null
})

let sig = await registry.lookup(fourBytePrefix)

if (!sig) {
sig = await fourByteSig
}

if (!sig) {
return {}
Expand All @@ -57,8 +81,8 @@ const registry = new MethodRegistry({ provider: global.ethereumProvider })
}
} catch (error) {
log.error(error)
const contractData = getTokenData(data)
const { name } = contractData || {}
const tokenData = getTokenData(data)
const { name } = tokenData || {}
return { name }
}

Expand Down

0 comments on commit 3f2889b

Please sign in to comment.