-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.js
88 lines (78 loc) · 2.87 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const fetch = require('node-fetch')
const querystring = require('querystring')
const axios = require('axios')
const delay = (ms) => new Promise(res => setTimeout(res, ms))
async function main() {
const apiUrl = 'https://api-rinkeby.etherscan.io/api'
const address = '0x94263a20b1Eea751d6C3B207A7A0ba8fF8Db9E90'
const res = await fetch(`https://sourcify.dev/server/files/4/${address}`)
const files = await res.json()
const metadata = JSON.parse(files.find(file => file.name === 'metadata.json').content)
const sources = files.filter(file => file.name !== 'metadata.json' && file.name !== 'constructor-args.txt')
const version = `v${metadata.compiler.version}`
console.log(version)
const target = Object.entries(metadata.settings.compilationTarget)[0].join(':')
console.log(target)
console.log(metadata.settings)
console.log(sources.length)
const standardJson = {
language: metadata.language,
sources: {},
settings: {
optimizer: metadata.settings.optimizer,
evmVersion: metadata.settings.evmVersion,
remappings: metadata.settings.remappings,
libraries: metadata.settings.libraries
}
}
const prefix = '/home/data/repository/contracts/full_match/4/0x94263a20b1Eea751d6C3B207A7A0ba8fF8Db9E90/sources/'
for (const file of sources) {
file.path = file.path.replace('sources/_', 'sources/@')
console.log(file.path)
standardJson.sources[file.path.slice(prefix.length)] = {
content: file.content
}
}
// console.log(sources)
console.log(standardJson)
const args = '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010666f7220566572696669636174696f6e00000000000000000000000000000000'
const apikey = 'MWBWHZH2CGU1KM4C28BH55IJHN439G41XQ'
const body = {
apikey,
module: 'contract',
action: 'verifysourcecode',
contractaddress: address,
sourceCode: JSON.stringify(standardJson),
codeformat: 'solidity-standard-json-input',
contractname: target,
compilerversion: version,
constructorArguements: ''
}
const str = querystring.stringify(body)
const result = await fetch(apiUrl, {
method: 'POST',
body: str,
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' }
}).then(res => res.json())
console.log(result)
const guid = result.result
while (true) {
await delay(5000)
try {
const qs = querystring.stringify({
apiKey: apikey,
module: 'contract',
action: 'checkverifystatus',
guid
})
const verificationResult = await fetch(`${apiUrl}?${qs}`).then(res => res.json())
if (verificationResult.result !== VerificationStatus.PENDING) {
console.log(verificationResult)
}
} catch (error) {
console.log(error)
throw new Error(`Failed to connect to Etherscan API at url ${apiUrl}`)
}
}
}
main()