-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplorer.html
More file actions
786 lines (760 loc) · 37.1 KB
/
Copy pathexplorer.html
File metadata and controls
786 lines (760 loc) · 37.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>HackMe Explorer · Pool</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Orbitron:wght@500;700&display=swap" rel="stylesheet" />
<style>
:root {
color-scheme: dark;
--bg: #05070b;
--panel: #0a1019;
--border: #1a2538;
--neon: #7fe7ff;
--matrix: #93ffb1;
--warn: #ffd37a;
--muted: #7b8aa4;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: Inter, system-ui, sans-serif;
background: radial-gradient(ellipse 120% 80% at 50% -20%, rgba(127, 231, 255, 0.08), transparent 55%), var(--bg);
color: #dce3ef;
min-height: 100vh;
}
.topbar {
border-bottom: 1px solid var(--border);
background: rgba(10, 16, 25, 0.92);
backdrop-filter: blur(8px);
position: sticky;
top: 0;
z-index: 20;
}
.topbar-inner {
max-width: 1200px;
margin: 0 auto;
padding: 12px 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
}
.brand {
font-family: Orbitron, sans-serif;
font-weight: 700;
font-size: 15px;
letter-spacing: 0.12em;
color: var(--neon);
text-decoration: none;
}
.nav-links { display: flex; gap: 14px; font-size: 12px; }
.nav-links a { color: var(--muted); text-decoration: none; }
.nav-links a:hover { color: var(--neon); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px; }
.hero { margin-bottom: 18px; }
.hero h1 {
margin: 0 0 6px;
font-family: Orbitron, sans-serif;
font-size: 26px;
font-weight: 700;
letter-spacing: 0.06em;
background: linear-gradient(90deg, #d9f1ff, var(--neon));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.row { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.card {
border: 1px solid var(--border);
border-radius: 12px;
background: linear-gradient(145deg, rgba(127, 231, 255, 0.04), transparent 40%), var(--panel);
padding: 14px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.value { font-size: 22px; font-weight: 700; margin-top: 6px; color: var(--neon); font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.title { font-size: 14px; font-weight: 700; margin: 0 0 10px; color: #d9f1ff; font-family: Orbitron, sans-serif; letter-spacing: 0.04em; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 8px; border-bottom: 1px solid #182233; text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.mono { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
input, button {
background: #0b1320;
color: #dce3ef;
border: 1px solid #26354d;
border-radius: 8px;
padding: 8px 10px;
font-size: 12px;
}
input:focus { outline: none; border-color: rgba(127, 231, 255, 0.45); box-shadow: 0 0 0 2px rgba(127, 231, 255, 0.12); }
button { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
button:hover { border-color: var(--neon); background: rgba(127, 231, 255, 0.08); }
.badge { border: 1px solid #2b3b54; border-radius: 999px; padding: 3px 10px; font-size: 10px; color: #8ea3c2; white-space: nowrap; }
.ok { color: var(--matrix); border-color: #24583a; background: rgba(147, 255, 177, 0.06); }
.warn { color: var(--warn); border-color: #5b4723; background: rgba(255, 211, 122, 0.06); }
.clickable { cursor: pointer; }
.clickable:hover { background: rgba(127, 231, 255, 0.06); }
.result-card { border: 1px solid #21314a; border-radius: 10px; background: #0a1320; padding: 10px; }
.result-title { font-size: 12px; color: #9eb6d8; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.result-grid { display: grid; grid-template-columns: 180px 1fr; gap: 6px 10px; }
.result-key { color: var(--muted); font-size: 12px; }
.result-val { color: #dce3ef; font-size: 13px; word-break: break-word; }
.result-highlight { color: var(--neon); font-weight: 700; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--matrix); box-shadow: 0 0 8px var(--matrix); margin-right: 6px; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.worker-online { color: var(--matrix); }
.worker-off { color: #5a6a82; }
@media (max-width: 1200px) { .row { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr; } }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<header class="topbar">
<div class="topbar-inner">
<a class="brand" href="/">HACKME</a>
<nav class="nav-links" id="explorer-nav">
<a href="https://hackme.tech/" data-nav="site">Site</a>
<a href="/" data-nav="dashboard">Dashboard</a>
<a href="/explorer" data-nav="explorer" style="color:var(--neon)">Explorer</a>
</nav>
</div>
</header>
<div class="wrap">
<div class="hero">
<h1><span class="live-dot"></span>HackMe Explorer</h1>
<p class="muted" style="margin:0;">Chain: <span class="mono">{{.ChainID}}</span> · Node: <span class="mono">{{.NodeID}}</span> · auto-refresh 5s</p>
</div>
<p id="explorer-wallet-path" class="muted mono" style="margin:0 0 14px;font-size:11px;line-height:1.45;">—</p>
<p class="muted" style="margin:0 0 14px;line-height:1.45;max-width:960px;" title="Block miner field = signing node HMC-…; dashboard wallet and pool accrual are separate until settled.">
<strong style="color:#b7c3d8;">PoH block “miner”</strong> — signing node address (<span class="mono">HMC-…</span>); dashboard wallet and pool accrual are tracked separately until settled.
</p>
<div class="grid2" style="margin-bottom:12px;">
<section class="card">
<div class="toolbar">
<h2 class="title" style="margin-right:auto;">Find TX / Task / Block</h2>
<input id="in-tx" placeholder="tx hash | task id | block hash prefix" class="mono" style="flex:1;min-width:220px;" />
<button id="btn-find-tx">Find</button>
</div>
<div id="tx-result" class="muted" style="margin:0;">—</div>
</section>
<section class="card">
<div class="toolbar">
<h2 class="title" style="margin-right:auto;">Address State</h2>
<input id="in-addr" placeholder="HMC-..." class="mono" style="flex:1;min-width:220px;" />
<button id="btn-find-addr">Find</button>
</div>
<pre id="addr-result" class="mono muted" style="white-space:pre-wrap;margin:0;">—</pre>
</section>
</div>
<div class="row">
<div class="card" id="kpi-height-card" title=""><div class="label" id="kpi-height-label">Chain height</div><div id="kpi-height" class="value">—</div></div>
<div class="card" id="kpi-tip-card" title=""><div class="label" id="kpi-tip-label">Chain head hash</div><div id="kpi-tip" class="value mono" style="font-size:15px;">—</div></div>
<div class="card" id="kpi-target-card" title="Pool PoH target from coordinator or canonical /api/metrics (same source as miners on VPS).">
<div class="label">PoH target (pool)</div><div id="kpi-pool-target" class="value mono" style="font-size:18px;">—</div>
</div>
<div class="card"><div class="label">Pending TX</div><div id="kpi-txpool" class="value">—</div></div>
<div class="card"><div class="label">Updated</div><div id="kpi-updated" class="value" style="font-size:16px;color:#b7c3d8;">—</div></div>
</div>
<div id="kpi-secondary-row" style="display:none;margin-top:8px;">
<div class="card"><div class="label">Local SQLite ledger (same DB as “Recent blocks”)</div><div id="kpi-local-pair" class="value mono" style="font-size:14px;color:#b7c3d8;">—</div></div>
</div>
<div class="toolbar" style="margin-bottom:12px;">
<span id="kpi-net-state" class="badge">node status: loading</span>
<span id="kpi-chain-sync" class="badge">chain sync: loading</span>
<span id="kpi-mining-producer" class="badge">local WASM producer: loading</span>
<span id="kpi-data-source" class="badge">data source: loading</span>
<span id="kpi-pool-strip" class="badge">pool lane: loading</span>
<span id="kpi-policy-hash" class="badge">policy: loading</span>
<span id="kpi-p2p-lag" class="badge" title="P2P peer height vs local SQLite (GET /api/status → network_sync)">P2P lag: n/a</span>
<span id="kpi-release" class="badge">release: …</span>
</div>
<section class="card" style="margin-bottom:12px;">
<div class="toolbar">
<h2 class="title" style="margin-right:auto;">Coordinator workers (live)</h2>
<button id="btn-refresh-workers" type="button">Refresh</button>
</div>
<table>
<thead><tr><th></th><th>Worker</th><th>Ranges</th><th>Attempts</th><th>Payout (accrued)</th></tr></thead>
<tbody id="workers-body"><tr><td colspan="5" class="muted">loading…</td></tr></tbody>
</table>
<p id="workers-note" class="muted" style="margin:8px 0 0;font-size:11px;">Pool miners = payout addresses; coord workers = registered rigs on coordinator.</p>
</section>
<div class="grid2">
<section class="card">
<p id="blocks-sync-note" class="muted" style="display:none;margin:0 0 10px;line-height:1.5;border-left:3px solid #5b4723;padding-left:10px;"></p>
<div class="toolbar">
<h2 class="title" style="margin-right:auto;">Recent Blocks</h2>
<button id="btn-refresh-blocks">Refresh</button>
</div>
<table>
<thead><tr><th>#</th><th>Time</th><th>Task</th><th>Task ID</th><th>Hash</th></tr></thead>
<tbody id="blocks-body"></tbody>
</table>
</section>
<section class="card">
<div class="toolbar">
<h2 class="title" style="margin-right:auto;">Transfer Pool</h2>
<button id="btn-refresh-tx">Refresh</button>
</div>
<table>
<thead><tr><th>Status</th><th>From</th><th>To</th><th>Amount</th><th>Nonce</th></tr></thead>
<tbody id="tx-body"></tbody>
</table>
</section>
</div>
</div>
<script>
const $ = (id) => document.getElementById(id);
const fmtTs = (u) => !u ? "—" : new Date(Number(u) * 1000).toISOString().replace("T"," ").replace(".000Z","Z");
const short = (s, n=16) => { s = String(s || ""); return s.length > n ? s.slice(0,n) + "…" : s; };
const hmc = (u) => (Number(u || 0) / 1e8).toFixed(8);
const esc = (s) => String(s || '').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
/** Public nginx proxies pool APIs under /pool/api; node adds coordinator token server-side. */
function apiUrl(path) {
const p = path.startsWith('/') ? path : '/' + path;
const host = String(location.hostname || '').toLowerCase();
if (host === 'hackme.tech' || host === 'www.hackme.tech' || String(location.pathname || '').indexOf('/pool/') === 0) {
return '/pool/api' + p;
}
return '/api' + p;
}
const isPublicWallet = (v) => String(v || '').trim().startsWith('HMC-');
const displayMinerFromBlock = (v) => {
const t = String(v || '').trim();
return t ? t : 'not available';
};
function renderLookupCard(title, rows) {
const htmlRows = rows.map((r) =>
'<div class="result-key">' + esc(r.key) + '</div>' +
'<div class="result-val ' + (r.highlight ? 'result-highlight' : '') + ' mono">' + esc(r.value) + '</div>'
).join('');
return '<section class="result-card"><div class="result-title">' + esc(title) + '</div><div class="result-grid">' + htmlRows + '</div></section>';
}
let pollInFlight = false;
/** Filled by refreshTop for refreshBlocks: note when canonical tip ≠ local blocks source. */
let explorerBlocksSyncNote = '';
function fetchJsonTimeout(path, ms) {
const ctrl = new AbortController();
const t = setTimeout(() => ctrl.abort(), ms);
return fetch(path, { cache: 'no-store', signal: ctrl.signal })
.finally(() => clearTimeout(t));
}
/** Match dashboard: GH/s below 1 TH/s (0.116 TH/s → ~116 GH/s). */
function fmtPoolAggTHS(ths) {
const th = Number(ths);
if (!Number.isFinite(th) || th <= 0) return '—';
if (th < 1) {
const gh = th * 1000;
const ghStr = gh < 0.01 ? gh.toFixed(4) : (gh < 1 ? gh.toFixed(2) : gh.toFixed(1));
return ghStr + ' GH/s';
}
return (th < 1 ? th.toFixed(3) : th.toFixed(2)) + ' TH/s';
}
function applyStatusPayload(s) {
if (!s || typeof s !== 'object') return;
const localTip = Number(s.tip_height || 0);
const localHash = String(s.tip_hash || '').trim();
const canonTip = Number(s.canonical_tip_height || 0);
const canonHash = String(s.canonical_tip_hash || '').trim();
const canonOk = !!(s.canonical_tip_ok && canonTip > 0 && canonHash.length > 0);
const netMode = !!s.network_mode_active;
const emptyLocal = canonOk && localTip === 0 && canonTip > 0;
const diverged = canonOk && localTip > 0 && canonTip > 0 && localTip !== canonTip;
const useCanonPrimary = netMode && canonOk;
let primaryH = localTip;
let primaryHash = localHash;
let primaryLabel = 'Local SQLite ledger';
if (useCanonPrimary) {
primaryH = canonTip;
primaryHash = canonHash;
primaryLabel = 'Public canonical chain (HACKME_CANONICAL_CHAIN_URL / peer)';
} else if (netMode && !canonOk) {
primaryLabel = 'Local SQLite (canonical tip unavailable — check canonical URL / network)';
}
$('kpi-height').textContent = String(primaryH || 0);
$('kpi-tip').textContent = short(primaryHash || '—', 22);
const poolTM = Number(s.pool_target_mod || 0);
const poolLoadHint = Number(s.pool_target_mod_load_hint || 0);
const poolLoadCapped = s.pool_target_mod_load_capped === true;
const poolTH = Number(s.pool_global_hashrate_th_s || 0);
const poolSrc = String(s.pool_target_mod_source || '').trim();
const ptEl = $('kpi-pool-target');
if (ptEl) {
ptEl.textContent = poolTM > 0 ? String(poolTM) : '—';
}
const poolStrip = $('kpi-pool-strip');
if (poolStrip) {
if (poolTM > 0) {
const th = fmtPoolAggTHS(poolTH);
const miners = Number(s.pool_total_miners || 0);
const wk = Number(s.pool_workers_count || 0);
const minerLbl = miners > 0 ? ('payout addrs ' + miners) : 'miners n/a';
const wkLbl = wk > 0 ? ('workers ' + wk) : '';
poolStrip.textContent = 'pool: target ' + poolTM + ' · hash ' + th + ' · ' + minerLbl + (wkLbl ? (' · ' + wkLbl) : '');
poolStrip.className = 'badge ok';
let poolTitle = poolSrc ? ('target_mod from ' + poolSrc) : 'pool lane from /api/status';
if (poolLoadHint > poolTM * 1.02) {
poolTitle += ' · load hint ~' + poolLoadHint + (poolLoadCapped ? ' (applied M capped)' : '');
}
poolStrip.title = poolTitle;
} else {
poolStrip.textContent = 'pool: target unavailable (set coordinator URL or canonical for metrics)';
poolStrip.className = 'badge warn';
poolStrip.title = String(s.pool_work_stats_error || s.pool_network_stats_error || 'no pool_target_mod on status');
}
}
const hLab = $('kpi-height-label');
const tLab = $('kpi-tip-label');
const hCard = $('kpi-height-card');
const tCard = $('kpi-tip-card');
if (hLab) hLab.textContent = useCanonPrimary ? 'Chain height (canonical)' : 'Chain height';
if (tLab) tLab.textContent = useCanonPrimary ? 'Chain head hash (canonical)' : 'Chain head hash';
const pairTitle = primaryLabel + ' — height and head hash always match the same source.';
if (hCard) hCard.title = pairTitle;
if (tCard) tCard.title = pairTitle;
const secRow = $('kpi-secondary-row');
const secPair = $('kpi-local-pair');
if (useCanonPrimary && (diverged || emptyLocal) && secRow && secPair) {
secRow.style.display = 'grid';
secPair.textContent = emptyLocal
? ('empty (height 0) — canonical at ' + canonTip)
: ('height ' + localTip + ' · head ' + short(localHash, 28));
} else if (secRow) {
secRow.style.display = 'none';
}
if (useCanonPrimary && (emptyLocal || diverged)) {
explorerBlocksSyncNote = emptyLocal
? ('Recent blocks: local SQLite is empty while canonical height is ' + canonTip + '. Enable P2P + state replay or follower bootstrap — pool mining still works.')
: ('Recent blocks: local SQLite height ' + localTip + ' vs canonical ' + canonTip + '. Sync ledger or use public node /explorer.');
}
const net = $('kpi-net-state');
const source = $('kpi-data-source');
const policy = $('kpi-policy-hash');
if (net) {
const mode = s.network_mode_active ? 'network mode' : 'solo mode';
net.textContent = 'node status: ' + mode;
net.className = 'badge ' + (s.network_mode_active ? 'ok' : 'warn');
}
const chainSync = $('kpi-chain-sync');
const minProd = $('kpi-mining-producer');
if (chainSync) {
if (useCanonPrimary && emptyLocal) {
chainSync.textContent = 'chain sync: local SQLite empty · canonical ' + canonTip;
chainSync.className = 'badge warn';
} else if (useCanonPrimary && canonOk && !diverged) {
chainSync.textContent = 'chain sync: aligned (canonical tip matches local height)';
chainSync.className = 'badge ok';
} else if (useCanonPrimary && diverged) {
chainSync.textContent = 'chain sync: local ledger behind canonical (see secondary row)';
chainSync.className = 'badge warn';
} else if (netMode && !canonOk) {
chainSync.textContent = 'chain sync: canonical tip unavailable';
chainSync.className = 'badge warn';
} else {
chainSync.textContent = 'chain sync: standalone ledger (not public-joined)';
chainSync.className = 'badge warn';
}
}
if (minProd) {
minProd.textContent = 'local WASM producer: ' + (s.mining ? 'running' : 'idle');
minProd.className = 'badge ' + (s.mining ? 'ok' : 'warn');
}
const rel = $('kpi-release');
if (rel) {
const ver = String(s.version || 'dev').trim();
rel.textContent = 'release: ' + (ver.length > 18 ? ver.slice(0, 16) + '…' : ver);
rel.className = 'badge ok';
rel.title = ver;
}
if (source) {
if (useCanonPrimary) {
if (emptyLocal) {
source.textContent = 'tip view: canonical ' + canonTip + ' · local SQLite empty';
source.className = 'badge warn';
source.title = 'KPIs show public chain. Recent blocks are local DB until P2P/bootstrap sync.';
} else if (diverged) {
source.textContent = 'tip view: canonical · local ledger ' + localTip + ' (see row below)';
source.className = 'badge warn';
source.title = 'Top row shows the public chain tip. Secondary row shows local SQLite; sync to align.';
} else {
source.textContent = 'tip view: canonical matches local ' + localTip;
source.className = 'badge ok';
source.title = 'Local and canonical tips are the same height.';
}
} else {
source.textContent = 'tip view: local SQLite · height ' + localTip;
source.className = 'badge ' + (netMode && !canonOk ? 'warn' : 'ok');
source.title = netMode && !canonOk
? 'Network mode is on but canonical tip could not be read; KPIs show local ledger only.'
: 'Height and hash are from this node database.';
}
}
if (policy) {
const ph = String((s.economics && s.economics.policy_hash) || '');
const shortPh = ph ? (ph.slice(0, 12) + '…') : 'n/a';
policy.textContent = 'policy: ' + shortPh;
policy.className = 'badge ' + (ph ? 'ok' : 'warn');
policy.title = ph || 'Policy hash unavailable';
}
const p2pLagEl = $('kpi-p2p-lag');
if (p2pLagEl) {
const ns = s.network_sync || {};
const ph = ns.p2p_sync_hint || {};
const lag = Number(ph.lag_blocks || 0);
const p2pOn = !!ns.p2p_enabled;
const bg = Number(ns.background_sync_interval_sec || 0);
if (!p2pOn) {
p2pLagEl.textContent = 'P2P lag: (peers off)';
p2pLagEl.className = 'badge';
p2pLagEl.title = 'Set HACKME_P2P_PEERS to enable follower height hints.';
} else if (lag > 0) {
p2pLagEl.textContent = 'P2P lag: ' + lag + ' blocks' + (bg > 0 ? ' · auto-sync ' + bg + 's' : '');
p2pLagEl.className = 'badge warn';
p2pLagEl.title = 'Local SQLite behind healthy P2P peer. Enable state replay + optional HACKME_P2P_BACKGROUND_SYNC_SEC on followers.';
} else {
p2pLagEl.textContent = 'P2P lag: aligned' + (bg > 0 ? ' · sync ' + bg + 's' : '');
p2pLagEl.className = 'badge ok';
p2pLagEl.title = 'Local height matches P2P peer snapshot (or no peer data yet).';
}
}
}
function applyWorkStatsPayload(j) {
if (!j || typeof j !== 'object') return;
const tm = Number(j.target_mod || 0);
if (tm > 0 && $('kpi-pool-target')) $('kpi-pool-target').textContent = String(tm);
const poolStrip = $('kpi-pool-strip');
if (poolStrip && tm > 0) {
let poolGh = Number(j.pool_hashrate_gh_s || 0);
if (!(poolGh > 0)) {
const rigs = Array.isArray(j.active_rigs) ? j.active_rigs : [];
rigs.forEach((r) => { poolGh += Number((r && r.hashrate_gh_s) || 0); });
}
const th = poolGh > 0 ? (poolGh / 1000) : Number(j.pool_global_hashrate_th_s || 0);
const miners = Number(j.workers_count || Object.keys(j.workers || {}).length || 0);
poolStrip.textContent = 'pool: target ' + tm + ' · hash ' + fmtPoolAggTHS(th) + ' · workers ' + miners;
poolStrip.className = 'badge ok';
poolStrip.title = 'from /api/work/stats';
}
}
async function refreshTop() {
explorerBlocksSyncNote = '';
const stamp = () => {
if ($('kpi-updated')) $('kpi-updated').textContent = new Date().toISOString().replace('T', ' ').slice(0, 19) + 'Z';
};
try {
const [liteR, poolR, workR] = await Promise.all([
fetchJsonTimeout(apiUrl('/status?lite=1'), 4000).catch(() => null),
fetchJsonTimeout(apiUrl('/tx/pool'), 5000).catch(() => null),
fetchJsonTimeout(apiUrl('/work/stats'), 6000).catch(() => null),
]);
if (liteR && liteR.ok) applyStatusPayload(await liteR.json());
if (poolR && poolR.ok) {
const p = await poolR.json();
if ($('kpi-txpool')) $('kpi-txpool').textContent = String((p.txs || []).length);
}
if (workR && workR.ok) applyWorkStatsPayload(await workR.json());
stamp();
} catch (e) {
if ($('kpi-updated')) $('kpi-updated').textContent = 'refresh error';
const net = $('kpi-net-state');
if (net) { net.textContent = 'node status: error'; net.className = 'badge warn'; }
}
void fetchJsonTimeout(apiUrl('/status'), 20000).then(async (statusR) => {
if (statusR && statusR.ok) applyStatusPayload(await statusR.json());
}).catch(() => {});
void fetchJsonTimeout(apiUrl('/wallet'), 4000).then(async (wr) => {
const meta = $('explorer-wallet-path');
if (!meta || !wr || !wr.ok) return;
try {
const j = await wr.json();
const db = j.database_file ? String(j.database_file) : '';
const fee = j.transfer_fee_platform_address ? String(j.transfer_fee_platform_address) : '';
meta.textContent = (db ? ('Wallet DB: ' + db) : 'Wallet DB: (see /api/wallet)') +
(fee ? (' · transfer fee platform addr: ' + fee) : '');
} catch (_) {}
}).catch(() => {});
}
async function refreshWorkers() {
const tb = $('workers-body');
const note = $('workers-note');
if (!tb) return;
try {
const r = await fetchJsonTimeout(apiUrl('/work/stats?details=1'), 8000);
if (!r.ok) throw new Error('HTTP ' + r.status);
const j = await r.json();
const workers = j.workers || {};
const ids = Object.keys(workers).sort();
tb.innerHTML = '';
if (!ids.length) {
tb.innerHTML = '<tr><td colspan="5" class="muted">no workers on coordinator</td></tr>';
return;
}
ids.forEach((id) => {
const w = workers[id] || {};
const live = w.live || {};
const seen = Number(w.last_seen_unix || live.last_seen_unix || 0);
const gh = Number(w.hashrate_gh_s || live.hashrate_gh_s || 0);
const pruned = w.coordinator_pruned === true;
const localOnly = w.local_pool_worker === true;
const online = !pruned && (!!(live.online) || localOnly || gh > 0.001 || (seen > 0 && (Math.floor(Date.now() / 1000) - seen) < 120));
const ranges = Number(w.accepted_ranges ?? w.ranges ?? 0);
const attempts = Number(w.accepted_attempts ?? w.attempts ?? 0);
const payout = Number(w.payout_hmc ?? w.payout ?? 0);
const tr = document.createElement('tr');
const nameSuffix = pruned ? ' <span class="muted">(mirror)</span>' : (localOnly ? ' <span class="muted">(local)</span>' : '');
tr.innerHTML =
'<td class="' + (online ? 'worker-online' : 'worker-off') + '">' + (online ? '●' : '○') + '</td>' +
'<td class="mono">' + esc(id) + nameSuffix + '</td>' +
'<td class="mono">' + String(ranges) + '</td>' +
'<td class="mono">' + String(attempts) + '</td>' +
'<td class="mono">' + payout.toFixed(6) + '</td>';
tb.appendChild(tr);
});
if (note) {
const wc = Number(j.workers_count || ids.length);
const stale = j.stale === true ? (' · stale ' + Number(j.stale_sec || 0) + 's') : '';
const desk = String(j.desktop_worker_id || '').trim();
const injected = j.desktop_worker_injected === true;
let extra = '';
if (injected && desk) extra = ' · ' + desk + ' shown from local mirror (re-start pool worker to re-register on coordinator)';
note.textContent = 'Registered coordinator workers: ' + wc + ' · pool attempts ' + String(j.accepted_attempts || 0) + stale + extra;
}
} catch (e) {
tb.innerHTML = '<tr><td colspan="5" class="muted">' + esc(String(e.message || 'unavailable')) + '</td></tr>';
if (note) note.textContent = 'Coordinator workers unavailable — check pool API path (/pool/api on hackme.tech).';
}
}
async function refreshBlocks() {
const noteEl = $('blocks-sync-note');
const r = await fetchJsonTimeout(apiUrl('/reports/blocks?limit=20&source=auto'), 6000);
const tb = $('blocks-body');
if (!tb) return;
tb.innerHTML = '';
if (!r.ok) {
tb.innerHTML = '<tr><td colspan="5" class="muted">failed to load</td></tr>';
return;
}
const j = await r.json();
const src = String(j.blocks_source || 'local_ledger');
if (noteEl) {
if (src === 'canonical_peer') {
noteEl.style.display = 'block';
noteEl.textContent = String(j.note || 'Block list proxied from canonical command node.').trim();
} else if (explorerBlocksSyncNote) {
noteEl.style.display = 'block';
noteEl.textContent = explorerBlocksSyncNote;
} else {
noteEl.style.display = 'none';
noteEl.textContent = '';
}
}
const rows = j.blocks || [];
if (!rows.length) {
tb.innerHTML = '<tr><td colspan="5" class="muted">no blocks</td></tr>';
return;
}
rows.forEach((b) => {
const tr = document.createElement('tr');
tr.className = 'clickable';
tr.title = 'Click to copy task id into TX search';
tr.addEventListener('click', () => {
const v = String(b.task_id || '').trim();
if (v) {
$('in-tx').value = v;
}
});
tr.innerHTML =
'<td class="mono">' + String(b.index || 0) + '</td>' +
'<td class="mono">' + fmtTs(b.timestamp_unix) + '</td>' +
'<td>' + esc(String(b.task_kind || '—')) + '</td>' +
'<td class="mono">' + esc(short(b.task_id || '—', 20)) + '</td>' +
'<td class="mono">' + esc(String(b.hash_prefix || '—')) + '</td>';
tb.appendChild(tr);
});
}
async function refreshTxPool() {
const r = await fetchJsonTimeout(apiUrl('/tx/pool'), 5000);
const tb = $('tx-body');
if (!tb) return;
tb.innerHTML = '';
if (!r.ok) {
tb.innerHTML = '<tr><td colspan="5" class="muted">failed to load</td></tr>';
return;
}
const j = await r.json();
const rows = j.txs || [];
if (!rows.length) {
tb.innerHTML = '<tr><td colspan="5" class="muted">no pending tx</td></tr>';
return;
}
rows.slice(0, 50).forEach((tx) => {
const tr = document.createElement('tr');
tr.className = 'clickable';
tr.title = 'Click to inspect sender/receiver';
tr.addEventListener('click', () => {
const from = String(tx.from || '').trim();
const to = String(tx.to || '').trim();
const pick = from || to;
if (pick) {
$('in-addr').value = pick;
void findAddr();
}
});
tr.innerHTML =
'<td>' + esc(String(tx.status || 'pending')) + '</td>' +
'<td class="mono">' + esc(short(tx.from || '—', 14)) + '</td>' +
'<td class="mono">' + esc(short(tx.to || '—', 14)) + '</td>' +
'<td class="mono">' + hmc(tx.amount_units) + '</td>' +
'<td class="mono">' + String(tx.nonce || 0) + '</td>';
tb.appendChild(tr);
});
}
async function findTx() {
const query = String($('in-tx').value || '').trim();
if (!query) return;
const out = $('tx-result');
out.innerHTML = '<span class="muted">loading...</span>';
// 1) First try strict TX lookup.
try {
const txR = await fetch(apiUrl('/tx/' + encodeURIComponent(query)), { cache: 'no-store' });
if (txR.ok) {
const tx = await txR.json();
const recipient = String(tx.to || '').trim();
out.innerHTML = renderLookupCard('Transaction match', [
{ key: 'Lookup type', value: 'tx_hash' },
{ key: 'Query', value: query },
{ key: 'Status', value: String(tx.status || 'unknown') },
{ key: 'TX hash', value: String(tx.tx_hash || query), highlight: true },
{ key: 'Recipient wallet', value: isPublicWallet(recipient) ? recipient : 'not available' }, // transfer: only public HMC- shown
{ key: 'Included in block', value: String(tx.block_index || 'pending') },
]);
return;
}
} catch (_) {}
// 2) Fallback: search recent blocks by task_id or hash_prefix.
try {
const blocksR = await fetch(apiUrl('/reports/blocks?limit=400'), { cache: 'no-store' });
if (blocksR.ok) {
const blocksJ = await blocksR.json();
const rows = blocksJ.blocks || [];
const q = query.toLowerCase();
const hit = rows.find((b) => {
const taskId = String(b.task_id || '').toLowerCase();
const hashPrefix = String(b.hash_prefix || '').toLowerCase();
return taskId === q || taskId.includes(q) || hashPrefix.startsWith(q) || hashPrefix.includes(q);
});
if (hit) {
let minerWallet = String(hit.miner_address || '').trim();
if (!minerWallet) {
try {
const br = await fetch(apiUrl('/reports/block?index=' + encodeURIComponent(String(hit.index))), { cache: 'no-store' });
if (br.ok) {
const one = await br.json();
minerWallet = String(one.miner_address || '').trim();
}
} catch (_) {}
}
if (!minerWallet) {
try {
const chainR = await fetch(apiUrl('/chain?limit=500'), { cache: 'no-store' });
if (chainR.ok) {
const cj = await chainR.json();
const blocks = cj.blocks || [];
const want = Number(hit.index);
const full = blocks.find((b) => Number(b.index) === want);
minerWallet = String((full && (full.miner_address_effective || full.miner_address)) || '').trim();
}
} catch (_) {}
}
out.innerHTML = renderLookupCard('Block / task match', [
{ key: 'Lookup type', value: 'block_task_or_hash' },
{ key: 'Query', value: query },
{ key: 'Block index', value: String(hit.index || 0), highlight: true },
{ key: 'Task kind', value: String(hit.task_kind || '—') },
{ key: 'Task ID', value: String(hit.task_id || '—') },
{ key: 'Block hash prefix', value: String(hit.hash_prefix || '—') },
{ key: 'Timestamp', value: fmtTs(hit.timestamp_unix) },
{ key: 'Miner / reward address', value: displayMinerFromBlock(minerWallet) },
{ key: 'Note', value: 'On-chain mint credits this miner address + node wallet row; another HMC- label with balance 0 simply never received mints/transfers.' },
]);
return;
}
}
} catch (_) {}
out.innerHTML = '<span class="muted">Not found in tx hash or recent block/task index.</span>';
}
async function findAddr() {
const addr = String($('in-addr').value || '').trim();
if (!addr) return;
const out = $('addr-result');
out.textContent = 'loading...';
const r = await fetch(apiUrl('/address/' + encodeURIComponent(addr)), { cache: 'no-store' });
if (!r.ok) {
out.textContent = 'not found';
return;
}
const j = await r.json();
const units = Number(j.balance_units || 0);
const hmcBal = (units / 1e8).toFixed(8);
out.textContent = JSON.stringify({
...j,
balance_hmc_estimate: hmcBal,
}, null, 2);
}
$('btn-refresh-blocks').addEventListener('click', refreshBlocks);
$('btn-refresh-tx').addEventListener('click', refreshTxPool);
const btnWk = $('btn-refresh-workers');
if (btnWk) btnWk.addEventListener('click', refreshWorkers);
$('btn-find-tx').addEventListener('click', findTx);
$('btn-find-addr').addEventListener('click', findAddr);
$('in-tx').addEventListener('keydown', (ev) => {
if (ev.key === 'Enter') {
ev.preventDefault();
findTx();
}
});
$('in-addr').addEventListener('keydown', (ev) => {
if (ev.key === 'Enter') {
ev.preventDefault();
findAddr();
}
});
async function refreshAll() {
if (pollInFlight) return;
pollInFlight = true;
try {
await Promise.all([refreshTop(), refreshBlocks(), refreshTxPool(), refreshWorkers()]);
} finally {
pollInFlight = false;
}
}
setInterval(() => { void refreshAll(); }, 5000);
void refreshAll();
(function wireExplorerNav() {
const host = String(location.hostname || '').toLowerCase();
const onPublic = host === 'hackme.tech' || host === 'www.hackme.tech';
const dash = document.querySelector('[data-nav="dashboard"]');
const site = document.querySelector('[data-nav="site"]');
const exp = document.querySelector('[data-nav="explorer"]');
if (onPublic) {
if (site) site.href = 'https://hackme.tech/';
if (dash) dash.href = 'https://hackme.tech/#downloads';
if (exp) exp.href = '/pool/explorer';
} else {
if (site) site.href = 'https://hackme.tech/';
if (dash) dash.href = '/';
if (exp) exp.href = '/explorer';
}
})();
</script>
</body>
</html>