-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: lay groundworks for handle registry
- Loading branch information
1 parent
c463e4e
commit 1f20f0a
Showing
4 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters