Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI][DB] Allow Custom Explorers #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions pet4l.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@
from PyQt5.QtWidgets import QApplication
from mainApp import App

# Create App
# Create QApplication
app = QApplication(sys.argv)

# --------------

# Create QMainWindow Widget
ex = App(imgDir, app, args)

# -- Launch RPC watchdog
# Launch RPC watchdog
ex.mainWindow.rpc_watchdogThread.start()

# Execute App
# Execute the application
app.exec_()
try:
app.deleteLater()
except Exception as e:
print(e)

sys.exit()


14 changes: 10 additions & 4 deletions src/apiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from blockbookClient import BlockBookClient
from cryptoIDClient import CryptoIDClient

from misc import getCallerName, getFunctionName, printException, printError
from misc import getCallerName, getFunctionName, printException, printError, printDbg


def process_api_exceptions(func):
Expand All @@ -31,9 +31,15 @@ def process_api_exceptions_int(*args, **kwargs):

class ApiClient:

def __init__(self, isTestnet=False):
self.isTestnet = isTestnet
self.api = BlockBookClient(isTestnet)
def __init__(self, main_wnd):
self.main_wnd = main_wnd
self.isTestnet = main_wnd.isTestnetRPC
self.api = BlockBookClient(main_wnd, self.isTestnet)

def updateExplorerUrl(self, new_url):
# Update the explorer URL in the BlockBookClient instance
printDbg(f"Updating explorer URL to: {new_url}")
self.api.updateBaseUrl(new_url)

@process_api_exceptions
def getAddressUtxos(self, address):
Expand Down
39 changes: 20 additions & 19 deletions src/blockbookClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.

import requests

from misc import getCallerName, getFunctionName, printException
from PyQt5.QtWidgets import QMessageBox
from misc import getCallerName, getFunctionName, printException, myPopUp, printDbg


def process_blockbook_exceptions(func):
Expand All @@ -15,30 +15,32 @@ def process_blockbook_exceptions_int(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
if client.isTestnet:
new_url = "https://testnet.fuzzbawls.pw"
else:
new_url = "https://zkbitcoin.com/"
message = "BlockBook Client exception on %s\nTrying backup server %s" % (client.url, new_url)
message = "BlockBook Client exception on %s" % (client.url)
printException(getCallerName(True), getFunctionName(True), message, str(e))
try:
client.url = new_url
return func(*args, **kwargs)

except Exception:
raise
myPopUp(None, QMessageBox.Critical, "Explorer Error", "Failed to connect to Explorer URL: %s\n%s" % (client.url, str(e)))
raise

return process_blockbook_exceptions_int


class BlockBookClient:

def __init__(self, isTestnet=False):
def __init__(self, main_wnd, isTestnet=False):
self.main_wnd = main_wnd
self.isTestnet = isTestnet
if isTestnet:
self.url = "https://testnet.rockdev.org/"
self.url = ""
self.loadURL()

def loadURL(self):
if self.isTestnet:
self.url = self.main_wnd.getExplorerURL('testnet')
else:
self.url = "https://explorer.rockdev.org/"
self.url = self.main_wnd.getExplorerURL('mainnet')
printDbg(f"Using Explorer URL: {self.url}")

def updateBaseUrl(self, new_url):
# Update the explorer URL
self.url = new_url
printDbg(f"Explorer URL updated to: {self.url}")

def checkResponse(self, method, param=""):
url = self.url + "/api/%s" % method
Expand All @@ -53,7 +55,6 @@ def checkResponse(self, method, param=""):
@process_blockbook_exceptions
def getAddressUtxos(self, address):
utxos = self.checkResponse("utxo", address)
# Add script for cryptoID legacy
for u in utxos:
u["script"] = ""
return utxos
Expand Down
6 changes: 6 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"splitter_x": 342,
"splitter_y": 133,
"console_hidden": False,
"selectedExplorer_index": 0,
"selectedHW_index": 0,
"selectedRPC_index": 0,
"isTestnetRPC": False,
Expand All @@ -52,6 +53,11 @@
["https", "latvia.fuzzbawls.pw:8080", "spmtUser", "8X88u7TuefPm7mQaJY52"],
["https", "charlotte.fuzzbawls.pw:8080", "spmtUser", "ZyD936tm9dvqmMP8A777"]]

trusted_explorers = [
["https://explorer.duddino.com/", False, False],
["https://testnet.duddino.com/", True, False],
["https://zkbitcoin.com/", False, False]
]

HW_devices = [
# (model name, api index)
Expand Down
Loading