From 64099481f0cf1b2d98cc0197c87748754f4803d4 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Tue, 29 Aug 2023 11:30:46 +0100 Subject: [PATCH] feat: add reset_subdomains function --- src/interface/naming.cairo | 2 ++ src/naming/main.cairo | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/interface/naming.cairo b/src/interface/naming.cairo index ed113e5..f28046b 100644 --- a/src/interface/naming.cairo +++ b/src/interface/naming.cairo @@ -37,6 +37,8 @@ trait INaming { fn transfer_domain(ref self: TContractState, domain: Span, target_id: u128); + fn reset_subdomains(ref self: TContractState, domain: Span); + // admin fn set_admin(ref self: TContractState, new_admin: ContractAddress); diff --git a/src/naming/main.cairo b/src/naming/main.cairo index ec9e6a2..4f20a18 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -29,6 +29,7 @@ mod Naming { DomainRenewal: DomainRenewal, DomainToResolver: DomainToResolver, DomainTransfer: DomainTransfer, + SubdomainsReset: SubdomainsReset, SaleMetadata: SaleMetadata, } @@ -62,6 +63,12 @@ mod Naming { new_owner: u128 } + #[derive(Drop, starknet::Event)] + struct SubdomainsReset { + #[key] + domain: Span, + } + #[derive(Drop, starknet::Event)] struct SaleMetadata { domain: felt252, @@ -299,6 +306,21 @@ mod Naming { .set_verifier_data(target_id, 'name', hashed_domain, 0); } + fn reset_subdomains(ref self: ContractState, domain: Span) { + self.assert_control_domain(domain, get_caller_address()); + let hashed_domain = self.hash_domain(domain); + let current_domain_data = self._domain_data.read(hashed_domain); + let new_domain_data = DomainData { + owner: current_domain_data.owner, + resolver: current_domain_data.resolver, + address: current_domain_data.address, + expiry: current_domain_data.expiry, + key: current_domain_data.key + 1, + parent_key: current_domain_data.parent_key, + }; + self._domain_data.write(hashed_domain, new_domain_data); + self.emit(Event::SubdomainsReset(SubdomainsReset { domain: domain, })); + } // ADMIN