Places the fixed-cost bet into the current round: builds and broadcasts the user->pool PSBT with change back to the user's own address, enforces at most one active bet per user, and registers the confirmation handler that marks a bet confirmed and adds the participant to the round. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
20 lines
677 B
Python
20 lines
677 B
Python
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db.models import PendingTransaction, RoundParticipant
|
|
from app.tx.confirmation import register_handler
|
|
|
|
|
|
async def _on_bet_confirmed(session: AsyncSession, pending: PendingTransaction) -> None:
|
|
participant = await session.scalar(
|
|
select(RoundParticipant).where(RoundParticipant.bet_txid == pending.current_txid)
|
|
)
|
|
if participant is not None and participant.status == "broadcast":
|
|
participant.status = "confirmed"
|
|
participant.confirmed_at = datetime.now(timezone.utc)
|
|
|
|
|
|
register_handler("bet", _on_bet_confirmed)
|