lthn.io/app/Mod/Home/Controllers/HomeController.php
Claude 756be80d04
feat: complete module scaffolding — all 6 modules with controllers, routes, services
Modules built:
- Home: landing page with live chain stats and service directory
- Chain: DaemonRpc singleton, config, events
- Explorer: web + API controllers (block, tx, alias, search, stats)
- Names: TLD registrar (availability, lookup, directory, registration)
- Trade: DEX controllers + API (config, pairs, orders)
- Pool: dashboard + PoolClient service (stats, blocks, payments, miner)

Infrastructure:
- composer.json: lthn/lthn.io deps (core/php + laravel 12)
- Dockerfile: FrankenPHP with Caddy
- Caddyfile: PHP server config

Co-Authored-By: Charon <charon@lethean.io>
2026-04-03 16:26:17 +01:00

58 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;
}
}