'A', 'host' => '@', 'value' => '1.2.3.4'], * ]); */ class UpdateDnsRecords { public function __construct( private readonly DaemonRpc $rpc, private readonly WalletRpc $wallet, ) {} public function handle(string $name, array $records): DnsTicket { $name = strtolower(trim($name)); // Edit lock $editLock = "dns_edit_lock:{$name}"; if (Cache::has($editLock)) { throw ValidationException::withMessages([ 'name' => 'A DNS update for this name is already pending.', ]); } $alias = $this->rpc->getAliasByName($name); if (! $alias) { throw ValidationException::withMessages([ 'name' => 'Name not registered.', ]); } $address = $alias['address'] ?? ''; $comment = $this->buildComment($records); $result = $this->wallet->updateAlias($name, $address, $comment); if (isset($result['tx_id'])) { Cache::put($editLock, true, 300); $ticket = DnsTicket::open($name, $records, $result['tx_id'], $address, $comment); } else { $ticket = DnsTicket::open($name, $records, null, $address, $comment); } NameActivity::log($name, 'dns_updated', [ 'ticket_id' => $ticket->ticket_id, 'records' => $records, ], request()?->ip()); return $ticket; } private function buildComment(array $records): string { $dnsEntries = []; foreach ($records as $record) { $type = $record['type'] ?? 'A'; $host = $record['host'] ?? '@'; $value = $record['value'] ?? ''; if ($value) { $dnsEntries[] = "{$type}:{$host}:{$value}"; } } $comment = 'v=lthn1;type=user'; if ($dnsEntries) { $comment .= ';dns=' . implode('|', $dnsEntries); } return $comment; } public static function run(string $name, array $records): DnsTicket { return app(static::class)->handle($name, $records); } }