2026-04-04 02:41:29 +01:00
|
|
|
<?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;
|
2026-04-04 12:06:00 +01:00
|
|
|
use Mod\Names\Models\DnsTicket;
|
2026-04-04 02:41:29 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* php artisan names:retry-dns
|
|
|
|
|
*
|
2026-04-04 12:06:00 +01:00
|
|
|
* Retries queued DNS change tickets and confirms pending ones.
|
2026-04-04 02:41:29 +01:00
|
|
|
*/
|
|
|
|
|
class RetryDnsTickets extends Command
|
|
|
|
|
{
|
|
|
|
|
protected $signature = 'names:retry-dns';
|
2026-04-04 12:06:00 +01:00
|
|
|
|
2026-04-04 02:41:29 +01:00
|
|
|
protected $description = 'Retry queued DNS change tickets';
|
|
|
|
|
|
|
|
|
|
public function handle(DaemonRpc $rpc, WalletRpc $wallet): int
|
|
|
|
|
{
|
|
|
|
|
$retried = 0;
|
|
|
|
|
$confirmed = 0;
|
|
|
|
|
|
2026-04-04 12:06:00 +01:00
|
|
|
// Confirm pending tickets
|
|
|
|
|
DnsTicket::pending()->each(function (DnsTicket $ticket) use ($rpc, &$confirmed) {
|
|
|
|
|
if (! $ticket->tx_id) {
|
|
|
|
|
return;
|
2026-04-04 02:41:29 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-04 12:06:00 +01:00
|
|
|
$alias = $rpc->getAliasByName($ticket->name);
|
|
|
|
|
if ($alias && str_contains($alias['comment'] ?? '', 'dns=')) {
|
|
|
|
|
$ticket->confirm();
|
|
|
|
|
Cache::forget("dns_edit_lock:{$ticket->name}");
|
|
|
|
|
$confirmed++;
|
|
|
|
|
$this->line(" Confirmed: {$ticket->name} (ticket {$ticket->ticket_id})");
|
2026-04-04 02:41:29 +01:00
|
|
|
}
|
2026-04-04 12:06:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Retry queued tickets
|
|
|
|
|
DnsTicket::queued()->each(function (DnsTicket $ticket) use ($wallet, &$retried) {
|
|
|
|
|
$result = $wallet->updateAlias(
|
|
|
|
|
$ticket->name,
|
|
|
|
|
$ticket->address ?? '',
|
|
|
|
|
$ticket->comment ?? ''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isset($result['tx_id'])) {
|
|
|
|
|
$ticket->update([
|
|
|
|
|
'status' => 'pending',
|
|
|
|
|
'tx_id' => $result['tx_id'],
|
|
|
|
|
]);
|
|
|
|
|
$retried++;
|
|
|
|
|
$this->line(" Retried: {$ticket->name} → tx {$result['tx_id']}");
|
|
|
|
|
} else {
|
|
|
|
|
$this->line(" Still queued: {$ticket->name} — " . ($result['error'] ?? 'chain busy'));
|
2026-04-04 02:41:29 +01:00
|
|
|
}
|
2026-04-04 12:06:00 +01:00
|
|
|
});
|
2026-04-04 02:41:29 +01:00
|
|
|
|
|
|
|
|
$this->info("Done. Retried: {$retried}, Confirmed: {$confirmed}");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|