Refonte Explorateur

This commit is contained in:
2019-12-21 19:54:39 +01:00
parent 315a82c2fb
commit 8621260f26
5 changed files with 469 additions and 113 deletions

View File

@@ -9,10 +9,10 @@ blockchainListener = function(){
var _last_block = null;
var _last_block_hooks = [];
function _logBlockHash(leblock)
function _logBlockHash(leblock, flag)
{
if (flag) return "logBlockHash";
console.log('Last Block detected : '+leblock.hash);
return true;
};
function _isBlockNew(leblock)
@@ -20,34 +20,43 @@ blockchainListener = function(){
return ((_last_block == null)||(_last_block.hash != leblock.hash));
};
function _getLastBlockInfo()
function _lastBlockTrigger()
{
$.get( "data/getBlockInfo.php", function( data ) {
if (_last_block_hooks.length > 0)
{
if (_isBlockNew(data))
{
{
if (_last_block = data != null)
{
_last_block_hooks.forEach(function(trigger) {
if (trigger instanceof Function) trigger(data);
});
}
_last_block = data;
_last_block_hooks.forEach(function(trigger) {
if (trigger instanceof Function)
trigger(data);
else
console.log(trigger);
});
}
}
}, "json" );
setTimeout(_getLastBlockInfo, 30000);
setTimeout(_lastBlockTrigger, 30000);
};
function _addBlockHook(addBlockHook){
_last_block_hooks.push(addBlockHook);
var hookname = addBlockHook(null, true);
var flag_add = true;
_last_block_hooks.forEach(function(trigger) {
if (trigger instanceof Function)
{
var local_hookname = trigger(null, true);
flag_add = flag_add && (local_hookname == hookname);
}
});
if (flag_add) _last_block_hooks.push(addBlockHook);
};
function _init(){
_last_block_hooks.push(_logBlockHash);
_getLastBlockInfo();
_addBlockHook(_logBlockHash);
_lastBlockTrigger();
};
return {init: _init, addBlockHook: _addBlockHook};