2026-07-21 10:26:25 +02:00
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
|
|
|
|
from app.db.models import PendingTransaction, Withdrawal
|
|
|
|
|
from app.tx.confirmation import register_handler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _on_withdrawal_confirmed(session: AsyncSession, pending: PendingTransaction) -> None:
|
|
|
|
|
if pending.withdrawal_id is None:
|
|
|
|
|
return
|
|
|
|
|
withdrawal = await session.get(Withdrawal, pending.withdrawal_id)
|
2026-07-27 00:31:24 +02:00
|
|
|
# "building" is reachable if we confirmed before the reconciler promoted the row
|
|
|
|
|
# (a crash between broadcast and commit — see app/tx/reconcile.py).
|
|
|
|
|
if withdrawal is not None and withdrawal.status in ("building", "broadcast"):
|
2026-07-21 10:26:25 +02:00
|
|
|
withdrawal.status = "confirmed"
|
|
|
|
|
withdrawal.confirmed_at = datetime.now(timezone.utc)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register_handler("withdrawal", _on_withdrawal_confirmed)
|