Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/.pytest_cache/
/.idea/
/.settings/
/__pycache__/
__pycache__/

# Virtual environments
/venv*/
Expand Down
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
60 changes: 39 additions & 21 deletions src/blockbookClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.

import requests

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


def process_blockbook_exceptions(func):
Expand All @@ -15,33 +14,53 @@ 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
# Primary explorer failed: retry against the other explorers
# configured for this network (e.g. zkbitcoin) before giving up.
for new_url in client.getFallbackUrls():
printDbg("Trying backup explorer %s" % new_url)
try:
client.url = new_url
return func(*args, **kwargs)
except Exception:
continue
# All explorers failed: re-raise so ApiClient can fall back further.
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/"
else:
self.url = "https://explorer.rockdev.org/"
self.url = ""
self.loadURL()

def network(self):
return 'testnet' if self.isTestnet else 'mainnet'

def loadURL(self):
self.url = self.main_wnd.getExplorerURL(self.network())
printDbg(f"Using Explorer URL: {self.url}")

def getFallbackUrls(self):
# Return the other explorer URLs for this network (current one excluded).
try:
urls = self.main_wnd.getExplorerURLList(self.network())
except Exception:
return []
return [u for u in urls if u != 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
# rstrip avoids a double slash when the URL already ends with '/'
url = self.url.rstrip('/') + "/api/%s" % method
if param != "":
url += "/%s" % param
resp = requests.get(url, data={}, verify=True)
Expand All @@ -53,7 +72,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
15 changes: 15 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@
log_File = os.path.join(user_dir, 'debug.log')
database_File = os.path.join(user_dir, 'application.db')

# Default explorers (url). zkbitcoin acts as a mainnet fallback if the primary
# explorer fails. Defined here so DefaultCache can reference them.
DEFAULT_MAINNET_EXPLORER = "https://explorer.duddino.com/"
DEFAULT_TESTNET_EXPLORER = "https://testnet.duddino.com/"

DefaultCache = {
"lastAddress": "",
"window_width": starting_width,
"window_height": starting_height,
"splitter_x": 342,
"splitter_y": 133,
"console_hidden": False,
# Selected explorer is stored per network, keyed by URL (stable across
# reordering), so switching networks never remaps to a different server.
"selectedExplorer_mainnet": DEFAULT_MAINNET_EXPLORER,
"selectedExplorer_testnet": DEFAULT_TESTNET_EXPLORER,
"selectedHW_index": 0,
"selectedRPC_index": 0,
"isTestnetRPC": False,
Expand All @@ -52,6 +61,12 @@
["https", "latvia.fuzzbawls.pw:8080", "spmtUser", "8X88u7TuefPm7mQaJY52"],
["https", "charlotte.fuzzbawls.pw:8080", "spmtUser", "ZyD936tm9dvqmMP8A777"]]

# Default explorer rows (url, isTestnet, isCustom).
trusted_explorers = [
[DEFAULT_MAINNET_EXPLORER, False, False],
[DEFAULT_TESTNET_EXPLORER, True, False],
["https://zkbitcoin.com/", False, False]
]

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