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>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.auth.dependencies import get_current_user
|
|
from app.bets.service import BetError, place_bet
|
|
from app.db.models import User
|
|
from app.db.session import get_session
|
|
|
|
router = APIRouter(prefix="/bets", tags=["bets"])
|
|
|
|
|
|
class BetResponse(BaseModel):
|
|
round_id: int
|
|
bet_txid: str
|
|
bet_amount_sats: int
|
|
status: str
|
|
|
|
|
|
@router.post("", response_model=BetResponse, status_code=status.HTTP_201_CREATED)
|
|
async def create_bet(
|
|
request: Request,
|
|
user: User = Depends(get_current_user),
|
|
session: AsyncSession = Depends(get_session),
|
|
) -> BetResponse:
|
|
listener = request.app.state.electrum_listener
|
|
if listener.client is None:
|
|
raise HTTPException(status.HTTP_503_SERVICE_UNAVAILABLE, "not connected to the network, try again shortly")
|
|
|
|
async with request.app.state.user_locks.acquire(user.id):
|
|
try:
|
|
participant = await place_bet(session, listener.client, user)
|
|
except BetError as exc:
|
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, str(exc)) from exc
|
|
|
|
return BetResponse(
|
|
round_id=participant.round_id,
|
|
bet_txid=participant.bet_txid,
|
|
bet_amount_sats=participant.bet_amount_sats,
|
|
status=participant.status,
|
|
)
|