Files
plm-lottery/apps/lottery/errors.py
T
davideandClaude Sonnet 5.5 eded058dbb A3: simulated ledger with idempotency (WEB-22, WEB-23, ADR-59, ARC-75..77, DAT-80)
One Ledger interface (deposit, bet, confirm, reject, exclude, payout) with a
simulated implementation chosen by LEDGER_BACKEND, refused on mainnet. Every
operation is a single write-locked transaction with its audit row; the same
request key is the same operation, a key reused for something else is an
error. The server validates round, deadline, the round's own quota, limits and
funds. The balance is derived from the ledger. Tests include six processes
racing on one SQLite file; the idempotency tests were checked to fail when
the replay is removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 13:23:29 +01:00

19 lines
628 B
Python

"""Domain errors with a stable code (the contract of the old API, `app/api/errors.py`).
`code` is what a page maps to its own text; `message` is plain English for logs and tests;
`params` carries the values to place in the text (amounts as `*_sats`).
"""
from typing import Any
class LedgerError(Exception):
def __init__(self, code: str, message: str, **params: Any) -> None:
super().__init__(message)
self.code = code
self.message = message
self.params = params
def as_dict(self) -> dict[str, Any]:
return {"code": self.code, "message": self.message, "params": self.params}