This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pools.html
623 lines (590 loc) · 28.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
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
<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 11 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>Iridium known pools list</h2>
<i id="pools_updated" class="fas fa-sync fa-spin"></i>
</div>
<!--Running pools-->
<div id="pool_table" class="card-body table-responsive">
<table class="table table-hover table-sm">
<thead>
<tr class="thead-dark">
<th colspan="8">Running pools</th>
</tr>
<tr class="table-dark">
<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="far fa-clock"></i> Last mined block</th>
<th><i class="fas fa-cubes"></i> Pending 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="pool_rows">
</tbody>
<thead id="mm_table" class="table-dark">
<tr class="thead-dark">
<th colspan="8">Merged mining pools</th>
</tr>
<tr class="table-dark">
<td>Address / Parent coin</td>
<td><i class="fa fa-bars"></i> height</td>
<td><i class="fas fa-tachometer-alt"></i> Hashrate</td>
<td><i class="fas fa-users"></i> Miners</td>
<td><i class="far fa-clock"></i> Last mined block</td>
<td><i class="fas fa-cubes"></i> Pending blocks</td>
<td><i class="fas fa-donate"></i> Donation</td>
<td><i class="fa fa-dollar-sign"></i> Total fee</td>
</tr>
</thead>
<tbody id="mm_rows">
</tbody>
<thead class="table-dark">
<tr id="pool_stats">
<th>Overall Statistics</th>
<th><span id=totalHeight></span></th>
<th><span id=totalHashrate></span> <span id=averageWindow></span></th>
<th><span id=totalMiners></span></th>
<th><span id=totalLastFound></span></th>
<th><span id=totalPending></span></th>
<th><span id=totalDonations></span></th>
<th><span id=totalFees></span></th>
</tr>
</thead>
</table>
<!--out of order pools-->
<table id="out_table" class="table table-hover table-sm d-none">
<thead>
<tr class="thead-light">
<th colspan="8">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="far fa-clock"></i> Last mining block</th>
<th><i class="fas fa-cubes"></i> Pending 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>
// to change to LF :-)
// todo : sortable collums on array
currentPage = {
destroy: function(){
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)) {
$('#blockchainHeight').attr('data-height', lastMinedBlockHeader.block_header.height);
getCurrentMinedBlock();
getBlocks(lastMinedBlockHeader.block_header.height);
}
},
update: function(){
if ((typeof lastMinedBlockHeader !== 'undefined') && parseInt(lastMinedBlockHeader.block_header.height, 10) !== parseInt($('#blockchainHeight').attr('data-height'), 10)) {
$('#blockchainHeight').attr('data-height', lastMinedBlockHeader.block_header.height);
getCurrentMinedBlock();
getBlocks(lastMinedBlockHeader.block_header.height);
}
}
};
var poolUpdate;
var poolPulse;
var poolData = [];
var mmData = [];
var xhrGetCurrentPoolStat;
var xhrGetCurrentMMStat;
function fetchPoolData(){
console.log("pools update tick");
$('#pools_updated').fadeIn('fast');
poolPulse = setTimeout(function() {
$('#pools_updated').fadeOut(2000);
}, 2000);
// fetch ird pools stats
poolData.length=0;
fetchedData = [];
for (let i = 0, len = poolList.length; i < len; i++) {
if(poolList[i].status) {
if (poolList[i].visible) {
fetchedData.length = 0;
poolData.length = 0;
xhrGetCurrentPoolStat = $.ajax({
url: poolList[i].api + '/stats',
method: "GET",
dataType: 'json',
cache: 'false',
timeout: 5000,
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};
fetchedData.push(d);
$.extend(true, poolData, fetchedData);
} else {
d = {"id": this.poolId, "url": this.poolUrl, "status": false, "error": status};
fetchedData.push(d); // not reachable
$.extend(true, poolData, fetchedData);
}
})
.fail(function (xhrGetCurrentPoolStat, status) {
d = {"id": this.poolId, "url": this.poolUrl, "status": false, "error": status};
fetchedData.push(d); // not reachable
$.extend(true, poolData, fetchedData);
})
.always(function () {
renderPoolData(poolData);
});
} // end if enabled
} else {
fetchedData.length = 0;
d = {"id": poolList[i].id, "url": poolList[i].url};
fetchedData.push(d); // not reachable
$.extend(true, poolData, fetchedData);
renderPoolData(poolData);
}
}
// fetch mm pools stats
mmData.length=0;
fetchedMmData= []
for (let i = 0, len = mmList.length; i < len; i++) {
if(mmList[i].status) {
if (mmList[i].visible) {
mmData.length = 0;
fetchedMmData.length = 0;
xhrGetCurrentMMStat = $.ajax({
url: mmList[i].api,
method: "GET",
dataType: 'json',
cache: 'false',
timeout: 5000,
mmId: mmList[i].id,
mmUrl: mmList[i].url,
mmStatus: mmList[i].status,
mmFlag: mmList[i].flag,
mmLoc: mmList[i].loc,
mmPair: mmList[i].pair
})
.done(function (data) {
if (data.length !== 0) {
if (data.hasOwnProperty('network')) { // normal response
d = {
"id": this.mmId,
"url": this.mmUrl,
"status": this.mmStatus,
"flag":this.mmFlag,
"loc":this.mmLoc,
"pair":this.mmPair,
"height":data.network.height,
"hr":data.pool.hashrate,
"miners":data.pool.miners,
"fee":data.config.fee,
"lastBlockFound":data.pool.lastBlockFound,
"blocks":calculatePending(data.pool.blocks)
};
fetchedMmData.push(d);
$.extend(true, mmData, fetchedMmData);
} else if(data[0].hasOwnProperty('coin') && data[0].coin === "IRD"){ // semipool
d = {"id": this.mmId,
"url": this.mmUrl,
"status": this.mmStatus,
"flag":this.mmFlag,
"loc":this.mmLoc,
"pair":this.mmPair,
"height":"N/A",
"hr":"N/A",
"miners":"N/A",
"fee":"N/A",
"lastBlockFound":data[0].ts,
"blocks":calculateMMPending(data)
};
fetchedMmData.push(d);
$.extend(true, mmData, fetchedMmData);
}
} else { // response ok, but nothing to show
d = {"id": this.mmId, "url": this.mmUrl, "status": false, "flag":this.mmFlag,"loc":this.mmLoc, "pair":this.mmPair, data};
fetchedMmData.push(d);
$.extend(true, mmData, fetchedMmData);
}
})
.fail(function (xhrGetCurrentPoolStat, status) {
d = {"id": this.mmId, "url": this.mmUrl, "status": false, "error": status};
fetchedMmData.push(d);
$.extend(true, mmData, fetchedMmData);
})
.always(function () {
renderMMData(mmData);
});
} // end visible
} else { // end status
d = {"id": mmList[i].id, "url": mmList[i].url};
fetchedMmData.push(d);
$.extend(true, mmData, fetchedMmData);
}
}
// update stats
poolUpdate = setTimeout(function() {
fetchPoolData();
}, 35000); // <-- time in milliseconds
}
var totalMMPending = 0;
var totalMMLastFound = 0;
var totalMMminers = 0;
var totalMMHr = 0;
function renderMMData(mmData){
totalMMHr = 0;
totalMMPending = 0;
for(let i= 0; i < mmData.length; i++){
if (mmData[i].status) {
blocTimeAgo = jQuery.timeago(new Date(parseInt(mmData[i].lastBlockFound)));
totalMMLastFound = mmData[i].lastBlockFound > totalMMLastFound ? mmData[i].lastBlockFound : totalMMLastFound;
height = mmData[i].height;
hr = mmData[i].hr;
totalMMHr+=mmData[i].hr !== "N/A" ? mmData[i].hr:0;
hr = mmData[i].hr !== "N/A" ? getReadableHashRateString(mmData[i].hr) : "N/A";
pending=mmData[i].blocks;
totalMMPending += pending;
miners = mmData[i].miners;
totalMMminers += miners !== "N/A" ? miners: 0 ;
// TODO : calculate overall fee
fee=mmData[i].fee;
if(Math.abs(parseInt($('#blockchainHeight').attr('data-height'), 10) - mmData[i].height)> 3) {
height = 'Out of sync'; // not synced
hr='N/A';
}
flag = mmData[i].flag !== undefined ? '<img class="flag" src="images/flags/'+mmData[i].flag.toLowerCase()+'.svg">' : '';
loc = mmData[i].loc !== undefined ? 'data-toggle="popover" data-trigger="hover" data-placement="top" data-content="'+mmData[i].loc+'" ' : '';
if (document.getElementById("mmHost-"+mmData[i].id)){
updateText('mmHeight-'+mmData[i].id, height);
updateText('mmHr-'+mmData[i].id, hr);
updateText('mmMiners-'+mmData[i].id, miners);
updateText('mmLastBlockFound-'+mmData[i].id, blocTimeAgo);
updateText('mmPending-'+mmData[i].id, pending);
updateText('mmFee-'+mmData[i].id, fee);
} else {
$('#mm_rows').append('<tr>' +
'<td id=mmHost-' + mmData[i].id + '>' +
'<a '+loc+'target=blank href='+ mmData[i].url + '>'+ flag + ' ' + mmData[i].url + '</a> <span class="badge badge-secondary float-right">'+ mmData[i].pair+'</span></td>' +
'<td id=mmHeight-' + mmData[i].id + '>'+height+'</td>'+
'<td id=mmHr-' + mmData[i].id + '>'+hr+'</td>'+
'<td id=mmMiners-' + mmData[i].id + '>'+miners+'</td>'+
'<td id=mmLastBlockFound-' + mmData[i].id + '>' + blocTimeAgo + '</td>' +
'<td id=mmPending-' + mmData[i].id + '>' + pending + '</td>' +
'<td>-</td>'+
'<td id=mmFee-' + mmData[i].id + '>' + fee + '</td>'+
'</tr>');
$('[data-toggle="popover"]').popover({});
}
}
}
updateText('totalHeight', parseInt($('#blockchainHeight').attr('data-height')));
}
function calculateMMPending(data) {
c = 0;
for(let i= 0; i < data.length; i++) {
if(data[i].height > ($('#blockchainHeight').attr('data-height') - 20)){
c++;
}
}
return c;
}
function renderPoolData(poolData){
let totalMiners = 0;
let totalHashrate = 0;
let nbPoolOk = 0;
let totalLastFound = 0;
let totalPending = 0;
let totalDonations = 0;
let totalFee = 0 ;
for(let i= 0; i < poolData.length; i++){
st = poolData[i].status; // false if an error occurs, get error in "error" and if disabled in config
if (st){
height = poolData[i].data.network.height;
hashrate = getReadableHashRateString(poolData[i].data.pool.hashrate);
poolCoeff=poolData[i].data.pool.hashrate/$('#networkHashrate').attr('data-globalHR');
miners = poolData[i].data.pool.miners;
blocTimeAgo = jQuery.timeago(new Date(parseInt(poolData[i].data.pool.lastBlockFound)));
pending = calculatePending(poolData[i].data.pool.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) - poolData[i].data.network.height) > 3){
hashrate = 'N/A'; // not synced
miners = 'N/A';
pending = 'N/A';
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('lastBlockFound-'+poolData[i].id, blocTimeAgo);
updateText('pending-'+poolData[i].id, pending);
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 target=blank href=' + poolData[i].url + '>flag' + poolData[i].url + '</a></td>' +
'<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=lastBlockFound-' + poolData[i].id + '>' + blocTimeAgo + '</td>' +
'<td id=pending-' + poolData[i].id + '>' + pending + '</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;
totalHashrate += poolData[i].data.pool.hashrate;
totalMiners += miners;
totalLastFound = poolData[i].data.pool.lastBlockFound > totalLastFound ? poolData[i].data.pool.lastBlockFound : totalLastFound;
totalPending += pending;
totalDonations += donation * poolCoeff;
totalFee += fee * poolCoeff;
}
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('lastBlockFound-'+poolData[i].id, blocTimeAgo);
updateText('pending-'+poolData[i].id, pending);
updateText('donation-'+poolData[i].id, donation);
updateText('totalFee-'+poolData[i].id, fee);
} else {
$('#pool_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=lastBlockFound-' + poolData[i].id + '>' + blocTimeAgo + '</td>' +
'<td id=pending-' + poolData[i].id + '>' + pending + '</td>' +
'<td id=donation-' + poolData[i].id + '>' + donation + '%</td>' +
'<td id=totalFee-' + poolData[i].id + '>' + fee + '%</td>' +
'</tr>');
$('[data-toggle="popover"]').popover({});
} // end if
} else { // unreachable
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
updateText('totalHeight', parseInt($('#blockchainHeight').attr('data-height')));
updateText('totalMiners', totalMiners+totalMMminers);
updateText('totalHashrate', getReadableHashRateString(totalHashrate+totalMMHr));
updateText('totalLastFound', jQuery.timeago(new Date(parseInt(totalMMLastFound > totalLastFound ? totalMMLastFound : totalLastFound))));
updateText('totalPending',totalPending+totalMMPending);
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(blocks) {
c = 0;
for(let i= 0; i < blocks.length; i++) {
if((i+1) % 2 === 0){
if(blocks[i] > ($('#blockchainHeight').attr('data-height') - 20)){
c++;
}
}
}
return c;
}
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: "ir3AmNVgaquFesnDNNBkZMGa8vqHhwvqX4JHKuHFj9DQSwDsr4kNunrWhXs1eG34PnDWx7cbn8nJ9bN2gnHC99eA1kceFnJ1k"
}
}),
dataType: 'json',
cache: 'false'
})
.done(function (data) {
if (data.hasOwnProperty('result')) {
currentMinedBlock = data.result;
updateText('networkHashrate', getReadableHashRateString(currentMinedBlock.difficulty / coinDifficultyTarget));
$('#networkHashrate').attr('data-globalHR', currentMinedBlock.difficulty / coinDifficultyTarget);
updateText('nextDifficulty', currentMinedBlock.difficulty.toString());
updateText('blockchainHeight', currentMinedBlock.height);
$('#blockchainHeight').attr('data-height', currentMinedBlock.height);
} else {
showalert('alert-danger','Core error : ',data.error.message);
$('#loading').hide();
}
})
.fail(function (xhrGetCurrentMinedBlock, textStatus) {
if (textStatus !== "abort") {
showalert('alert-danger','Can\'t connect to api : ',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();
}
if(typeof poolUpdate !== 'undefined') {
clearTimeout(poolUpdate);
}
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 < 11; i ++){
block = blocksResults[i];
sumDiff += blocksResults[i].difficulty;
}
averageHashRate = sumDiff / 11;
updateText('averageHashrate', getReadableHashRateString(averageHashRate / coinDifficultyTarget));
}
// enable popover
$(document).ready(function () {
$('[data-toggle="popover"]').popover({})
});
</script>