Skip to content

Commit

Permalink
feat: add support for ccip reverse resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Apr 11, 2024
1 parent 202d72b commit b15f7c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/interface/naming.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait INaming<TContractState> {
self: @TContractState, domain: Span<felt252>, hint: Span<felt252>
) -> ContractAddress;

fn address_to_domain(self: @TContractState, address: ContractAddress) -> Span<felt252>;
fn address_to_domain(self: @TContractState, address: ContractAddress, hint: Span<felt252>) -> Span<felt252>;

// external
fn buy(
Expand Down Expand Up @@ -85,7 +85,7 @@ trait INaming<TContractState> {

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252> {
fn address_to_domain(self: @ContractState, address: ContractAddress, hint: Span<felt252>) -> Span<felt252> {
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 {
Expand Down Expand Up @@ -582,10 +582,10 @@ mod Naming {


// will override your main id
fn set_address_to_domain(ref self: ContractState, domain: Span<felt252>) {
fn set_address_to_domain(ref self: ContractState, domain: Span<felt252>, hint: Span<felt252>) {
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 }));
Expand Down
8 changes: 4 additions & 4 deletions src/tests/naming/test_usecases.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down

0 comments on commit b15f7c1

Please sign in to comment.