|
| 1 | +<% |
| 2 | +const fmtN = (n) => new Intl.NumberFormat('en-US').format(n || 0); |
| 3 | +const fmtTs = (t) => t ? new Date(t * 1000).toISOString().replace('T', ' ').slice(0, 19) + 'Z' : '—'; |
| 4 | +const ago = (t) => { |
| 5 | + if (!t) return '—'; |
| 6 | + const s = Math.max(0, Math.floor(Date.now() / 1000) - t); |
| 7 | + if (s < 60) return s + 's ago'; |
| 8 | + if (s < 3600) return Math.floor(s / 60) + 'm ago'; |
| 9 | + if (s < 86400) return Math.floor(s / 3600) + 'h ago'; |
| 10 | + return Math.floor(s / 86400) + 'd ago'; |
| 11 | +}; |
| 12 | +const fmtSats = (sats) => { |
| 13 | + if (!sats) return '0 sats'; |
| 14 | + const btc = sats / 1e8; |
| 15 | + if (btc >= 0.01) return fmtN(sats) + ' sats (' + btc.toFixed(8) + ' BTC)'; |
| 16 | + return fmtN(sats) + ' sats'; |
| 17 | +}; |
| 18 | +%> |
| 19 | +<!doctype html> |
| 20 | +<html lang="en"> |
| 21 | +<head> |
| 22 | + <meta charset="utf-8"> |
| 23 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 24 | + <meta http-equiv="refresh" content="15"> |
| 25 | + <title>admin · simplepool</title> |
| 26 | + <link rel="stylesheet" href="/static/style.css"> |
| 27 | +</head> |
| 28 | +<body> |
| 29 | + <header class="top"> |
| 30 | + <a href="/" class="brand">simplepool</a> |
| 31 | + <span class="tag">pool operator</span> |
| 32 | + </header> |
| 33 | + <main class="wrap"> |
| 34 | + <section class="card info"> |
| 35 | + <h2>Pool operator view</h2> |
| 36 | + <p class="muted small"> |
| 37 | + Read-only. Reserve balance is a live probe of Thunder's |
| 38 | + JSON-RPC; everything else is the same SQLite the pool |
| 39 | + writes. Reconciliation is manual — see |
| 40 | + <code>payout/README.md</code> for the runbook. |
| 41 | + </p> |
| 42 | + </section> |
| 43 | + |
| 44 | + <section class="card"> |
| 45 | + <h2>Thunder reserve</h2> |
| 46 | + <% if (reserve.ok) { %> |
| 47 | + <div class="grid"> |
| 48 | + <div><label>Available</label><strong><%= fmtSats(reserve.available_sats) %></strong></div> |
| 49 | + <div><label>Total</label><strong><%= fmtSats(reserve.total_sats) %></strong></div> |
| 50 | + </div> |
| 51 | + <p class="mono small muted" style="margin-top:0.5em;word-break:break-all"><%= reserveAddress %></p> |
| 52 | + <% } else { %> |
| 53 | + <p class="muted">Thunder RPC unreachable: <em><%= reserve.error %></em></p> |
| 54 | + <p class="mono small muted" style="margin-top:0.5em;word-break:break-all"><%= reserveAddress %></p> |
| 55 | + <% } %> |
| 56 | + </section> |
| 57 | + |
| 58 | + <section class="card"> |
| 59 | + <h2>PPS ledger totals</h2> |
| 60 | + <div class="grid"> |
| 61 | + <div><label>Owed (needs payout)</label><strong><%= fmtSats(totals.owed) %></strong></div> |
| 62 | + <div><label>Accrued (all time)</label><strong><%= fmtSats(totals.accrued) %></strong></div> |
| 63 | + <div><label>Paid (all time)</label><strong><%= fmtSats(totals.paid) %></strong></div> |
| 64 | + <div><label>Workers with a balance</label><strong><%= fmtN(totals.workers) %></strong></div> |
| 65 | + </div> |
| 66 | + <% if (reserve.ok && totals.owed > reserve.available_sats) { %> |
| 67 | + <p class="muted small" style="margin-top:0.75em;color:#c66"> |
| 68 | + ⚠ Reserve is short by |
| 69 | + <%= fmtSats(totals.owed - reserve.available_sats) %>. |
| 70 | + The payout worker will keep skipping ticks until this is closed |
| 71 | + (deposit BTC into the reserve via the two-step deposit service). |
| 72 | + </p> |
| 73 | + <% } %> |
| 74 | + </section> |
| 75 | + |
| 76 | + <section class="card"> |
| 77 | + <h2>Per-worker balances</h2> |
| 78 | + <% if (workers.length === 0) { %> |
| 79 | + <p class="muted">No workers have a PPS balance yet.</p> |
| 80 | + <% } else { %> |
| 81 | + <table> |
| 82 | + <thead> |
| 83 | + <tr> |
| 84 | + <th>Worker</th> |
| 85 | + <th>Thunder address</th> |
| 86 | + <th>Owed</th> |
| 87 | + <th>Accrued</th> |
| 88 | + <th>Paid</th> |
| 89 | + <th>Updated</th> |
| 90 | + </tr> |
| 91 | + </thead> |
| 92 | + <tbody> |
| 93 | + <% workers.forEach(w => { %> |
| 94 | + <tr> |
| 95 | + <td class="mono small"><%= w.worker_name %></td> |
| 96 | + <td class="mono small"><%= w.thunder_address %></td> |
| 97 | + <td><strong><%= fmtSats(w.owed) %></strong></td> |
| 98 | + <td><%= fmtSats(w.accrued) %></td> |
| 99 | + <td><%= fmtSats(w.paid) %></td> |
| 100 | + <td class="muted small" title="<%= fmtTs(w.last_updated) %>"><%= ago(w.last_updated) %></td> |
| 101 | + </tr> |
| 102 | + <% }) %> |
| 103 | + </tbody> |
| 104 | + </table> |
| 105 | + <% } %> |
| 106 | + </section> |
| 107 | + |
| 108 | + <section class="card"> |
| 109 | + <h2>In-flight payouts</h2> |
| 110 | + <% if (inFlight.length === 0) { %> |
| 111 | + <p class="muted">Nothing in flight — clean.</p> |
| 112 | + <% } else { %> |
| 113 | + <p class="muted small"> |
| 114 | + Rows here need operator attention. Empty <em>txid</em> |
| 115 | + means the Thunder broadcast may not have gone out; a |
| 116 | + set <em>txid</em> means the broadcast succeeded but the |
| 117 | + DB finalize crashed. Never auto-resolved. |
| 118 | + </p> |
| 119 | + <table> |
| 120 | + <thead> |
| 121 | + <tr> |
| 122 | + <th>#</th> |
| 123 | + <th>Worker</th> |
| 124 | + <th>Amount</th> |
| 125 | + <th>Age</th> |
| 126 | + <th>txid</th> |
| 127 | + <th>State</th> |
| 128 | + </tr> |
| 129 | + </thead> |
| 130 | + <tbody> |
| 131 | + <% inFlight.forEach(r => { %> |
| 132 | + <tr> |
| 133 | + <td><%= r.id %></td> |
| 134 | + <td class="mono small"><%= r.worker_name %></td> |
| 135 | + <td><%= fmtSats(r.sats) %></td> |
| 136 | + <td class="muted small" title="<%= fmtTs(r.started_at) %>"><%= ago(r.started_at) %></td> |
| 137 | + <td class="mono small"><%= r.txid || '—' %></td> |
| 138 | + <td><%= r.txid ? 'broadcast, finalize pending' : 'unbroadcast' %></td> |
| 139 | + </tr> |
| 140 | + <% }) %> |
| 141 | + </tbody> |
| 142 | + </table> |
| 143 | + <% } %> |
| 144 | + </section> |
| 145 | + </main> |
| 146 | + <footer class="foot"> |
| 147 | + <span>read-only · auto-refresh 15s</span> |
| 148 | + <span class="sep">·</span> |
| 149 | + <span>pool operator view</span> |
| 150 | + </footer> |
| 151 | +</body> |
| 152 | +</html> |
0 commit comments