lthn.io/app/Core/Webhook/WebhookController.php
Claude 41a90cbff8
feat: lthn.io API serving live chain data
Fixed: basePath self→static binding, namespace detection, event wiring,
SQLite cache, file cache driver. All Mod Boot classes converted to
$listens pattern for lifecycle event discovery.

Working endpoints:
- /v1/explorer/info — live chain height, difficulty, aliases
- /v1/explorer/stats — formatted chain statistics
- /v1/names/directory — alias directory grouped by type
- /v1/names/available/{name} — name availability check
- /v1/names/lookup/{name} — name details

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

49 lines
1.3 KiB
PHP

<?php
/*
* Core PHP Framework
*
* Licensed under the European Union Public Licence (EUPL) v1.2.
* See LICENSE file for details.
*/
declare(strict_types=1);
namespace Core\Webhook;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class WebhookController
{
public function handle(Request $request, string $source): JsonResponse
{
$signatureValid = null;
// Check for registered verifier
$verifier = app()->bound("webhook.verifier.{$source}")
? app("webhook.verifier.{$source}")
: null;
if ($verifier instanceof WebhookVerifier) {
$secret = config("webhook.secrets.{$source}", '');
$signatureValid = $verifier->verify($request, $secret);
}
// Extract event type from common payload patterns
$payload = $request->json()->all();
$eventType = $payload['type'] ?? $payload['event_type'] ?? $payload['event'] ?? null;
$call = WebhookCall::create([
'source' => $source,
'event_type' => is_string($eventType) ? $eventType : null,
'headers' => $request->headers->all(),
'payload' => $payload,
'signature_valid' => $signatureValid,
]);
event(new WebhookReceived($source, $call->id));
return response()->json(['ok' => true]);
}
}