Skip to content

Commit

Permalink
implement setup for token uri component
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Jul 23, 2024
1 parent 4ebf018 commit 2afd3ed
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 8 deletions.
44 changes: 44 additions & 0 deletions src/base/token_uris/token_uris.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use starknet::ContractAddress;


#[starknet::component]
mod TokenURIComponent {
// *************************************************************************
// IMPORT
// *************************************************************************
use alexandria_bytes::{Bytes, BytesTrait};
use alexandria_encoding::sol_abi::{SolBytesTrait, SolAbiEncodeTrait};
use karst::base::utils::byte_array_extra::FeltTryIntoByteArray;

// *************************************************************************
// STORAGE
// *************************************************************************
#[storage]
struct Storage {}


// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[embeddable_as(KarstTokenURI)]
impl TokenUriImpl<
TContractState, +HasComponent<TContractState>
> of ITokenURI<ComponentState<TContractState>> {
fn profile_get_token_uri(
token_id: u256, mint_timestamp: u64, profile: Profile
) -> ByteArray {
"TODO"
}
fn handle_get_token_uri(
token_id: u256, local_name: felt252, namespace: felt252
) -> ByteArray {
"TODO"
}

fn follow_get_token_uri(
follow_token_id: u256, followed_profile_address: ContractAddress, follow_timestamp: u64
) -> ByteArray {
"TODO"
}
}
}
15 changes: 13 additions & 2 deletions src/follownft/follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ mod Follow {
use karst::interfaces::{IFollowNFT::IFollowNFT};
use karst::base::{
constants::{errors::Errors, types::FollowData},
utils::hubrestricted::HubRestricted::hub_only, token_uris::follow_token_uri::FollowTokenUri,
utils::hubrestricted::HubRestricted::hub_only,
// token_uris::follow_token_uri::FollowTokenUri,
};

use karst::base::token_uris::token_uris::TokenURIComponent;
component!(path: TokenURIComponent, storage: token_uri, event: TokenUriEvent);


#[abi(embed_v0)]
impl TokenURIImpl = TokenURIComponent::KarstTokenURI<ContractState>;
// *************************************************************************
// STORAGE
// *************************************************************************
Expand All @@ -23,6 +30,8 @@ mod Follow {
follow_data_by_follow_id: LegacyMap<u256, FollowData>,
initialized: bool,
karst_hub: ContractAddress,
#[substorage(v0)]
token_uri: TokenURIComponent::Storage,
}

// *************************************************************************
Expand Down Expand Up @@ -180,7 +189,9 @@ mod Follow {
let follow_data = self.follow_data_by_follow_id.read(follow_id);
let timestamp = follow_data.follow_timestamp;
let followed_profile_address = self.followed_profile_address.read();
FollowTokenUri::get_token_uri(follow_id, followed_profile_address, timestamp)

// call token uri component
self.token_uri.profile_get_token_uri(token_id, mint_timestamp, profile);
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/interfaces/ITokenURI.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use starknet::ContractAddress;

// *************************************************************************
// INTERFACE of TOKEN URI
// *************************************************************************
#[starknet::interface]
pub trait ITokenURI<TState>{
fn profile_get_token_uri(token_id: u256, mint_timestamp: u64, profile: Profile) -> ByteArray;

fn handle_get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray;

fn follow_get_token_uri(
follow_token_id: u256, followed_profile_address: ContractAddress, follow_timestamp: u64
) -> ByteArray

}
20 changes: 18 additions & 2 deletions src/karstnft/karstnft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod KarstNFT {
use karst::interfaces::IKarstNFT;
use karst::base::{
utils::hubrestricted::HubRestricted::hub_only, constants::errors::Errors::ALREADY_MINTED,
token_uris::profile_token_uri::ProfileTokenUri,
// token_uris::profile_token_uri::ProfileTokenUri,
};
use openzeppelin::{
account, access::ownable::OwnableComponent,
Expand All @@ -52,6 +52,10 @@ pub mod KarstNFT {
introspection::{src5::SRC5Component}
};


use karst::base::token_uris::token_uris::TokenURIComponent;
component!(path: TokenURIComponent, storage: token_uri, event: TokenUriEvent);

use karst::profile::profile::ProfileComponent;
component!(path: ProfileComponent, storage: profile, event: ProfileEvent);

Expand All @@ -75,6 +79,12 @@ pub mod KarstNFT {
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
impl ProfileImpl = ProfileComponent::KarstProfile<ContractState>;

#[abi(embed_v0)]
impl TokenURIImpl = TokenURIComponent::KarstTokenURI<ContractState>;


// *************************************************************************
// STORAGE
Expand All @@ -89,6 +99,8 @@ pub mod KarstNFT {
ownable: OwnableComponent::Storage,
#[substorage(v0)]
profile: ProfileComponent::Storage,
#[substorage(v0)]
token_uri: TokenURIComponent::Storage,
admin: ContractAddress,
last_minted_id: u256,
mint_timestamp: LegacyMap<u256, u64>,
Expand All @@ -109,6 +121,8 @@ pub mod KarstNFT {
OwnableEvent: OwnableComponent::Event,
#[flat]
ProfileEvent: ProfileComponent::Event
#[flat]
TokenUriEvent: TokenURIComponent::Event
}

// *************************************************************************
Expand Down Expand Up @@ -183,7 +197,9 @@ pub mod KarstNFT {

let profile = self.profile.get_profile(get_caller_address());

ProfileTokenUri::get_token_uri(token_id, mint_timestamp, profile)
// call token uri component
self.token_uri.profile_get_token_uri(token_id, mint_timestamp, profile);

}
}
}
17 changes: 13 additions & 4 deletions src/namespaces/handles.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ mod Handles {
introspection::{src5::SRC5Component}
};
use karst::base::{
constants::errors::Errors, utils::byte_array_extra::FeltTryIntoByteArray,
token_uris::handle_token_uri::HandleTokenUri,
constants::errors::Errors,
utils::byte_array_extra::FeltTryIntoByteArray, // token_uris::handle_token_uri::HandleTokenUri,
};
use karst::interfaces::{
IKarstNFT::{IKarstNFTDispatcher, IKarstNFTDispatcherTrait}, IHandle::IHandle
};

use karst::base::token_uris::token_uris::TokenURIComponent;
component!(path: TokenURIComponent, storage: token_uri, event: TokenUriEvent);


component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: ERC721Component, storage: erc721, event: ERC721Event);
Expand All @@ -78,6 +82,9 @@ mod Handles {
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
impl TokenURIImpl = TokenURIComponent::KarstTokenURI<ContractState>;

// *************************************************************************
// STORAGE
// *************************************************************************
Expand All @@ -89,6 +96,8 @@ mod Handles {
src5: SRC5Component::Storage,
#[substorage(v0)]
ownable: OwnableComponent::Storage,
#[substorage(v0)]
token_uri: TokenURIComponent::Storage,
admin: ContractAddress,
total_supply: u256,
local_names: LegacyMap::<u256, felt252>,
Expand Down Expand Up @@ -148,7 +157,6 @@ mod Handles {
self.erc721.initializer("KARST HANDLES", "KARST", "");
}

// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[abi(embed_v0)]
Expand Down Expand Up @@ -237,7 +245,8 @@ mod Handles {
fn get_handle_token_uri(
self: @ContractState, token_id: u256, local_name: felt252
) -> ByteArray {
HandleTokenUri::get_token_uri(token_id, local_name, NAMESPACE)
// call token uri component
self.token_uri.profile_get_token_uri(token_id, mint_timestamp, profile);
}
}

Expand Down

0 comments on commit 2afd3ed

Please sign in to comment.