// Init array
var liste_blocks = [
{
name : 'WHALE201810',
hash : '0000000000000000000f9f2dadfb8f312572183272802cbfcc4ff95b4ee6777d',
height : 545911
},
{
name : 'BLOCK21E800',
hash : '00000000000000000021e800c1e8df51b22c1588e5a624bea17e9faa34b2dc4a',
height : 528249
},
{
name : 'HURRICANE_1',
hash : '0000000000000000000fe6d521a187a5523d5cef6f6c178923ff82ffe5a0f372',
height : 506734
},
{
name : 'SEGWIT',
hash : '000000000000000000cbeff0b533f8e1189cf09dfbebf57a8ebe349362811b80',
height : 481823
},
{
name : 'SEGWIT_LOCK',
hash : '0000000000000000012e6060980c6475a9a8e62a1bf44b76c5d51f707d54522c',
height : 479808
},
{
name : 'BCC',
hash : '00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148',
height : 478559
},
{
name : 'BIP_91_LOCK',
hash : '0000000000000000015411ca4b35f7b48ecab015b14de5627b647e262ba0ec40',
height : 477120
},
{
name : 'HALVING_2',
hash : '000000000000000002cce816c0ab2c5c269cb081896b7dcb34b8422d6b74ffa1',
height : 420000
},
{
name : 'WHALE201311',
hash : '0000000000000001bc7156dd1183c87859b326affa3a5cdd157e809537f0b284',
height : 270953
},
{
name : 'HALVING_1',
hash : '000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e',
height : 210000
},
{
name : 'PIZZA',
hash : '00000000006de085dadb3ec413ef074022fe781121b467e98960280dd246bb00',
height : 57035
},
{
name : 'TOPISTO',
hash : '000000000a73e64735a2b75c97ea674950a9018da1420d01328a918c9ff9852c',
height : 5637
},
{
name : 'LEET',
hash : '000000008bf44a528a09d203203a6a97c165cf53a92ecc27aed0b49b86a19564',
height : 1337
},
{
name : 'LUCIFER',
hash : '00000000fc5b3c76f27f810ee775e480ae7fd604fd196b2d8da4257fcd39f4f9',
height : 666
},
{
name : 'THE_ANSWER',
hash : '00000000314e90489514c787d615cea50003af2023796ccdd085b6bcc1fa28f5',
height : 42
},
{
name : 'GENESIS',
hash : '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
height : 0
}
];
var flag_nav = true;
var classes = ['bg-grey-even','bg-grey-odd'];
var cur_class = 0;
var cur_height = [];
var cur_methode = 'hasard';
function precisionRound(number) {
var precision = 4;
var factor = Math.pow(10, precision);
return Math.round((number/100000000) * factor) / factor;
}
function getblockNameFromHash(hash)
{
var retour = '';
liste_blocks.forEach(function(item){
if (hash == item.hash) retour = item.name;
});
return retour;
}
function getblocHashFromName(name)
{
var retour = '';
liste_blocks.forEach(function(item){
if (name == item.name) retour = item.hash;
});
return retour;
}
function addInfoForBlock(block)
{
var height = '300px';
var contenu = '';
var downloadingImage = new Image();
cur_height.push(block.height);
cur_class = 1 - cur_class;
blockName = getblockNameFromHash(block.hash);
if (blockName != '') blockName = ' ( '+blockName+' )';
contenu += '
block '+block.height+blockName+'
';
contenu += ' ';
//contenu += ' | hash | '+block.hash+' |
';
//contenu += ' | index | '+block.block_index+' |
';
contenu += ' | timestamp | '+block.time+' |
';
contenu += ' | nonce | '+block.nonce+' |
';
contenu += ' | nb tx | '+block.n_tx+' |
';
contenu += ' | outputs | '+precisionRound(block.topisto_outputs).toFixed(4)+' |
';
contenu += ' | inputs | '+precisionRound(block.topisto_inputs).toFixed(4)+' |
';
contenu += ' | fees | '+precisionRound(block.topisto_fees).toFixed(4)+' |
';
contenu += ' | reward | '+precisionRound(block.topisto_reward).toFixed(4)+' |
';
contenu += '
';
$('#info_'+block.height).html(contenu);
downloadingImage.onload = function(){
$('#img_'+block.height).attr('src', this.src);
//$('#img_'+block.height).attr('height', height);
//$('#img_'+block.height).attr('width','auto');
flag_nav = true;
};
downloadingImage.src = 'images/block_image.php?methode='+cur_methode+'&hash='+block.hash;
return true;
}
function addDivForBlock(block_height)
{
var contenu = '';
contenu += '';
contenu += '
';
contenu += '
';
contenu += '
COMPUTING ...
';
contenu += ' ';
contenu += '
';
contenu += '
';
contenu += '

';
contenu += '
';
contenu += '
';
contenu += '
';
contenu += '
';
$('#blockchain').append(contenu);
return true;
}
function addDivForVoid()
{
var contenu = '';
contenu += '';
contenu += '
';
contenu += '
';
contenu += '
the VOID ...
';
contenu += ' ';
contenu += '
';
contenu += '
';
contenu += '

';
contenu += '
';
contenu += '
';
contenu += '
';
contenu += '
';
$('#blockchain').append(contenu);
return true;
}
function toggleForwardBtn()
{
if (cur_height.length < 3)
{
$('#fast_forward_btn').removeClass('btn-success');
$('#fast_forward_btn').addClass('btn-secondary');
$('#btn-forward').removeClass('btn-info');
$('#btn-forward').addClass('btn-secondary');
} else {
$('#fast_forward_btn').removeClass('btn-secondary');
$('#fast_forward_btn').addClass('btn-success');
$('#btn-forward').removeClass('btn-secondary');
$('#btn-forward').addClass('btn-info');
}
return true;
}
function gotoBlock(block_name)
{
$(document).scrollTop( $("#explorer").offset().top );
// Bloquer la navigation pendant le calcul
if (!flag_nav)
{
window.alert('A block image is currently computed, please wait ...');
return false;
}
flag_nav = false;
if (block_name == 'NEXT')
{
flag_nav = true;
// Supprimer un block
if (cur_height.length < 3)
{
window.alert('No Next Block, you are at '+$('#blockSelector').val()+' block !');
return false;
}
liste_blocks['PREVIOUS'] = liste_blocks['BLOCK_'+cur_height[cur_height.length-1]];
cur_height.pop();
toggleForwardBtn();
$('#block_'+cur_height[cur_height.length-2]).slideDown(400, function() {
// Animation complete.
$('#blockchain').children('div:last').remove();
cur_class = 1 - cur_class;
});
} else {
// Ajouter un block
addDivForBlock(cur_height[cur_height.length-1] - 1);
// Décaler d'un block vers le haut
if (cur_height.length > 1) $('#block_'+cur_height[cur_height.length-2]).slideUp();
block_hash = '';
if (block_name != 'LAST') block_hash = '?block_hash='+liste_blocks[block_name];
$.getJSON('data/getBlockInfo.php'+block_hash, function( data ) {
liste_blocks['PREVIOUS'] = data.prev;
liste_blocks['BLOCK_'+data.height] = data.hash;
addInfoForBlock(data);
toggleForwardBtn();
});
}
return true;
}
function ajouterPreviousBlock()
{
// Bloquer la navigation pendant le calcul
if (!flag_nav) return false;
flag_nav = false;
// Ajouter un div
addDivForBlock(cur_height[cur_height.length-1] - 1);
// Mettre les infos du
block_hash = '?block_hash='+liste_blocks['PREVIOUS'];
$.getJSON('data/getBlockInfo.php'+block_hash, function( data ) {
liste_blocks['PREVIOUS'] = data.prev;
liste_blocks['BLOCK_'+data.height] = data.hash;
addInfoForBlock(data);
});
}
function initBlockchain(block_name)
{
$(document).scrollTop( $("#explorer").offset().top );
$('#blockchain').html('');
cur_height = [];
cur_class = 0;
flag_nav = true;
block_hash = '';
if (block_name != 'LAST') block_hash = '?block_hash='+getblocHashFromName(block_name);
$.getJSON('data/getBlockInfo.php'+block_hash, function( data ) {
addDivForBlock(data.height);
addInfoForBlock(data);
liste_blocks['PREVIOUS'] = data.prev;
if (data.prev != '0000000000000000000000000000000000000000000000000000000000000000')
gotoBlock('PREVIOUS');
else
addDivForVoid();
});
return true;
}
function blockSelectorChange()
{
initBlockchain($('#blockSelector').val());
$('#fast_forward_btn').attr('data-original-title', $('#blockSelector').val());
}
function initBlockSelector()
{
// Init the selector
var select = $('#blockSelector');
if (typeof select.isInitSelector == 'undefined')
{
select.isInitSelector = true;
$.each(liste_blocks, function (key, bloc) {
select.append(new Option(bloc.name, bloc.name));
});
}
}
function initBlockExplorer(leblock)
{
initBlockSelector();
if (cur_height.length == 0) initBlockchain('LAST');
return true;
}
$(document).ready(function(){
blockchainListener.addBlockHook(initBlockExplorer);
});