explorer: improve the diff graph

handle some multi algos coins and more blocks
This commit is contained in:
Tanguy Pruvot 2015-09-18 20:03:45 +02:00
parent 9efad94548
commit dc0bb5a0d8
4 changed files with 56 additions and 17 deletions

View file

@ -1,6 +1,6 @@
<?php
include "util.php";
require_once("util.php");
class ExplorerController extends CommonController
{

View file

@ -2,7 +2,7 @@
JavascriptFile("/extensions/jqplot/jquery.jqplot.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.dateAxisRenderer.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.barRenderer.js");
//JavascriptFile("/extensions/jqplot/plugins/jqplot.barRenderer.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.highlighter.js");
$this->pageTitle = $coin->name." bloc explorer";
@ -16,6 +16,10 @@ if ($coin) echo <<<ENDJS
</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>";
@ -28,6 +32,7 @@ echo "<tr>";
echo "<th>Time</th>";
echo "<th>Height</th>";
echo "<th>Diff</th>";
if ($multiAlgos) echo "<th>Algo</th>";
echo "<th>Transactions</th>";
echo "<th>Confirmations</th>";
echo "<th>Blockhash</th>";
@ -35,7 +40,7 @@ echo "</tr>";
echo "</thead>";
$remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
for($i = $coin->block_height; $i > $coin->block_height-25; $i--)
for($i = $coin->block_height; $i > max(0, $coin->block_height-25); $i--)
{
$hash = $remote->getblockhash($i);
if(!$hash) continue;
@ -47,12 +52,14 @@ for($i = $coin->block_height; $i > $coin->block_height-25; $i--)
$confirms = isset($block['confirmations'])? $block['confirmations']: '';
$tx = count($block['tx']);
$diff = $block['difficulty'];
$algo = versionToAlgo($coin, $block['version']);
// 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>";
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>";

View file

@ -3,13 +3,15 @@
$series = array();
$n = 0;
echo '[';
$json = controller()->memcache->get("yiimp-explorer-diff-".$coin->symbol);
$series['diff'] = controller()->memcache->get("yiimp-explorer-diff-".$coin->symbol);
if (empty($json)) {
// version is used in multi algo coins
$multiAlgos = versionToAlgo($coin, 0) !== false;
if (empty($series['diff'])) {
$remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
for($i = $coin->block_height; $i > $coin->block_height-100; $i--)
for($i = $coin->block_height; $i > max(0, $coin->block_height-500); $i--)
{
$hash = $remote->getblockhash($i);
if(!$hash) continue;
@ -21,20 +23,33 @@ if (empty($series['diff'])) {
$tm = $block['time'];
$dt = date('Y-m-d H:i:s', $tm);
$tx = count($block['tx']);
// $tx = count($block['tx']);
$diff = $block['difficulty'];
$vers = $block['version'];
$algo = versionToAlgo($coin, $vers);
$series['diff'][$n] = array($dt,$diff);
$series['txs'][$n] = array($dt,$tx);
if (!$multiAlgos)
$series['diff'][$n] = array($dt,$diff);
else {
if ($algo == 'sha256') $diff /= 100000.;
if ($algo == 'skein') $diff /= 10.;
$series[$algo][$n] = array($dt,$diff);
}
}
if (!$multiAlgos)
$json = json_encode(array_values($series['diff']));
else {
$json = '';
foreach ($series as $algo => $data) {
$values = array_values($data);
$json .= json_encode($values).',';
}
$json = rtrim($json, ',');
}
}
echo json_encode(array_values($series['diff']));
//echo ",";
//echo json_encode(array_values($series['txs']));
echo ']';
echo "[$json]";
// memcache the data
if (!empty($series['diff']))
controller()->memcache->set("yiimp-explorer-diff-".$coin->symbol, $series['diff'], 120);
controller()->memcache->set("yiimp-explorer-diff-".$coin->symbol, $json, 120);

View file

@ -144,3 +144,20 @@ function remove0x($string)
return $string;
}
// version is used for multi algo coins
function versionToAlgo($coin, $version)
{
$algos['DGB'] = array(
0=>'scrypt', 1=>'sha256', 2=>'groestl', 3=>'skein', 4=>'qubit'
);
$algos['J'] = array(
2 =>'sha256', 3=>'x11', 4=>'x13', 5=>'x15', 6=>'scrypt',
7 =>'nist5', 8 =>'groestl', 9=>'penta', 10=>'whirl',
11=>'luffa', 12=>'keccak', 13=>'quark', 15=>'bastion'
);
if ($coin->symbol == 'DGB')
return arraySafeVal($algos['DGB'], ($version >> 9) & 7, '');
else if (isset($algos[$coin->symbol]))
return arraySafeVal($algos[$coin->symbol], $version, '');
return false;
}