灵符lingfu
L

ling-wallet

↓ 0 downloads

Ling Wallet: a post-quantum privacy-coin wallet, full node and HyperTorus miner for LNG

Windows · x86-64 ✕Linux · x86-64 ✕LingOS · x86-64LingOS · Pi 5 ARM64 ✕
Keywords wallet, cryptocurrency, lng, node, miner, ling
lingfu install ling-wallet
LicenseMIT
Authorsling-lin
READMECode / FilesVersionsDependency GraphDependentsSecurityBuildsSettings

Code / Files (116)

ling/ui/network.ling
# network.ling — NETWORK: chain stats, peers, node identity and the
# per-denomination supply audit.

fn network_draw(ax, ay, aw, ah) {
    bind n = d_net()
    if n == () { return () }
    bind tor = str_starts_with(str_lower(n.route), "tor")
    bind tw = floor((aw - 64) / 5)
    bind keys = ["Height", "Difficulty", "Mempool", "Route", "Seed list"]
    bind vals = [num_str(n.height), thousands(n.difficulty), num_str(n.mempool) + " tx", n.route, sel(n.seeds_verified, "Verified", "Unverified")]
    bind i = 0
    while i < 5 {
        bind x = ax + i * (tw + 16)
        bind col = C_TEXT_STRONG
        if i == 3 && tor { bind col = lift(C_VIOLET, 0.3) }
        if i == 4 { bind col = sel(n.seeds_verified, lift(C_GREEN, 0.2), C_RED) }
        fill(x, ay, tw, 84, C_PANEL)
        outline(x, ay, tw, 84, C_LINE_SOFT, 1)
        bind bc = C_INDIGO
        if i == 4 { bind bc = sel(n.seeds_verified, C_GREEN, C_RED) }
        brackets(x, ay, tw, 84, 6, bc, 1)
        label(x + 16, ay + 26, list_get(keys, i), C_TEXT_DIM)
        bind vx = x + 16
        if i == 3 {
            icon_draw("lock", vx, ay + 54, sel(tor, C_VIOLET, C_GREEN))
            bind vx = vx + 24
        }
        if i == 4 {
            icon_draw(sel(n.seeds_verified, "check", "warn"), vx, ay + 54, col)
            bind vx = vx + 24
        }
        bind f = sel(i < 3, F_MONO, F_UI)
        bind size = sel(i < 3, 30, 20)
        t_text(f, size, vx, ay + 62, t_fit(f, size, x + tw - vx - 12, list_get(vals, i)), col)
        bind i = i + 1
    }

    bind py = ay + 84 + 32
    bind ph = ah - 84 - 32
    bind lw = floor(aw * 56 / 100)
    bind inn = panel(ax, py, lw, ph, "PEERS", C_INDIGO)
    bind x = list_get(inn, 0)
    bind y = list_get(inn, 1)
    bind iw = list_get(inn, 2)
    t_right(F_UI, 15, x + iw, y - 2, num_str(len(n.peers)) + " connected", C_TEXT_FAINT)
    bind hy = y + 18
    label(x, hy, "Dir", C_TEXT_FAINT)
    label(x + 64, hy, "Peer · identity", C_TEXT_FAINT)
    label_r(x + iw, hy, "Uptime", C_TEXT_FAINT)
    hline(x, hy + 10, iw, C_LINE_SOFT, 1)
    bind lx = x - 4
    bind lty = hy + 14
    bind lww = iw + 8
    bind lhh = py + ph - lty - 120
    bind row_h = 60
    bind maxs = max(0, len(n.peers) * row_h - lhh)
    bind scroll = clampf(st_get("n_scroll", 0) + u_scroll_in(lx, lty, lww, lhh), 0, maxs)
    st_set("n_scroll", scroll)
    clip_push(lx, lty, lww, lhh)
    if len(n.peers) == 0 { t_center(F_UI, 17, lx, lty, lww, 60, "No peers yet.", C_TEXT_FAINT) }
    bind j = 0
    while j < len(n.peers) {
        bind p = list_get(n.peers, j)
        bind ry = lty + j * row_h - scroll
        if u_hover(lx, ry, lww, row_h) { fill(lx, ry, lww, row_h, C_ROW_HOVER) }
        hline(lx + 4, ry + row_h - 1, lww - 8, C_LINE_FAINT, 1)
        bind inbound = list_get(p, 1)
        badge(x, ry + 30, sel(inbound, "IN", "OUT"), sel(inbound, C_BLUE, C_ORANGE), false)
        bind aw2 = round(t_text(F_MONO, 22, x + 64, ry + 27, list_get(p, 0), C_TEXT_STRONG))
        if list_get(p, 3) { badge(x + 64 + aw2 + 12, ry + 21, "Seed · pinned", C_GREEN, true) }
        bind fp = list_get(p, 2)
        bind eph = fp == "ephemeral" || fp == ""
        t_text(F_MONO, 19, x + 64, ry + 47, sel(eph, "ephemeral identity (not tracked)", "id " + fp), sel(eph, C_TEXT_FAINT, C_TEXT_DIM))
        t_right(F_MONO, 22, x + iw, ry + 36, duration(list_get(p, 4)), C_TEXT_DIM)
        bind j = j + 1
    }
    clip_pop()

    bind ny = py + ph - 104
    hline(x, ny, iw, C_LINE_SOFT, 1)
    label(x, ny + 28, "This node", C_TEXT_DIM)
    icon_draw("shield", x, ny + 56, C_VIOLET)
    t_text(F_MONO, 26, x + 26, ny + 63, sel(n.node_fp == "", "-", n.node_fp), C_TEXT_STRONG)
    t_para(F_UI, 15, x + 260, ny + 18, iw - 260, 19, "The identity peers see for this node. Seed peers must present their pinned key.", C_TEXT_FAINT)

    bind inr = panel(ax + lw + 24, py, aw - lw - 24, ph, "SUPPLY AUDIT", C_INDIGO)
    audit_draw(list_get(inr, 0), list_get(inr, 1), list_get(inr, 2), list_get(inr, 3))
}

fn audit_draw(x, y0, w, h) {
    bind rows = st_get("d_audit", [])
    bind nbad = 0
    bind i = 0
    while i < len(rows) {
        bind r = list_get(rows, i)
        if list_get(r, 2) > list_get(r, 1) { bind nbad = nbad + 1 }
        bind i = i + 1
    }
    bind y = y0 + 4
    icon_draw(sel(nbad == 0, "check", "warn"), x, y + 8, sel(nbad == 0, C_GREEN, C_RED))
    t_text(F_UI, 17, x + 26, y + 14, sel(nbad == 0, "Every denomination within its supply.", "Anomaly: spends exceed outputs."), sel(nbad == 0, C_TEXT, C_RED))
    bind y = y + 40
    if len(rows) == 0 { t_text(F_UI, 15, x, y + 20, "No audit data yet.", C_TEXT_FAINT) }
    bind lw = 72
    bind k = 0
    while k < len(rows) {
        bind r = list_get(rows, k)
        bind outs = list_get(r, 1)
        bind kis = list_get(r, 2)
        bind over = kis > outs
        bind col = sel(over, C_RED, C_INDIGO)
        bind dw = round(t_text(F_MONO, 24, x, y + 22, format_lng(list_get(r, 0)), C_TEXT_STRONG))
        t_text(F_UI, 13, x + dw + 4, y + 21, "LNG", C_TEXT_FAINT)
        bind bx = x + lw
        bind bw = w - lw
        fill(bx, y + 6, bw, 18, C_BG_DEEP)
        outline(bx, y + 6, bw, 18, sel(over, C_RED, C_LINE_SOFT), 1)
        bind frac = 0
        if outs > 0 { bind frac = min(1, kis / outs) }
        if outs == 0 && kis > 0 { bind frac = 1 }
        bind fw = floor((bw - 4) * frac)
        fill_a(bx + 2, y + 8, fw, 14, col, 0.25)
        cross(bx + 2, y + 8, fw, 14, col, 3, 0.7)
        t_text(F_UI, 15, bx, y + 42, thousands(kis) + " spent / " + thousands(outs) + " created", sel(over, C_RED, C_TEXT_DIM))
        t_right(F_MONO, 20, bx + bw, y + 43, num_str(round(kis * 100 / max(1, outs))) + " %", sel(over, C_RED, C_TEXT))
        bind y = y + 62
        bind k = k + 1
    }
    bind note_y = y0 + h - 56
    if y < note_y {
        t_para(F_UI, 15, x, note_y, w, 19, "Blocks that would make spends exceed outputs for a denomination are rejected by consensus.", C_TEXT_FAINT)
    }
}

← Back to index