59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Mod\Home\Controllers;
|
||
|
|
|
||
|
|
use Illuminate\Routing\Controller;
|
||
|
|
use Mod\Chain\Services\DaemonRpc;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* lthn.io landing page.
|
||
|
|
*
|
||
|
|
* GET / — ecosystem overview with live chain stats
|
||
|
|
*/
|
||
|
|
class HomeController extends Controller
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private readonly DaemonRpc $rpc,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
public function index(): \Illuminate\View\View
|
||
|
|
{
|
||
|
|
$info = $this->rpc->getInfo();
|
||
|
|
$aliases = $this->rpc->getAllAliases();
|
||
|
|
|
||
|
|
return view('home::index', [
|
||
|
|
'height' => $info['height'] ?? 0,
|
||
|
|
'aliases' => count($aliases['aliases'] ?? []),
|
||
|
|
'transactions' => $info['tx_count'] ?? 0,
|
||
|
|
'hashrate' => $info['current_network_hashrate_350'] ?? 0,
|
||
|
|
'difficulty' => [
|
||
|
|
'pow' => $info['pow_difficulty'] ?? 0,
|
||
|
|
'pos' => $info['pos_difficulty'] ?? '0',
|
||
|
|
],
|
||
|
|
'services' => $this->countServicesByType($aliases['aliases'] ?? []),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
private function countServicesByType(array $aliases): array
|
||
|
|
{
|
||
|
|
$counts = ['gateway' => 0, 'service' => 0, 'exit' => 0, 'user' => 0];
|
||
|
|
|
||
|
|
foreach ($aliases as $alias) {
|
||
|
|
$comment = $alias['comment'] ?? '';
|
||
|
|
if (str_contains($comment, 'type=gateway')) {
|
||
|
|
$counts['gateway']++;
|
||
|
|
} elseif (str_contains($comment, 'type=exit')) {
|
||
|
|
$counts['exit']++;
|
||
|
|
} elseif (str_contains($comment, 'type=service')) {
|
||
|
|
$counts['service']++;
|
||
|
|
} else {
|
||
|
|
$counts['user']++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $counts;
|
||
|
|
}
|
||
|
|
}
|