Ajout du dernier block par le haut
This commit is contained in:
@@ -19,9 +19,10 @@ blockchainExplorer = function(){
|
||||
function _getblockNameFromHash(hash)
|
||||
{
|
||||
var retour = '';
|
||||
liste_blocks.forEach(function(item){
|
||||
if (hash == item.hash) retour = item.name;
|
||||
});
|
||||
if (liste_blocks != null)
|
||||
liste_blocks.forEach(function(item){
|
||||
if (hash == item.hash) retour = item.name;
|
||||
});
|
||||
return retour;
|
||||
}
|
||||
|
||||
@@ -209,6 +210,25 @@ blockchainExplorer = function(){
|
||||
return true;
|
||||
}
|
||||
|
||||
function _ajouterTopBlock(data)
|
||||
{
|
||||
// Bloquer la navigation pendant le calcul
|
||||
if (!flag_nav) return false;
|
||||
flag_nav = false;
|
||||
|
||||
// Ajouter un div
|
||||
_addDivForBlock(data.height);
|
||||
|
||||
// Mettre les infos dans le div
|
||||
_addInfoForBlock(data);
|
||||
|
||||
// Décaler le tableau cur_height par le haut
|
||||
cur_height.unshift(data.height);
|
||||
|
||||
// Maintenir la liste des blocks
|
||||
liste_blocks['BLOCK_'+data.height] = data.hash;
|
||||
}
|
||||
|
||||
function _ajouterPreviousBlock()
|
||||
{
|
||||
// Bloquer la navigation pendant le calcul
|
||||
@@ -246,6 +266,11 @@ blockchainExplorer = function(){
|
||||
_gotoBlock('PREVIOUS');
|
||||
else
|
||||
_addDivForVoid();
|
||||
|
||||
// Ajouter le trigger sur les nouveaux blocks
|
||||
if (block_name == 'LAST')
|
||||
blockchainListener.addBlockHook(_ajouterTopBlock);
|
||||
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -289,6 +314,7 @@ blockchainExplorer = function(){
|
||||
|
||||
ajouterPreviousBlock: _ajouterPreviousBlock,
|
||||
getblocHashFromName: _getblocHashFromName,
|
||||
ajouterTopBlock : _ajouterTopBlock,
|
||||
|
||||
init: _init
|
||||
};
|
||||
|
||||
@@ -17,19 +17,26 @@ blockchainListener = function(){
|
||||
|
||||
function _isBlockNew(leblock)
|
||||
{
|
||||
return true;
|
||||
return ((_last_block == null)||(_last_block.hash != leblock.hash));
|
||||
};
|
||||
|
||||
function _getLastBlockInfo()
|
||||
{
|
||||
$.get( "data/getBlockInfo.php", function( data ) {
|
||||
if (_isBlockNew(data))
|
||||
{
|
||||
_last_block = data;
|
||||
_last_block_hooks.forEach(function(trigger) {
|
||||
trigger(data);
|
||||
});
|
||||
}
|
||||
if (_last_block_hooks.length > 0)
|
||||
{
|
||||
if (_isBlockNew(data))
|
||||
{
|
||||
_last_block = data;
|
||||
_last_block_hooks.forEach(function(trigger) {
|
||||
if (trigger instanceof Function)
|
||||
trigger(data);
|
||||
else
|
||||
console.log(trigger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, "json" );
|
||||
|
||||
setTimeout(_getLastBlockInfo, 30000);
|
||||
|
||||
Reference in New Issue
Block a user