info = { type = "app", title = "CKPOOL", author = "BRRRO", license = "MIT", desc = "Solo mining stats from ckpool", category = "btc", api = 43, } txt = { addr = "Bitcoin address", addr_h = "The address you mine to on ckpool (a .worker suffix is ignored)", server = "Server", server_h = "The one your miner is connected to", server_o = { "solo (global)", "eusolo (Europe)", "ausolo (Australia)" }, view = "Pages", view_o = { "rotate", "hashrate", "shares", "trend" }, glint = "Highlight", p2 = "SHARES", p3 = "TREND", avg = "5M AVG", workers = "WORKERS", last = "LAST", best = "BEST", best_s = "BEST SHARE", ever = "BEST EVER", total = "SHARES", no1 = "NO ADDRESS", no2 = "ENTER IT", no3 = "IN SETTINGS", nf1 = "ADDRESS", nf2 = "NOT FOUND", nf3 = "CHECK IT", nd = "NO DATA", nd2 = "ADDRESS OR", nd3 = "SERVER?", loading = "LOADING", nowifi = "NO WIFI", offline = "OFFLINE", console = "SEE CONSOLE" } for k, v in pairs(({ sk = { addr = "Bitcoinová adresa", addr_h = "Adresa, na ktorú ťažíš na ckpool (prípona .worker sa ignoruje)", server = "Server", server_h = "Ten, na ktorý je pripojený tvoj miner", server_o = { "solo (svet)", "eusolo (Európa)", "ausolo (Austrália)" }, view = "Stránky", view_o = { "striedať", "hashrate", "shares", "trend" }, glint = "Odlesk", avg = "5M PRIEM.", workers = "WORKERY", last = "POSL.", best = "NAJ.", best_s = "NAJ. SHARE", ever = "REKORD", total = "SHAROV", no1 = "BEZ ADRESY", no2 = "ZADAJ JU V", no3 = "NASTAVENIACH", nf1 = "ADRESA", nf2 = "NENAJDENA", nf3 = "SKONTROLUJ", nd = "BEZ DAT", nd2 = "ADRESA ALEBO", nd3 = "SERVER?", loading = "NACITAVAM", nowifi = "BEZ WIFI", console = "POZRI KONZOLU" }, cs = { addr = "Bitcoinová adresa", addr_h = "Adresa, na kterou těžíš na ckpool (přípona .worker se ignoruje)", server = "Server", server_h = "Ten, ke kterému je připojený tvůj miner", server_o = { "solo (svět)", "eusolo (Evropa)", "ausolo (Austrálie)" }, view = "Stránky", view_o = { "střídat", "hashrate", "shares", "trend" }, glint = "Odlesk", avg = "5M PRUMER", workers = "WORKERY", last = "POSL.", best = "NEJ.", best_s = "NEJ. SHARE", ever = "REKORD", total = "SHARU", no1 = "BEZ ADRESY", no2 = "ZADEJ JI V", no3 = "NASTAVENI", nf1 = "ADRESA", nf2 = "NENALEZENA", nf3 = "ZKONTROLUJ", nd = "BEZ DAT", nd2 = "ADRESA NEBO", nd3 = "SERVER?", loading = "NACITAM", nowifi = "BEZ WIFI", console = "VIZ KONZOLI" }, })[lang] or {}) do txt[k] = v end local SERVERS = { "solo", "eusolo", "ausolo" } local TAG = { solo = "SOLO", eusolo = "EU", ausolo = "AU" } local VIEWS = { "auto", "main", "shares", "trend" } settings = { { key = "addr", type = "text", default = "", label = txt.addr, hint = txt.addr_h, secret = true, demo = "bc1qdemodemodemodemodemodemodemodemodemo" }, { key = "server", type = "int", default = "solo", label = txt.server, hint = txt.server_h, opts = { keys = SERVERS, table.unpack(txt.server_o) } }, { key = "view", type = "int", default = "auto", label = txt.view, opts = { keys = VIEWS, table.unpack(txt.view_o) } }, { key = "glint", type = "bool", default = true, label = txt.glint }, } local function addr() return (cfg.addr or ""):match("^%s*(%w+)") end sources = { solo = { url = "https://solo.ckpool.org", limit = 30, fields = { "hashrate1m", "hashrate5m", "hashrate1hr", "hashrate1d", "hashrate7d", "lastshare", "workers", "shares", "bestshare", "bestever" }, demo = [[{"hashrate1m":"2.12P","hashrate5m":"1.98P","hashrate1hr":"1.59P","hashrate1d":"1.24P","hashrate7d":"20.2P","lastshare":1793390259,"workers":61,"shares":85714809120640,"bestshare":21413005279.992764,"bestever":272328676618843,"authorised":1761432964}]] }, eusolo = { url = "https://eusolo.ckpool.org", limit = 30, fields = { "hashrate1m", "hashrate5m", "hashrate1hr", "hashrate1d", "hashrate7d", "lastshare", "workers", "shares", "bestshare", "bestever" }, demo = [[{"hashrate1m":"2.12P","hashrate5m":"1.98P","hashrate1hr":"1.59P","hashrate1d":"1.24P","hashrate7d":"20.2P","lastshare":1793390259,"workers":61,"shares":85714809120640,"bestshare":21413005279.992764,"bestever":272328676618843,"authorised":1761432964}]] }, ausolo = { url = "https://ausolo.ckpool.org", limit = 30, fields = { "hashrate1m", "hashrate5m", "hashrate1hr", "hashrate1d", "hashrate7d", "lastshare", "workers", "shares", "bestshare", "bestever" }, demo = [[{"hashrate1m":"2.12P","hashrate5m":"1.98P","hashrate1hr":"1.59P","hashrate1d":"1.24P","hashrate7d":"20.2P","lastshare":1793390259,"workers":61,"shares":85714809120640,"bestshare":21413005279.992764,"bestever":272328676618843,"authorised":1761432964}]] }, } function on_settings() local a = addr() for _, s in ipairs(SERVERS) do if s == cfg.server and a then net.fetch(s, "/users/" .. a, 120) else net.stop(s) end end end local W, H, FPS = gfx.W, gfx.H, gfx.FPS local rect, blend_rect = gfx.rect, gfx.blend_rect local text, text_center, text_width, text_ink = gfx.text, gfx.text_center, gfx.text_width, gfx.text_ink local floor, min, max = math.floor, math.min, math.max local fmt = string.format local F5 = { font = "5x7" } local F4 = { font = "4x6" } local FBIG = { font = "8x13b" } local HDR = { 20, 52, 78 } local TTL = { 225, 238, 250 } local DOT = { 70, 100, 130 } local DOT_ON = { 120, 230, 240 } local LBL = { 120, 150, 180 } local VAL = { 230, 240, 250 } local CYAN = { 90, 225, 235 } local GOLD = { 255, 196, 64 } local COIN do local WID = { 6, 10, 12, 14, 14, 16, 16, 16, 16, 16, 16, 14, 14, 12, 10, 6 } local SIGN = { "00101000", "11111100", "01100110", "01100110", "01111100", "01100011", "01100011", "11111110", "00101000" } local BLACK, ORANGE, WHITE = string.char(0, 0, 0), string.char(247, 147, 26), string.char(255, 255, 255) local px = {} for y = 0, 15 do local w = WID[y + 1] local s = SIGN[y - 3] for x = 0, 15 do local p = BLACK if x >= (16 - w) // 2 and x < (16 + w) // 2 then p = (s and x >= 4 and x < 12 and s:sub(x - 3, x - 3) == "1") and WHITE or ORANGE end px[#px + 1] = p end end COIN = table.concat(px) end local GREEN = { 90, 220, 130 } local AMBER = { 235, 170, 50 } local RED = { 235, 90, 90 } local LINE = { 50, 75, 105 } local TRACK = { 36, 48, 70 } local IDLE = { 210, 90, 90 } local PAGE_S = 7 local NPAGE = 3 local DOT_X = { 49, 54, 59 } local PFX = { k = 1e3, M = 1e6, G = 1e9, T = 1e12, P = 1e15, E = 1e18 } local function parse_hr(s) local n, p = tostring(s):match("^([%d.]+)(%a?)$") if not n then return "-", "", 0 end return n, p, (tonumber(n) or 0) * (PFX[p] or 1) end local function human(v) if type(v) ~= "number" then return "-" end local i = 0 while v >= 999.5 and i < 6 do v = v / 1000; i = i + 1 end local s = v >= 99.5 and fmt("%d", floor(v + 0.5)) or v >= 9.95 and fmt("%.1f", v) or fmt("%.2f", v) return s .. ("kMGTPE"):sub(i, i) end local function age_str(s) if s < 0 then s = 0 end if s < 60 then return fmt("%dS", s) elseif s < 3600 then return fmt("%dM", s // 60) elseif s < 86400 then return fmt("%dH", s // 3600) end return fmt("%dD", s // 86400) end local D, seen_last, pulse_at = nil, nil, -1000 local ROWY = { 38, 47, 56 } local TR_LBL = { "1M", "1H", "1D", "7D" } local TR_KEY = { "hashrate1m", "hashrate1hr", "hashrate1d", "hashrate7d" } local function rebuild(j) local m5, p5, v5 = parse_hr(j.hashrate5m) local unit = p5:upper() .. "H/S" local wn, wu = text_width(m5, FBIG), text_width(unit, F5) local _, bot = text_ink(m5, FBIG) D = { j = j, mant = m5, unit = unit, idle = v5 == 0, x0 = (W - (wn + 3 + wu)) // 2, wn = wn, bot = bot, workers = fmt("%d", j.workers or 0), best = human(j.bestshare), ever = human(j.bestever), total = human(j.shares) .. " " .. txt.total, tr = {} } D.best_x = (W - text_width(D.best, FBIG)) // 2 D.ever_x = (W - text_width(D.ever, FBIG)) // 2 D.total_x = (W - text_width(D.total, F4)) // 2 D.avg = txt.avg .. " " .. TAG[cfg.server] local vmax = 0 for i = 1, 4 do local m, p, v = parse_hr(j[TR_KEY[i]]) D.tr[i] = { s = m .. p, v = v } if v > vmax then vmax = v end end for i = 1, 4 do local t = D.tr[i] t.x = 62 - text_width(t.s, F5) t.bw = vmax > 0 and t.v > 0 and max(1, floor(60 * t.v / vmax + 0.5)) or 0 end local ls = j.lastshare if type(ls) == "number" and ls > 0 then if seen_last and ls > seen_last then pulse_at = frame end seen_last = ls end end local VIEWIX = { main = 1, shares = 2, trend = 3 } local page, base, prev_frame = 1, 0, 0 local sec, age_s, age_c, age_x = -1, "-", LBL, 0 local function pick() local j = web[cfg.server] if j ~= (D and D.j) and type(j) == "table" then rebuild(j) end return j end function update() if frame < prev_frame then base = 0; page = 1; D = nil end prev_frame = frame page = VIEWIX[cfg.view] or (frame - base) // (PAGE_S * FPS) % NPAGE + 1 end function on_button(which) if cfg.view ~= "auto" then return end page = (page - 1 + (which == "up" and 1 or NPAGE - 1)) % NPAGE + 1 base = frame - (page - 1) * PAGE_S * FPS end local function header(title, pg) rect(0, 0, W, 9, HDR[1], HDR[2], HDR[3]) text(2, 1, title, TTL[1], TTL[2], TTL[3], F5) for i = 1, NPAGE do local c = i == pg and DOT_ON or DOT rect(DOT_X[i], 3, 3, 3, c[1], c[2], c[3]) end end local function glint() local t, a if frame - pulse_at < FPS then t, a = (frame - pulse_at) / FPS, 0.5 elseif cfg.glint and frame % (10 * FPS) < FPS * 3 // 4 then t, a = (frame % (10 * FPS)) / (FPS * 3 // 4), 0.16 else return end local x = floor(t * (W + 8)) - 8 local x0, x1 = max(x, 0), min(x + 6, W) if x1 > x0 then blend_rect(x0, 0, x1 - x0, 9, 255, 255, 255, a) end end local function message(y, l1, l2, l3) text_center(y, l1, VAL[1], VAL[2], VAL[3], F5) if l2 then text_center(y + 11, l2, LBL[1], LBL[2], LBL[3], F4) end if l3 then text_center(y + 18, l3, LBL[1], LBL[2], LBL[3], F4) end end local function row(i, label, s, c) local y = ROWY[i] text(2, y, label, LBL[1], LBL[2], LBL[3], F5) text(62 - text_width(s, F5), y, s, c[1], c[2], c[3], F5) end local function page_main(j) header("CKPOOL", 1) local c = D.idle and IDLE or CYAN text(D.x0, 13, D.mant, c[1], c[2], c[3], FBIG) text(D.x0 + D.wn + 3, 13 + D.bot - 6, D.unit, VAL[1], VAL[2], VAL[3], F5) text_center(28, D.avg, LBL[1], LBL[2], LBL[3], F4) rect(2, 35, 60, 1, LINE[1], LINE[2], LINE[3]) row(1, txt.workers, D.workers, VAL) local ls, now = j.lastshare, data.time if now.ok and type(ls) == "number" and ls > 0 then if now.unix ~= sec then sec = now.unix age_s = age_str(sec - ls) local d = sec - ls age_c = d < 120 and GREEN or d < 1800 and AMBER or RED end row(2, txt.last, age_s, frame - pulse_at < FPS * 3 // 2 and VAL or age_c) else row(2, txt.last, "-", LBL) end row(3, txt.best, D.best, GOLD) end local function page_shares() header(txt.p2, 2) text(2, 11, txt.best_s, LBL[1], LBL[2], LBL[3], F5) text(D.best_x, 19, D.best, CYAN[1], CYAN[2], CYAN[3], FBIG) rect(2, 33, 60, 1, LINE[1], LINE[2], LINE[3]) text(2, 36, txt.ever, LBL[1], LBL[2], LBL[3], F5) text(D.ever_x, 44, D.ever, GOLD[1], GOLD[2], GOLD[3], FBIG) text(D.total_x, 58, D.total, LBL[1], LBL[2], LBL[3], F4) end local function page_trend() header(txt.p3, 3) for i = 1, 4 do local y, t = 12 + (i - 1) * 12, D.tr[i] text(2, y, TR_LBL[i], LBL[1], LBL[2], LBL[3], F5) text(t.x, y, t.s, VAL[1], VAL[2], VAL[3], F5) rect(2, y + 9, 60, 2, TRACK[1], TRACK[2], TRACK[3]) if t.bw > 0 then rect(2, y + 9, t.bw, 2, CYAN[1], CYAN[2], CYAN[3]) end 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() gfx.clear(0, 0, 0) local a = addr() if not a then gfx.blit_rgb(COIN, 24, 8, 16, 16, 0, 0, 0) message(28, txt.no1, txt.no2, txt.no3) return end local j = pick() if not j then local src = data.src[cfg.server] if src.code == 404 then message(14, txt.nf1, nil, nil) text_center(25, txt.nf2, VAL[1], VAL[2], VAL[3], F5) text_center(37, txt.nf3, LBL[1], LBL[2], LBL[3], F4) text_center(44, TAG[cfg.server], LBL[1], LBL[2], LBL[3], F4) return end if not gate(src, 24) then return end message(18, txt.nd, txt.nd2, txt.nd3) return end if page == 1 then page_main(j) elseif page == 2 then page_shares() else page_trend() end glint() end