-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchaininspect.py
More file actions
72 lines (57 loc) · 2.55 KB
/
chaininspect.py
File metadata and controls
72 lines (57 loc) · 2.55 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
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
72
import asyncio
import logging
import os
from tkinter import messagebox, scrolledtext, Button, Tk, Label, Entry
from core.downloader import download_smart_contract
from core.parser import parse_smart_contract
from core.scanner import scan_smart_contract
from core.report_generator import generate_pdf_report
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
class MainWindow:
def __init__(self):
self.root = Tk()
self.root.title("ChainInspect")
self.root.geometry("800x600")
self.url_label = Label(self.root, text="Smart Contract URL:")
self.url_label.pack(pady=10)
self.url_entry = Entry(self.root, width=70)
self.url_entry.pack(pady=10)
self.download_button = Button(self.root, text="Download", command=self.download_contract)
self.download_button.pack(pady=10)
self.scan_button = Button(self.root, text="Scan", command=self.scan_contract)
self.scan_button.pack(pady=10)
self.report_text = scrolledtext.ScrolledText(self.root, height=20, width=80)
self.report_text.pack(pady=20)
async def download_contract(self):
url = self.url_entry.get()
if not url:
messagebox.showwarning("Input Error", "Please enter a URL.")
return
try:
contract_code = await download_smart_contract(url)
self.report_text.insert("end", "\n\nDownloaded Contract:\n" + contract_code)
messagebox.showinfo("Download", "Downloaded the smart contract.")
except Exception as e:
messagebox.showerror("Download Error", str(e))
async def scan_contract(self):
url = self.url_entry.get()
if not url:
messagebox.showwarning("Input Error", "Please enter a URL.")
return
try:
contract_code = await download_smart_contract(url)
parsed_code = await parse_smart_contract(contract_code)
scan_result = await scan_smart_contract(parsed_code)
self.report_text.insert("end", "\n\nScan Result:\n" + scan_result)
report_file = os.path.join(os.path.dirname(__file__), "report.pdf")
await generate_pdf_report(scan_result, report_file)
messagebox.showinfo("Scan", "Scanned the smart contract. Report saved as report.pdf")
except Exception as e:
messagebox.showerror("Scan Error", str(e))
def run(self):
self.root.mainloop()
async def main():
app = MainWindow()
app.run()
if __name__ == "__main__":
asyncio.run(main())