code wiki / _hdl_build / nx_fin_member.nx
nx_fin_member.nx source
↩ module page · 43 lines · 3354 B
1// nx_fin_member.nx -- NISHI FINANCE joins the team: registers the `finance` DOMAIN into THE NISHI BUILDER
2// (the one universal self-growing builder, alongside ad/web/game), plus a `member` card for Nishi Finance
3// itself. Every entry is sovereign-safe DATA (nb_template_safe: no <script, no external src=). Idempotent
4// (nb_register skips already-known rows) and FAIL-CLOSED at the boundary (#12): a template that fails the
5// sovereignty check is REFUSED, never written. This is how a new capability-member is banked into the
6// builder so the builder can emit finance UIs the same way it emits ad/web/game. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
9import "nx_nishi_builder.nx"
10
11func m_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
13// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
15// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
16func m_putn(v: i64) -> i64 { nxi_out(v); return 0 }
17// register one entry, FAIL-CLOSED on sovereignty. returns nb_register's result, or -9 if refused.
18func m_reg(path: *u8, kind: *u8, id: *u8, label: *u8, tpl: *u8) -> i64 {
19 if nb_template_safe(tpl) == 0 {
20 m_puts(" REFUSED (unsafe template) "); m_puts(id); m_puts("\n"); return 0 - 9
21 }
22 let r: i64 = nb_register(path, "finance\x00" as *u8, kind, id, label, tpl)
23 m_puts(" nb_register finance/"); m_puts(kind); m_puts("/"); m_puts(id); m_puts(" -> "); m_putn(r); m_puts("\n")
24 return r
25}
26
27func main() -> i64 {
28 let path: *u8 = NB_PATH
29 m_puts("=== NISHI FINANCE -> THE NISHI BUILDER: register the finance domain (idempotent, fail-closed) ===\n")
30 m_reg(path, "member\x00" as *u8, "nishi-finance\x00" as *u8, "Nishi Finance (team member)\x00" as *u8,
31 "<section class=\"member fin\"><h2>Nishi Finance</h2><p>Sovereign no-float money engine, append-only double-entry ledger, exact debt & amortization. Built the Nishi way: build, gate, measure, bank.</p></section>\x00" as *u8)
32 m_reg(path, "dashboard\x00" as *u8, "main\x00" as *u8, "Finance Dashboard\x00" as *u8,
33 "<section class=\"fin-dash\"><h2>Your money, hardware rung up</h2><p class=\"muted\">Exact cents. Behind the OPAQUE wall. Zero JavaScript.</p></section>\x00" as *u8)
34 m_reg(path, "debt-plan\x00" as *u8, "avalanche-snowball\x00" as *u8, "Debt Payoff Plan\x00" as *u8,
35 "<table class=\"debt\"><thead><tr><th>Strategy</th><th>Months</th><th>Interest</th></tr></thead><tbody></tbody></table>\x00" as *u8)
36 m_reg(path, "ledger\x00" as *u8, "net-worth\x00" as *u8, "Net Worth (double-entry view)\x00" as *u8,
37 "<div class=\"networth\"><span class=\"label\">Net worth</span><span class=\"value\"></span></div>\x00" as *u8)
38 let total: i64 = nb_count(path, "finance\x00" as *u8, "*\x00" as *u8)
39 m_puts("finance domain entries in the builder catalog="); m_putn(total); m_puts("\n")
40 if total >= 4 { m_puts("NISHI FINANCE: registered into the builder\n"); return 0 }
41 m_puts("NISHI FINANCE: registration incomplete\n")
42 return 1
43}