This commit is contained in:
2026-08-24 08:11:59 -07:00
commit 53df0eed10
275 changed files with 133056 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
class Ledger:
def __init__(self) -> None:
self._balances: dict[str, int] = {}
self._applied: set[str] = set()
def balance(self, account: str) -> int:
return self._balances.get(account, 0)
def apply(self, operation_id: str, account: str, delta: int) -> int:
if operation_id in self._applied:
return self.balance(account)
self._applied.add(operation_id)
updated = self.balance(account) + delta
if updated < 0:
raise ValueError("insufficient funds")
self._balances[account] = updated
return updated