B6: atomic UTXO reservation, bet signed by the worker and saved before broadcast, broadcast verdicts (BET-30..33)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2acd4ccd1c
commit
feff993584
25 files changed
+995
-53
No files matched your search
@@ -18,6 +18,7 @@ from .models import Deposit, DepositAddress, LotteryConfig, Movement, Transactio
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
WAITING = ("detected", "orphaned") # deposit statuses that are still being watched
|
||||
COINBASE_MATURITY = 120 # DEP-21: PLM coinbase maturity (palladiumcore consensus.h)
|
||||
|
||||
|
||||
@@ -75,14 +76,14 @@ def plan() -> Policy:
|
||||
addresses=tuple(DepositAddress.objects.order_by("derivation_index").values_list("address", flat=True)),
|
||||
own_txids=frozenset(TransactionVersion.objects.values_list("txid", flat=True)),
|
||||
deposit_confirmations=LotteryConfig.get().deposit_confirmations,
|
||||
credited=frozenset(Utxo.objects.filter(deposit__status=Deposit.Status.CREDITED).values_list("txid", "vout")),
|
||||
credited=frozenset(Utxo.objects.exclude(deposit__status__in=WAITING).values_list("txid", "vout")),
|
||||
waiting=_waiting_by_address(),
|
||||
)
|
||||
|
||||
|
||||
def _waiting_by_address() -> dict[str, frozenset[tuple[str, int]]]:
|
||||
grouped: dict[str, set[tuple[str, int]]] = {}
|
||||
rows = Utxo.objects.filter(deposit__status__in=[Deposit.Status.DETECTED, Deposit.Status.ORPHANED])
|
||||
rows = Utxo.objects.filter(deposit__status__in=WAITING)
|
||||
for address, txid, vout in rows.values_list("address", "txid", "vout"):
|
||||
grouped.setdefault(address, set()).add((txid, vout))
|
||||
return {address: frozenset(outpoints) for address, outpoints in grouped.items()}
|
||||
@@ -119,6 +120,13 @@ def apply_observations(result: ScanResult, policy: Policy, now: datetime | None
|
||||
|
||||
def _apply_entry(owner, entry: Seen, tip: int, policy: Policy, observation: Observation, now, done) -> None:
|
||||
outpoint = (entry.txid, entry.vout)
|
||||
if entry.txid in policy.own_txids:
|
||||
# The change of one of our own transactions is spendable money, not a deposit: it was already taken
|
||||
# from the player's balance when the transaction was placed (BET-30), so no movement is written.
|
||||
with transaction.atomic():
|
||||
Utxo.objects.get_or_create(txid=entry.txid, vout=entry.vout, defaults=dict(
|
||||
amount_sats=entry.value, address=owner.address, user=owner.user, confirmed_height=entry.height, created_at=now))
|
||||
return
|
||||
have = confirmations(tip, entry.height)
|
||||
need = threshold_for(entry.txid, policy, observation.coinbase)
|
||||
ready = have >= need and outpoint in observation.verified
|
||||
|
||||
Reference in new issue
Block a user