Skip to content

Commit

Permalink
chore: lay groundworks for handle registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Jun 3, 2024
1 parent c463e4e commit 1f20f0a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/IHandle.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet::ContractAddress;

// *************************************************************************
// INTERFACE of FollowNFT
// INTERFACE of HANDLE NFT
// *************************************************************************
#[starknet::interface]
pub trait IHandle<TState> {
Expand Down
17 changes: 17 additions & 0 deletions src/interfaces/IHandleRegistry.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use starknet::ContractAddress;
// *************************************************************************
// INTERFACE OF HANDLE REGISTRY
// *************************************************************************
#[starknet::interface]
pub trait IHandleRegistry<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn link(ref self: TState, handle_id: u256, profile_address: ContractAddress);
fn unlink(ref self: TState, handle_id: u256, profile_address: ContractAddress);
// *************************************************************************
// GETTERS
// *************************************************************************
fn resolve(self: @TState, handle_id: u256) -> ContractAddress;
fn get_handle(self: @TState, profile_address: ContractAddress) -> u256;
}
93 changes: 93 additions & 0 deletions src/namespaces/handle_registry.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,94 @@
#[starknet::contract]
mod HandleRegistry {
// *************************************************************************
// IMPORT
// *************************************************************************
use core::traits::TryInto;
use starknet::{ContractAddress, get_caller_address};
use karst::interfaces::IHandleRegistry::IHandleRegistry;

// *************************************************************************
// STORAGE
// *************************************************************************
#[storage]
struct Storage {
hub_address: ContractAddress,
handle_address: ContractAddress,
handle_to_profile_address: LegacyMap::<u256, ContractAddress>,
profile_address_to_handle: LegacyMap::<ContractAddress, u256>,
}

// *************************************************************************
// EVENTS
// *************************************************************************
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Linked: Linked,
Unlinked: Unlinked,
}

#[derive(Drop, starknet::Event)]
struct HandleLinked {
handle_id: u256,
profile_address: ContractAddress,
caller: ContractAddress,
timestamp: u64
}

#[derive(Drop, starknet::Event)]
struct HandleUnlinked {
handle_id: u256,
profile_address: ContractAddress,
caller: ContractAddress,
timestamp: u64
}

// *************************************************************************
// CONSTRUCTOR
// *************************************************************************
#[constructor]
fn constructor(hub_address: ContractAddress, handle_address: ContractAddress) {
self.hub_address.write(hub_address);
self.handle_address.write(handle_address);
}

// *************************************************************************
// EXTERNALS
// *************************************************************************
#[abi(embed_v0)]
impl HandleRegistryImpl of IHandleRegistry<ContractState> {
fn link(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) {
self._link(handle_id, profile_address);
}

fn unlink(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) {
let caller = get_caller_address();
self._unlink(handle_id, profile_address, caller);
}

// *************************************************************************
// GETTERS
// *************************************************************************
fn resolve(self: @ContractState, handle_id: u256) -> ContractAddress {
// TODO
}

fn get_handle(self: @ContractState, profile_address: ContractAddress) -> u256 {
// TODO
}
}

// *************************************************************************
// PRIVATE FUNCTIONS
// *************************************************************************
impl Private of PrivateTrait {
fn _link(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) {
// TODO
}

fn _unlink(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) {
// TODO
}
}
}
6 changes: 3 additions & 3 deletions src/namespaces/handles.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ mod Handles {
// *************************************************************************
#[generate_trait]
impl Private of PrivateTrait {
fn _mint_handle(address: ContractAddress, local_name: felt252) -> u256 {
fn _mint_handle(ref self: ContractState, address: ContractAddress, local_name: felt252) -> u256 {
// TODO
return 123;
}

fn _validate_local_name(local_name: felt252) { // TODO
fn _validate_local_name(ref self: ContractState, local_name: felt252) { // TODO
}

fn _is_alpha_numeric(char: felt252) -> bool {
fn _is_alpha_numeric(self: @ContractState, char: felt252) -> bool {
// TODO
return false;
}
Expand Down

0 comments on commit 1f20f0a

Please sign in to comment.