-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.py
More file actions
46 lines (38 loc) · 1.46 KB
/
Copy pathextract.py
File metadata and controls
46 lines (38 loc) · 1.46 KB
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
import json
import glob
from sha3 import keccak_256
functionHashes = open("extract/functionHashes.txt","w+")
for file in list(glob.glob('build/contracts/*.json')):
reader = open(file)
j = json.load(reader)
index_of_dot = reader.name.index('.')
file_name_without_extension1 = reader.name[:index_of_dot]
file_name_without_extension = file_name_without_extension1.split('/')[-1]
f = open("extract/"+file_name_without_extension+".abi.txt","w+")
f.write(json.dumps(j['abi']))
f.close
f = open("extract/"+file_name_without_extension+".bytecode.txt","w+")
f.write(j['bytecode'])
f.close
abi = j['abi']
functionSelector = []
for fields in abi:
if(fields['type'] == 'function'):
functionName = fields['name']
functionInputs = []
for inputs in fields['inputs']:
functionInputs.append(inputs['type'])
functionSelector.append([functionName, functionInputs])
for functions in functionSelector:
functionName = functions[0]
functionType = functions[1]
s = functionName + '('
for i in range(len(functionType)):
s += functionType[i]
if(i+1 < len(functionType)):
s += ','
s += ')'
sha3_hash = keccak_256(s.encode('utf-8')).hexdigest()
ss = "functionHashes.set('" + sha3_hash[:8] + "', '" + s + "');"
print >> functionHashes, ss
functionHashes.close