-
Notifications
You must be signed in to change notification settings - Fork 0
/
etherscan_api.py
executable file
·42 lines (33 loc) · 1007 Bytes
/
etherscan_api.py
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
#!/usr/bin/env python3
import json
import os
import sys
'''
curlie -v https://api.etherscan.io/api module==contract action==getsourcecode address==??? apikey==??? | tee abi.json
'''
def write(path, content):
path = './contract/' + path.lstrip('/')
print(f'Writing {path}')
dir = os.path.dirname(path)
os.makedirs(dir, mode=0o755, exist_ok=True)
with open(path, 'w') as f:
f.write(content)
pass
def main():
source_path = sys.argv[1]
with open(source_path, 'r') as f:
source_resp = json.load(f)
result = source_resp['result']
for xr in result:
source_code = xr['SourceCode']
if source_code.startswith('{{'):
source_code = source_code[1:]
if source_code.endswith('}}'):
source_code = source_code[:-1]
sources = json.loads(source_code)['sources']
for x, v in sources.items():
code = v['content']
write(x, code)
pass
if __name__ == '__main__':
main()