Skip to content

Commit

Permalink
feat: add resolve function
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Aug 9, 2023
1 parent 6f46409 commit 6fc0cfd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.0"
[dependencies]
starknet = "2.1.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", branch = "cairo-2" }
identity = { git = "https://github.com/starknet-id/identity.git", branch = "master" }

[[target.starknet-contract]]
# Enable Sierra codegen.
Expand Down
4 changes: 3 additions & 1 deletion src/interface.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mod identity;
mod naming;
mod resolver;
mod pricing;
mod naming;
20 changes: 20 additions & 0 deletions src/interface/identity.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use starknet::ContractAddress;

#[starknet::interface]
trait IIdentity<TContractState> {
fn get_user_data(
self: @TContractState, starknet_id: felt252, field: felt252, domain: felt252
) -> felt252;

fn get_crosschecked_user_data(
self: @TContractState, starknet_id: felt252, field: felt252
) -> felt252;

fn get_verifier_data(
self: @TContractState, starknet_id: felt252, field: felt252, domain: felt252
) -> felt252;

fn get_crosschecked_verifier_data(
self: @TContractState, starknet_id: felt252, field: felt252
) -> felt252;
}
6 changes: 6 additions & 0 deletions src/interface/resolver.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use starknet::ContractAddress;

#[starknet::interface]
trait IResolver<TContractState> {
fn resolve(self: @TContractState, domain: Span<felt252>, field: felt252) -> felt252;
}
20 changes: 18 additions & 2 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ mod Naming {
use array::{ArrayTrait, SpanTrait};
use zeroable::Zeroable;
use starknet::class_hash::ClassHash;
use naming::interface::naming::{INaming, INamingDispatcher, INamingDispatcherTrait};
use naming::interface::{
naming::{INaming, INamingDispatcher, INamingDispatcherTrait},
resolver::{IResolver, IResolverDispatcher, IResolverDispatcherTrait},
identity::{IIdentity, IIdentityDispatcher, IIdentityDispatcherTrait}
};
use integer::{u256_safe_divmod, u256_as_non_zero};
use core::pedersen;

Expand Down Expand Up @@ -45,9 +49,21 @@ mod Naming {

#[external(v0)]
impl NamingImpl of INaming<ContractState> {
// This function allows to read the single felt target of any domain for a specific field
// For example, it allows to find the Bitcoin address of Alice.stark by calling
// naming.resolve(['alice'], 'bitcoin')
fn resolve(self: @ContractState, domain: Array<felt252>, field: felt252) -> felt252 {
let (resolver, parent_start) = self.domain_to_resolver(@domain, 0);
1
if (resolver != ContractAddressZeroable::zero()) {
IResolverDispatcher {
contract_address: resolver
}.resolve(domain.span().slice(parent_start, domain.len() - parent_start), field)
} else {
let domain_data = self._domain_data.read(self.hash_domain(domain.span()));
IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.get_crosschecked_user_data(domain_data.owner, field)
}
}
}

Expand Down

0 comments on commit 6fc0cfd

Please sign in to comment.