L
ling-wallet
↓ 0 downloadsLing Wallet: a post-quantum privacy-coin wallet, full node and HyperTorus miner for LNG
Keywords wallet, cryptocurrency, lng, node, miner, ling
lingfu install ling-walletCode / Files (116)
ling/ui/mining.ling
# mining.ling — MINING: miner controls, output stats and the HyperTorus view.
fn mining_draw(ax, ay, aw, ah) {
bind m = st_get("d_mining", ())
if m == () { return () }
bind t = u_now()
if t - st_get("m_last_sample", 0 - 10) > 0.25 || st_llen("m_rates") == 0 {
st_set("m_last_sample", t)
st_lpush("m_rates", m.hashrate)
if st_llen("m_rates") > 80 { st_ldel("m_rates", 0) }
}
bind lw = 380
bind ctl_h = 352
bind en = m.enabled
bind th = m.threads
bind inten = m.intensity
bind pause = m.pause_when_busy
bind changed = false
bind inn = panel(ax, ay, lw, ctl_h, "MINER", C_YELLOW)
bind x = list_get(inn, 0)
bind y = list_get(inn, 1)
bind iw = list_get(inn, 2)
if big_switch(x, y + 8, 128, 56, en) {
bind en = !en
bind changed = true
}
bind state = "Mining"
bind sub = num_str(m.threads) + sel(m.threads == 1, " thread", " threads") + " · " + num_str(m.intensity) + " % duty"
if !m.enabled {
bind state = "Stopped"
bind sub = "Toggle to mine in the background"
} else if m.paused_reason != "" {
bind state = "Paused"
bind sub = m.paused_reason
}
t_text(F_HEAD, 20, x + 148, y + 34, str_upper(state), sel(m.enabled, lift(C_YELLOW, 0.2), C_TEXT_DIM))
t_text(F_UI, 15, x + 148, y + 56, sub, C_TEXT_DIM)
bind y = y + 8 + 56 + 40
label(x, y, "Threads", C_TEXT_DIM)
t_text(F_UI, 15, x + 220, y + 34, "of " + num_str(m.max_threads), C_TEXT_FAINT)
bind nv = stepper(x, y + 10, th, 1, max(1, m.max_threads), C_YELLOW)
if nv >= 0 {
bind th = nv
bind changed = true
}
bind y = y + 86
label(x, y, "Intensity", C_TEXT_DIM)
t_right(F_MONO, 24, x + iw, y + 2, num_str(inten) + " %", C_TEXT_STRONG)
bind sv = slider("mining.intensity", x, y + 14, iw, 20, (inten - 5) / 95, C_YELLOW)
if sv >= 0 {
bind ni = round(5 + sv * 95)
if ni != inten {
bind inten = ni
bind changed = true
}
}
t_text(F_UI, 14, x, y + 58, "Gentle", C_TEXT_FAINT)
t_right(F_UI, 14, x + iw, y + 58, "Full speed", C_TEXT_FAINT)
bind y = y + 84
if toggle(x, y, pause, "Pause while I'm using the computer", C_YELLOW) {
bind pause = !pause
bind changed = true
}
if changed {
be_set_mining(en, th, inten, pause)
st_set("d_mining", be_mining())
}
bind oy = ay + ctl_h + 32
bind oh = ah - ctl_h - 32
bind ino = panel(ax, oy, lw, oh, "OUTPUT", C_YELLOW)
bind x = list_get(ino, 0)
bind y = list_get(ino, 1)
bind iw = list_get(ino, 2)
bind diff = to_number(m.difficulty)
bind expect = "-"
if m.hashrate > 0 { bind expect = "≈ " + duration(diff / m.hashrate) }
bind keys = ["Hashrate", "Blocks found", "Difficulty", "Expected block"]
bind vals = [num_str(round(m.hashrate * 100) / 100) + " H/s", num_str(m.blocks_found), thousands(m.difficulty), expect]
bind cw = floor((iw - 16) / 2)
bind i = 0
while i < 4 {
bind cx = x + (i % 2) * (cw + 16)
bind cy = y + 8 + floor(i / 2) * 64
label(cx, cy + 6, list_get(keys, i), C_TEXT_DIM)
bind v = list_get(vals, i)
t_text(F_MONO, sel(str_len(v) > 10, 26, 30), cx, cy + 38, v, C_TEXT_STRONG)
bind i = i + 1
}
bind sy = y + 8 + 128 + 8
sparkline(x, sy, iw, max(24, oy + oh - 16 - sy), C_YELLOW)
bind vx = ax + lw + 24
bind vw = aw - lw - 24
bind inv = panel(vx, ay, vw, ah, "HYPERTORUS", C_YELLOW)
bind ix = list_get(inv, 0)
bind iy = list_get(inv, 1)
bind ivw = list_get(inv, 2)
bind ivh = list_get(inv, 3)
fill(vx + 4, ay + 4, vw - 8, ah - 8, hex_to_number("010102"))
if !m.enabled { tz_clear("tz") }
tz_draw("tz", vx + 4, ay + 4, vw - 8, ah - 8, t, m.enabled, true)
label(ix, iy + 8, "4-torus walk · Clifford embedding in S3", C_TEXT_DIM)
label(ix, iy + 28, "rotating in the xw and yz planes", C_TEXT_FAINT)
bind hp = tz_head("tz")
if len(hp) > 4 && m.enabled {
bind names = ["x", "y", "z", "w"]
bind j = 0
while j < 4 {
bind yy = iy + 16 + j * 22
t_right(F_MONO, 20, ix + ivw - 92, yy, list_get(names, j), C_TEXT_FAINT)
t_right(F_MONO, 20, ix + ivw, yy, hex8(list_get(hp, j)), C_TEXT)
bind j = j + 1
}
bind twv = list_get(hp, 4)
t_right(F_MONO, 20, ix + ivw, iy + 16 + 88, "twist " + num_str(twv) + " · vertex V" + num_str(floor(list_get(hp, 3) / 1073741824)), twist_color(twv, list_get(hp, 3)))
}
if !m.enabled { t_center(F_HEAD, 16, vx, ay + floor(ah / 2) - 10, vw, 20, "MINER STOPPED", C_TEXT_DIM) }
bind ly = iy + ivh + 4
bind lx = ix
label(lx, ly, "Twist", C_TEXT_FAINT)
bind lx = lx + 56
bind tt = 0
while tt < 4 {
fill(lx, ly - 9, 9, 9, twist_color(tt, 0))
fill(lx + 12, ly - 9, 9, 9, twist_color(tt, 2147483648))
bind lx = lx + 24
bind lx = lx + round(t_text(F_MONO, 18, lx + 2, ly + 1, num_str(tt), C_TEXT_DIM)) + 14
bind tt = tt + 1
}
label(lx + 10, ly, "· trails = latest steps", C_TEXT_FAINT)
}
fn hex8(v) {
bind hexd = "0123456789abcdef"
bind out = ""
bind n = floor(v)
bind i = 0
while i < 8 {
bind out = substr(hexd, n % 16, 1) + out
bind n = floor(n / 16)
bind i = i + 1
}
return out
}
# Large hatched on/off switch; returns true when clicked.
fn big_switch(x, y, w, h, on) {
bind hot = u_hover(x, y, w, h)
fill(x, y, w, h, C_BG_DEEP)
bind oc = C_LINE_SOFT
if hot { bind oc = C_LINE }
if on { bind oc = C_YELLOW }
outline(x, y, w, h, oc, 1)
brackets(x - 3, y - 3, w + 6, h + 6, 8, sel(on, lift(C_YELLOW, 0.3), C_TEXT_FAINT), 1)
bind half = floor(w / 2)
bind kx = sel(on, x + half, x) + 4
bind ky = y + 4
bind kw = half - 8
bind kh = h - 8
if on {
fill_a(kx, ky, kw, kh, C_YELLOW, 0.25)
cross(kx, ky, kw, kh, C_YELLOW, 3, 0.8)
outline(kx, ky, kw, kh, lift(C_YELLOW, 0.3), 1)
t_center(F_HEAD, 14, x, y, half, h, "OFF", C_TEXT_FAINT)
} else {
fill(kx, ky, kw, kh, hex_to_number("15161a"))
outline(kx, ky, kw, kh, C_LINE, 1)
t_center(F_HEAD, 14, x + half, y, half, h, "ON", C_TEXT_FAINT)
}
t_center(F_HEAD, 14, kx, ky, kw, kh, sel(on, "ON", "OFF"), C_TEXT_STRONG)
return hot && u_pressed()
}
fn sparkline(x, y, w, h, col) {
fill(x, y, w, h, C_BG_DEEP)
outline(x, y, w, h, C_LINE_FAINT, 1)
label(x + 8, y + 18, "Hashrate · last 20 s", C_TEXT_FAINT)
bind n = st_llen("m_rates")
if n < 2 { return () }
bind mx = 0.000000001
bind i = 0
while i < n {
bind mx = max(mx, st_lget("m_rates", i))
bind i = i + 1
}
bind mx = mx * 1.2
bind slots = 80
bind px = 0
bind py = 0
bind k = 0
while k < n {
bind vx = x + 4 + (w - 8) * (k + slots - n) / (slots - 1)
bind vy = y + h - 4 - (h - 28) * st_lget("m_rates", k) / mx
if k > 0 {
line(px, py, vx, vy, col, 1)
hatch(floor(px), floor(max(py, vy)) + 2, max(1, floor(vx) - floor(px)), floor(y + h - 3 - max(py, vy) - 2), col, true, 3, 0.25)
}
bind px = vx
bind py = vy
bind k = k + 1
}
}