Skip to content

Commit

Permalink
feat: allows to clear old domain target record
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Dec 11, 2023
1 parent fe75b14 commit 7edd27a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/interface/naming.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ trait INaming<TContractState> {

fn set_address_to_domain(ref self: TContractState, domain: Span<felt252>);

fn clear_legacy_domain_to_address(ref self: TContractState, domain: Span<felt252>);

fn reset_address_to_domain(ref self: TContractState);

fn set_domain_to_resolver(ref self: TContractState, domain: Span<felt252>, resolver: ContractAddress);
fn set_domain_to_resolver(
ref self: TContractState, domain: Span<felt252>, resolver: ContractAddress
);

// admin
fn set_admin(ref self: TContractState, new_admin: ContractAddress);
Expand Down
25 changes: 25 additions & 0 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod Naming {
DomainMint: DomainMint,
DomainRenewal: DomainRenewal,
DomainResolverUpdate: DomainResolverUpdate,
LegacyDomainToAddressClear: LegacyDomainToAddressClear,
AddressToDomainUpdate: AddressToDomainUpdate,
DomainTransfer: DomainTransfer,
SubdomainsReset: SubdomainsReset,
Expand Down Expand Up @@ -62,6 +63,12 @@ mod Naming {
resolver: ContractAddress
}

#[derive(Drop, starknet::Event)]
struct LegacyDomainToAddressClear {
#[key]
domain: Span<felt252>,
}

#[derive(Drop, starknet::Event)]
struct AddressToDomainUpdate {
#[key]
Expand Down Expand Up @@ -372,6 +379,24 @@ mod Naming {
self.set_address_to_domain_util(address, domain);
}

// this allows to reset the target set via Cairo Zero, can't be tested
fn clear_legacy_domain_to_address(ref self: ContractState, domain: Span<felt252>) {
let address = get_caller_address();
self.assert_control_domain(domain, address);
self.emit(Event::LegacyDomainToAddressClear(LegacyDomainToAddressClear { domain }));
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: ContractAddressZeroable::zero(),
expiry: current_domain_data.expiry,
key: current_domain_data.key,
parent_key: current_domain_data.parent_key,
};
self._domain_data.write(hashed_domain, new_domain_data);
}

fn reset_address_to_domain(ref self: ContractState) {
let address = get_caller_address();
self
Expand Down

0 comments on commit 7edd27a

Please sign in to comment.