Skip to main content

Module finance

Module finance 

Source
Expand description

Single source of truth for record envelopes, double-entry finance, and cooperative projects. Personal and cooperative double-entry finance ledger — signed, replay-safe entries with derived balances, integer banker’s rounding, and multi-book journal envelopes.

Implements the master plan’s money-safety rules (§5 SyncService, §17 risk table): ledger and journal entries merge add-wins by stable entry id and never by raw sum, and balances are a pure derivation over the unique-id set, so duplicate, reordered, or replayed sync operations can never duplicate money.

Structs§

BalanceReport
Derived balance across all currencies present in the ledger.
CurrencyBalance
Net position and entry count for a single currency.
JournalEntryRecord
An immutable double-entry journal entry record assigned to a LedgerBook.
JournalLine
A single double-entry journal line denominated in integer minor units (cents).
LedgerEntry
A single immutable ledger entry. Amount is signed minor units (cents): positive = credit/income, negative = debit/expense. Entries are never mutated; a correction is a new entry, so the id is a stable content anchor for dedup.

Enums§

LedgerBook
Canonical ledger books across personal, cooperative project, and finite compensation accounting.

Functions§

build_ledger_entry_envelope
Builds ledger-entry-envelope.
derived_balance
Derive the balance purely from the unique-id set. Duplicate ids in the input are collapsed first, so the result is invariant under duplication/reordering.
div_round_bankers
Integer division with round-half-to-even (banker’s rounding) for minor-unit (i64) and basis-point (i128) monetary arithmetic. Zero heap allocation, zero float math.
ledger_entry_record_id
ledger-entry-record ID.
ledger_entry_summary
Lossless JSON summary of a LedgerEntry for journal storage and sync.
ledger_summary
Alias for ledger_entry_summary.
merge_journal_entries
Replay-safe, order-independent union of double-entry JournalEntryRecords by stable id. Unbalanced entries are rejected so corrupted frames cannot poison the ledger.
merge_ledger
Merge two ledger sets add-wins by stable entry id (never sum-merge), returning a deterministically ordered union.
parse_ledger_entry_summary
Reconstruct a full LedgerEntry from a summary JSON string (preserving counterparty, project_id, category, description, and occurred_at_instant losslessly).
parse_ledger_summary
Parse a ledger summary JSON back into a full LedgerEntry.