diff --git a/src/interface/naming.cairo b/src/interface/naming.cairo index 5aba5c2..f598e6d 100644 --- a/src/interface/naming.cairo +++ b/src/interface/naming.cairo @@ -49,6 +49,8 @@ trait INaming { fn reset_address_to_domain(ref self: TContractState); + fn migrate_domain(ref self: TContractState, domain: Span); + fn set_domain_to_resolver( ref self: TContractState, domain: Span, resolver: ContractAddress ); diff --git a/src/naming/main.cairo b/src/naming/main.cairo index a5e745f..026e0d8 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -36,6 +36,7 @@ mod Naming { LegacyDomainToAddressClear: LegacyDomainToAddressClear, AddressToDomainUpdate: AddressToDomainUpdate, DomainTransfer: DomainTransfer, + DomainMigrated: DomainMigrated, SubdomainsReset: SubdomainsReset, SaleMetadata: SaleMetadata, StorageReadEvent: storage_read_component::Event @@ -84,6 +85,12 @@ mod Naming { new_owner: u128 } + #[derive(Drop, starknet::Event)] + struct DomainMigrated { + #[key] + domain: Span, + } + #[derive(Drop, starknet::Event)] struct SubdomainsReset { #[key] @@ -332,6 +339,10 @@ mod Naming { } }; + // if a subdomain is created + if self._hash_to_domain.read((hashed_domain, 0)) == 0 { + self.store_unhashed_domain(domain, hashed_domain); + }; self._domain_data.write(hashed_domain, new_domain_data); self .emit( @@ -408,6 +419,13 @@ mod Naming { self.set_address_to_domain_util(address, array![0].span()); } + // allows to unhash domains minted in Cairo Zero + fn migrate_domain(ref self: ContractState, domain: Span) { + let hashed_domain = self.hash_domain(domain); + self.store_unhashed_domain(domain, hashed_domain); + self.emit(Event::DomainMigrated(DomainMigrated { domain })); + } + fn set_domain_to_resolver( ref self: ContractState, domain: Span, resolver: ContractAddress ) { diff --git a/src/naming/utils.cairo b/src/naming/utils.cairo index 5c73168..ff767e8 100644 --- a/src/naming/utils.cairo +++ b/src/naming/utils.cairo @@ -1,3 +1,4 @@ +use core::array::SpanTrait; use naming::{ naming::main::{Naming, Naming::{_hash_to_domain, _hash_to_domainContractMemberStateTrait}} }; @@ -16,6 +17,17 @@ impl UtilsImpl of UtilsTrait { return hashed_domain; } + fn store_unhashed_domain( + ref self: Naming::ContractState, mut domain: Span, hashed: felt252 + ) { + loop { + match domain.pop_back() { + Option::Some(x) => { self._hash_to_domain.write((hashed, domain.len()), *x); }, + Option::None => { break; } + } + }; + } + fn unhash_domain(self: @Naming::ContractState, domain_hash: felt252) -> Span { let mut i = 0; let mut domain = ArrayTrait::new();