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>
62 lines
1.6 KiB
PHP
62 lines
1.6 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 () {
|
|
$response = Http::timeout(5)->get("{$this->apiUrl}/stats");
|
|
|
|
return $response->successful() ? $response->json() : [];
|
|
});
|
|
}
|
|
|
|
public function getBlocks(): array
|
|
{
|
|
return Cache::remember('pool.blocks', $this->cacheTtl, function () {
|
|
$response = Http::timeout(5)->get("{$this->apiUrl}/get_blocks");
|
|
|
|
return $response->successful() ? $response->json() : [];
|
|
});
|
|
}
|
|
|
|
public function getPayments(): array
|
|
{
|
|
return Cache::remember('pool.payments', $this->cacheTtl, function () {
|
|
$response = Http::timeout(5)->get("{$this->apiUrl}/get_payments");
|
|
|
|
return $response->successful() ? $response->json() : [];
|
|
});
|
|
}
|
|
|
|
public function getMinerStats(string $address): array
|
|
{
|
|
$response = Http::timeout(5)->get("{$this->apiUrl}/stats_address", [
|
|
'address' => $address,
|
|
]);
|
|
|
|
return $response->successful() ? $response->json() : [];
|
|
}
|
|
}
|