-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
71 lines (56 loc) · 1.85 KB
/
app.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
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
from solcx import compile_source, compile_files, install_solc
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
def output(compilerVersion, output_values, myContract):
install_solc(compilerVersion)
method = 1
file_path = 'contracts/hello_world.sol'
if (method == 1):
compiled_sol = compile_source(
myContract,
output_values = output_values,
solc_version = compilerVersion
)
elif (method == 2):
compiled_sol = compile_files(
[file_path],
output_values = output_values,
solc_version = compilerVersion
)
else:
print("Wrong option")
contract_id, contract_interface = compiled_sol.popitem()
if len(output_values) == 2:
both = dict()
both['abi'] = contract_interface['abi']
both ['bytecode'] = contract_interface['bin']
return both
elif output_values[0] == 'bin':
bytecode = contract_interface['bin']
return bytecode
elif output_values[0] == 'abi':
abi = contract_interface['abi']
return abi
@app.route('/')
def home():
return render_template('index.html')
@app.route('/join', methods=['GET','POST'])
def my_form_post():
compilerVersion = request.form['compilerVersion']
binContract = request.form['bin']
abiContract = request.form['abi']
myContract = request.form['contract']
output_values = []
if abiContract == "true":
output_values.append('abi')
if binContract == "true":
output_values.append('bin')
op = str(output(compilerVersion, output_values, myContract))
print(op)
result = {
"output": op
}
result = {str(key): value for key, value in result.items()}
return jsonify(result=result)
if __name__ == '__main__':
app.run(debug=True)