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]
|
2020-02-14 16:03:48 +00:00
|
|
|
REPORT_FILE = open("report.txt", mode="w", encoding='utf8', newline='\n')
|
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 = {}
|
2020-11-20 14:31:11 +00:00
|
|
|
sources[f] = {'content': open(f, mode='r', encoding='utf8').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-12-09 14:15:49 +00:00
|
|
|
'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}},
|
|
|
|
'modelChecker': { "engine": 'none' }
|
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-20 10:20:18 +00:00
|
|
|
(out, err) = proc.communicate(json.dumps(input_json).encode('utf-8'))
|
2020-12-22 01:08:40 +00:00
|
|
|
|
|
|
|
result = json.loads(out.decode('utf-8').strip())
|
|
|
|
if (
|
|
|
|
'contracts' not in result or
|
|
|
|
len(result['contracts']) == 0 or
|
|
|
|
all(len(file_results) == 0 for file_name, file_results in result['contracts'].items())
|
|
|
|
):
|
|
|
|
REPORT_FILE.write(f + ": ERROR\n")
|
|
|
|
else:
|
2019-03-04 15:19:34 +00:00
|
|
|
for filename in sorted(result['contracts'].keys()):
|
|
|
|
for contractName in sorted(result['contracts'][filename].keys()):
|
2020-12-22 01:08:40 +00:00
|
|
|
bytecode = result['contracts'][filename][contractName].get('evm', {}).get('bytecode', {}).get('object', 'NO BYTECODE')
|
|
|
|
metadata = result['contracts'][filename][contractName]['metadata']
|
|
|
|
|
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' ' + bytecode + '\n')
|
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' ' + metadata + '\n')
|