2020-01-13 15:14:18 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-03-22 19:19:57 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
2020-01-15 13:21:33 +00:00
|
|
|
SOLC_BIN = sys.argv[1]
|
|
|
|
REPORT_FILE = open("report.txt", "wb")
|
2017-03-22 19:19:57 +00:00
|
|
|
|
2017-03-22 19:56:44 +00:00
|
|
|
for optimize in [False, True]:
|
|
|
|
for f in sorted(glob.glob("*.sol")):
|
2019-03-04 15:19:34 +00:00
|
|
|
sources = {}
|
|
|
|
sources[f] = {'content': open(f, 'r').read()}
|
2020-01-15 13:21:33 +00:00
|
|
|
input_json = {
|
2019-03-04 15:19:34 +00:00
|
|
|
'language': 'Solidity',
|
|
|
|
'sources': sources,
|
|
|
|
'settings': {
|
|
|
|
'optimizer': {
|
|
|
|
'enabled': optimize
|
|
|
|
},
|
2020-01-15 13:21:33 +00:00
|
|
|
'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}
|
2019-03-04 15:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-15 13:21:33 +00:00
|
|
|
args = [SOLC_BIN, '--standard-json']
|
2017-03-22 19:56:44 +00:00
|
|
|
if optimize:
|
|
|
|
args += ['--optimize']
|
2019-03-04 15:19:34 +00:00
|
|
|
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2020-01-15 13:21:33 +00:00
|
|
|
(out, err) = proc.communicate(json.dumps(input_json))
|
2017-03-22 19:56:44 +00:00
|
|
|
try:
|
|
|
|
result = json.loads(out.strip())
|
2019-03-04 15:19:34 +00:00
|
|
|
for filename in sorted(result['contracts'].keys()):
|
|
|
|
for contractName in sorted(result['contracts'][filename].keys()):
|
|
|
|
contractData = result['contracts'][filename][contractName]
|
|
|
|
if 'evm' in contractData and 'bytecode' in contractData['evm']:
|
2020-01-15 13:21:33 +00:00
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['evm']['bytecode']['object'] + '\n')
|
2019-03-04 15:19:34 +00:00
|
|
|
else:
|
2020-01-15 13:21:33 +00:00
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' NO BYTECODE\n')
|
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n')
|
2019-03-04 15:19:34 +00:00
|
|
|
except KeyError:
|
2020-01-15 13:21:33 +00:00
|
|
|
REPORT_FILE.write(f + ": ERROR\n")
|