From 2afd3edb012b0728790e31b5d012eb84da4a2923 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Tue, 23 Jul 2024 15:52:27 +0100 Subject: [PATCH] implement setup for token uri component --- src/base/token_uris/token_uris.cairo | 44 ++++++++++++++++++++++++++++ src/follownft/follownft.cairo | 15 ++++++++-- src/interfaces/ITokenURI.cairo | 16 ++++++++++ src/karstnft/karstnft.cairo | 20 +++++++++++-- src/namespaces/handles.cairo | 17 ++++++++--- 5 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 src/base/token_uris/token_uris.cairo create mode 100644 src/interfaces/ITokenURI.cairo diff --git a/src/base/token_uris/token_uris.cairo b/src/base/token_uris/token_uris.cairo new file mode 100644 index 0000000..993193a --- /dev/null +++ b/src/base/token_uris/token_uris.cairo @@ -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 + > of ITokenURI> { + 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" + } + } +} diff --git a/src/follownft/follownft.cairo b/src/follownft/follownft.cairo index ec48c3a..7267348 100644 --- a/src/follownft/follownft.cairo +++ b/src/follownft/follownft.cairo @@ -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; // ************************************************************************* // STORAGE // ************************************************************************* @@ -23,6 +30,8 @@ mod Follow { follow_data_by_follow_id: LegacyMap, initialized: bool, karst_hub: ContractAddress, + #[substorage(v0)] + token_uri: TokenURIComponent::Storage, } // ************************************************************************* @@ -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); } } diff --git a/src/interfaces/ITokenURI.cairo b/src/interfaces/ITokenURI.cairo new file mode 100644 index 0000000..7cedb7c --- /dev/null +++ b/src/interfaces/ITokenURI.cairo @@ -0,0 +1,16 @@ +use starknet::ContractAddress; + +// ************************************************************************* +// INTERFACE of TOKEN URI +// ************************************************************************* +#[starknet::interface] +pub trait ITokenURI{ + 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 + +} \ No newline at end of file diff --git a/src/karstnft/karstnft.cairo b/src/karstnft/karstnft.cairo index fad7478..ba2c06c 100644 --- a/src/karstnft/karstnft.cairo +++ b/src/karstnft/karstnft.cairo @@ -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, @@ -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); @@ -75,6 +79,12 @@ pub mod KarstNFT { impl OwnableImpl = OwnableComponent::OwnableImpl; impl OwnableInternalImpl = OwnableComponent::InternalImpl; + #[abi(embed_v0)] + impl ProfileImpl = ProfileComponent::KarstProfile; + + #[abi(embed_v0)] + impl TokenURIImpl = TokenURIComponent::KarstTokenURI; + // ************************************************************************* // STORAGE @@ -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, @@ -109,6 +121,8 @@ pub mod KarstNFT { OwnableEvent: OwnableComponent::Event, #[flat] ProfileEvent: ProfileComponent::Event + #[flat] + TokenUriEvent: TokenURIComponent::Event } // ************************************************************************* @@ -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); + } } } diff --git a/src/namespaces/handles.cairo b/src/namespaces/handles.cairo index 220155e..e71e8d7 100644 --- a/src/namespaces/handles.cairo +++ b/src/namespaces/handles.cairo @@ -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); @@ -78,6 +82,9 @@ mod Handles { impl OwnableImpl = OwnableComponent::OwnableImpl; impl OwnableInternalImpl = OwnableComponent::InternalImpl; + #[abi(embed_v0)] + impl TokenURIImpl = TokenURIComponent::KarstTokenURI; + // ************************************************************************* // STORAGE // ************************************************************************* @@ -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::, @@ -148,7 +157,6 @@ mod Handles { self.erc721.initializer("KARST HANDLES", "KARST", ""); } - // ************************************************************************* // EXTERNAL FUNCTIONS // ************************************************************************* #[abi(embed_v0)] @@ -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); } }