code wiki / (root) / nx_fin_fund_research_fetch.nx

nx_fin_fund_research_fetch.nx source

↩ module page · 86 lines · 5984 B

1// nx_fin_fund_research_fetch.nx -- the Nishi RESEARCHER's sovereign fetch for AFFORDABLE / ALTERNATIVE / 2// INTERNATIONAL FUNDING + the RISK side (operator: the US system isn't offering an affordable rate -- find 3// real cheaper funding AND don't get scammed). Grounds nx_fin_finance (R7 financing-cost optimizer + scam 4// shield). Mirrors nx_fin_research_fetch (own TLS-1.3, Mozilla CA, idempotent have-skip, 100% sovereign). 5// Three legs: AFFORDABLE-DOMESTIC (credit unions / CDFIs / counseling / DMP / balance transfer / P2P), 6// INTERNATIONAL/ALTERNATIVE (microfinance / DFIs / remittance / FX risk / interest-free Islamic finance), 7// and RISK/PROTECTION (predatory lending / ADVANCE-FEE fraud / loan sharks / usury / payday / TILA) -- the 8// "international affordable loan" cold-offer space is mostly advance-fee fraud, so the danger side is core 9// research, not an afterthought. -> knowledge/fetched/fund_*.raw. expect_exit: 0 license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_x509_trust_store.nx" 12import "nx_trust_store_load_from_certdata.nx" 13import "nx_https_fetch_follow.nx" 14const K_MAGIC_4194304: i64 = 4194304 15const K_MAGIC_8388608: i64 = 8388608 16 17func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 18func ff_putn(v: i64) -> i64 { 19 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 20 var m: i64 = v 21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 22 let d: *u8 = sys_mmap(24); var k: i64 = 0 23 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 var j: i64 = k - 1 25 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 26 return 0 27} 28func have_file(path: *u8) -> i64 { 29 let fd: i64 = sys_openat_rd(path) 30 if fd < 0 { return 0 } 31 sys_close(fd) 32 return 1 33} 34func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 35 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n"); return 1 } 36 let status: *i64 = sys_mmap(8) as *i64 37 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 38 ff_puts(url); ff_puts(" status="); ff_putn(status[0]); ff_puts(" bytes="); ff_putn(n) 39 if n <= 0 { ff_puts(" FETCH-FAIL\n"); return 0 } 40 var gz: i64 = 0 41 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 42 if gz == 1 { ff_puts(" [GZIP-skip]\n"); return 0 } 43 let fd: i64 = sys_openat_wr(opath, 0x1a4) 44 if fd < 0 { ff_puts(" SAVE-FAIL\n"); return 0 } 45 sys_write(fd, out, n) 46 sys_close(fd) 47 ff_puts(" SAVED\n") 48 return 1 49} 50 51func main() -> i64 { 52 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 53 if r <= 0 { ff_puts("FUND: certdata load failed\n"); return 1 } 54 let store: *TrustStore = r as *TrustStore 55 ff_puts("CA roots="); ff_putn(trust_store_count(store)); ff_puts("\n") 56 let cap: i64 = K_MAGIC_8388608 57 let out: *u8 = sys_mmap(cap) 58 var ok: i64 = 0 59 60 ff_puts("== AFFORDABLE / ALTERNATIVE DOMESTIC ==\n") 61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Credit_union" as *u8, "knowledge/fetched/fund_aff_creditunion.raw" as *u8, store, out, cap) 62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Community_development_financial_institution" as *u8, "knowledge/fetched/fund_aff_cdfi.raw" as *u8, store, out, cap) 63 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Credit_counseling" as *u8, "knowledge/fetched/fund_aff_counseling.raw" as *u8, store, out, cap) 64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Debt_management_plan" as *u8, "knowledge/fetched/fund_aff_dmp.raw" as *u8, store, out, cap) 65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Balance_transfer" as *u8, "knowledge/fetched/fund_aff_baltransfer.raw" as *u8, store, out, cap) 66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Peer-to-peer_lending" as *u8, "knowledge/fetched/fund_aff_p2p.raw" as *u8, store, out, cap) 67 68 ff_puts("== INTERNATIONAL / ALTERNATIVE-INTEREST ==\n") 69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Microfinance" as *u8, "knowledge/fetched/fund_intl_microfinance.raw" as *u8, store, out, cap) 70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Microcredit" as *u8, "knowledge/fetched/fund_intl_microcredit.raw" as *u8, store, out, cap) 71 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Development_finance_institution" as *u8, "knowledge/fetched/fund_intl_dfi.raw" as *u8, store, out, cap) 72 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Remittance" as *u8, "knowledge/fetched/fund_intl_remittance.raw" as *u8, store, out, cap) 73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Foreign_exchange_risk" as *u8, "knowledge/fetched/fund_intl_fxrisk.raw" as *u8, store, out, cap) 74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Islamic_banking_and_finance" as *u8, "knowledge/fetched/fund_intl_islamic.raw" as *u8, store, out, cap) 75 76 ff_puts("== RISK / PROTECTION (the scam shield) ==\n") 77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Predatory_lending" as *u8, "knowledge/fetched/fund_risk_predatory.raw" as *u8, store, out, cap) 78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Advance-fee_scam" as *u8, "knowledge/fetched/fund_risk_advancefee.raw" as *u8, store, out, cap) 79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Loan_shark" as *u8, "knowledge/fetched/fund_risk_loanshark.raw" as *u8, store, out, cap) 80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Usury" as *u8, "knowledge/fetched/fund_risk_usury.raw" as *u8, store, out, cap) 81 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Payday_loan" as *u8, "knowledge/fetched/fund_risk_payday.raw" as *u8, store, out, cap) 82 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Truth_in_Lending_Act" as *u8, "knowledge/fetched/fund_risk_tila.raw" as *u8, store, out, cap) 83 84 ff_puts("FUND RESEARCH SAVED THIS PASS+HAVE: "); ff_putn(ok); ff_puts(" / 18\n") 85 return 0 86}