feat: Replace most prints with logger calls to help with debugging
All checks were successful
Tests and Linting / Tests-Linting (3.10) (push) Successful in 32s
Tests and Linting / Tests-Linting (3.13) (push) Successful in 32s
Tests and Linting / Tests-Linting (3.11) (push) Successful in 34s
Build Docker / Build Images (map[dockerfile:Dockerfile tag_suffix: target:default]) (push) Successful in 48s
Build Docker / Build Images (map[dockerfile:Dockerfile.hsd tag_suffix:-hsd target:hsd]) (push) Successful in 50s

This commit is contained in:
2025-09-10 17:14:32 +10:00
parent 63e0f0b804
commit 9f8daa8b88
2 changed files with 25 additions and 17 deletions

View File

@@ -352,6 +352,7 @@ def getBalance(account: str):
# Get the total balance # Get the total balance
info = hsw.getBalance('default', account) info = hsw.getBalance('default', account)
if 'error' in info: if 'error' in info:
logger.error(f"Error getting balance for account {account}: {info['error']}")
return {'available': 0, 'total': 0} return {'available': 0, 'total': 0}
total = info['confirmed'] total = info['confirmed']
@@ -361,6 +362,7 @@ def getBalance(account: str):
# Convert to HNS # Convert to HNS
total = total / 1000000 total = total / 1000000
available = available / 1000000 available = available / 1000000
logger.debug(f"Initial balance for account {account}: total={total}, available={available}, locked={locked}")
domains = getDomains(account) domains = getDomains(account)
domainValue = 0 domainValue = 0
@@ -404,6 +406,7 @@ def getBalance(account: str):
if domain_info.get('info', {}).get('state', "") == "CLOSED": if domain_info.get('info', {}).get('state', "") == "CLOSED":
domainValue += domain_info.get('info', {}).get('value', 0) domainValue += domain_info.get('info', {}).get('value', 0)
except json.JSONDecodeError: except json.JSONDecodeError:
logger.warning(f"Error parsing cached data for domain {domain_name}")
# Only add for update if not already being updated # Only add for update if not already being updated
with DOMAIN_UPDATE_LOCK: with DOMAIN_UPDATE_LOCK:
if domain_name not in ACTIVE_DOMAIN_UPDATES: if domain_name not in ACTIVE_DOMAIN_UPDATES:
@@ -426,6 +429,7 @@ def getBalance(account: str):
total = total - (domainValue/1000000) total = total - (domainValue/1000000)
locked = locked - (domainValue/1000000) locked = locked - (domainValue/1000000)
logger.debug(f"Adjusted balance for account {account}: total={total}, available={available}, locked={locked}")
# Only keep 2 decimal places # Only keep 2 decimal places
total = round(total, 2) total = round(total, 2)

34
main.py
View File

@@ -43,6 +43,12 @@ formatter = logging.Formatter('[%(asctime)s] %(levelname)s in %(module)s: %(mess
handler.setFormatter(formatter) handler.setFormatter(formatter)
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.WARNING) logger.setLevel(logging.WARNING)
# Disable werkzeug logging
logging.getLogger('werkzeug').setLevel(logging.INFO)
logging.getLogger("urllib3").setLevel(logging.ERROR)
logging.getLogger("requests").setLevel(logging.ERROR)
logger.addHandler(handler) logger.addHandler(handler)
@app.route('/') @app.route('/')
@@ -71,7 +77,7 @@ def index():
branch = info['refs'] branch = info['refs']
commit = info['commit'] commit = info['commit']
if commit != latestVersion(branch): if commit != latestVersion(branch):
print("New version available",flush=True) logger.info("New version available")
plugins += render_template('components/dashboard-alert.html', name='Update', output='A new version of FireWallet is available') plugins += render_template('components/dashboard-alert.html', name='Update', output='A new version of FireWallet is available')
alerts = get_alerts(account) alerts = get_alerts(account)
@@ -602,7 +608,7 @@ def finalize(domain: str):
domain = domain.lower() domain = domain.lower()
response = account_module.finalize(request.cookies.get("account"),domain) response = account_module.finalize(request.cookies.get("account"),domain)
if response['error'] is not None: if response['error'] is not None:
print(response) logger.error(f"Error finalizing transfer for {domain}: {response['error']}")
return redirect("/manage/" + domain + "?error=" + response['error']['message']) return redirect("/manage/" + domain + "?error=" + response['error']['message'])
return redirect("/success?tx=" + response['result']['hash']) return redirect("/success?tx=" + response['result']['hash'])
@@ -621,7 +627,7 @@ def cancelTransfer(domain: str):
response = account_module.cancelTransfer(request.cookies.get("account"),domain) response = account_module.cancelTransfer(request.cookies.get("account"),domain)
if 'error' in response: if 'error' in response:
if response['error'] is not None: if response['error'] is not None:
print(response) logger.error(f"Error canceling transfer for {domain}: {response['error']}")
return redirect("/manage/" + domain + "?error=" + response['error']['message']) return redirect("/manage/" + domain + "?error=" + response['error']['message'])
return redirect("/success?tx=" + response['result']['hash']) return redirect("/success?tx=" + response['result']['hash'])
@@ -677,7 +683,7 @@ def revokeConfirm(domain: str):
response = account_module.revoke(request.cookies.get("account"),domain) response = account_module.revoke(request.cookies.get("account"),domain)
if 'error' in response: if 'error' in response:
if response['error'] is not None: if response['error'] is not None:
print(response) logger.error(f"Error revoking {domain}: {response['error']}")
return redirect("/manage/" + domain + "?error=" + response['error']['message']) return redirect("/manage/" + domain + "?error=" + response['error']['message'])
return redirect(f"/success?tx={response['hash']}") return redirect(f"/success?tx={response['hash']}")
@@ -783,7 +789,7 @@ def editSave(domain: str):
dns = urllib.parse.unquote(dns) dns = urllib.parse.unquote(dns)
response = account_module.setDNS(request.cookies.get("account"),domain,dns) response = account_module.setDNS(request.cookies.get("account"),domain,dns)
if 'error' in response: if 'error' in response:
print(response) logger.error(f"Error setting DNS for {domain}: {response['error']}")
return redirect(f"/manage/{domain}/edit?dns={raw_dns}&error={response['error']}") return redirect(f"/manage/{domain}/edit?dns={raw_dns}&error={response['error']}")
return redirect(f"/success?tx={response['hash']}") return redirect(f"/success?tx={response['hash']}")
@@ -929,13 +935,11 @@ def auction(domain):
if state == 'CLOSED': if state == 'CLOSED':
if not domainInfo['info']['registered']: if not domainInfo['info']['registered']:
if account_module.isOwnDomain(account,domain): if account_module.isOwnDomain(account,domain):
print("Waiting to be registered")
state = 'PENDING REGISTER' state = 'PENDING REGISTER'
next = "Pending Register" next = "Pending Register"
next_action = f'<a href="/auction/{domain}/register">Register Domain</a>' next_action = f'<a href="/auction/{domain}/register">Register Domain</a>'
else: else:
print("Not registered")
state = 'AVAILABLE' state = 'AVAILABLE'
next = "Available Now" next = "Available Now"
next_action = f'<a href="/auction/{domain}/open">Open Auction</a>' next_action = f'<a href="/auction/{domain}/open">Open Auction</a>'
@@ -1500,7 +1504,7 @@ def plugin(ptype,plugin):
plugin = f"{ptype}/{plugin}" plugin = f"{ptype}/{plugin}"
if not plugins_module.pluginExists(plugin): if not plugins_module.pluginExists(plugin):
print(f"Plugin {plugin} not found") logger.warning(f"Plugin not found: {plugin}")
return redirect("/plugins") return redirect("/plugins")
data = plugins_module.getPluginData(plugin) data = plugins_module.getPluginData(plugin)
@@ -1635,13 +1639,11 @@ def api_hsd(function):
if state == 'CLOSED': if state == 'CLOSED':
if not domainInfo['info']['registered']: if not domainInfo['info']['registered']:
if account_module.isOwnDomain(account,domain): if account_module.isOwnDomain(account,domain):
print("Waiting to be registered")
state = 'PENDING REGISTER' state = 'PENDING REGISTER'
next = "Pending Register" next = "Pending Register"
next_action = f'<a href="/auction/{domain}/register">Register Domain</a>' next_action = f'<a href="/auction/{domain}/register">Register Domain</a>'
else: else:
print("Not registered")
state = 'AVAILABLE' state = 'AVAILABLE'
next = "Available Now" next = "Available Now"
next_action = f'<a href="/auction/{domain}/open">Open Auction</a>' next_action = f'<a href="/auction/{domain}/open">Open Auction</a>'
@@ -1934,7 +1936,6 @@ def get_alerts(account:str) -> list:
"name": "Wallet", "name": "Wallet",
"output": f"The wallet is not synced ({wallet_status}). Please wait for it to sync." "output": f"The wallet is not synced ({wallet_status}). Please wait for it to sync."
}) })
print(account)
# Try to read from notifications sqlite database # Try to read from notifications sqlite database
if os.path.exists("user_data/notifications.db"): if os.path.exists("user_data/notifications.db"):
try: try:
@@ -1950,7 +1951,7 @@ def get_alerts(account:str) -> list:
}) })
conn.close() conn.close()
except Exception as e: except Exception as e:
print(f"Error reading notifications: {e}",flush=True) logger.error(f"Error reading notifications: {e}")
pass pass
return alerts return alerts
@@ -1977,7 +1978,7 @@ def add_alert(name:str,output:str,account:str="all"):
conn.commit() conn.commit()
conn.close() conn.close()
except Exception as e: except Exception as e:
print(f"Error adding notification: {e}",flush=True) logger.error(f"Error adding notification: {e}")
pass pass
def dismiss_alert(alert_id:int,account:str="all"): def dismiss_alert(alert_id:int,account:str="all"):
@@ -1997,7 +1998,7 @@ def dismiss_alert(alert_id:int,account:str="all"):
conn.commit() conn.commit()
conn.close() conn.close()
except Exception as e: except Exception as e:
print(f"Error dismissing notification: {e}",flush=True) logger.error(f"Error dismissing notification: {e}")
pass pass
@app.route('/dismiss/<int:alert_id>') @app.route('/dismiss/<int:alert_id>')
@@ -2072,16 +2073,19 @@ if __name__ == '__main__':
port = int(sys.argv[port_index]) port = int(sys.argv[port_index])
except ValueError: except ValueError:
pass pass
print(f"Starting FireWallet on http://{host}:{port}",flush=True)
# Print logs to console if --debug is set
if "--debug" in sys.argv: if "--debug" in sys.argv:
console_handler = logging.StreamHandler(sys.stdout) console_handler = logging.StreamHandler(sys.stdout)
# Use a simple format for console # Use a simple format for console
console_formatter = logging.Formatter('%(message)s') console_formatter = logging.Formatter('%(message)s')
console_handler.setFormatter(console_formatter) console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.WARNING)
logger.addHandler(console_handler) logger.addHandler(console_handler)
logger.setLevel(logging.DEBUG)
app.run(debug=True, host=host, port=port) app.run(debug=True, host=host, port=port)
else: else:
app.run(host=host, port=port) app.run(host=host, port=port)
def tests(): def tests():