Fix crypto wallet: correct MySQL INSERT IGNORE syntax, improve error logging

- Replace invalid 'ON CONFLICT DO NOTHING' (PostgreSQL) with 'INSERT IGNORE' (MySQL)
  for user_crypto_wallets upsert
- Use repr() and full traceback in exception logging so blank-message exceptions
  are still diagnosable
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 17f5a500
......@@ -6,6 +6,7 @@ Each crypto type has its own encrypted master seed, from which user addresses
are deterministically derived.
"""
import logging
import traceback
from mnemonic import Mnemonic
from bip32 import BIP32
from cryptography.fernet import Fernet
......@@ -195,16 +196,21 @@ class CryptoWalletManager:
pass
if attempt == 4:
raise
logger.warning(f"crypto address derivation conflict (attempt {attempt+1}): {exc}")
logger.warning(f"crypto address derivation conflict (attempt {attempt+1}): {exc!r}\n{traceback.format_exc()}")
with self.db._get_connection() as conn:
cursor = conn.cursor()
insert_or_ignore = "INSERT OR IGNORE" if self.db.db_type == 'sqlite' else "INSERT"
on_conflict = "" if self.db.db_type == 'sqlite' else " ON CONFLICT DO NOTHING"
if self.db.db_type == 'sqlite':
cursor.execute(f"""
INSERT OR IGNORE INTO user_crypto_wallets
(user_id, crypto_type, balance_crypto, balance_fiat)
VALUES ({placeholder}, {placeholder}, 0, 0)
""", (user_id, crypto_type))
else:
cursor.execute(f"""
{insert_or_ignore} INTO user_crypto_wallets
INSERT IGNORE INTO user_crypto_wallets
(user_id, crypto_type, balance_crypto, balance_fiat)
VALUES ({placeholder}, {placeholder}, 0, 0){on_conflict}
VALUES ({placeholder}, {placeholder}, 0, 0)
""", (user_id, crypto_type))
conn.commit()
......
......@@ -8330,7 +8330,8 @@ async def dashboard_wallet_topup(request: Request):
try:
address = await ps.wallet_manager.get_or_create_user_address(user_id, crypto_type)
except Exception as e:
logger.error(f"Crypto address generation error: {e}")
import traceback as _tb
logger.error(f"Crypto address generation error: {e!r}\n{_tb.format_exc()}")
return JSONResponse({"error": "Could not generate deposit address"}, status_code=503)
return JSONResponse({
"type": "crypto",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment