rationaliser robot blockchain

This commit is contained in:
2018-12-30 10:40:10 +01:00
parent b932e778c6
commit 37442a9506
6 changed files with 16 additions and 165 deletions

View File

@@ -24,29 +24,21 @@ $block_hash = 'LAST';
// ---
if (isset($argv[1])) $block_hash = $argv[1];
echo $block_hash.' ';
// ---
// --- On interroge la blockchain
// --- => Ce qui a pour effet de placer le block dans le cache
// ---
$the_block = blockchain::getSpecialBlock($block_hash);
if ($the_block === FALSE) die();
echo $block_hash.' '.$the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL;
if ($block_hash == 'LAST')
{
$max = 0;
// On se met en retard d'au moins un bloc ...
while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip'))
for($max=0;($max<8)&&(!file_exists(DATA_PATH.'/json/'.$the_block->prev_block.'.zip'));$max++)
{
$block_hash = $the_block->prev_block;
$the_block = blockchain::getSpecialBlock($block_hash);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
// Mais pas plus de 5 blocs de retard ...
$max += 1;if ($max > 5) break;
echo 'CACHE '.$the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL;
}
}
echo $the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL;
?>