code wiki / _hdl_build / nx_seedlib_gate.nx

nx_seedlib_gate.nx source

↩ module page · 117 lines · 8102 B

1// nx_seedlib_gate.nx -- GATE: the capability is REAL (it gates a real feature). T1 a gardener WITHOUT the 2// host_seed_library capability is REFUSED node creation (the reward is enforced, not cosmetic). T2 the HOLDER 3// (earned it via rewards) CAN create a node. T3 stock the library. T4 borrow (can't take more than available). 4// T5 return MORE than taken (the seed-library ethic) -- additive loan ledger, net positive. T6 node page ships. 5// license_tier: ORIGINAL 6import "nx_seedlib.nx" 7import "nx_rewards.nx" 8import "nx_publisher.nx" 9import "nx_seg_store.nx" 10import "nx_syscalls.nx" 11import "nx_gate_verdict.nx" 12 13const LG_SEED: *u8 = "knowledge/store/seedlib-" 14const LG_REWARD: *u8 = "knowledge/store/slrw-reward-" 15const LG_STAGE_FILE: *u8 = "knowledge/staging/seedlib/node.html" 16const LG_LIVE_FILE: *u8 = "knowledge/publish/seedlib-live/node.html" 17 18func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 19func g_i(v: i64) -> i64 { 20 let bb: *u8 = sys_mmap(28); var m: i64 = v 21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 22 let t: *u8 = sys_mmap(28); var k: i64 = 0 23 if m == 0 { t[0] = 48 as u8; k = 1 } 24 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 25 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 26} 27func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 28 29func main() -> i64 { 30 g_p("=== nx_seedlib_gate (the capability is real: it gates a real feature) ===\n" as *u8) 31 32 // Alice EARNS the host_seed_library capability (via a real reward); Bob does not. 33 rw_def_achievement(LG_REWARD, "swap_master" as *u8, "Swap Master" as *u8, "swap" as *u8, "CAPABILITY" as *u8, 0, "host_seed_library" as *u8, "completed a swap set" as *u8) 34 rw_grant(LG_REWARD, "alice" as *u8, "swap_master" as *u8, 100) 35 36 var pass: i64 = 0 37 var tot: i64 = 0 38 39 // T1 capability ENFORCED: Bob (no capability) is REFUSED 40 let bobtry: i64 = sl_create_node(LG_SEED, LG_REWARD, "bobnode" as *u8, "bob" as *u8, "Bob's Library" as *u8, "TX-Austin" as *u8, 101) 41 g_p("bob (no cap) create -> " as *u8); g_i(bobtry); g_p(" exists=" as *u8); g_i(sl_node_exists(LG_SEED, "bobnode" as *u8)); g_p("\n" as *u8) 42 tot = tot + 1 43 if bobtry == 0 { if sl_node_exists(LG_SEED, "bobnode" as *u8) == 0 { pass = pass + 1; g_p("PASS T1 capability ENFORCED: without host_seed_library, creating a node is REFUSED (reward is real)\n" as *u8) } else { g_p("FAIL T1 node created\n" as *u8) } } else { g_p("FAIL T1 not refused\n" as *u8) } 44 45 // T2 the holder CAN create 46 let alicetry: i64 = sl_create_node(LG_SEED, LG_REWARD, "atxnode" as *u8, "alice" as *u8, "Austin Seed Library" as *u8, "TX-Austin" as *u8, 102) 47 let host: *u8 = sys_mmap(48); sl_node_str(LG_SEED, "atxnode" as *u8, 0, host) 48 g_p("alice (has cap) create -> " as *u8); g_i(alicetry); g_p(" host=" as *u8); g_p(host); g_p("\n" as *u8) 49 tot = tot + 1 50 if alicetry == 1 { if fd_streq(host, "alice" as *u8) == 1 { pass = pass + 1; g_p("PASS T2 the capability-holder CAN run a node (Alice hosts the Austin Seed Library)\n" as *u8) } else { g_p("FAIL T2 host\n" as *u8) } } else { g_p("FAIL T2 create\n" as *u8) } 51 52 // T3 stock the library 53 sl_contribute(LG_SEED, "atxnode" as *u8, "basil" as *u8, 50) 54 sl_contribute(LG_SEED, "atxnode" as *u8, "tomato" as *u8, 30) 55 g_p("stock basil=" as *u8); g_i(sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8)); g_p(" tomato=" as *u8); g_i(sl_stock(LG_SEED, "atxnode" as *u8, "tomato" as *u8)); g_p("\n" as *u8) 56 tot = tot + 1 57 if sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8) == 50 { if sl_stock(LG_SEED, "atxnode" as *u8, "tomato" as *u8) == 30 { pass = pass + 1; g_p("PASS T3 library stocked (basil 50, tomato 30)\n" as *u8) } else { g_p("FAIL T3 tomato\n" as *u8) } } else { g_p("FAIL T3 basil\n" as *u8) } 58 59 // T4 borrow; can't take more than available 60 let took: i64 = sl_take(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8, 5, 103) 61 let overreach: i64 = sl_take(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8, 1000, 103) 62 let after: i64 = sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8) 63 g_p("bob took 5 -> " as *u8); g_i(took); g_p("; took 1000 -> " as *u8); g_i(overreach); g_p("; basil now=" as *u8); g_i(after); g_p("\n" as *u8) 64 tot = tot + 1 65 var ok4: i64 = 1 66 if took != 1 { ok4 = 0 } 67 if overreach != 0 { ok4 = 0 } // can't take what isn't there 68 if after != 45 { ok4 = 0 } // 50 - 5, the failed take changed nothing 69 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 borrow works; over-borrow refused (basil 50->45, the 1000 attempt left stock untouched)\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 70 71 // T5 return MORE than taken (the ethic); additive ledger 72 sl_return(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8, 12, 200) 73 let net: i64 = sl_member_net(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8) 74 let stockf: i64 = sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8) 75 let loans: i64 = sl_loann(LG_SEED, "atxnode" as *u8) 76 let firstq: i64 = sl_loan_int(LG_SEED, "atxnode" as *u8, 0, 2) // first loan (the take of 5) still intact 77 g_p("after return 12: net=" as *u8); g_i(net); g_p(" stock=" as *u8); g_i(stockf); g_p(" loans=" as *u8); g_i(loans); g_p(" first-loan-qty=" as *u8); g_i(firstq); g_p("\n" as *u8) 78 tot = tot + 1 79 var ok5: i64 = 1 80 if net != 7 { ok5 = 0 } // returned 12 - took 5 = +7 to the commons 81 if stockf != 57 { ok5 = 0 } // 45 + 12 82 if loans != 2 { ok5 = 0 } // take + return logged; the failed over-borrow was NOT logged 83 if firstq != 5 { ok5 = 0 } // additive: the original take record is intact 84 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 returned MORE than taken (+7 to the commons); additive ledger intact\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 85 86 // T6 node page renders + ships 87 let page: *u8 = sys_mmap(65536) 88 let np: i64 = sl_render_node(LG_SEED, "atxnode" as *u8, page) 89 g_p("node page = " as *u8); g_i(np); g_p(" bytes\n" as *u8) 90 tot = tot + 1 91 var ok6: i64 = 1 92 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } 93 if as_contains(page, np, "Austin Seed Library" as *u8) != 1 { ok6 = 0 } 94 if as_contains(page, np, "basil" as *u8) != 1 { ok6 = 0 } 95 if as_contains(page, np, "return more than you took" as *u8) != 1 { ok6 = 0 } 96 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 97 sys_mkdir("knowledge/staging/seedlib" as *u8, 0x1ed) 98 let sfd: i64 = sys_openat_wr(LG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 99 pub_init() 100 sys_mkdir("knowledge/publish/seedlib-stage" as *u8, 0x1ed) 101 sys_mkdir("knowledge/publish/seedlib-live" as *u8, 0x1ed) 102 pub_submit_to("knowledge/publish/seedlib-queue.tsv" as *u8, LG_STAGE_FILE, "node.html" as *u8, "nishifoodfamily" as *u8, "nishi-seedlib" as *u8, "internal" as *u8) 103 pub_run_full("knowledge/publish/seedlib-queue.tsv" as *u8, "knowledge/publish/seedlib-ledger.tsv" as *u8, "knowledge/publish/seedlib-stage" as *u8, "knowledge/publish/seedlib-live" as *u8, "publish:seedlib" as *u8) 104 if g_exists(LG_LIVE_FILE) != 1 { ok6 = 0 } 105 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 seed-library node page renders sovereign + ships\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 106 107 g_p("nx_seedlib_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 108 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 109 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 110 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 111 let ctr__dry: *i64 = gv_ctr() 112 ctr__dry[0] = pass 113 ctr__dry[1] = tot 114 let rc__dry: i64 = gv_verdict("SEEDLIB-GATE" as *u8, ctr__dry, "the earned capability runs a real seed-library node; borrow, grow, return more)" as *u8) 115 sys_exit(rc__dry) 116 return rc__dry 117}