forked from bittorium/bittorium-blockexplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pools.html
511 lines (489 loc) · 23.4 KB
/
pools.html
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
<div class="cardpad card">
<div class="card-header">
<div class="row">
<div class="col-sm-3">
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Current mined block height">
<i class="fa fa-bars"></i> Height: <span id="blockchainHeight" data-height="0"></span>
</span>
</div>
<div class="col-sm-3">
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Based on the current mined block">
<i class="fas fa-tachometer-alt"></i> Instant Hash Rate: <span id="networkHashrate"></span>
</span>
</div>
<div class="col-sm-3">
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Difficulty of the current mined block">
<i class="fas fa-microchip"></i> Next Difficulty: <span id="nextDifficulty"></span>
</span>
</div>
<div class="col-sm-3">
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="On the last 31 blocks">
<i class="fas fa-percent"></i> Average Hash Rate: <span id="averageHashrate"></span>
</span>
</div>
</div>
</div>
</div>
<div class="cardpad card">
<div class="card-header text-center">
<h2>Talleo known pools list</h2>
<i id="pools_updated" class="fas fa-sync fa-spin"></i>
</div>
<div id="pool_div" class="card-body table-responsive">
<!--Running pools-->
<table id="running_table" class="table table-hover table-sm">
<thead>
<tr class="thead-dark">
<th colspan="10">Running pools</th>
</tr>
<tr>
<th>Address</th>
<th><i class="fa fa-bars"></i> Height</th>
<th><i class="fas fa-tachometer-alt"></i> Hashrate</th>
<th><i class="fas fa-users"></i> Miners</th>
<th><i class="fa fa-gavel"></i> Workers</th>
<th><i class="far fa-clock"></i> Last mining block</th>
<th><i class="fas fa-cubes"></i> Pending blocks</th>
<th><i class="fa fa-th-large"></i> Total blocks</th>
<th><i class="fas fa-donate"></i> Donation</th>
<th><i class="fa fa-dollar-sign"></i> Total fee</th>
</tr>
</thead>
<tfoot>
<!--<tr><td colspan="8"></td></tr>-->
<tr class="table-dark">
<td>Stats</td>
<td><span id=totalHeight></span></td>
<td><span id=totalHashrate></span> <span id=averageWindow></span></td>
<td><span id=totalMiners></span></td>
<td><span id=totalWorkers></span></td>
<td><span id=totalLastFound></span></td>
<td><span id=totalPending></span></td>
<td><span id=totalBlocks></span></td>
<td><span id=totalDonations></span></td>
<td><span id=totalFees></span></td>
</tr>
</tfoot>
<tbody id="running_rows">
</tbody>
</table>
<!--out of order pools-->
<table id="out_table" class="table table-hover table-sm d-none">
<thead>
<tr class="thead-light">
<th colspan="10">Out of order pools (not synced or stucked)</th>
</tr>
<tr>
<th>Address</th>
<th><i class="fa fa-bars"></i> Height</th>
<th><i class="fas fa-tachometer-alt"></i> Hashrate</th>
<th><i class="fas fa-users"></i> Miners</th>
<th><i class="fa fa-gavel"></i> Workers</th>
<th><i class="far fa-clock"></i> Last mining block</th>
<th><i class="fas fa-cubes"></i> Pending blocks</th>
<th><i class="fa fa-th-large"></i> Total blocks</th>
<th><i class="fas fa-donate"></i> Donation</th>
<th><i class="fa fa-dollar-sign"></i> Total fee</th>
</tr>
</thead>
<tbody id="out_rows">
</tbody>
</table>
<!--dead pools-->
<table id="dead_table" class="table table-hover table-sm d-none">
<thead>
<tr class="thead-light">
<th colspan="8">Unreachable or dead pools</th>
</tr>
<tr>
<th colspan="8">Address</th>
</tr>
</thead>
<tbody id="dead_rows">
</tbody>
</table>
</div>
</div>
<script>
// todo : sortable columns on array
currentPage = {
destroy: function(){
if (xhrGetCurrentMinedBlock) {
xhrGetCurrentMinedBlock.abort();
}
if (xhrGetCurrentPoolStat) {
xhrGetCurrentPoolStat.abort();
}
if(typeof poolUpdate !== 'undefined') {
clearTimeout(poolUpdate);
}
if(typeof poolPulse !== 'undefined') {
clearTimeout(poolPulse);
}
},
init: function (){
if(typeof txPulse !== 'undefined') {
clearTimeout(txPulse);
}
if(typeof tx_wheel !== 'undefined') {
clearTimeout(tx_wheel);
}
if ((typeof lastMinedBlockHeader !== 'undefined') && parseInt(lastMinedBlockHeader.block_header.height, 10) !== parseInt($('#blockchainHeight').attr('data-height'), 10)) {
getCurrentMinedBlock();
getBlocks(lastMinedBlockHeader.block_header.height);
}
},
update: function(){
if ((typeof lastMinedBlockHeader !== 'undefined') && parseInt(lastMinedBlockHeader.block_header.height, 10) !== parseInt($('#blockchainHeight').attr('data-height'), 10)) {
getCurrentMinedBlock();
getBlocks(lastMinedBlockHeader.block_header.height);
}
}
};
var poolUpdate;
var poolPulse;
var poolData = [];
var xhrGetCurrentPoolStat;
function fetchPoolData(){
console.log("pool update tick");
$('#pools_updated').fadeIn('fast');
poolPulse = setTimeout(function() {
$('#pools_updated').fadeOut(10000);
},10000); // <-- time in milliseconds
fetchedData=[];
for (let i = 0, len = poolList.length; i < len; i++) {
if (!poolData[i]){
poolData[i] = {"id": poolList[i].id, "url": poolList[i].url, "status": false, "error": "Not reachable"};
}
if(poolList[i].status) {
if (poolList[i].visible) {
xhrGetCurrentPoolStat = $.ajax({
url: poolList[i].api + '/stats',
method: "GET",
dataType: 'json',
cache: 'false',
timeout: 9000,
poolId: poolList[i].id,
poolUrl: poolList[i].url,
poolStatus: poolList[i].status,
poolFlag: poolList[i].flag,
poolLoc: poolList[i].loc
})
.done(function (data, status) {
if (data.hasOwnProperty('network')) {
d = {"id": this.poolId, "url": this.poolUrl, "status": this.poolStatus, "flag":this.poolFlag,"loc":this.poolLoc, data};
poolData[i] = d;
} else {
d = {"id": this.poolId, "url": this.poolUrl, "status": false, "error": status};
poolData[i] = d;
}
})
.fail(function (xhrGetCurrentPoolStat, status) {
d = {"id": this.poolId, "url": this.poolUrl, "status": false, "error": status};
poolData[i] = d;
})
.always(function () {
renderPoolData(poolData);
});
} // end if enabled
} else {
d = {"id": poolList[i].id, "url": poolList[i].url, "status": false, "error": "disabled"};
poolData[i] = d;
renderPoolData(poolData);
}
}
poolUpdate = setTimeout(function() {
fetchPoolData();
}, 35000); // <-- time in milliseconds
}
function renderPoolData(poolData){
let totalMiners = 0;
let totalWorkers = 0;
let totalHashrate = 0;
let totalHeight = 0;
let nbPoolOk = 0;
let totalLastFound = 0;
let totalPending = 0;
let totalBlocks = 0;
let totalDonations = 0;
let totalFee = 0 ;
for(let i= 0; i < poolList.length; i++){
if (!poolData[i]){
poolData[i] = {"id": poolList[i].id, "url": poolList[i].url, "status": false, "error": "Not reachable"};
}
st = poolData[i].status; // false if an error occurs or disabled in config, get error in "error"
if (st){
height = poolData[i].data.network.height;
solohashrate = poolData[i].data.pool.solo_hashrate || 0;
hashrate = getReadableHashRateString(poolData[i].data.pool.hashrate + solohashrate);
poolCoeff= (poolData[i].data.pool.hashrate + solohashrate)/$('#networkHashrate').attr('data-globalHR');
solominers = parseInt(poolData[i].data.pool.solo_miners || 0);
miners = poolData[i].data.pool.miners + solominers;
soloworkers = parseInt(poolData[i].data.pool.solo_workers || 0);
workers = poolData[i].data.pool.workers + soloworkers;
solo_lastblock = parseInt(poolData[i].data.pool.solo_lastBlockFound || 0);
lastblock = parseInt(poolData[i].data.pool.lastBlockFound || 0);
if (solo_lastblock > lastblock){
lastblock = solo_lastblock;
}
blocTimeAgo = lastblock ? jQuery.timeago(new Date(lastblock)) : 'Never';
pending = calculatePending(poolData[i].data);
solo_blocks = parseInt(poolData[i].data.pool.solo_totalBlocks || 0);
blocks = poolData[i].data.pool.totalBlocks + solo_blocks;
donation = calculateDonations(poolData[i].data);
fee = calculateTotalFee(poolData[i].data);
flag = poolData[i].flag != undefined ? '<img class="flag" src="images/flags/'+poolData[i].flag.toLowerCase()+'.svg">' : '';
loc = poolData[i].loc != undefined ? 'data-toggle="popover" data-trigger="hover" data-placement="top" data-content="'+poolData[i].loc+'" ' : '';
// test if pool is synced
if(Math.abs(parseInt($('#blockchainHeight').attr('data-height'), 10) - height) > 3){
hashrate = 'N/A'; // not synced
miners = 'N/A';
pending = 'N/A';
row = document.getElementById("host-"+poolData[i].id);
if (row && row.parentElement && row.parentElement.parentElement && row.parentElement.parentElement.id !== "out_rows"){
row.parentElement.remove();
}
if (document.getElementById("host-"+poolData[i].id)){
updateText('height-'+poolData[i].id, height);
updateText('hashrate-'+poolData[i].id, hashrate);
updateText('miners-'+poolData[i].id, miners);
updateText('workers-'+poolData[i].id, workers);
updateText('lastBlockFound-'+poolData[i].id, blocTimeAgo);
updateText('pending-'+poolData[i].id, pending);
updateText('blocks-'+poolData[i].id, blocks);
updateText('donation-'+poolData[i].id, donation + '%');
updateText('totalFee-'+poolData[i].id, fee + '%');
} else {
$('#out_rows').append('<tr>' +
'<td id=host-' + poolData[i].id + '>' +
'<i id="flag-' + poolData[i].id + '" class="fas fa-exclamation-circle"></i>'+
'<a '+loc+'target=blank href='+ poolData[i].url + '>'+ flag + ' ' + poolData[i].url + '</a></td>' +
'<td id=height-' + poolData[i].id + '>' + height + '</td>' +
'<td id=hashrate-' + poolData[i].id + '>' + hashrate + '</td>' +
'<td id=miners-' + poolData[i].id + '>' + miners + '</td>' +
'<td id=workers-' + poolData[i].id + '>' + workers + '</td>' +
'<td id=lastBlockFound-' + poolData[i].id + '>' + blocTimeAgo + '</td>' +
'<td id=pending-' + poolData[i].id + '>' + pending + '</td>' +
'<td id=blocks-' + poolData[i].id + '>' + blocks + '</td>' +
'<td id=donation-' + poolData[i].id + '>' + donation + '%</td>' +
'<td id=totalFee-' + poolData[i].id + '>' + fee + '%</td>' +
'</tr>');
}
$('#out_table').removeClass('d-none');
} else { //synced
nbPoolOk += 1;
totalHeight = height > totalHeight ? height : totalHeight;
totalHashrate += poolData[i].data.pool.hashrate;
totalMiners += miners;
totalWorkers += workers;
totalLastFound = poolData[i].data.pool.lastBlockFound > totalLastFound ? poolData[i].data.pool.lastBlockFound : totalLastFound;
totalPending += pending;
totalBlocks += blocks;
totalDonations += donation * poolCoeff;
totalFee += fee * poolCoeff;
}
row = document.getElementById("host-"+poolData[i].id);
if (row && row.parentElement && row.parentElement.parentElement && row.parentElement.parentElement.id !== "running_rows"){
row.parentElement.remove();
}
if (document.getElementById("host-"+poolData[i].id)){
updateText('height-'+poolData[i].id, height);
updateText('hashrate-'+poolData[i].id, hashrate);
updateText('miners-'+poolData[i].id, miners);
updateText('workers-'+poolData[i].id, workers);
updateText('lastBlockFound-'+poolData[i].id, blocTimeAgo);
updateText('pending-'+poolData[i].id, pending);
updateText('blocks-'+poolData[i].id, blocks);
updateText('donation-'+poolData[i].id, donation + '%');
updateText('totalFee-'+poolData[i].id, fee + '%');
} else {
$('#running_rows').append('<tr>' +
'<td id=host-' + poolData[i].id + '>' +
'<a '+loc+'target=blank href='+ poolData[i].url + '>'+ flag + ' ' + poolData[i].url + '</a></td>' +
'<td id=height-' + poolData[i].id + '>' + height + '</td>' +
'<td id=hashrate-' + poolData[i].id + '>' + hashrate + '</td>' +
'<td id=miners-' + poolData[i].id + '>' + miners + '</td>' +
'<td id=workers-' + poolData[i].id + '>' + workers + '</td>' +
'<td id=lastBlockFound-' + poolData[i].id + '>' + blocTimeAgo + '</td>' +
'<td id=pending-' + poolData[i].id + '>' + pending + '</td>' +
'<td id=blocks-' + poolData[i].id + '>' + blocks + '</td>' +
'<td id=donation-' + poolData[i].id + '>' + donation + '%</td>' +
'<td id=totalFee-' + poolData[i].id + '>' + fee + '%</td>' +
'</tr>');
$('[data-toggle="popover"]').popover({});
$('#running_table').removeClass('d-none');
} // end if
} else { // unreachable
row = document.getElementById("host-"+poolData[i].id);
if (row && row.parentElement && row.parentElement.parentElement && row.parentElement.parentElement.id !== "dead_rows"){
row.parentElement.remove();
}
if (! document.getElementById("host-"+poolData[i].id)) {
$('#dead_rows').append('<tr colspan="8">' +
'<td id=host-' + poolData[i].id + '><i id="flag-' + poolData[i].id + '" class="fas fa-exclamation-circle invisible"></i> <a target=blank href=' + poolData[i].url + '>' + poolData[i].url + '</a></td>' +
'</tr>');
$("#flag-"+poolData[i].id).removeClass("invisible");
$('#dead_table').removeClass('d-none');
}
}
} // end for
if ($('#running_rows').find('tr').length === 0){
$('#running_table').addClass('d-none');
}
if ($('#out_rows').find('tr').length === 0){
$('#out_table').addClass('d-none');
}
if ($('#dead_rows').find('tr').length === 0){
$('#dead_table').addClass('d-none');
}
updateText('totalHeight', parseInt($('#blockchainHeight').attr('data-height')));
updateText('totalMiners', totalMiners);
updateText('totalWorkers', totalWorkers);
updateText('totalHashrate', getReadableHashRateString(totalHashrate));
updateText('totalLastFound', totalLastFound ? jQuery.timeago(new Date(parseInt(totalLastFound))) : 'Never');
updateText('totalPending',totalPending);
updateText('totalBlocks',totalBlocks);
updateText('totalDonations', totalDonations.toFixed(2)+'%');
updateText('totalFees', totalFee.toFixed(2)+'%');
}
function calculateTotalFee(data) {
let totalFee = data.config.fee;
if(data.config.hasOwnProperty("coreDonation")){
totalFee += data.config.donation;
totalFee += data.config.coreDonation;
} else {
for ( property in data.config.donation) {
if (data.config.donation.hasOwnProperty(property)) {
totalFee += data.config.donation[property];
}
}
}
return totalFee;
}
function calculateDonations(data) {
let totalDonations = 0;
if(data.config.hasOwnProperty("coreDonation")){
totalDonations += data.config.donation;
totalDonations += data.config.coreDonation;
} else {
for ( property in data.config.donation) {
if (data.config.donation.hasOwnProperty(property)) {
totalDonations += data.config.donation[property];
}
}
}
return totalDonations;
}
function calculatePending(data) {
totalPending = 0;
for(let i= 0; i < data.pool.blocks.length; i++) {
if((i+1) % 2 == 0){
if(data.pool.blocks[i] >= ($('#blockchainHeight').attr('data-height') - data.config.depth)){
totalPending++;
}
}
}
if (data.pool.solo_blocks){
for(let i= 0; i < data.pool.solo_blocks.length; i++) {
if((i+1) % 2 == 0){
if(data.pool.solo_blocks[i] >= ($('#blockchainHeight').attr('data-height') - data.config.depth)){
totalPending++;
}
}
}
}
return totalPending;
}
var xhrGetCurrentMinedBlock;
// get last block template (current mining block)
function getCurrentMinedBlock() {
if (xhrGetCurrentMinedBlock) xhrGetCurrentMinedBlock.abort();
xhrGetCurrentMinedBlock = $.ajax({
url: api + '/json_rpc',
method: "POST",
data: JSON.stringify({
jsonrpc: "2.0",
id: "2",
method: "getblocktemplate",
params: {
reserve_size: 0,
wallet_address: "TA4yACzMYuFYq7V6xVAWYHeS39jQ8w4mKRowpY6NskGuS1rZpjcWuCpdeCypwUCJrK9mGqVW9o1pY2EG3HW7BZkR2YRcc4YNa"
}
}),
dataType: 'json',
cache: 'false'
})
.done(function (data) {
if (data.hasOwnProperty('result')) {
let currentMinedBlock = data.result;
updateText('networkHashrate', getReadableHashRateString(currentMinedBlock.difficulty / coinDifficultyTarget));
$('#networkHashrate').attr('data-globalHR', (currentMinedBlock.difficulty / coinDifficultyTarget).toString());
updateText('nextDifficulty', currentMinedBlock.difficulty.toString());
$('#blockchainHeight').attr('data-height', currentMinedBlock.height);
updateText('blockchainHeight', currentMinedBlock.height);
} else {
showalert('alert-danger','Core error : ',data.error.message);
$('#loading').hide();
}
})
.fail(function (xhrGetCurrentMinedBlock, textStatus) {
if (textStatus != "abort") {
showalert('alert-danger','Request error : ',textStatus);
$('#loading').hide();
}
});
}
var xhrGetLastBlocks;
function getBlocks(heightAsked) {
if (xhrGetLastBlocks) xhrGetLastBlocks.abort();
xhrGetLastBlocks = $.ajax({
url: api + '/json_rpc',
method: "POST",
data: JSON.stringify({
jsonrpc: "2.0",
id: "4",
method: "f_blocks_list_json",
params: {
height:heightAsked
}
}),
dataType: 'json',
cache: 'false'
})
.done(function (data) {
if (data.hasOwnProperty('result')) {
lastBlocksList = data.result.blocks;
averageBlocks(lastBlocksList);
$('#loading').hide();
} else {
showalert('alert-danger','Core error : ',data.error.message);
$('#loading').hide();
}
fetchPoolData();
})
.fail(function (xhrGetLastBlocks, textStatus) {
if (textStatus != "abort") {
showalert('alert-danger','Can\'t connect to api : ',textStatus);
$('#loading').hide();
}
});
}
// Handle Blocks list
function averageBlocks(blocksResults){
sumDiff = 0;
for ( i = 0; i < blocksResults.length; i ++){
block = blocksResults[i];
sumDiff += blocksResults[i].difficulty;
}
averageHashRate = sumDiff / blocksResults.length;
updateText('averageHashrate', getReadableHashRateString(averageHashRate / coinDifficultyTarget));
}
// enable popover
$(document).ready(function () {
$('[data-toggle="popover"]').popover({})
});
</script>