1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// The ledger contract.
//
// This module defines the shapes the ledger works with.
// Concrete implementations live in nanny-ledger.
//
// The same separation applies here as with the policy:
// nanny-core defines the contract
// nanny-ledger implements it
// nanny-core's executor uses the contract
//
// The ledger tracks one thing: how much has been spent.
// It does not know about pricing, currencies, or payment rails.
// It enforces: balance reaches zero → execution stops.
use Error;
// ── Receipt ───────────────────────────────────────────────────────────────────
/// Proof that a debit happened.
///
/// Emitted by the ledger on every successful debit.
/// Written into the event log as a CostDebited event.
/// The paper trail that makes every spend auditable.
// ── LedgerDecision ────────────────────────────────────────────────────────────
/// What the ledger says when asked if a spend is possible.
///
/// Used by the executor to build PolicyContext before each step.
/// The policy uses `cost_units_spent` to decide whether to allow or deny.
// ── LedgerError ───────────────────────────────────────────────────────────────
/// Errors that can occur during a debit operation.
///
/// A debit error means the executor attempted to spend more than available.
/// This should not happen if the policy is checking budget correctly —
/// but we handle it explicitly rather than panicking.
// ── Ledger trait ──────────────────────────────────────────────────────────────
/// The ledger contract.
///
/// Any type that implements this can track and enforce spending.
/// In local mode: FakeLedger — abstract units, no real money.
/// In managed mode: AP2-backed ledger — real currency, real settlement.
///
/// The implementation swaps. The contract never changes.