lthn.io/app/Mod/Trade/Controllers/TradeApiController.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

73 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Mod\Trade\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Mod\Chain\Services\DaemonRpc;
/**
* DEX trade API — compatible with the upstream zano_trade_backend.
*
* GET /v1/trade/pairs — available trading pairs
* GET /v1/trade/pair/{id} — single pair details
* POST /v1/trade/order — create order
* GET /v1/trade/orders — list orders
* GET /v1/trade/config — exchange configuration
*/
class TradeApiController extends Controller
{
public function __construct(
private readonly DaemonRpc $rpc,
) {}
public function config(): JsonResponse
{
$info = $this->rpc->getInfo();
return response()->json([
'success' => true,
'data' => [
'currencies' => [
[
'name' => 'LTHN',
'code' => 'lethean',
'type' => 'crypto',
'asset_id' => 'd6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a',
'asset_info' => ['decimal_point' => 12],
],
],
'network' => config('chain.network'),
'height' => $info['height'] ?? 0,
],
]);
}
public function pairs(): JsonResponse
{
// Pairs are configured, not discovered — for now return LTHN native
return response()->json([
'success' => true,
'data' => [],
]);
}
public function pair(int $id): JsonResponse
{
return response()->json([
'success' => false,
'error' => 'Pair not found',
], 404);
}
public function orders(): JsonResponse
{
return response()->json([
'success' => true,
'data' => [],
]);
}
}