-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (23 loc) · 953 Bytes
/
Copy pathmain.py
File metadata and controls
29 lines (23 loc) · 953 Bytes
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
from flask import Flask, request, jsonify
from flask_cors import CORS
import subprocess
import tempfile
import os
app = Flask(__name__)
CORS(app, resources={r"/analyze": {"origins": "*"}})
@app.route('/analyze', methods=['POST'])
def analyze_solidity():
code = request.data.decode()
with tempfile.NamedTemporaryFile(delete=False, suffix='.sol', mode='w+') as temp_file:
temp_file_path = temp_file.name
temp_file.write(code)
try:
result = subprocess.run(['slither', temp_file_path], capture_output=True, text=True)
os.remove(temp_file_path)
combined_output = result.stdout + "\n" + result.stderr
return jsonify({'result': combined_output})
except Exception as e:
print(f"Exception during Slither execution: {str(e)}")
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0', port=int(os.getenv("PORT", 5000)))