CorePHP manages the testnet chain binaries via ConsoleBooting lifecycle. chain:start checks if daemon/wallet are running, starts them if not, waits for RPC readiness. chain:status shows daemon height, aliases, PoS status, wallet and LNS node state. Config-driven paths for binary locations, data dirs, mining address. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
60 lines
2 KiB
PHP
60 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mod\Chain\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Mod\Chain\Services\DaemonRpc;
|
|
|
|
/**
|
|
* Show chain daemon and wallet status.
|
|
*
|
|
* php artisan chain:status
|
|
*/
|
|
class ChainStatus extends Command
|
|
{
|
|
protected $signature = 'chain:status';
|
|
|
|
protected $description = 'Show testnet chain daemon and wallet status';
|
|
|
|
public function handle(DaemonRpc $rpc): int
|
|
{
|
|
$this->info('=== Chain Status ===');
|
|
|
|
// Daemon — safe: hardcoded process name, no user input
|
|
$daemonRunning = $this->isRunning('lethean-testnet-chain-node');
|
|
$this->line('Daemon: ' . ($daemonRunning ? '<fg=green>running</>' : '<fg=red>stopped</>'));
|
|
|
|
if ($daemonRunning) {
|
|
$info = $rpc->getInfo();
|
|
if (! isset($info['_offline'])) {
|
|
$this->line(" Height: {$info['height']}");
|
|
$this->line(" Aliases: {$info['alias_count']}");
|
|
$this->line(" TX Pool: {$info['tx_pool_size']}");
|
|
$this->line(' PoS: ' . (($info['pos_allowed'] ?? false) ? 'active' : 'inactive'));
|
|
$this->line(" Difficulty: {$info['pow_difficulty']}");
|
|
} else {
|
|
$this->warn(' RPC unreachable');
|
|
}
|
|
}
|
|
|
|
// Wallet — safe: hardcoded process name
|
|
$walletRunning = $this->isRunning('lethean-wallet-cli');
|
|
$this->line('Wallet: ' . ($walletRunning ? '<fg=green>running</>' : '<fg=red>stopped</>'));
|
|
|
|
// LNS — safe: hardcoded process name
|
|
$lnsRunning = $this->isRunning('lns-new');
|
|
$this->line('LNS: ' . ($lnsRunning ? '<fg=green>running</>' : '<fg=red>stopped</>'));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
private function isRunning(string $processName): bool
|
|
{
|
|
// Safe: escapeshellarg prevents injection, process names are hardcoded
|
|
exec("pgrep -f " . escapeshellarg($processName), $output); // @codeCoverageIgnore
|
|
|
|
return ! empty($output);
|
|
}
|
|
}
|