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 ...@@ -6,6 +6,7 @@ Each crypto type has its own encrypted master seed, from which user addresses
are deterministically derived. are deterministically derived.
""" """
import logging import logging
import traceback
from mnemonic import Mnemonic from mnemonic import Mnemonic
from bip32 import BIP32 from bip32 import BIP32
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
...@@ -195,16 +196,21 @@ class CryptoWalletManager: ...@@ -195,16 +196,21 @@ class CryptoWalletManager:
pass pass
if attempt == 4: if attempt == 4:
raise 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: with self.db._get_connection() as conn:
cursor = conn.cursor() cursor = conn.cursor()
insert_or_ignore = "INSERT OR IGNORE" if self.db.db_type == 'sqlite' else "INSERT" if self.db.db_type == 'sqlite':
on_conflict = "" if self.db.db_type == 'sqlite' else " ON CONFLICT DO NOTHING" 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""" cursor.execute(f"""
{insert_or_ignore} INTO user_crypto_wallets INSERT IGNORE INTO user_crypto_wallets
(user_id, crypto_type, balance_crypto, balance_fiat) (user_id, crypto_type, balance_crypto, balance_fiat)
VALUES ({placeholder}, {placeholder}, 0, 0){on_conflict} VALUES ({placeholder}, {placeholder}, 0, 0)
""", (user_id, crypto_type)) """, (user_id, crypto_type))
conn.commit() conn.commit()
......
...@@ -8330,7 +8330,8 @@ async def dashboard_wallet_topup(request: Request): ...@@ -8330,7 +8330,8 @@ async def dashboard_wallet_topup(request: Request):
try: try:
address = await ps.wallet_manager.get_or_create_user_address(user_id, crypto_type) address = await ps.wallet_manager.get_or_create_user_address(user_id, crypto_type)
except Exception as e: 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({"error": "Could not generate deposit address"}, status_code=503)
return JSONResponse({ return JSONResponse({
"type": "crypto", "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