dementedpop commited on
Commit
42fc15a
·
verified ·
1 Parent(s): d31e36f

create p2sh-qt.py

Browse files
Files changed (1) hide show
  1. p2sh-qt.py +214 -0
p2sh-qt.py ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import json
3
+ import logging
4
+ from PyQt5.QtWidgets import (
5
+ QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
6
+ QLabel, QLineEdit, QPushButton, QTextEdit, QTabWidget,
7
+ QTreeWidget, QTreeWidgetItem, QMessageBox
8
+ )
9
+ from PyQt5.QtGui import QFont, QIcon
10
+ from PyQt5.QtCore import Qt, QThread, pyqtSignal
11
+
12
+ # Import the P2SH Transaction Debugger
13
+ from p2sh_transaction_debugger import P2SHTransactionDebugger
14
+
15
+ class TransactionDebuggerThread(QThread):
16
+ """
17
+ Background thread for processing transaction debugging
18
+ to prevent UI freezing
19
+ """
20
+ debug_complete = pyqtSignal(dict)
21
+ error_occurred = pyqtSignal(str)
22
+
23
+ def __init__(self, debugger, tx_hash, network):
24
+ super().__init__()
25
+ self.debugger = debugger
26
+ self.tx_hash = tx_hash
27
+ self.network = network
28
+
29
+ def run(self):
30
+ try:
31
+ # Temporarily switch network if needed
32
+ original_network = self.debugger.network
33
+ self.debugger.network = self.network
34
+
35
+ # Debug the transaction
36
+ tx_details = self.debugger.debug_p2sh_transaction(self.tx_hash)
37
+
38
+ # Restore original network
39
+ self.debugger.network = original_network
40
+
41
+ if tx_details:
42
+ self.debug_complete.emit(tx_details)
43
+ else:
44
+ self.error_occurred.emit("Failed to retrieve transaction details")
45
+ except Exception as e:
46
+ self.error_occurred.emit(str(e))
47
+
48
+ class P2SHDebuggerApp(QMainWindow):
49
+ def __init__(self):
50
+ super().__init__()
51
+ self.setWindowTitle("P2SH Transaction Debugger")
52
+ self.setGeometry(100, 100, 800, 600)
53
+
54
+ # Initialize debugger
55
+ self.debugger = P2SHTransactionDebugger()
56
+
57
+ # Setup main UI
58
+ self.init_ui()
59
+
60
+ def init_ui(self):
61
+ """
62
+ Create the main user interface
63
+ """
64
+ # Central widget and main layout
65
+ central_widget = QWidget()
66
+ main_layout = QVBoxLayout()
67
+ central_widget.setLayout(main_layout)
68
+ self.setCentralWidget(central_widget)
69
+
70
+ # Transaction input section
71
+ input_layout = QHBoxLayout()
72
+
73
+ # Network selection
74
+ self.network_input = QLineEdit()
75
+ self.network_input.setPlaceholderText("Network (mainnet/testnet)")
76
+ self.network_input.setText("mainnet")
77
+ input_layout.addWidget(self.network_input)
78
+
79
+ # Transaction hash input
80
+ self.tx_hash_input = QLineEdit()
81
+ self.tx_hash_input.setPlaceholderText("Enter Bitcoin Transaction Hash")
82
+ input_layout.addWidget(self.tx_hash_input)
83
+
84
+ # Transaction serialData input
85
+ self.tx_data_input = QLineEdit()
86
+ self.tx_data_input.setPlaceholderText("Enter Serialized Bitcoin Transaction Data")
87
+ input_layout.addWidget(self.tx_data_input)
88
+
89
+ # Debug button
90
+ debug_button = QPushButton("Debug Transaction")
91
+ debug_button.clicked.connect(self.start_transaction_debug)
92
+ input_layout.addWidget(debug_button)
93
+
94
+ main_layout.addLayout(input_layout)
95
+
96
+ # Tabs for different views
97
+ self.tabs = QTabWidget()
98
+ main_layout.addWidget(self.tabs)
99
+
100
+ # Create tabs
101
+ self.details_tab = QTextEdit()
102
+ self.details_tab.setReadOnly(True)
103
+ self.tree_tab = QTreeWidget()
104
+ self.tree_tab.setHeaderLabel("Transaction Structure")
105
+
106
+ self.tabs.addTab(self.details_tab, "Detailed View")
107
+ self.tabs.addTab(self.tree_tab, "Structured View")
108
+
109
+ def start_transaction_debug(self):
110
+ """
111
+ Initiate transaction debugging process
112
+ """
113
+ # Validate inputs
114
+ tx_hash = self.tx_hash_input.text().strip()
115
+ network = self.network_input.text().strip().lower()
116
+
117
+ if not tx_hash:
118
+ QMessageBox.warning(self, "Input Error", "Please enter a transaction hash")
119
+ return
120
+
121
+ if network not in ['mainnet', 'testnet']:
122
+ QMessageBox.warning(self, "Network Error", "Invalid network. Use 'mainnet' or 'testnet'")
123
+ return
124
+
125
+ # Clear previous results
126
+ self.details_tab.clear()
127
+ self.tree_tab.clear()
128
+
129
+ # Start debugging thread
130
+ self.debug_thread = TransactionDebuggerThread(
131
+ self.debugger,
132
+ tx_hash,
133
+ network
134
+ )
135
+ self.debug_thread.debug_complete.connect(self.display_debug_results)
136
+ self.debug_thread.error_occurred.connect(self.handle_debug_error)
137
+ self.debug_thread.start()
138
+
139
+ def display_debug_results(self, results):
140
+ """
141
+ Display debugging results in both tabs
142
+ """
143
+ # Detailed Text View
144
+ self.details_tab.setPlainText(
145
+ json.dumps(results, indent=2)
146
+ )
147
+
148
+ # Structured Tree View
149
+ self._populate_tree_view(results)
150
+
151
+ def _populate_tree_view(self, results):
152
+ """
153
+ Populate the tree view with transaction details
154
+ """
155
+ self.tree_tab.clear()
156
+
157
+ # Transaction hash root item
158
+ root = QTreeWidgetItem(self.tree_tab,
159
+ [f"Transaction: {results.get('transaction_hash', 'N/A')}"])
160
+
161
+ # Inputs section
162
+ inputs_item = QTreeWidgetItem(root, ["Inputs"])
163
+ for idx, input_data in enumerate(results.get('inputs', [])):
164
+ input_item = QTreeWidgetItem(inputs_item, [f"Input {idx+1}"])
165
+ for key, value in input_data.items():
166
+ QTreeWidgetItem(input_item, [f"{key}: {str(value)}"])
167
+
168
+ # Outputs section
169
+ outputs_item = QTreeWidgetItem(root, ["Outputs"])
170
+ for idx, output_data in enumerate(results.get('outputs', [])):
171
+ output_item = QTreeWidgetItem(outputs_item, [f"Output {idx+1}"])
172
+ for key, value in output_data.items():
173
+ QTreeWidgetItem(output_item, [f"{key}: {str(value)}"])
174
+
175
+ self.tree_tab.expandAll()
176
+
177
+ def handle_debug_error(self, error_message):
178
+ """
179
+ Handle errors during debugging process
180
+ """
181
+ QMessageBox.critical(
182
+ self,
183
+ "Debugging Error",
184
+ f"An error occurred: {error_message}"
185
+ )
186
+
187
+ def main():
188
+ """
189
+ Main application entry point
190
+ """
191
+ # Configure logging
192
+ logging.basicConfig(
193
+ level=logging.INFO,
194
+ format='%(asctime)s - %(levelname)s - %(message)s'
195
+ )
196
+
197
+ # Create application
198
+ app = QApplication(sys.argv)
199
+
200
+ # Set application style
201
+ app.setStyle('Fusion') # Modern, cross-platform style
202
+
203
+ # Create and show main window
204
+ debugger_app = P2SHDebuggerApp()
205
+ debugger_app.show()
206
+
207
+ # Execute the application
208
+ sys.exit(app.exec_())
209
+
210
+ if __name__ == "__main__":
211
+ main()
212
+
213
+ # Required dependencies:
214
+ # pip install PyQt5 requests base58