nx_ledger.nx
buildroot/runtime/nx_ledger.nx
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
imports: none
imported by: nx_balance.nxnx_escrow_hold.nx
structs
| 77 | struct LedgerAccount |
| 129 | struct LedgerLine |
| 143 | struct LedgerTransaction |
consts
| 32 | const NX_LEDGER_ACCT_ASSET: i64 = 1 // debit normal |
| 33 | const NX_LEDGER_ACCT_LIABILITY: i64 = 2 // credit normal |
| 34 | const NX_LEDGER_ACCT_EQUITY: i64 = 3 // credit normal |
| 35 | const NX_LEDGER_ACCT_REVENUE: i64 = 4 // credit normal |
| 36 | const NX_LEDGER_ACCT_EXPENSE: i64 = 5 // debit normal |
| 38 | const NX_LEDGER_ACCT_BUYER_ESCROW: i64 = 6 // liability (we hold buyer's funds) |
| 39 | const NX_LEDGER_ACCT_SELLER_PAYABLE: i64 = 7 // liability (we owe seller) |
| 40 | const NX_LEDGER_ACCT_PLATFORM_FEE_REV: i64 = 8 // revenue |
| 41 | const NX_LEDGER_ACCT_TAX_PAYABLE: i64 = 9 // liability (we collect state sales tax) |
| 42 | const NX_LEDGER_ACCT_REFUND_RESERVE: i64 = 10 // liability (dispute reserve) |
| 90 | const NX_LEDGER_ACCOUNT_BYTES: i64 = 80 // 10 fields * 8 bytes |
| 97 | const NX_CCY_USD: i64 = 840 |
| 98 | const NX_CCY_EUR: i64 = 978 |
| 99 | const NX_CCY_GBP: i64 = 826 |
| 100 | const NX_CCY_JPY: i64 = 392 |
| 101 | const NX_CCY_CAD: i64 = 124 |
| 102 | const NX_CCY_BTC: i64 = 999 // substrate-assigned (no ISO code) |
| 103 | const NX_CCY_BTC_SATS: i64 = 998 // Bitcoin satoshis (sub-unit) |
| 104 | const NX_CCY_LIGHTNING: i64 = 997 // Lightning Network msats |
| 107 | const NX_CCY_NISHI_HOURS: i64 = 8001 // community-currency hours |
| 108 | const NX_CCY_NISHI_SEEDS: i64 = 8002 // gift-economy seed units (catalog-indexed) |
| 139 | const NX_LEDGER_LINE_BYTES: i64 = 56 // 7 fields * 8 bytes |
| 161 | const NX_LEDGER_TRANSACTION_BYTES: i64 = 120 // 15 fields * 8 bytes |
| 165 | const NX_JOURNAL_KIND_OPENING: i64 = 1 // initial balances |
| 166 | const NX_JOURNAL_KIND_DEPOSIT: i64 = 2 // funds enter the platform |
| 167 | const NX_JOURNAL_KIND_WITHDRAWAL: i64 = 3 |
| 168 | const NX_JOURNAL_KIND_SALE: i64 = 4 // buyer pays for marketplace listing |
| 169 | const NX_JOURNAL_KIND_ESCROW_HOLD: i64 = 5 |
| 170 | const NX_JOURNAL_KIND_ESCROW_RELEASE: i64 = 6 // to seller |
| 171 | const NX_JOURNAL_KIND_ESCROW_REFUND: i64 = 7 // back to buyer |
| 172 | const NX_JOURNAL_KIND_PLATFORM_FEE: i64 = 8 |
| 173 | const NX_JOURNAL_KIND_SALES_TAX: i64 = 9 |
| 174 | const NX_JOURNAL_KIND_REVERSAL: i64 = 10 |
| 175 | const NX_JOURNAL_KIND_ADJUSTMENT: i64 = 11 // reconciliation |
| 194 | const NX_LEDGER_OK: i64 = 1 |
| 195 | const NX_LEDGER_UNBALANCED: i64 = 2 // debit != credit (rejected) |
| 196 | const NX_LEDGER_ACCOUNT_NOT_FOUND: i64 = 3 |
| 197 | const NX_LEDGER_CURRENCY_MISMATCH: i64 = 4 // mixing currencies in one tx |
| 198 | const NX_LEDGER_AMOUNT_INVALID: i64 = 5 |
| 199 | const NX_LEDGER_REVERSAL_NOT_ALLOWED: i64 = 6 // already reversed or original |
| 200 | const NX_LEDGER_INSUFFICIENT_BALANCE: i64 = 7 // for accounts with no-overdraft policy |
| 201 | const NX_LEDGER_POST_FAIL: i64 = 8 // append-only-log write fail |
| 298 | const NX_LEDGER_MAX_LINES_PER_QUERY: i64 = 1048576 |
functions
| 44 | func nx_ledger_acct_kind_name(k: i64) -> *u8 |
| 61 | func nx_ledger_acct_normal_is_debit(k: i64) -> i64 |
| 110 | func nx_ccy_code_name(c: i64) -> *u8 |
| 177 | func nx_journal_kind_name(k: i64) -> *u8 |
| 203 | func nx_ledger_verdict_name(v: i64) -> *u8 |
| 220 | func nx_ledger_check_balanced( called by 1: nx_ledger_post_transaction |
| 243 | func nx_ledger_post_transaction( calls 1: nx_ledger_check_balanced |
| 278 | func nx_ledger_post_reversal( |
| 300 | func nx_ledger_account_balance_minor_q10( called by 1: nx_balance_reconcile |
| 331 | func nx_ledger_trial_balance_check( |