Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ function __construct() {
$blockInfo = $bitcoind->getblock($blockchainInfo["bestblockhash"]);
$this->bHeightAgo = round((time()-checkInt($blockInfo["time"]))/60, 1);
$this->bcSize = bytesToGb($blockchainInfo["size_on_disk"], 1);
$this->diff = checkInt($blockchainInfo["difficulty"]);
$this->hashRate = round(checkInt($miningInfo["networkhashps"])/1000000000000000000,3);
$this->diff = formatDiff($blockchainInfo["difficulty"], 2);
$this->hashRate = formatHash($miningInfo["networkhashps"], 3);
$this->mNetTime = getDateTime($blockchainInfo["mediantime"]);
// Blockchain -> Soft forks
if(isset($blockchainInfo["softforks"])) {
Expand All @@ -166,3 +166,5 @@ function __construct() {
}
}
}


33 changes: 33 additions & 0 deletions src/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,36 @@ function bytesToGb($size, int $round = 1){
return $size;
}

function formatDiff($diff, int $round = 1){
// Define the units ('', Kb, Mb, Gb, Tb, Pb, Eb)
$units = array('', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb');
$i = 0;

// Loop until the hashrate is less than 1000, incrementing the unit
while ($diff >= 1000 && $i < count($units) - 1) {
$diff /= 1000;
$i++;
}

// Format the number with the specified precision and append the unit
return number_format($diff, $round) . ' ' . $units[$i];
}

function formatHash($hashes, int $round = 1){
// Define the units (H/s, KH/s, MH/s, GH/s, TH/s, PH/s, EH/s)
$units = array('H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s', 'EH/s', 'ZH/s');
$i = 0;

// Loop until the hashrate is less than 1000, incrementing the unit
while ($hashes >= 1000 && $i < count($units) - 1) {
$hashes /= 1000;
$i++;
}

// Format the number with the specified precision and append the unit
return number_format($hashes, $round) . ' ' . $units[$i];
}

function getDateTime($timestamp){
$date = date("Y-m-d H:i:s",(int) $timestamp);
return $date;
Expand Down Expand Up @@ -721,3 +751,6 @@ function compare($a, $b)
}

?>



3 changes: 2 additions & 1 deletion views/main.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<tr><td style="width:50%;"><i class="fa fa-clone fa-fw"></i> Chain </td><td> <span class="badge"><?= $content['node']->chain ?></span></td></tr>
<tr><td><i class="fa fa-hdd-o fa-fw"></i> Size </td><td> <?= $content['node']->bcSize ?> GB</td></tr>
<tr><td><i class="fa fa-key fa-fw"></i> Difficulty </td><td> <?= $content['node']->diff ?></td></tr>
<tr><td><i class="fa fa-cogs fa-fw"></i> Hashrate </td><td> <?= $content['node']->hashRate ?> EH/s</td></tr>
<tr><td><i class="fa fa-cogs fa-fw"></i> Hashrate </td><td> <?= $content['node']->hashRate ?></td></tr>
<tr><td><i class="fa fa-clock-o fa-fw"></i> Mediantime </td><td> <?= $content['node']->mNetTime ?></td></tr>
</table>
</div>
Expand Down Expand Up @@ -352,3 +352,4 @@

</body>
</html>