Add withdrawal flow
Builds and broadcasts a user->external-address PSBT with change back to the user's own address, fee deducted from the withdrawn amount, and registers the confirmation handler that marks the withdrawal confirmed. Shares the per-user lock with bets so a build never races a spend from the same UTXO set. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5ce49d7b88
commit
8380b80d12
5 files changed
+251
No files matched your search
@@ -0,0 +1,18 @@
|
||||
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)
|
||||
if withdrawal is not None and withdrawal.status == "broadcast":
|
||||
withdrawal.status = "confirmed"
|
||||
withdrawal.confirmed_at = datetime.now(timezone.utc)
|
||||
|
||||
|
||||
register_handler("withdrawal", _on_withdrawal_confirmed)
|
||||
Reference in new issue
Block a user