Skip to content

Commit

Permalink
chore: rename publication struct & clean up struct update
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed Oct 1, 2024
1 parent 442caed commit ee3d443
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 63 deletions.
5 changes: 2 additions & 3 deletions src/collectnft/collectnft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub mod CollectNFT {
use openzeppelin::token::erc721::interface::IERC721Metadata;
use starknet::{ContractAddress, get_caller_address, get_block_timestamp};
use core::num::traits::zero::Zero;
use karst::interfaces::ICollect::ICollectNFT;
use karst::interfaces::ICollectNFT::ICollectNFT;
use karst::interfaces::IHub::{IHubDispatcher, IHubDispatcherTrait};
use karst::base::{
utils::hubrestricted::HubRestricted::hub_only,
Expand Down Expand Up @@ -129,15 +129,14 @@ pub mod CollectNFT {
}

#[abi(embed_v0)]
impl CollectImpl of ICollectNFT<ContractState> {
impl CollectNFTImpl of ICollectNFT<ContractState> {
// *************************************************************************
// EXTERNAL
// *************************************************************************
/// @notice mints the collect NFT
/// @param address address of user trying to mint the collect NFT
fn mint_nft(ref self: ContractState, address: ContractAddress) -> u256 {
let balance = self.erc721.balance_of(address);
// hub_only(self.karst_hub.read()); //assert only hub
assert(balance.is_zero(), ALREADY_MINTED);

let mut token_id = self.last_minted_id.read() + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub mod IPublication;
pub mod IHandle;
pub mod IHandleRegistry;
pub mod IHub;
pub mod ICollect;
pub mod ICollectNFT;
File renamed without changes.
8 changes: 1 addition & 7 deletions src/profile/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,7 @@ mod ProfileComponent {
) -> u256 {
let mut profile: Profile = self.profile.read(profile_address);
let new_pub_count = profile.pub_count + 1;
let updated_profile = Profile {
profile_address: profile.profile_address,
profile_owner: profile.profile_owner,
pub_count: new_pub_count,
metadata_URI: profile.metadata_URI,
follow_nft: profile.follow_nft
};
let updated_profile = Profile { pub_count: new_pub_count, ..profile };

self.profile.write(profile_address, updated_profile);
new_pub_count
Expand Down
64 changes: 12 additions & 52 deletions src/publication/publication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod PublicationComponent {
// *************************************************************************
// IMPORTS
// *************************************************************************
use karst::interfaces::ICollect::ICollectNFTDispatcherTrait;
use karst::interfaces::ICollectNFT::ICollectNFTDispatcherTrait;
use core::num::traits::zero::Zero;
use core::starknet::SyscallResultTrait;
use core::traits::TryInto;
Expand All @@ -14,7 +14,7 @@ pub mod PublicationComponent {
deploy_syscall, class_hash::ClassHash
};
use karst::interfaces::IPublication::IKarstPublications;
use karst::interfaces::ICollect::{ICollectNFT, ICollectNFTDispatcher};
use karst::interfaces::ICollectNFT::{ICollectNFT, ICollectNFTDispatcher};
use karst::base::{
constants::errors::Errors::{NOT_PROFILE_OWNER, UNSUPPORTED_PUB_TYPE, ALREADY_REACTED},
utils::hubrestricted::HubRestricted::hub_only,
Expand Down Expand Up @@ -48,8 +48,8 @@ pub mod PublicationComponent {
RepostCreated: RepostCreated,
Upvoted: Upvoted,
Downvoted: Downvoted,
CollectNFT: CollectNFT,
DeployCollectNFT: DeployCollectNFT
CollectedNFT: CollectedNFT,
DeployedCollectNFT: DeployedCollectNFT
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -91,15 +91,15 @@ pub mod PublicationComponent {
}

#[derive(Drop, starknet::Event)]
pub struct CollectNFT {
pub struct CollectedNFT {
publication_id: u256,
transaction_executor: ContractAddress,
token_id: u256,
block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct DeployCollectNFT {
pub struct DeployedCollectNFT {
publication_id: u256,
profile_address: ContractAddress,
collect_nft: ContractAddress,
Expand Down Expand Up @@ -246,19 +246,7 @@ pub mod PublicationComponent {
let has_voted = self.vote_status.read((caller, pub_id));
let upvote_current_count = publication.upvote + 1;
assert(has_voted == false, ALREADY_REACTED);
let updated_publication = Publication {
pointed_profile_address: publication.pointed_profile_address,
pointed_pub_id: publication.pointed_pub_id,
content_URI: publication.content_URI,
pub_Type: publication.pub_Type,
root_profile_address: publication.root_profile_address,
root_pub_id: publication.root_pub_id,
upvote: upvote_current_count,
downvote: publication.downvote,
channel_id: publication.channel_id,
collect_nft: publication.collect_nft,
tipped_amount: publication.tipped_amount
};
let updated_publication = Publication { upvote: upvote_current_count, ..publication };
self.vote_status.write((caller, pub_id), true);
self.publication.write((profile_address, pub_id), updated_publication);

Expand All @@ -283,17 +271,7 @@ pub mod PublicationComponent {
let downvote_current_count = publication.downvote + 1;
assert(has_voted == false, ALREADY_REACTED);
let updated_publication = Publication {
pointed_profile_address: publication.pointed_profile_address,
pointed_pub_id: publication.pointed_pub_id,
content_URI: publication.content_URI,
pub_Type: publication.pub_Type,
root_profile_address: publication.root_profile_address,
root_pub_id: publication.root_pub_id,
upvote: publication.upvote,
downvote: downvote_current_count,
channel_id: publication.channel_id,
collect_nft: publication.collect_nft,
tipped_amount: publication.tipped_amount
downvote: downvote_current_count, ..publication
};
self.publication.write((profile_address, pub_id), updated_publication);
self.vote_status.write((caller, pub_id), true);
Expand All @@ -320,17 +298,7 @@ pub mod PublicationComponent {
let mut publication = self.get_publication(profile_address, pub_id);
let current_tip_amount = publication.tipped_amount;
let updated_publication = Publication {
pointed_profile_address: publication.pointed_profile_address,
pointed_pub_id: publication.pointed_pub_id,
content_URI: publication.content_URI,
pub_Type: publication.pub_Type,
root_profile_address: publication.root_profile_address,
root_pub_id: publication.root_pub_id,
upvote: publication.upvote,
downvote: publication.downvote,
channel_id: publication.channel_id,
collect_nft: publication.collect_nft,
tipped_amount: current_tip_amount + amount
tipped_amount: current_tip_amount + amount, ..publication
};
self.publication.write((profile_address, pub_id), updated_publication)
}
Expand All @@ -351,7 +319,7 @@ pub mod PublicationComponent {

self
.emit(
CollectNFT {
CollectedNFT {
publication_id: pub_id,
transaction_executor: get_caller_address(),
token_id: token_id,
Expand Down Expand Up @@ -610,7 +578,7 @@ pub mod PublicationComponent {

self
.emit(
DeployCollectNFT {
DeployedCollectNFT {
publication_id: pub_id,
profile_address: profile_address,
collect_nft: account_address,
Expand Down Expand Up @@ -639,16 +607,8 @@ pub mod PublicationComponent {
// Update the publication with the deployed Collect NFT address
let updated_publication = Publication {
pointed_profile_address: publication.pointed_profile_address,
pointed_pub_id: publication.pointed_pub_id,
content_URI: publication.content_URI,
pub_Type: publication.pub_Type,
root_profile_address: publication.root_profile_address,
root_pub_id: publication.root_pub_id,
upvote: publication.upvote,
downvote: publication.downvote,
channel_id: publication.channel_id,
collect_nft: deployed_collect_nft_address,
tipped_amount: publication.tipped_amount
..publication
};

// Write the updated publication with the new Collect NFT address
Expand Down

0 comments on commit ee3d443

Please sign in to comment.