lthn.io/app/Mod/Pool/Services/PoolClient.php
Claude 0899881138
feat(lthn.io): name registration API, Blade views, wallet RPC
- POST /v1/names/register endpoint with wallet RPC integration
- WalletRpc service for alias registration via daemon wallet
- Blade views for homepage, explorer, names directory, network status
- Explorer and Names modules with view namespaces and web controllers
- Pool endpoint graceful offline handling
- Explorer block detail, aliases, search views

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 23:04:27 +01:00

78 lines
2 KiB
PHP

<?php
declare(strict_types=1);
namespace Mod\Pool\Services;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
/**
* Mining pool API client.
*
* $pool = app(PoolClient::class);
* $stats = $pool->getStats();
*/
class PoolClient
{
private string $apiUrl;
private int $cacheTtl;
public function __construct()
{
$this->apiUrl = config('pool.api_url', 'http://127.0.0.1:2117');
$this->cacheTtl = config('pool.cache_ttl', 15);
}
public function getStats(): array
{
return Cache::remember('pool.stats', $this->cacheTtl, function () {
try {
$response = Http::timeout(5)->get("{$this->apiUrl}/stats");
return $response->successful() ? ($response->json() ?? []) : [];
} catch (\Throwable) {
return [];
}
});
}
public function getBlocks(): array
{
return Cache::remember('pool.blocks', $this->cacheTtl, function () {
try {
$response = Http::timeout(5)->get("{$this->apiUrl}/get_blocks");
return $response->successful() ? ($response->json() ?? []) : [];
} catch (\Throwable) {
return [];
}
});
}
public function getPayments(): array
{
return Cache::remember('pool.payments', $this->cacheTtl, function () {
try {
$response = Http::timeout(5)->get("{$this->apiUrl}/get_payments");
return $response->successful() ? ($response->json() ?? []) : [];
} catch (\Throwable) {
return [];
}
});
}
public function getMinerStats(string $address): array
{
try {
$response = Http::timeout(5)->get("{$this->apiUrl}/stats_address", [
'address' => $address,
]);
return $response->successful() ? ($response->json() ?? []) : [];
} catch (\Throwable) {
return [];
}
}
}