pub struct LedgerStore { /* private fields */ }Expand description
F-046’s optional local ledger: appends/reads/garbage-collects redacted LedgerRecord
metadata at a JSONL file path (see the module doc for the .db-named-but-JSONL decision).
Implementations§
Source§impl LedgerStore
impl LedgerStore
pub fn new(path: impl Into<PathBuf>) -> Self
Sourcepub fn default_path() -> PathBuf
pub fn default_path() -> PathBuf
$XDG_DATA_HOME/tokenfold/ledger.db, falling back to
<home>/.local/share/tokenfold/ledger.db — mirrors
retrieval_store::default_store_path’s HOME/USERPROFILE fallback.
pub fn path(&self) -> &Path
pub fn append(&self, record: &LedgerRecord) -> Result<(), TokenFoldError>
Sourcepub fn read_all(&self) -> Result<Vec<LedgerRecord>, TokenFoldError>
pub fn read_all(&self) -> Result<Vec<LedgerRecord>, TokenFoldError>
Reads every well-formed record. A line that fails to parse (e.g. a partial write left by a crash mid-append) is skipped rather than failing the whole read. A missing file reads as an empty ledger, not an error (an analytics-enabled run before any record exists yet is the common case, not a failure).
Sourcepub fn gc(&self, retention_days: u64) -> Result<LedgerGcOutcome, TokenFoldError>
pub fn gc(&self, retention_days: u64) -> Result<LedgerGcOutcome, TokenFoldError>
Rewrites the ledger file keeping only records whose timestamp is within
retention_days of now; records with an unparsable timestamp are kept (fail safe rather
than silently discarding data this can’t confidently date). Survivors keep their original
relative order — nothing about a kept record is touched or reordered.