forked from Scottcjn/Rustchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboard.html
More file actions
291 lines (255 loc) · 9.12 KB
/
leaderboard.html
File metadata and controls
291 lines (255 loc) · 9.12 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RustChain Miner Leaderboard</title>
<link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0a0a;
--surface: #1a1a1a;
--primary: #00ff41;
--text: #e0e0e0;
--gold: #ffd700;
--silver: #c0c0c0;
--bronze: #cd7f32;
}
body {
font-family: 'Space Mono', monospace;
background: var(--bg);
color: var(--text);
margin: 0;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
header {
text-align: center;
margin-bottom: 40px;
}
h1 {
color: var(--primary);
text-transform: uppercase;
letter-spacing: 2px;
margin: 0;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 40px;
}
.card {
background: var(--surface);
padding: 20px;
border-radius: 8px;
border: 1px solid #333;
text-align: center;
}
.card h3 {
margin: 0 0 10px 0;
font-size: 0.8rem;
color: #888;
text-transform: uppercase;
}
.card .value {
font-size: 1.5rem;
font-weight: bold;
color: var(--primary);
}
table {
width: 100%;
border-collapse: collapse;
background: var(--surface);
border-radius: 8px;
overflow: hidden;
border: 1px solid #333;
}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #333;
}
th {
background: #252525;
color: #888;
font-size: 0.8rem;
text-transform: uppercase;
cursor: pointer;
}
th:hover {
color: var(--primary);
}
tr:hover {
background: #222;
}
.badge {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.7rem;
font-weight: bold;
text-transform: uppercase;
}
.badge-vintage { background: var(--gold); color: black; }
.badge-modern { background: var(--silver); color: black; }
.rank { font-weight: bold; width: 40px; }
.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: var(--bronze); }
.loading {
text-align: center;
padding: 40px;
color: var(--primary);
}
.error {
color: #ff4141;
text-align: center;
padding: 20px;
}
footer {
margin-top: 40px;
text-align: center;
font-size: 0.8rem;
color: #555;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>RustChain Leaderboard</h1>
<p>Live stats from the Proof-of-Antiquity network</p>
</header>
<div class="stats-grid" id="stats">
<div class="card">
<h3>Total Miners</h3>
<div class="value" id="stat-miners">-</div>
</div>
<div class="card">
<h3>Active Epoch</h3>
<div class="value" id="stat-epoch">-</div>
</div>
<div class="card">
<h3>Architecture Diversity</h3>
<div class="value" id="stat-diversity">-</div>
</div>
<div class="card">
<h3>Best Multiplier</h3>
<div class="value" id="stat-multiplier">-</div>
</div>
</div>
<div id="leaderboard-wrapper">
<table id="leaderboard">
<thead>
<tr>
<th onclick="sortTable(0)">Rank</th>
<th onclick="sortTable(1)">Miner</th>
<th onclick="sortTable(2)">Hardware</th>
<th onclick="sortTable(3)">Multiplier</th>
<th onclick="sortTable(4)">Last Activity</th>
</tr>
</thead>
<tbody id="leaderboard-body">
<tr>
<td colspan="5" class="loading">Initializing connection to Node 1...</td>
</tr>
</tbody>
</table>
</div>
<footer>
Data fetched from https://50.28.86.131/api/miners • Update every 60s
</footer>
</div>
<script>
const API_MINERS = 'https://50.28.86.131/api/miners';
const API_EPOCH = 'https://50.28.86.131/epoch';
async function fetchData() {
try {
const [minersRes, epochRes] = await Promise.all([
fetch(API_MINERS).catch(() => null),
fetch(API_EPOCH).catch(() => null)
]);
if (!minersRes) throw new Error('Could not connect to RustChain node');
const miners = await minersRes.json();
const epochData = await epochRes.json();
updateStats(miners, epochData);
updateTable(miners);
} catch (err) {
document.getElementById('leaderboard-body').innerHTML = `
<tr><td colspan="5" class="error">Error: ${err.message}<br>Make sure you've accepted the self-signed certificate at https://50.28.86.131</td></tr>
`;
}
}
function updateStats(miners, epochData) {
document.getElementById('stat-miners').textContent = miners.length;
document.getElementById('stat-epoch').textContent = epochData.epoch || '-';
const archs = new Set(miners.map(m => m.device_arch));
document.getElementById('stat-diversity').textContent = archs.size;
const maxMult = Math.max(...miners.map(m => m.antiquity_multiplier));
document.getElementById('stat-multiplier').textContent = maxMult.toFixed(1) + 'x';
}
function updateTable(miners) {
miners.sort((a, b) => b.antiquity_multiplier - a.antiquity_multiplier);
const tbody = document.getElementById('leaderboard-body');
tbody.innerHTML = '';
miners.forEach((m, i) => {
const tr = document.createElement('tr');
const isVintage = m.hardware_type.includes('Vintage');
const timeAgo = Math.floor((Date.now() / 1000) - m.last_attest);
tr.innerHTML = `
<td class="rank rank-${i+1}">${i + 1}</td>
<td title="${m.miner}">${m.miner.substring(0, 12)}...</td>
<td>
${m.device_family} ${m.device_arch}
<span class="badge ${isVintage ? 'badge-vintage' : 'badge-modern'}">${isVintage ? 'Vintage' : 'Modern'}</span>
</td>
<td style="color: var(--primary)">${m.antiquity_multiplier.toFixed(1)}x</td>
<td>${timeAgo}s ago</td>
`;
tbody.appendChild(tr);
});
}
function sortTable(n) {
const table = document.getElementById("leaderboard");
let rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
switching = true;
dir = "asc";
while (switching) {
switching = false;
rows = table.rows;
for (i = 1; i < (rows.length - 1); i++) {
shouldSwitch = false;
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + 1].getElementsByTagName("TD")[n];
if (dir == "asc") {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
shouldSwitch = true;
break;
}
} else if (dir == "desc") {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
switchcount ++;
} else {
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
}
fetchData();
setInterval(fetchData, 60000);
</script>
</body>
</html>