info = { type = "app", title = "Lightning", author = "BRRRO", license = "MIT", desc = "Network capacity, nodes and channels", category = "btc", api = 43, } txt = { own = "Own mempool server", own_h = "e.g. http://umbrel.local:3006 - only with the mempool.space source", plate = "Backing under the numbers", plate_h = "on = a dark backing under the numbers (network view)", nodata = "NO DATA", nodes = "NODES", chans = "CHANNELS", d30 = " 30D", src = "Source", src_h = "mempool.space statistics are often out of date", view = "View", view_o = { "network", "network in a strip", "world map" }, loading = "LOADING", nowifi = "NO WIFI", offline = "OFFLINE", console = "SEE CONSOLE" } for k, v in pairs(({ sk = { own = "Vlastný mempool server", own_h = "napr. http://umbrel.local:3006 - len pri zdroji mempool.space", plate = "Podklad pod číslami", plate_h = "zapnutý = tmavý podklad pod číslami (zobrazenie sieť)", nodata = "BEZ DAT", nodes = "UZLY", chans = "KANALY", d30 = " 30 DNI", src = "Zdroj", src_h = "štatistika mempool.space býva neaktuálna", view = "Zobrazenie", view_o = { "sieť", "sieť v páse", "mapa sveta" }, loading = "NACITAVAM", nowifi = "BEZ WIFI", console = "POZRI KONZOLU" }, cs = { own = "Vlastní mempool server", own_h = "např. http://umbrel.local:3006 - jen u zdroje mempool.space", plate = "Podklad pod čísly", plate_h = "zapnutý = tmavý podklad pod čísly (zobrazení síť)", nodata = "BEZ DAT", nodes = "UZLY", chans = "KANALY", d30 = " 30 DNI", src = "Zdroj", src_h = "statistika mempool.space bývá neaktuální", view = "Zobrazení", view_o = { "síť", "síť v pruhu", "mapa světa" }, loading = "NACITAM", nowifi = "BEZ WIFI", console = "VIZ KONZOLI" }, })[lang] or {}) do txt[k] = v end sources = { ml = { url = "https://1ml.com", limit = 300, fields = { "numberofnodes", "numberofchannels", "networkcapacity", "networkcapacity30dchange", "tornodes", "publicipnodes" }, demo = [[{"numberofnodes":5923,"numberofchannels":19508,"networkcapacity":244910182975, "networkcapacity30dchange":1.42,"tornodes":2824,"publicipnodes":4591}]] }, ln = { url = "https://mempool.space", limit = 60, own = "node", fields = { "latest.channel_count", "latest.node_count", "latest.total_capacity", "latest.tor_nodes", "latest.clearnet_nodes", "previous.total_capacity" }, demo = [[{"latest":{"node_count":12483,"channel_count":48211, "total_capacity":486312000000,"tor_nodes":8121,"clearnet_nodes":4362}, "previous":{"total_capacity":485340000000}}]] }, } settings = { { key = "src", type = "int", default = "1ml", label = txt.src, hint = txt.src_h, opts = { keys = { "1ml", "mempool" }, "1ML", "mempool.space" } }, { key = "node", type = "server", label = txt.own, hint = txt.own_h }, { key = "view", type = "int", default = "full", label = txt.view, opts = { keys = { "full", "strip", "map" }, table.unpack(txt.view_o) } }, { key = "plate", type = "bool", default = false, label = txt.plate, hint = txt.plate_h }, } local W, H = gfx.W, gfx.H local blend, rect, clear = gfx.blend, gfx.rect, gfx.clear local text, text_center, text_width, text_ink = gfx.text, gfx.text_center, gfx.text_width, gfx.text_ink local CAP_S = gfx.font("3x5").cap local F_SMALL = { font = "3x5" } local snapshot, blit_rgb = gfx.snapshot, gfx.blit_rgb local floor, sin, cos, asin, fmod, abs, sqrt = math.floor, math.sin, math.cos, math.asin, math.fmod, math.abs, math.sqrt local hash32, umod, max, min = math.hash32, math.umod, math.max, math.min local fmt = string.format local FPS = gfx.FPS local PI, TAU = math.pi, math.pi * 2 local function lround(v) if v >= 0 then return floor(v + 0.5) else return -floor(-v + 0.5) end end local NODATA_Y = 28 local BG = { 0, 0, 0 } local TITLE_C = { 255, 205, 80 } local CAP_C = { 245, 248, 255 } local UNIT_C = { 150, 165, 205 } local UP_C = { 120, 225, 150 } local DOWN_C = { 240, 130, 115 } local CNT_C = { 200, 215, 245 } local LBL_C = { 125, 140, 180 } local NODATA_C= { 190, 200, 215 } local NET_C = { 110, 175, 255 } local TOR_C = { 185, 120, 255 } local NET_HUB = { 175, 210, 255 } local TOR_HUB = { 220, 180, 255 } local PULSE_C = { 255, 225, 120 } local WAVE_C = { 255, 245, 210 } local LAND_C = { { 44, 104, 66 }, { 72, 66, 96 }, { 30, 40, 92 } } local COLS = { { nx = 2, ny = 46, nw = 29, na = "center", lx = 2, ly = 55, lw = 29, la = "center" }, { nx = 33, ny = 46, nw = 29, na = "center", lx = 33, ly = 55, lw = 31, la = "center" }, } local LAYOUT = { full = { title = 0, cap = 26, trend = 40, gate = 28, cells = COLS, split = { 0, 62, W }, my = 0, mh = H, plate = 45, link = { 40, 50, 96 }, n_inside = 14, pays = 16, nodes = { { 16, 18, true }, { 46, 14, true }, { 3, 12 }, { 21, 9 }, { 5, 27 }, { 29, 26 }, { 35, 9 }, { 60, 11 }, { 61, 23 }, { 52, 31 }, { 9, 44 }, { 60, 42 }, { 30, 58 }, { 6, 60 }, { -8, 21 }, { 72, 31 }, { 1, -8 }, { 45, 71 }, { -7, 53 }, { 70, 4 }, }, tor = { 3, 9, 1, 12, 6, 2, 7, 11, 4, 8, 5, 10, 13, 14 }, links = { { 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 1, 6 }, { 1, 11 }, { 2, 6 }, { 2, 7 }, { 2, 8 }, { 2, 9 }, { 2, 10 }, { 3, 4 }, { 7, 8 }, { 9, 10 }, { 5, 11 }, { 10, 12 }, { 11, 14 }, { 13, 14 }, { 12, 13 }, { 3, 15 }, { 5, 15 }, { 9, 16 }, { 12, 16 }, { 3, 17 }, { 13, 18 }, { 11, 19 }, { 8, 20 }, } }, strip = { title = 0, cap = 8, trend = 21, gate = 18, cells = { { nx = 0, ny = 27, nw = 30, na = "right", lx = 32, ly = 29, lw = 32, la = "left" }, { nx = 0, ny = 42, nw = 30, na = "right", lx = 32, ly = 44, lw = 32, la = "left" }, }, split = { 0, 37, W }, my = 50, mh = H - 50, link = { 30, 70, 220 }, n_inside = 8, pays = 9, nodes = { { 17, 55, true }, { 45, 53, true }, { 5, 51 }, { 29, 51 }, { 21, 62 }, { 37, 62 }, { 57, 61 }, { 60, 51 }, { -9, 60 }, { 73, 57 }, { 30, 72 }, { -8, 49 }, { 69, 63 }, }, tor = { 3, 6, 1, 8, 4, 7, 2, 5 }, links = { { 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 1, 9 }, { 2, 4 }, { 2, 6 }, { 2, 7 }, { 2, 8 }, { 2, 10 }, { 3, 5 }, { 4, 6 }, { 6, 11 }, { 7, 8 }, { 3, 12 }, { 7, 13 }, } }, map = { cap = 26, trend = 40, gate = 28, cells = COLS, bolt = true, globe = true, split = { 0, 62, W }, my = 0, mh = 25, plate = 45, n_inside = 19, pays = 10, nodes = { { 18, 6, true }, { 33, 4, true }, { 10, 6 }, { 13, 6 }, { 16, 11 }, { 18, 13 }, { 23, 18 }, { 21, 20 }, { 30, 6 }, { 38, 3 }, { 32, 12 }, { 38, 14 }, { 36, 19 }, { 41, 9 }, { 45, 10 }, { 50, 13 }, { 52, 9 }, { 55, 7 }, { 58, 20 }, }, tor = { 9, 3, 14, 6, 17, 11, 2, 19, 5, 15, 8, 12, 1, 16, 4, 18, 7, 13, 10 }, links = { { 1, 2 }, { 1, 4 }, { 3, 4 }, { 1, 5 }, { 5, 6 }, { 6, 7 }, { 7, 8 }, { 1, 9 }, { 9, 2 }, { 2, 10 }, { 9, 11 }, { 11, 13 }, { 12, 13 }, { 12, 14 }, { 2, 14 }, { 14, 15 }, { 15, 16 }, { 16, 17 }, { 17, 18 }, { 18, 3 }, { 16, 19 }, { 19, 3 }, { 7, 13 }, { 10, 17 }, } }, } local MAP_LAT0, MAP_LAT1 = 72, -56 local MAP = { "...#################..######.......###...#######################", "..###############.###..##...#.....##############################", "...##..#########..###............##.#########################...", ".........########.####.........#.########################...#...", "..........############.........##########################.......", "..........##########...........######..#################........", "..........#########...........##...####################.........", "...........#######............####....################.#........", "............###..#............########################..........", ".............##..............##############.#########...........", "..............###............#############...##..##.............", "................#............############....#...##.............", "..................####........###########.......................", "..................#####..........#######.........##.#...........", "..................#######.........#####...........#.##..#.......", "..................########........#####..................#......", "..................#######.........#####................#........", "...................######.........#####.#.............####......", "...................######.........####..#...........#######.....", "...................####............###..............#######.....", "...................####............##...............##..###.....", "...................###...................................#.....#", "...................##.........................................#.", "...................#............................................", "...................#............................................", } local GROW_V = 60 local function span(lay, a, b) local dx, dy = b[1] - a[1], b[2] - a[2] if lay.globe and abs(dx) > W / 2 then dx = dx - (dx > 0 and W or -W) end return dx, dy, sqrt(dx * dx + dy * dy) end for _, lay in pairs(LAYOUT) do local nodes, links = lay.nodes, lay.links local d = {} for i = 1, #nodes do d[i] = nodes[i][3] and 0 or 1e9 end for _ = 1, #nodes do for i = 1, #links do local l = links[i] local _, _, len = span(lay, nodes[l[1]], nodes[l[2]]) if d[l[1]] + len < d[l[2]] then d[l[2]] = d[l[1]] + len end if d[l[2]] + len < d[l[1]] then d[l[1]] = d[l[2]] + len end end end lay.grow_s = 0 for i = 1, #links do local l = links[i] if d[l[2]] < d[l[1]] then l[1], l[2] = l[2], l[1] end l.dx, l.dy, l.len = span(lay, nodes[l[1]], nodes[l[2]]) l.steep = abs(l.dy) > abs(l.dx) l.n = max(1, floor(l.steep and abs(l.dy) or abs(l.dx))) l.lift = lay.globe and min(5, 0.15 * l.len) or 0 l.t0 = d[l[1]] / GROW_V l.t1 = (d[l[1]] + l.len) / GROW_V if l.t1 > lay.grow_s then lay.grow_s = l.t1 end end lay.reach, lay.adj = {}, {} for i = 1, #nodes do lay.reach[i], lay.adj[i] = d[i] / GROW_V, {} end for i = 1, #links do local l = links[i] local p, q = lay.adj[l[1]], lay.adj[l[2]] p[#p + 1] = { l[2], l } q[#q + 1] = { l[1], l } end end local L = LAYOUT.full local PLATE = false local seen = {} local shown = {} local src local prev_a, vis, from, data_at, ev_at = -1, nil, nil, nil, -99 local function short(n) if n < 1000 then return fmt("%.0f", n) end if n < 100000 then return fmt("%.1fK", n / 1000) end if n < 1000000 then return fmt("%.0fK", n / 1000) end if n < 100000000 then return fmt("%.1fM", n / 1000000) end return fmt("%.0fM", n / 1000000) end local function rebuild() local btc = seen.cap / 100000000.0 shown.capfmt = (btc >= 1000) and "%.0f" or "%.1f" shown.cap = fmt(shown.capfmt, btc) shown.nodes = short(seen.nodes) shown.chans = short(seen.chans) local tot = seen.tor + seen.clear seen.share = (tot > 0) and (seen.tor / tot) or nil local is_tor = {} for i = 1, (seen.share and lround(seen.share * L.n_inside) or 0) do is_tor[L.tor[i]] = true end shown.is_tor = is_tor local pct = seen.pct shown.trend = pct and fmt("%s%.1f%%%s", pct >= 0 and "+" or "-", abs(pct), seen.per) or nil shown.up = pct and pct >= 0 end local MESH, MESH_KEY = nil, nil function on_settings() if cfg.src == "mempool" then net.stop("ml") net.fetch("ln", "/api/v1/lightning/statistics/latest", 3600) else net.stop("ln") net.fetch("ml", "/statistics?json=true", 3600) end L = LAYOUT[cfg.view] or LAYOUT.full PLATE = cfg.plate == true MESH = nil if cfg.src ~= src then src, seen, shown, vis, data_at = cfg.src, {}, {}, nil, nil elseif seen.cap then rebuild() end end function update() local cap, nodes, chans, tor, clr, pct, per if src == "mempool" then local d = web.ln local l = d and d.latest cap = l and tonumber(l.total_capacity) if not (cap and l.node_count) then return end nodes, chans = tonumber(l.node_count) or 0, tonumber(l.channel_count) or 0 tor, clr = tonumber(l.tor_nodes) or 0, tonumber(l.clearnet_nodes) or 0 local p = d.previous and tonumber(d.previous.total_capacity) if p and p > 0 then pct, per = (cap - p) / p * 100.0, "" end else local d = web.ml cap = d and tonumber(d.networkcapacity) if not (cap and d.numberofnodes) then return end nodes, chans = tonumber(d.numberofnodes) or 0, tonumber(d.numberofchannels) or 0 tor, clr = tonumber(d.tornodes) or 0, tonumber(d.publicipnodes) or 0 pct, per = tonumber(d.networkcapacity30dchange), txt.d30 end if cap <= 0 then return end if seen.cap == cap and seen.pct == pct and seen.nodes == nodes and seen.chans == chans and seen.tor == tor and seen.clear == clr then return end seen = { cap = cap, pct = pct, per = per, nodes = nodes, chans = chans, tor = tor, clear = clr } rebuild() end local function clock() local t = data.time if t and t.ok then return t.unix, t.ms end return frame // FPS, (frame % FPS) * 1000 // FPS end local RAMP_S, EV_S = 1.4, 1.5 local function ease(k) return 1 - (1 - k) ^ 3 end local function cur(key, a) local v = seen[key] if not v then return nil end local k = (a - data_at) / RAMP_S if k < 1 then return v * ease(k) end local f = from and from[key] k = (a - ev_at) / EV_S if f and k < 1 then return f + (v - f) * ease(k) end return v end local function dot_aa(x, y, steep, c, a) local top = L.my if steep then local xi = floor(x) local fr = x - xi local yr = lround(y) if yr >= top then blend(xi, yr, c[1], c[2], c[3], a * (1.0 - fr)) blend(xi + 1, yr, c[1], c[2], c[3], a * fr) end else local yi = floor(y) local fr = y - yi local xr = lround(x) if yi >= top then blend(xr, yi, c[1], c[2], c[3], a * (1.0 - fr)) end if yi + 1 >= top then blend(xr, yi + 1, c[1], c[2], c[3], a * fr) end end end local function link_pt(l, rev, u) if rev then u = 1 - u end local a = L.nodes[l[1]] local x = a[1] + l.dx * u if L.globe then x = x % W end return x, a[2] + l.dy * u - l.lift * sin(PI * u) end local function draw_links(e) local links, c = L.links, L.link for i = 1, #links do local l = links[i] local u = e and (e - l.t0) / (l.t1 - l.t0) or 1 if u > 0 then if u > 1 then u = 1 end if c then for k = 0, floor(l.n * u) do local x, y = link_pt(l, false, k / l.n) dot_aa(x, y, l.steep, c, 0.95) end end if u < 1 then local x, y = link_pt(l, false, u) dot_aa(x, y, l.steep, PULSE_C, 1) end end end end local EPOCH = 1767225600 local D2R = PI / 180 local function land_key() local t = data.time return (t and t.ok) and (t.unix - EPOCH) // 600 or -1 end local function draw_land(key) local sd, cd, ls = 0, 1, nil if key >= 0 then local yday = floor(key // 144 % 365.2422) + 1 local B = 360 * (yday - 81) / 365 * D2R local eot = 9.87 * sin(2 * B) - 7.53 * cos(B) - 1.5 * sin(B) local dec = asin(0.39795 * cos(0.98563 * (yday - 173) * D2R)) sd, cd = sin(dec), cos(dec) ls = (720 - key % 144 * 10 - eot) / 4 end local h = #MAP for y = 0, h - 1 do local lat = (MAP_LAT0 - (y + 0.5) * (MAP_LAT0 - MAP_LAT1) / h) * D2R local zs, zc = sin(lat) * sd, cos(lat) * cd local row, x0, c0 = MAP[y + 1], 0, nil for x = 0, W do local c if x < W and row:byte(x + 1) == 35 then c = 1 if ls then local z = zs + zc * cos(((x + 0.5) * 360 / W - 180 - ls) * D2R) c = z > 0 and 1 or (z > -0.1 and 2 or 3) end end if c ~= c0 then if c0 then local k = LAND_C[c0]; rect(x0, y, x - x0, 1, k[1], k[2], k[3]) end x0, c0 = x, c end end end end local function draw_bg(e) if e and not L.globe then draw_links(e) return end local key = L.globe and land_key() or 0 if MESH and MESH_KEY == key then blit_rgb(MESH, 0, L.my, W, L.mh) else if L.globe then draw_land(key) else draw_links(nil) end MESH, MESH_KEY = snapshot(0, L.my, W, L.mh), key end if e then draw_links(e) end end local BREATH = 1.2 local function draw_nodes(T, e) local is_tor = shown.is_tor or {} for i = 1, L.n_inside do local n = L.nodes[i] local k = 0.75 + 0.25 * sin(fmod(T * BREATH + i * 0.9, TAU)) if e then k = k * max(0, min(1, (e - L.reach[i]) / 0.25)) end local c = is_tor[i] and (n[3] and TOR_HUB or TOR_C) or (n[3] and NET_HUB or NET_C) local x, y = n[1], n[2] blend(x, y, c[1], c[2], c[3], k) local arm = n[3] and 0.7 or 0.35 blend(x + 1, y, c[1], c[2], c[3], arm * k) blend(x - 1, y, c[1], c[2], c[3], arm * k) blend(x, y + 1, c[1], c[2], c[3], arm * k) blend(x, y - 1, c[1], c[2], c[3], arm * k) if n[3] then blend(x + 1, y + 1, c[1], c[2], c[3], 0.3 * k) blend(x - 1, y - 1, c[1], c[2], c[3], 0.3 * k) blend(x + 1, y - 1, c[1], c[2], c[3], 0.3 * k) blend(x - 1, y + 1, c[1], c[2], c[3], 0.3 * k) end end end local function node_flash(i, s, c, amp) if i > L.n_inside or s < 0 or s > 0.5 then return end local n, a = L.nodes[i], amp * (1 - s / 0.5) local x, y = n[1], n[2] blend(x, y, c[1], c[2], c[3], a) blend(x + 1, y, c[1], c[2], c[3], 0.6 * a) blend(x - 1, y, c[1], c[2], c[3], 0.6 * a) blend(x, y + 1, c[1], c[2], c[3], 0.6 * a) blend(x, y - 1, c[1], c[2], c[3], 0.6 * a) end local function draw_wave(ev) local links = L.links for i = 1, #links do local l = links[i] local u = (ev - l.t0) / (l.t1 - l.t0) if u >= 0 and u <= 1.15 then for k = 0, 3 do local v = u - k * 0.05 if v >= 0 and v <= 1 then local x, y = link_pt(l, false, v) dot_aa(x, y, l.steep, WAVE_C, 1 - k / 4) end end end end for i = 1, L.n_inside do node_flash(i, ev - L.reach[i], WAVE_C, 1) end end local PN, PL, PC = {}, {}, {} local function walk(h, start, hops) local adj = L.adj PN[1], PC[1] = start, 0 local n = 1 for j = 1, hops do local here = PN[n] if n > 1 and here > L.n_inside then break end local opts = adj[here] local c = #opts local pick = umod(hash32(h + j), c) local nxt for q = 0, c - 1 do nxt = opts[1 + (pick + q) % c] for m = 1, n do if PN[m] == nxt[1] then nxt = nil break end end if nxt then break end end if not nxt then break end n = n + 1 PN[n], PL[n], PC[n] = nxt[1], nxt[2], PC[n - 1] + nxt[2].len end return n, PC[n] end local function path_at(n, p) local j = 2 while j < n and PC[j] < p do j = j + 1 end local l = PL[j] local x, y = link_pt(l, PN[j - 1] ~= l[1], (p - PC[j - 1]) / (PC[j] - PC[j - 1])) return x, y, l.steep end local function draw_packet(n, d, c, tail, glow) local total = PC[n] for k = 0, tail - 1 do local p = d - k if p >= 0 and p <= total then local x, y, steep = path_at(n, p) dot_aa(x, y, steep, c, 1 - k / tail) if glow and k == 0 then dot_aa(x + 1, y, steep, c, 0.35); dot_aa(x - 1, y, steep, c, 0.35) dot_aa(x, y + 1, steep, c, 0.35); dot_aa(x, y - 1, steep, c, 0.35) end end end end local PAY_WIN = 6 local function draw_payments(u, ms) for i = 1, L.pays do local tt = u + i * 7 local h = hash32((tt // PAY_WIN) * 0x85EBCA6B + i * 0x27D4EB2F) local n, total = walk(h, 1 + umod(h, #L.nodes), 2 + umod(h >> 4, 4)) if n > 1 then local go = umod(h >> 8, 1000) / 1000 local sp = max(14 + umod(h >> 20, 12), total / (PAY_WIN - 0.6 - go)) local d = (tt % PAY_WIN + ms / 1000 - go) * sp if d >= 0 then if d <= total + 4 then draw_packet(n, d, PULSE_C, 4) end node_flash(PN[n], (d - total) / sp, PULSE_C, 0.7) end end end end local GUEST_WIN, GUEST_V, GUEST_TAIL, GUEST_MIN = 40, 30, 8, 70 local function draw_guest(u, ms) local h = hash32((u // GUEST_WIN) * 0x27D4EB2F + 29) if umod(h, 4) == 0 then return end local n, total local first, cnt = L.n_inside + 1, #L.nodes - L.n_inside if cnt == 0 then first, cnt = 1, #L.nodes end for k = 1, 4 do h = hash32(h + k) n, total = walk(h, first + umod(h, cnt), 10) if total >= GUEST_MIN then break end end if total < GUEST_MIN then return end local dur = (total + GUEST_TAIL) / GUEST_V + 0.5 local d = (u % GUEST_WIN + ms / 1000 - umod(h >> 8, floor(GUEST_WIN - dur))) * GUEST_V if d < 0 then return end if d <= total + GUEST_TAIL then draw_packet(n, d, WAVE_C, GUEST_TAIL, true) end for j = 1, n do node_flash(PN[j], (d - PC[j]) / GUEST_V, WAVE_C, 1) end end local UNIT = "BTC" local BOLT, BOLT_W = { "..#", ".##", ".#.", "##.", "###", ".##", ".#.", "#..", "#.." }, 3 local function draw_bolt(x, y) for r = 1, #BOLT do local row = BOLT[r] for i = 1, BOLT_W do if row:byte(i) == 35 then rect(x + i - 1, y + r - 1, 1, 1, TITLE_C[1], TITLE_C[2], TITLE_C[3]) end end end end local CAP_F = { { { font = "9x15b" }, { font = "9x15b", w = 1, align = "right", pad = 0, cell = true }, 0 }, { { font = "8x13b" }, { font = "8x13b", w = 1, align = "right", pad = 0, cell = true }, 1 }, { { font = "6x10" }, { font = "6x10", w = 1, align = "right", pad = 0, cell = true }, 4 }, } local function draw_capacity(s) local final = shown.cap local uw = text_width(UNIT, F_SMALL) local bw = L.bolt and BOLT_W + 3 or 0 local f, nw for i = 1, #CAP_F do f = CAP_F[i] nw = text_width(final, f[1]) if bw + nw + 3 + uw <= W then break end end local y = L.cap + f[3] local it, ib = text_ink(final, f[1]) local top, bot = y + it, y + ib if bw + nw + 3 + uw > W then bw = 0 end local x = (W - (bw + nw + 3 + uw)) // 2 if x < 0 then x = 0 end if L.plate and PLATE then rect(x - 2, top - 1, bw + nw + 3 + uw + 5, bot - top + 3, BG[1], BG[2], BG[3]) end if bw > 0 then draw_bolt(x, top + (bot - top + 1 - #BOLT) // 2); x = x + bw end f[2].w = nw text(x, y, s, CAP_C[1], CAP_C[2], CAP_C[3], f[2]) text(x + nw + 3, bot - (CAP_S - 1), UNIT, UNIT_C[1], UNIT_C[2], UNIT_C[3], F_SMALL) end local O_NUM = { w = 1, align = "left", pad = 0 } local O_LAB = { font = "3x5", w = 1, align = "left", pad = 0 } local function draw_count(c, num, lab) O_NUM.w, O_NUM.align = c.nw, c.na O_LAB.w, O_LAB.align = c.lw, c.la text(c.nx, c.ny, num, CNT_C[1], CNT_C[2], CNT_C[3], O_NUM) text(c.lx, c.ly, lab, LBL_C[1], LBL_C[2], LBL_C[3], O_LAB) end local function draw_split(f) if not f then return end local s = L.split local x, y, w = s[1], s[2], s[3] local wt = lround(f * w) if wt > 0 then rect(x, y, wt, 2, TOR_C[1], TOR_C[2], TOR_C[3]) end if wt < w then rect(x + wt, y, w - wt, 2, NET_C[1], NET_C[2], NET_C[3]) end end local F_GATE = { font = "4x6" } local function gate(s, y, r, g, b) if s.ok then return true end r, g, b = r or 255, g or 250, b or 232 text_center(y, data.net.mode ~= "online" and txt.offline or not data.net.up and txt.nowifi or s.code ~= 0 and "ERR " .. s.code or txt.loading, r, g, b) if s.code ~= 0 then text_center(y + 10, txt.console, r, g, b, F_GATE) end return false end function render() local a = frame / FPS if a < prev_a then vis, from, data_at, ev_at = nil, nil, nil, -99 end prev_a = a local u, ms = clock() local e = data.arrive and a < L.grow_s and a or nil local ev = a - ev_at if ev > L.grow_s + 0.3 then ev = nil end clear(BG[1], BG[2], BG[3]) draw_bg(e) draw_nodes(u % 3600 + ms / 1000, e) if ev then draw_wave(ev) end if not e then draw_payments(u, ms); draw_guest(u, ms) end if L.title then text_center(L.title, "LIGHTNING", TITLE_C[1], TITLE_C[2], TITLE_C[3]) end if not gate(src == "mempool" and data.src.ln or data.src.ml, L.gate) then return end if not shown.cap then text_center(NODATA_Y, txt.nodata, NODATA_C[1], NODATA_C[2], NODATA_C[3], F_SMALL) return end if vis and vis ~= seen then from, ev_at = vis, a end vis = seen data_at = data_at or (data.arrive and a or a - RAMP_S) local cap_s, nod_s, ch_s = shown.cap, shown.nodes, shown.chans if a - data_at < RAMP_S or a - ev_at < EV_S then cap_s = fmt(shown.capfmt, cur("cap", a) / 100000000.0) nod_s, ch_s = short(cur("nodes", a)), short(cur("chans", a)) end draw_capacity(cap_s) if shown.trend then local c = shown.up and UP_C or DOWN_C text_center(L.trend, shown.trend, c[1], c[2], c[3], F_SMALL) end if L.plate and PLATE then rect(0, L.plate, W, H - L.plate, BG[1], BG[2], BG[3]) end draw_count(L.cells[1], nod_s, txt.nodes) draw_count(L.cells[2], ch_s, txt.chans) draw_split(cur("share", a)) end