- artisan names:retry-dns command retries queued tickets - Checks pending tx confirmation against chain - Tracks ticket IDs in cache for iteration - Registered via ConsoleBooting event Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mod\Names\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Mod\Chain\Services\DaemonRpc;
|
|
use Mod\Chain\Services\WalletRpc;
|
|
|
|
/**
|
|
* php artisan names:retry-dns
|
|
*
|
|
* Retries queued DNS change tickets that failed due to busy chain.
|
|
*/
|
|
class RetryDnsTickets extends Command
|
|
{
|
|
protected $signature = 'names:retry-dns';
|
|
protected $description = 'Retry queued DNS change tickets';
|
|
|
|
public function handle(DaemonRpc $rpc, WalletRpc $wallet): int
|
|
{
|
|
$retried = 0;
|
|
$confirmed = 0;
|
|
|
|
// Scan cache for dns_ticket:* keys
|
|
// Cache driver must support tags or we scan known ticket IDs
|
|
// For file/array cache, we check tickets stored in a known list
|
|
$ticketIds = Cache::get('dns_ticket_ids', []);
|
|
|
|
if (empty($ticketIds)) {
|
|
$this->info('No tickets to process.');
|
|
|
|
return 0;
|
|
}
|
|
|
|
foreach ($ticketIds as $id) {
|
|
$ticket = Cache::get("dns_ticket:{$id}");
|
|
if (! $ticket) {
|
|
continue;
|
|
}
|
|
|
|
if ($ticket['status'] === 'confirmed') {
|
|
continue;
|
|
}
|
|
|
|
// Check if pending tx confirmed
|
|
if ($ticket['status'] === 'pending' && ! empty($ticket['tx_id'])) {
|
|
$alias = $rpc->getAliasByName($ticket['name']);
|
|
if ($alias && str_contains($alias['comment'] ?? '', 'dns=')) {
|
|
$ticket['status'] = 'confirmed';
|
|
Cache::put("dns_ticket:{$id}", $ticket, 3600);
|
|
$confirmed++;
|
|
$this->line(" Confirmed: {$ticket['name']} (ticket {$id})");
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
// Retry queued tickets
|
|
if ($ticket['status'] === 'queued') {
|
|
$result = $wallet->updateAlias(
|
|
$ticket['name'],
|
|
$ticket['address'],
|
|
$ticket['comment']
|
|
);
|
|
|
|
if (isset($result['tx_id'])) {
|
|
$ticket['status'] = 'pending';
|
|
$ticket['tx_id'] = $result['tx_id'];
|
|
Cache::put("dns_ticket:{$id}", $ticket, 3600);
|
|
$retried++;
|
|
$this->line(" Retried: {$ticket['name']} → tx {$result['tx_id']} (ticket {$id})");
|
|
} else {
|
|
$this->line(" Still queued: {$ticket['name']} — " . ($result['error'] ?? 'chain busy'));
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->info("Done. Retried: {$retried}, Confirmed: {$confirmed}");
|
|
|
|
return 0;
|
|
}
|
|
}
|