Bläddra i källkod

Ajout mode empty blocks

nft
MEUNIER Thibaud 4 år sedan
förälder
incheckning
130852ee98
4 ändrade filer med 97 tillägg och 6 borttagningar
  1. +48
    -0
      data/getEmptyBlocksList.php
  2. +1
    -0
      index.php
  3. +42
    -4
      js/blockexplorer.js
  4. +6
    -2
      nft.php

+ 48
- 0
data/getEmptyBlocksList.php Visa fil

@ -0,0 +1,48 @@
<?php
// ---
// --- La config globale
// ---
chdir('/opt/TOPISTO/apps');
require_once '/opt/TOPISTO/apps/global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
function cmp_emptyblocks($a, $b)
{
if ($a[1] == $b[1]) {
return 0;
}
return ($a[1] < $b[1]) ? 1 : -1;
}
header('Content-Type: application/json');
$emptyblocks_list = [];
$filename=DATA_PATH."/emptybot/list.txt";
if (file_exists($filename))
{
$file = fopen(DATA_PATH."/emptybot/list.txt","r");
while(!feof($file))
{
$ligne=fgets($file);
$tableau=explode(' ', $ligne);
if ($tableau[1] != null)
$emptyblocks_list[] = [ $tableau[1], $tableau[2] ];
}
fclose($file);
}
usort($emptyblocks_list, "cmp_emptyblocks");
die(json_encode($emptyblocks_list));
?>

+ 1
- 0
index.php Visa fil

@ -98,6 +98,7 @@
<br><select id="mode_selector" onchange="showInfos()">
<option value=0>Full Blockchain Explorer</option>
<option value=1>My special Blocks list</option>
<option value=2>Empty Blocks list</option>
</select>
<br>
<label>show block infos&nbsp;</label><input id="mode_checkbox" type="checkbox" onchange="toggleInfos()">

+ 42
- 4
js/blockexplorer.js Visa fil

@ -2,6 +2,7 @@ blockchainExplorer = function(){
// Init array
var _known_blocks = null;
var _empty_blocks = null;
var _liste_blocks = [];
var _classes = ['bg-grey-even','bg-grey-odd'];
var _cur_class = 0;
@ -76,9 +77,12 @@ blockchainExplorer = function(){
blockName = _getblockNameFromHash(block.hash);
if (block.hash == _liste_blocks['TOP']) {
blockName = 'LAST BLOCK';
if (_mode == 1)
div_label = 'LAST';
if (_mode != 2)
{
blockName = 'LAST BLOCK';
if (_mode == 1)
div_label = 'LAST';
}
}
if (blockName == '') blockName = 'block';
else blockName = '<b>'+blockName+'</b>';
@ -105,6 +109,8 @@ blockchainExplorer = function(){
$('#info_'+div_label).html(contenu);
if (_mode == 2) _cur_methode = 'emptybot';
downloadingImage.onload = function(){
var div0 = document.getElementById('img_'+div_label);
div0.style.backgroundImage = "url(" + this.src + ")";
@ -263,7 +269,15 @@ blockchainExplorer = function(){
}
//_liste_blocks['BOTTOM'] = _known_blocks[_liste_blocks['LENGTH']-1].hash;
break;
}
case 2:
// En mode "Blocks Vides", on prend le prochain de la liste
_liste_blocks['BOTTOM'] = _empty_blocks[0][0];
for(i = 0; i < _empty_blocks.length; i++){
if (data.height == _empty_blocks[i][1])
_liste_blocks['BOTTOM'] = _empty_blocks[i+1][0];
}
break;
}
if (data.height > 0)
if (_liste_blocks['LENGTH'] % 15)
@ -298,6 +312,9 @@ blockchainExplorer = function(){
$('#blockchain').html('');
// Mode "Empty Blocks"
if (_mode == 2) block_hash_url += '?block_hash='+_empty_blocks[0][0];
else
if (block_name != 'LAST') block_hash_url += '?block_hash='+_getblocHashFromName(block_name);
$.getJSON(block_hash_url, function( data ) {
@ -352,6 +369,13 @@ blockchainExplorer = function(){
return true;
});
}
if (_empty_blocks == null)
{
$.getJSON('data/getEmptyBlocksList.php', function( data ) {
_empty_blocks = data;
return true;
});
}
}
function _init(mode, infos)
@ -375,6 +399,13 @@ blockchainExplorer = function(){
});
}
if (_empty_blocks == null)
{
$.getJSON('data/getEmptyBlocksList.php', function( data ) {
_empty_blocks = data;
return true;
});
}
return _initBlockchain('LAST');
}
@ -441,6 +472,11 @@ blockchainExplorer = function(){
return true;
}
function _initEmptyBlocks()
{
_init(2,false);
}
function _showBlockAllMethod(blockname)
{
allMethod = [
@ -480,6 +516,8 @@ blockchainExplorer = function(){
initOneBlock : _initOneBlock,
initBlockSelector : _initBlockSelector,
initEmptyBlocks : _initEmptyBlocks,
toggleInfos: _toggleInfos,
getLength: _getLength,

+ 6
- 2
nft.php Visa fil

@ -43,7 +43,7 @@
if ( window.scrollY > (2200+lastScroll))
{
lastScroll = window.scrollY;
if ($('#blockSelector').val() == 'FULL')
if ($('#blockSelector').val() == 'EMPTY')
blockchainExplorer.addBottomBlock();
}
});
@ -66,7 +66,10 @@
function selectBlock()
{
lastScroll = 0;
blockchainExplorer.initOneBlock($('#blockSelector').val());
if ($('#blockSelector').val() != 'EMPTY')
blockchainExplorer.initOneBlock($('#blockSelector').val());
else
blockchainExplorer.initEmptyBlocks();
}
</script>
@ -103,6 +106,7 @@
<br>
<select id="blockSelector" onchange="selectBlock()">
<option value='LAST'>LAST</option>
<option value='EMPTY'>EMPTY BLOCKS</option>
</select>
<br>
<label>show block infos&nbsp;</label><input id="mode_checkbox" type="checkbox" onchange="toggleInfos()">

Laddar…
Avbryt
Spara