first commit
This commit is contained in:
50
blockchain/cache.php
Normal file
50
blockchain/cache.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
// ---
|
||||
// --- Listening to blockchain.info to get the last block
|
||||
// ---
|
||||
|
||||
// ---
|
||||
// --- La config globale
|
||||
// ---
|
||||
require_once '../global/inc/config.php';
|
||||
|
||||
// ---
|
||||
// --- Internal dependances
|
||||
// ---
|
||||
require_once 'inc/block.php';
|
||||
|
||||
// ---
|
||||
// --- Par défaut on cherche le dernier block
|
||||
// ---
|
||||
$block_hash = 'LAST';
|
||||
|
||||
// ---
|
||||
// --- 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();
|
||||
|
||||
// ---
|
||||
// --- On en recherche 3 sur approximativement 6 heures (36 blocks)
|
||||
// ---
|
||||
$max = 3;
|
||||
$max2 = 36;
|
||||
while(($max > 0)&&($max2 > 0))
|
||||
{
|
||||
$block_hash = $the_block->prev_block;
|
||||
|
||||
if (!file_exists(DATA_PATH.'/json/'.$block_hash.'.zip'))
|
||||
{
|
||||
$max--;
|
||||
echo 'CACHE '.$block_hash.' '.($the_block->height-1).PHP_EOL;
|
||||
}
|
||||
|
||||
$the_block = blockchain::getBlockWithHash($block_hash);
|
||||
if ($the_block === FALSE) die();
|
||||
|
||||
$max2--;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user