code wiki / (root) / nx_ledger.nx

nx_ledger.nx

buildroot/runtime/nx_ledger.nx

15064 B352 linesdepth 0pulls 0 transitivereach 2 importersview sourcekind librarytopic ledger
docsdependenciesstructsconstsfunctions

about

nx_ledger.nx -- double-entry bookkeeping primitive (L13 foundational). module: nishi-core.finance.ledger depends: nishi-core.io.syscalls, nishi-core.io.iso8601 disk_kb: 7 capability: MARKETPLACE license_tier: PUBLIC_DOMAIN_FINANCE genealogy_id: pacioli_1494_summa_de_arithmetica_double_entry + ifrs_iasb_accounting_standards_2026 + nishi_cardinal_13_additive_only + nishi_pillar_4_bits_up_sovereign_payments The foundational double-entry-bookkeeping primitive that all L13 payment substrate composes against. Pacioli 1494 invariant: every transaction is a balanced (debit_sum == credit_sum) entry. Substrate enforces at the type-system layer. Per Cardinal 13 (additive-only): NO ledger entry is ever deleted or modified. Corrections are NEW entries that REVERSE earlier entries. The full transaction log is the truth. Per Pillar 4 sovereignty: NO Stripe / Plaid / QuickBooks / etc. Pure NishiLang ledger storing entries in additive log file. ===== Account-kind sealed enum =================================== Standard accounting taxonomy. Substrate enforces normal-balance direction (assets+expenses normally debit; liabilities+equity+ revenue normally credit).

dependencies 0 imports · 2 importers

nx_ledger.nx nx_balance.nx nx_escrow_hold.nx

imports: none

imported by: nx_balance.nxnx_escrow_hold.nx

structs

77struct LedgerAccount
129struct LedgerLine
143struct LedgerTransaction

consts

32const NX_LEDGER_ACCT_ASSET: i64 = 1 // debit normal
33const NX_LEDGER_ACCT_LIABILITY: i64 = 2 // credit normal
34const NX_LEDGER_ACCT_EQUITY: i64 = 3 // credit normal
35const NX_LEDGER_ACCT_REVENUE: i64 = 4 // credit normal
36const NX_LEDGER_ACCT_EXPENSE: i64 = 5 // debit normal
38const NX_LEDGER_ACCT_BUYER_ESCROW: i64 = 6 // liability (we hold buyer's funds)
39const NX_LEDGER_ACCT_SELLER_PAYABLE: i64 = 7 // liability (we owe seller)
40const NX_LEDGER_ACCT_PLATFORM_FEE_REV: i64 = 8 // revenue
41const NX_LEDGER_ACCT_TAX_PAYABLE: i64 = 9 // liability (we collect state sales tax)
42const NX_LEDGER_ACCT_REFUND_RESERVE: i64 = 10 // liability (dispute reserve)
90const NX_LEDGER_ACCOUNT_BYTES: i64 = 80 // 10 fields * 8 bytes
97const NX_CCY_USD: i64 = 840
98const NX_CCY_EUR: i64 = 978
99const NX_CCY_GBP: i64 = 826
100const NX_CCY_JPY: i64 = 392
101const NX_CCY_CAD: i64 = 124
102const NX_CCY_BTC: i64 = 999 // substrate-assigned (no ISO code)
103const NX_CCY_BTC_SATS: i64 = 998 // Bitcoin satoshis (sub-unit)
104const NX_CCY_LIGHTNING: i64 = 997 // Lightning Network msats
107const NX_CCY_NISHI_HOURS: i64 = 8001 // community-currency hours
108const NX_CCY_NISHI_SEEDS: i64 = 8002 // gift-economy seed units (catalog-indexed)
139const NX_LEDGER_LINE_BYTES: i64 = 56 // 7 fields * 8 bytes
161const NX_LEDGER_TRANSACTION_BYTES: i64 = 120 // 15 fields * 8 bytes
165const NX_JOURNAL_KIND_OPENING: i64 = 1 // initial balances
166const NX_JOURNAL_KIND_DEPOSIT: i64 = 2 // funds enter the platform
167const NX_JOURNAL_KIND_WITHDRAWAL: i64 = 3
168const NX_JOURNAL_KIND_SALE: i64 = 4 // buyer pays for marketplace listing
169const NX_JOURNAL_KIND_ESCROW_HOLD: i64 = 5
170const NX_JOURNAL_KIND_ESCROW_RELEASE: i64 = 6 // to seller
171const NX_JOURNAL_KIND_ESCROW_REFUND: i64 = 7 // back to buyer
172const NX_JOURNAL_KIND_PLATFORM_FEE: i64 = 8
173const NX_JOURNAL_KIND_SALES_TAX: i64 = 9
174const NX_JOURNAL_KIND_REVERSAL: i64 = 10
175const NX_JOURNAL_KIND_ADJUSTMENT: i64 = 11 // reconciliation
194const NX_LEDGER_OK: i64 = 1
195const NX_LEDGER_UNBALANCED: i64 = 2 // debit != credit (rejected)
196const NX_LEDGER_ACCOUNT_NOT_FOUND: i64 = 3
197const NX_LEDGER_CURRENCY_MISMATCH: i64 = 4 // mixing currencies in one tx
198const NX_LEDGER_AMOUNT_INVALID: i64 = 5
199const NX_LEDGER_REVERSAL_NOT_ALLOWED: i64 = 6 // already reversed or original
200const NX_LEDGER_INSUFFICIENT_BALANCE: i64 = 7 // for accounts with no-overdraft policy
201const NX_LEDGER_POST_FAIL: i64 = 8 // append-only-log write fail
298const NX_LEDGER_MAX_LINES_PER_QUERY: i64 = 1048576

functions

44func nx_ledger_acct_kind_name(k: i64) -> *u8
61func nx_ledger_acct_normal_is_debit(k: i64) -> i64
110func nx_ccy_code_name(c: i64) -> *u8
177func nx_journal_kind_name(k: i64) -> *u8
203func nx_ledger_verdict_name(v: i64) -> *u8
220func nx_ledger_check_balanced(
243func nx_ledger_post_transaction(
278func nx_ledger_post_reversal(
300func nx_ledger_account_balance_minor_q10(
331func nx_ledger_trial_balance_check(