Add draw_animation_seconds config and expose winner info during a round
RoundConfig gains draw_animation_seconds (default 20) — the minimum time the frontend's "estrazione in corso" animation plays before revealing a winner. It's purely a UI cue: the real draw still waits for a confirmed block for its entropy (rounds/scheduler.py), which usually takes much longer than this value, so it only ever extends the animation, never truncates the real wait. GET /rounds/current now also returns draw_animation_seconds, winner_user_id and winner_amount_sats (all populated once the scheduler sets them on the round, i.e. from "paying_out" onward) so a client can determine and reveal the outcome. GET /users/me now returns the user's own id, needed client-side to compare against winner_user_id. Admin config CRUD refactored to a shared field tuple (_CONFIG_FIELDS) instead of repeating the same 7-then-8 field list three times. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+16
-18
@@ -20,6 +20,18 @@ async def require_admin(x_admin_token: str = Header(default="")) -> None:
|
||||
raise HTTPException(status.HTTP_403_FORBIDDEN, "invalid admin token")
|
||||
|
||||
|
||||
_CONFIG_FIELDS = (
|
||||
"fee_address",
|
||||
"bet_amount_sats",
|
||||
"round_duration_seconds",
|
||||
"round_cooldown_seconds",
|
||||
"min_amount_sats",
|
||||
"fee_rate_sat_vb",
|
||||
"rbf_timeout_seconds",
|
||||
"draw_animation_seconds",
|
||||
)
|
||||
|
||||
|
||||
class RoundConfigResponse(BaseModel):
|
||||
fee_address: str
|
||||
bet_amount_sats: int
|
||||
@@ -28,6 +40,7 @@ class RoundConfigResponse(BaseModel):
|
||||
min_amount_sats: int
|
||||
fee_rate_sat_vb: int
|
||||
rbf_timeout_seconds: int
|
||||
draw_animation_seconds: int
|
||||
|
||||
|
||||
class RoundConfigUpdate(BaseModel):
|
||||
@@ -38,18 +51,11 @@ class RoundConfigUpdate(BaseModel):
|
||||
min_amount_sats: int | None = None
|
||||
fee_rate_sat_vb: int | None = None
|
||||
rbf_timeout_seconds: int | None = None
|
||||
draw_animation_seconds: int | None = None
|
||||
|
||||
|
||||
def _config_response(config) -> RoundConfigResponse:
|
||||
return RoundConfigResponse(
|
||||
fee_address=config.fee_address,
|
||||
bet_amount_sats=config.bet_amount_sats,
|
||||
round_duration_seconds=config.round_duration_seconds,
|
||||
round_cooldown_seconds=config.round_cooldown_seconds,
|
||||
min_amount_sats=config.min_amount_sats,
|
||||
fee_rate_sat_vb=config.fee_rate_sat_vb,
|
||||
rbf_timeout_seconds=config.rbf_timeout_seconds,
|
||||
)
|
||||
return RoundConfigResponse(**{field: getattr(config, field) for field in _CONFIG_FIELDS})
|
||||
|
||||
|
||||
@router.get("/config", response_model=RoundConfigResponse, dependencies=[Depends(require_admin)])
|
||||
@@ -64,15 +70,7 @@ async def update_config(
|
||||
body: RoundConfigUpdate, session: AsyncSession = Depends(get_session)
|
||||
) -> RoundConfigResponse:
|
||||
config = await get_round_config(session)
|
||||
for field in (
|
||||
"fee_address",
|
||||
"bet_amount_sats",
|
||||
"round_duration_seconds",
|
||||
"round_cooldown_seconds",
|
||||
"min_amount_sats",
|
||||
"fee_rate_sat_vb",
|
||||
"rbf_timeout_seconds",
|
||||
):
|
||||
for field in _CONFIG_FIELDS:
|
||||
value = getattr(body, field)
|
||||
if value is not None:
|
||||
setattr(config, field, value)
|
||||
|
||||
@@ -21,6 +21,9 @@ class CurrentRoundResponse(BaseModel):
|
||||
participant_count: int = 0
|
||||
bet_amount_sats: int
|
||||
jackpot_sats: int = 0
|
||||
draw_animation_seconds: int
|
||||
winner_user_id: int | None = None
|
||||
winner_amount_sats: int | None = None
|
||||
|
||||
|
||||
@router.get("/current", response_model=CurrentRoundResponse)
|
||||
@@ -29,7 +32,9 @@ async def current_round(session: AsyncSession = Depends(get_session)) -> Current
|
||||
round_ = await get_active_round(session)
|
||||
if round_ is None:
|
||||
await session.commit()
|
||||
return CurrentRoundResponse(bet_amount_sats=config.bet_amount_sats)
|
||||
return CurrentRoundResponse(
|
||||
bet_amount_sats=config.bet_amount_sats, draw_animation_seconds=config.draw_animation_seconds
|
||||
)
|
||||
|
||||
participant_count = await session.scalar(
|
||||
select(func.count()).select_from(RoundParticipant).where(RoundParticipant.round_id == round_.id)
|
||||
@@ -46,4 +51,7 @@ async def current_round(session: AsyncSession = Depends(get_session)) -> Current
|
||||
participant_count=participant_count,
|
||||
bet_amount_sats=config.bet_amount_sats,
|
||||
jackpot_sats=participant_count * config.bet_amount_sats,
|
||||
draw_animation_seconds=config.draw_animation_seconds,
|
||||
winner_user_id=round_.winner_user_id,
|
||||
winner_amount_sats=round_.winner_amount_sats,
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ router = APIRouter(prefix="/users", tags=["users"])
|
||||
|
||||
|
||||
class MeResponse(BaseModel):
|
||||
id: int
|
||||
username: str
|
||||
address: str
|
||||
balance_sats: int
|
||||
@@ -15,4 +16,6 @@ class MeResponse(BaseModel):
|
||||
|
||||
@router.get("/me", response_model=MeResponse)
|
||||
async def me(user: User = Depends(get_current_user)) -> MeResponse:
|
||||
return MeResponse(username=user.username, address=user.address, balance_sats=user.cached_balance_sats)
|
||||
return MeResponse(
|
||||
id=user.id, username=user.username, address=user.address, balance_sats=user.cached_balance_sats
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user