You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
2.0 KiB

<?php
// ---
// --- La config globale
// ---
chdir('/opt/TOPISTO/apps');
require_once '/opt/TOPISTO/apps/global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
// ---
// --- Par défaut on cherche le dernier block en cache
// ---
$block_hash = blockchain::getLastCacheBlockHash();
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($_REQUEST['block_hash'])) $block_hash = $_REQUEST['block_hash'];
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$the_name = blockchain::hash2SpecialName($the_block->hash);
if ($the_name == $the_block->hash) $the_name ='';
// ---
// --- Si on a passé un hash, le navigateur peut le mettre en cache
// ---
if (isset($_REQUEST['block_hash'])) 
{
	$seconds_to_cache = 180; // 3 minutes de cache HTTP
	$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
	header("Expires: $ts");
	header("Pragma: cache");
	header("Cache-Control: max-age=$seconds_to_cache");
	header('Content-Type: application/json');
}
// ---
// --- Récupérer la liste des images existantes pour ce bloc
// --- 
$img_liste = glob(DATA_PATH.'/*/'.$the_block->hash.'.png');
$json_img_liste = json_encode($img_liste);
$message = '{"hash":"'.$the_block->hash.'", "block_index":"'.$the_block->block_index.'", "time":"'.$the_block->time.'", "height":"'.$the_block->height.'", "topisto_outputs":"'.$the_block->topisto_outputs.'", "prev":"'.$the_block->prev_block.'", "topisto_inputs":"'.$the_block->topisto_inputs.'", "topisto_fees":"'.$the_block->topisto_fees.'", "topisto_reward":"'.$the_block->topisto_reward.'", "nonce":"'.$the_block->nonce.'", "n_tx":"'.$the_block->n_tx.'", "img_list":'.$json_img_liste.'}';
if ($_REQUEST['FULL'] == 'OK') $message = json_encode($the_block);
header('Content-Type: application/json');
die($message);
?>