All 10 build-order stages complete and unit-tested (49 tests). Verified live on mainnet: registration/address derivation, deposit crediting, a real 10 PLM bet (broadcast + confirmed + change credited). A full round close->draw->payout cycle was triggered live and was in progress at commit time. Withdrawal and RBF bump are unit-tested but not yet exercised against a live broadcast. Known gaps (scheduler doesn't resume mid-flight rounds after restart, payout has no retry, no deployment setup, etc.) are documented in CLAUDE.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
23 lines
798 B
Python
23 lines
798 B
Python
import asyncio
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
class UserLocks:
|
|
"""Per-user asyncio.Lock registry, shared by PLAY and WITHDRAW so a user can
|
|
never have a bet-build and a withdrawal-build in flight at once (both would
|
|
otherwise spend from the same UTXO set on the user's dedicated address).
|
|
|
|
Single-process-only by design (an in-memory dict of asyncio.Lock) — this is an
|
|
accepted MVP constraint; a multi-process deployment would need a DB or Redis
|
|
lock instead (e.g. a Postgres advisory lock).
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
self._locks: dict[int, asyncio.Lock] = {}
|
|
|
|
@asynccontextmanager
|
|
async def acquire(self, user_id: int):
|
|
lock = self._locks.setdefault(user_id, asyncio.Lock())
|
|
async with lock:
|
|
yield
|