code wiki / (root) / nx_offer_ledger_store.nx

nx_offer_ledger_store.nx source

↩ module page · 33 lines · 1288 B

1// nx_offer_ledger_store.nx -- durability for the outreach/offer ledger. 2// Mirrors nx_rights_ledger_store / nx_dms_catalog_store: snapshot the fixed 3// offer rows through nx_seg_store (append-only, rename-commit) so the 4// acquisition pipeline survives restart. Row count derived from value length. 5// license_tier: ORIGINAL 6 7import "nx_syscalls.nx" 8import "nx_offer_ledger.nx" 9import "nx_seg_store.nx" 10 11func nx_offer_save(l: *NxOfferLedger, prefix: *u8, segid: i64) -> i64 { 12 let w: *i64 = ss_begin() 13 let vbytes: i64 = (l.count as i64) * NX_OF_BYTES 14 ss_add(w, 1, "offers:snapshot" as *u8, (l.offers as i64) as *u8, vbytes) 15 return ss_commit(prefix, w, segid) 16} 17 18func nx_offer_load(prefix: *u8) -> *NxOfferLedger { 19 let h: *i64 = ss_open(prefix) 20 let ptrout: *i64 = sys_mmap(16) as *i64 21 let lenout: *i64 = sys_mmap(16) as *i64 22 let rc: i64 = ss_hget(h, "offers:snapshot" as *u8, ptrout, lenout) 23 if rc != 1 { return nx_offer_ledger_new(16) } 24 let blob: *u8 = ptrout[0] as *u8 25 let vbytes: i64 = lenout[0] 26 let n: nx_size = vbytes / NX_OF_BYTES 27 let l: *NxOfferLedger = nx_offer_ledger_new(n + 16) 28 let dst: *u8 = (l.offers as i64) as *u8 29 var i: i64 = 0 30 while i < vbytes { dst[i] = blob[i]; i = i + 1 } 31 l.count = n 32 return l 33}