Skip to content

Commit

Permalink
Merge pull request #15 from 0xAWM/main
Browse files Browse the repository at this point in the history
feat: Submit Dedaub decompile when unsupported
  • Loading branch information
cong1223 authored Dec 21, 2023
2 parents f10a5fd + 27225be commit a59a379
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
32 changes: 31 additions & 1 deletion src/content/etherscan/components/DecompileInDedaubBtn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,37 @@ const DecompileInDedaubBtn: FC<Props> = ({ mainAddress, chain }) => {
`https://library.dedaub.com/${item.pathname}/address/${mainAddress}/decompiled`
)
} else {
window.open('https://library.dedaub.com/decompile')
const url = 'https://library.dedaub.com/api/on_demand'
const bytecode = document.getElementById('dividcode')
if (bytecode == null) {
window.open('https://library.dedaub.com/decompile')
return
}
const data = {
hex_bytecode: bytecode.innerText
}
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
authority: 'api.dedaub.com',
origin: 'https://library.dedaub.com',
referer: 'https://library.dedaub.com/'
},
body: JSON.stringify(data),
mode: 'cors'
})
.then(response => response.text())
.then(data => {
console.log('Success:', data)
window.open(
'https://library.dedaub.com/decompile?md5=' + data.replace(/"/g, '')
)
})
.catch(error => {
console.error('Error:', error)
window.open('https://library.dedaub.com/decompile')
})
}
}

Expand Down
33 changes: 31 additions & 2 deletions src/content/scans/components/DecompileInDedaubBtn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,42 @@ interface Props {
const DecompileInDedaubBtn: FC<Props> = ({ mainAddress, chain }) => {
const toDedaub = () => {
const item = DEDAUB_SUPPORT_DIRECT_LIST.find(item => item.chain === chain)

if (item) {
window.open(
`https://library.dedaub.com/${item.pathname}/address/${mainAddress}/decompiled`
)
} else {
window.open('https://library.dedaub.com/decompile')
const url = 'https://library.dedaub.com/api/on_demand'
const bytecode = document.getElementById('dividcode')
if (bytecode == null) {
window.open('https://library.dedaub.com/decompile')
return
}
const data = {
hex_bytecode: bytecode.innerText
}
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
authority: 'api.dedaub.com',
origin: 'https://library.dedaub.com',
referer: 'https://library.dedaub.com/'
},
body: JSON.stringify(data),
mode: 'cors'
})
.then(response => response.text())
.then(data => {
console.log('Success:', data)
window.open(
'https://library.dedaub.com/decompile?md5=' + data.replace(/"/g, '')
)
})
.catch(error => {
console.error('Error:', error)
window.open('https://library.dedaub.com/decompile')
})
}
}

Expand Down

0 comments on commit a59a379

Please sign in to comment.