pool/web/yaamp/modules/explorer/coin.php
Tanguy Pruvot 5be767009d explorer: basic page ruler and enhance diff graph
pool blocks are now displayed on the graph
2016-01-11 16:27:20 +01:00

198 lines
No EOL
4.9 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
JavascriptFile("/extensions/jqplot/jquery.jqplot.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.dateAxisRenderer.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.highlighter.js");
$this->pageTitle = $coin->name." bloc explorer";
$start = (int) getparam('start');
if ($coin) echo <<<ENDJS
<script>
$(function() {
$('#favicon').remove();
$('head').append('<link href="{$coin->image}" id="favicon" rel="shortcut icon">');
});
</script>
ENDJS;
// version is used for multi algo coins
// but each coin use different values...
$multiAlgos = versionToAlgo($coin, 0) !== false;
echo "<br>";
echo "<div class='main-left-box'>";
echo "<div class='main-left-title'>$coin->name Explorer</div>";
echo "<div class='main-left-inner'>";
echo "<table class='dataGrid2'>";
echo "<thead>";
echo "<tr>";
echo "<th>Time</th>";
echo "<th>Height</th>";
echo "<th>Diff</th>";
echo "<th>Type</th>";
if ($multiAlgos) echo "<th>Algo</th>";
echo "<th>Transactions</th>";
echo "<th>Confirmations</th>";
echo "<th>Blockhash</th>";
echo "</tr>";
echo "</thead>";
$remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
if (!$start || $start > $coin->block_height)
$start = $coin->block_height;
for($i = $start; $i > max(1, $start-21); $i--)
{
$hash = $remote->getblockhash($i);
if(!$hash) continue;
$block = $remote->getblock($hash);
if(!$block) continue;
$d = datetoa2($block['time']);
$confirms = isset($block['confirmations'])? $block['confirmations']: '';
$tx = count($block['tx']);
$diff = $block['difficulty'];
$algo = versionToAlgo($coin, $block['version']);
$type = '';
if (arraySafeval($block,'nonce',0) > 0) $type = 'PoW';
else if (isset($block['auxpow'])) $type = 'Aux';
else if (isset($block['mint']) || arraySafeVal($block,'flags') == 'proof-of-stake') $type = 'PoS';
// debuglog($block);
echo "<tr class='ssrow'>";
echo "<td>$d</td>";
echo "<td><a href='/explorer?id=$coin->id&height=$i'>$i</a></td>";
echo "<td>$diff</td>";
echo "<td>$type</td>";
if ($multiAlgos) echo "<td>$algo</td>";
echo "<td>$tx</td>";
echo "<td>$confirms</td>";
echo "<td><span style='font-family: monospace;'><a href='/explorer?id=$coin->id&hash=$hash'>$hash</a></span></td>";
echo "</tr>";
}
echo "</table>";
$pager = '';
if ($start <= $coin->block_height - 20)
$pager = '<a href="?id='.$coin->id.'&start='.min($coin->block_height,$start+20).'"><< Prev</a>';
if ($start != $coin->block_height)
$pager .= '&nbsp; <a href="?id='.$coin->id.'">Now</a>';
if ($start > 20)
$pager .= '&nbsp; <a href="?id='.$coin->id.'&start='.max(1,$start-20).'">Next >></a>';
echo <<<end
<div id="pager" style="float: right; width: 200px; text-align: right; margin-right: 20px; margin-top: 4px;">$pager</div>
<div id="form" style="width: 650px; height: 50px;">
<form action="/explorer" method="get" style="padding-top: 4px; width: 650px;">
<input type="hidden" name="id" value="{$coin->id}">
<input type="text" name="height" class="main-text-input" placeholder="Height" style="width: 80px;">
<input type="text" name="txid" class="main-text-input" placeholder="Transaction hash" style="width: 450px;">
<input type="submit" value="Search" class="main-submit-button" >
</form>
</div>
end;
if ($start != $coin->block_height)
return;
echo <<<end
<div id="diff_graph" style="margin-right: 8px;">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>
<style type="text/css">
.jqplot-title {
margin-bottom: 3px;
}
.jqplot-xaxis-tick {
margin-top: 4px;
font-size: 10px;
}
.jqplot-yaxis-tick {
font-size: 7pt;
margin-top: -4px;
margin-right: 8px;
}
</style>
<script type="text/javascript" event="">
var last_graph_update = 0;
function graph_refresh()
{
var now = Date.now()/1000;
if (now < last_graph_update + 900) return;
last_graph_update = now;
var url = "/explorer/graph?id={$coin->id}";
$.get(url, '', diff_graph_data);
}
function diff_graph_data_trace(data)
{
$('#diff_graph').html(data);
}
function diff_graph_data(data)
{
var t = $.parseJSON(data);
var plot1 = $.jqplot('diff_graph', t,
{
title: '<b>Network diff</b>',
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: { formatString: '%H:%M' }
},
yaxis: {
min: 0.0,
tickOptions: { labelPosition: 'top', formatString: '%.3f' }
}
},
seriesDefaults:
{
markerOptions: { style: 'none' }
},
series:[
{
highlighter: { yvalues: 2, formatString: '<font size="1">%s %.3f<br/>Block %u</font>' }
},
{
showLine: false,
markerOptions: { style: 'circle', size: 6, color: 'silver' },
animation: { show: true },
highlighter: { yvalues: 3, formatString: '<font size="1">%s <span style="display:none;">%.1f</span>%g<br/>User block %u</font>' }
}
],
grid:
{
borderWidth: 1,
shadowWidth: 0,
shadowDepth: 0,
background: '#ffffff'
},
highlighter:
{
show: true
},
});
}
</script>
end;
app()->clientScript->registerScript('graph',"
graph_refresh();
", CClientScript::POS_READY);