From b15f7c142fc0fcd0bf7c4cf093b9ca74a7e8a757 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 11 Apr 2024 09:54:45 +0200 Subject: [PATCH] feat: add support for ccip reverse resolving --- src/interface/naming.cairo | 4 ++-- src/naming/main.cairo | 8 ++++---- src/tests/naming/test_usecases.cairo | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/interface/naming.cairo b/src/interface/naming.cairo index c38c0d9..ec6eaaf 100644 --- a/src/interface/naming.cairo +++ b/src/interface/naming.cairo @@ -19,7 +19,7 @@ trait INaming { self: @TContractState, domain: Span, hint: Span ) -> ContractAddress; - fn address_to_domain(self: @TContractState, address: ContractAddress) -> Span; + fn address_to_domain(self: @TContractState, address: ContractAddress, hint: Span) -> Span; // external fn buy( @@ -85,7 +85,7 @@ trait INaming { fn reset_subdomains(ref self: TContractState, domain: Span); - fn set_address_to_domain(ref self: TContractState, domain: Span); + fn set_address_to_domain(ref self: TContractState, domain: Span, hint: Span); fn clear_legacy_domain_to_address(ref self: TContractState, domain: Span); diff --git a/src/naming/main.cairo b/src/naming/main.cairo index 1aa1f98..bd94562 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -232,11 +232,11 @@ mod Naming { } // This function allows to find which domain to use to display an account - fn address_to_domain(self: @ContractState, address: ContractAddress) -> Span { + fn address_to_domain(self: @ContractState, address: ContractAddress, hint: Span) -> Span { let mut domain = ArrayTrait::new(); self.read_address_to_domain(address, ref domain); if domain.len() != 0 - && self.domain_to_address(domain.span(), array![].span()) == address { + && self.domain_to_address(domain.span(), hint) == address { domain.span() } else { let identity = IIdentityDispatcher { @@ -582,10 +582,10 @@ mod Naming { // will override your main id - fn set_address_to_domain(ref self: ContractState, domain: Span) { + fn set_address_to_domain(ref self: ContractState, domain: Span, hint: Span) { let address = get_caller_address(); assert( - self.domain_to_address(domain, array![].span()) == address, + self.domain_to_address(domain, hint) == address, 'domain not pointing back' ); self.emit(Event::AddressToDomainUpdate(AddressToDomainUpdate { address, domain })); diff --git a/src/tests/naming/test_usecases.cairo b/src/tests/naming/test_usecases.cairo index f08ad75..2317ae6 100644 --- a/src/tests/naming/test_usecases.cairo +++ b/src/tests/naming/test_usecases.cairo @@ -257,18 +257,18 @@ fn test_set_address_to_domain() { // set reverse resolving identity.set_main_id(id1); - let expect_domain1 = naming.address_to_domain(caller); + let expect_domain1 = naming.address_to_domain(caller, array![].span()); assert(expect_domain1 == first_domain, 'wrong rev resolving 1'); // override reverse resolving let second_domain = array![second_domain_top].span(); - naming.set_address_to_domain(second_domain); - let expect_domain2 = naming.address_to_domain(caller); + naming.set_address_to_domain(second_domain, array![].span()); + let expect_domain2 = naming.address_to_domain(caller, array![].span()); assert(expect_domain2 == second_domain, 'wrong rev resolving 2'); // remove override naming.reset_address_to_domain(); - let expect_domain1 = naming.address_to_domain(caller); + let expect_domain1 = naming.address_to_domain(caller, array![].span()); assert(expect_domain1 == first_domain, 'wrong rev resolving b'); }