2026-07-27 15:27:58 +02:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
Give every round its own pool address (B-80, RND-35, DAT-60, DAT-11, REG-14, SEC-08, BET-12, RND-22, WDR-14, SEC-43, API-23, API-36)
2026-10-14 13:52:32 +02:00
|
|
|
from app.db.models import Round, User
|
|
|
|
|
from app.wallet.hd import derive_user_address
|
2026-07-27 15:27:58 +02:00
|
|
|
|
|
|
|
|
|
Give every round its own pool address (B-80, RND-35, DAT-60, DAT-11, REG-14, SEC-08, BET-12, RND-22, WDR-14, SEC-43, API-23, API-36)
2026-10-14 13:52:32 +02:00
|
|
|
async def own_address_for(
|
|
|
|
|
session: AsyncSession, kind: str, user_id: int | None, round_id: int | None = None
|
|
|
|
|
) -> str:
|
2026-07-27 15:27:58 +02:00
|
|
|
"""The address that owns every input of a PendingTransaction of this kind —
|
Give every round its own pool address (B-80, RND-35, DAT-60, DAT-11, REG-14, SEC-08, BET-12, RND-22, WDR-14, SEC-43, API-23, API-36)
2026-10-14 13:52:32 +02:00
|
|
|
a user's own address for a bet/withdrawal, the pool address of the round for a
|
|
|
|
|
payout (B-80: each round has its own, stored on the round).
|
2026-07-27 15:27:58 +02:00
|
|
|
All our builders only ever spend one address's UTXOs per tx (see
|
|
|
|
|
tx/broadcast.py:_signing_context, which derives the same address alongside
|
|
|
|
|
the signing key it also needs).
|
|
|
|
|
|
|
|
|
|
Shared by tx/confirmation.py and tx/reconcile.py (B-41): both now check
|
|
|
|
|
blockchain.scripthash.get_history for this address instead of asking
|
|
|
|
|
blockchain.transaction.get for a verbose reply, so the two can't derive
|
|
|
|
|
different addresses for the same row.
|
|
|
|
|
"""
|
|
|
|
|
if kind == "payout":
|
Give every round its own pool address (B-80, RND-35, DAT-60, DAT-11, REG-14, SEC-08, BET-12, RND-22, WDR-14, SEC-43, API-23, API-36)
2026-10-14 13:52:32 +02:00
|
|
|
round_ = await session.get(Round, round_id) if round_id is not None else None
|
|
|
|
|
if round_ is None or not round_.pool_address:
|
|
|
|
|
raise ValueError(f"payout of round {round_id}: the round has no pool address")
|
|
|
|
|
return round_.pool_address
|
2026-07-27 15:27:58 +02:00
|
|
|
user = await session.get(User, user_id)
|
|
|
|
|
return derive_user_address(user.derivation_index)
|