Flip status to "closing" the instant the round timer expires, rather than leaving it "open" (invisible) while in-flight bets confirm — /rounds/current now surfaces this wait as its own phase instead of collapsing it into "drawing". _tick() is updated to keep re-checking pending bets while status is "closing" instead of short-circuiting on the old "status != open" guard. Also re-stamp closed_at at actual payout confirmation time (not at the earlier "closing" transition), since round_cooldown_seconds counts from closed_at — with a short cooldown (e.g. 20s) and ~2 block-time draw+payout wait, the old anchor meant the cooldown had already elapsed by the time the round actually closed, making it a no-op. Expose draw_block_height/draw_block_hash on GET /rounds/current so clients can show which block the winner was drawn from.
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db.models import PendingTransaction, Round
|
|
from app.tx.confirmation import register_handler
|
|
|
|
|
|
async def _on_payout_confirmed(session: AsyncSession, pending: PendingTransaction) -> None:
|
|
round_ = await session.scalar(select(Round).where(Round.payout_txid == pending.current_txid))
|
|
if round_ is not None and round_.status == "paying_out":
|
|
round_.status = "closed"
|
|
# closed_at is what round_cooldown_seconds counts from (service.py's
|
|
# open_new_round_if_needed) — re-stamp it here at actual payout
|
|
# confirmation time rather than leaving it at the earlier "closing"
|
|
# timestamp, so a short cooldown (e.g. 20s) is a real pause after the
|
|
# winner's tx confirms, not swallowed by the ~2 block-time draw+payout wait.
|
|
round_.closed_at = datetime.now(timezone.utc)
|
|
# The winner's own address is already watched by the Electrum listener, so
|
|
# their balance is credited by the normal deposit path once this confirms.
|
|
|
|
|
|
register_handler("payout", _on_payout_confirmed)
|