Skip to content

Commit

Permalink
ft: post & comment implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed May 31, 2024
1 parent 1027072 commit f25da19
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 80 deletions.
54 changes: 34 additions & 20 deletions src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use core::option::OptionTrait;
// *************************************************************************
use starknet::ContractAddress;

// /**
// * @notice A struct containing token follow-related data.
// *
// * @param follower_profile_address The ID of the profile using the token to follow.
// * @param followTimestamp The timestamp of the current follow, if a profile is using the token to follow.
// */
#[derive(Drop, Serde, starknet::Store)]
pub struct FollowData {
follower_profile_address: ContractAddress,
Expand All @@ -14,12 +20,12 @@ pub struct FollowData {
pub struct PostParams {
contentURI: ByteArray,
profile_address: ContractAddress,
//actionModule,
//actionModulesInitDatas,
//referenceModule
//referenceModuleInitData

}
// * @notice A struct containing profile data.
// * profile_address The profile ID of a karst profile
// * profile_owner The address that created the profile_address
// * @param pub_count The number of publications made to this profile.
// * @param metadataURI MetadataURI is used to store the profile's metadata, for example: displayed name, description, interests, etc.

#[derive(Drop, Serde, starknet::Store)]
pub struct Profile {
Expand All @@ -29,6 +35,20 @@ pub struct Profile {
metadata_URI: ByteArray,
}

// /**
// * @notice A struct containing publication data.
// *
// * @param pointed_profile_address The profile token ID to point the publication to.
// * @param pointed_pub_id The publication ID to point the publication to.
// * These are used to implement the "reference" feature of the platform and is used in:
// * - Mirrors
// * - Comments
// * - Quotes
// * @param content_URI The URI to set for the content of publication (can be ipfs, arweave, http, etc).
// * @param pub_Type The type of publication, can be Nonexistent, Post, Comment, Mirror or Quote.
// * @param root_profile_address The profile ID of the root post (to determine if comments/quotes and mirrors come from it).
// * @param root_pub_id The publication ID of the root post (to determine if comments/quotes and mirrors come from it).
// */

#[derive(Debug, Drop, Serde, starknet::Store)]
pub struct Publication {
Expand All @@ -40,7 +60,15 @@ pub struct Publication {
root_pub_id: u256
}


// /**
// * @notice An enum specifically used in a helper function to easily retrieve the publication type for integrations.
// *
// * @param Nonexistent An indicator showing the queried publication does not exist.
// * @param Post A standard post, having an URI, and no pointer to another publication.
// * @param Comment A comment, having an URI, and a pointer to another publication.
// * @param Mirror A mirror, having a pointer to another publication, but no URI.
// * @param Quote A quote, having an URI, and a pointer to another publication.
// */
#[derive(Debug, Drop, Serde, starknet::Store, PartialEq)]
enum PublicationType {
Nonexistent,
Expand All @@ -57,13 +85,6 @@ struct ReferencePubParams {
content_URI: ByteArray,
pointed_profile_address: ContractAddress,
pointed_pub_id: u256
// uint256[] referrerProfileIds;
// uint256[] referrerPubIds;
// bytes referenceModuleData;
// address[] actionModules;
// bytes[] actionModulesInitDatas;
// address referenceModule;
// bytes referenceModuleInitData;
}


Expand All @@ -73,11 +94,4 @@ struct CommentParams {
contentURI: ByteArray,
pointedProfile_address: ContractAddress,
pointedPubId: u256,
// uint256[] referrerProfileIds;
// uint256[] referrerPubIds;
// bytes referenceModuleData;
// address[] actionModules;
// bytes[] actionModulesInitDatas;
// address referenceModule;
// bytes referenceModuleInitData;
}
3 changes: 0 additions & 3 deletions src/interfaces/IPublication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub trait IKarstPublications<T> {
contentURI: ByteArray,
profile_address: ContractAddress,
profile_contract_address: ContractAddress,
user: ContractAddress
) -> u256;
fn comment(
ref self: T,
Expand All @@ -21,8 +20,6 @@ pub trait IKarstPublications<T> {
pointed_pub_id: u256,
profile_contract_address: ContractAddress,
) -> u256;
// fn get_content_uri(self: @T, user: ContractAddress) -> ByteArray;
// fn get_pub_type(self: @T, user: ContractAddress) -> Option<PublicationType>;
fn get_publication(self: @T, user: ContractAddress, pubIdAssigned: u256) -> Publication;
fn get_publication_type(
self: @T, profile_address: ContractAddress, pub_id_assigned: u256
Expand Down
3 changes: 2 additions & 1 deletion src/profile/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ mod KarstProfile {

/// @notice increments user's publication count
/// @params profile_address the targeted profile address
/// how do we get the function? it acts an pub_count increase for all publication type.
fn increment_publication_count(
ref self: ContractState, profile_address: ContractAddress
) -> u256 {
hub_only(self.karst_hub.read());
let mut profile = self.profile.read(profile_address);
// assert(get_caller_address() == profile.profile_owner, NOT_PROFILE_OWNER);
let updated_profile = Profile {
profile_address: profile.profile_address,
profile_owner: profile.profile_owner,
Expand Down
16 changes: 8 additions & 8 deletions src/publication/publication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub mod Publications {
struct Storage {
publication: LegacyMap<(ContractAddress, u256), Publication>,
blocked_profile_address: LegacyMap<(ContractAddress, ContractAddress), bool>,
karst_hub: ContractAddress,
}
// *************************************************************************
// EVENTS
Expand Down Expand Up @@ -92,10 +91,6 @@ pub mod Publications {
// *************************************************************************
// CONSTRUCTOR
// *************************************************************************
#[constructor]
fn constructor(ref self: ContractState, hub: ContractAddress) {
self.karst_hub.write(hub);
}

// *************************************************************************
// EXTERNAL FUNCTIONS
Expand All @@ -113,7 +108,13 @@ pub mod Publications {
profile_address: ContractAddress,
profile_contract_address: ContractAddress
) -> u256 {
hub_only(self.karst_hub.read());
// assert that the person that created the profile can make a post
let profile_owner = IKarstProfileDispatcher {
contract_address: profile_contract_address
}
.get_profile(profile_address)
.profile_owner;
assert(profile_owner == get_caller_address(), NOT_PROFILE_OWNER);
let pubIdAssigned = IKarstProfileDispatcher {
contract_address: profile_contract_address
}
Expand Down Expand Up @@ -178,7 +179,6 @@ pub mod Publications {
pointed_pub_id: u256,
profile_contract_address: ContractAddress
) -> ContractAddress {
hub_only(self.karst_hub.read());
let mut publication = self.publication.read((profile_address, pointed_pub_id));
let pointed = self.publication.read((profile_address, pointed_pub_id));
let publication_type = pointed.pub_Type;
Expand Down Expand Up @@ -247,7 +247,7 @@ pub mod Publications {
content_URI,
pointed_profile_address,
pointed_pub_id,
referencePubType,
PublicationType::Comment,
profile_contract_address
);

Expand Down
Loading

0 comments on commit f25da19

Please sign in to comment.