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
//! Store binding for IOU envelopes.
//!
//! A small abstraction over the durable store that persists IOU
//! envelopes minted by [`CreditEvaluatorHook`].
//! The binding lives in `chio-credit` so the trait surface stays
//! economic-crate-owned: the SQLite implementation lives in
//! `chio-store-sqlite::iou_store`.
//!
//! The binding is deliberately narrow: it does not expose query or
//! lifecycle methods, only the idempotent insert and a single
//! lookup keyed by `receipt_id`. A richer lifecycle surface can be
//! layered on top.
use Error;
use crateIouEnvelope;
/// Errors surfaced by an [`IouEnvelopeStore`] implementation.
///
/// Implementations should map their underlying transport / driver
/// errors into this enum so consumers in `chio-credit` can pattern
/// match without taking a hard dep on a specific store crate.
/// Persistence surface for [`IouEnvelope`] values.
///
/// Implementations MUST:
///
/// - Treat insertion as idempotent on `receipt_id`. Re-inserting the
/// same envelope (byte-equivalent body) returns `Ok(false)`. A
/// first insertion returns `Ok(true)`.
/// - Reject insertion with [`IouEnvelopeStoreError::Conflict`] if a
/// different envelope is already persisted for the same
/// `receipt_id`. Receipt finalization is append-only and the IOU
/// is bound to it; mismatching IOUs MUST NOT silently overwrite.
///
/// Lookup returns the previously-inserted envelope for the receipt
/// when one exists.