Skip to content

Commit

Permalink
ft: publication-still inview
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed May 26, 2024
1 parent 78a8e60 commit 60234cf
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 70 deletions.
1 change: 1 addition & 0 deletions src/base/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod Errors {
pub const HUB_RESTRICTED: felt252 = 'CALLER_IS_NOT_HUB';
pub const FOLLOWING: felt252 = 'USER_ALREADY_FOLLOWING';
pub const NOT_FOLLOWING: felt252 = 'USER_NOT_FOLLOWING';
pub const BLOCKED_STATUS: felt252 = 'BLOCKED';
}
74 changes: 74 additions & 0 deletions src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,77 @@ pub struct FollowData {
follower_profile_address: ContractAddress,
follow_timestamp: u64
}

#[derive(Drop, Serde, starknet::Store)]
pub struct PostParams {
profileId: ContractAddress,
contentURI: ByteArray,
profile_address: ContractAddress,
//actionModule,
//actionModulesInitDatas,
//referenceModule
//referenceModuleInitData

}

#[derive(Drop, Serde, starknet::Store)]
pub struct Profile {
pubCount: u256,
metadataURI: ByteArray,
profile_address: ContractAddress,
profile_owner: ContractAddress
}


#[derive(Drop, Serde, starknet::Store)]
pub struct Publication {
pointed_profile_address: ContractAddress,
pointedPubId: u256,
contentURI: ByteArray,
pubType: PublicationType,
root_profile_address: ContractAddress,
rootPubId: u256
}


#[derive(Drop, Serde, starknet::Store, PartialEq)]
enum PublicationType {
Nonexistent,
Post,
Comment,
Mirror,
Quote
}



#[derive(Drop, Serde, starknet::Store)]
struct ReferencePubParams {
profile_address: ContractAddress,
contentURI: ByteArray,
pointedProfile_address: ContractAddress,
pointedPubId: u256
// uint256[] referrerProfileIds;
// uint256[] referrerPubIds;
// bytes referenceModuleData;
// address[] actionModules;
// bytes[] actionModulesInitDatas;
// address referenceModule;
// bytes referenceModuleInitData;
}


#[derive(Drop, Serde, starknet::Store)]
struct CommentParams {
profile_address: ContractAddress,
contentURI: ByteArray,
pointedProfile_address: ContractAddress,
pointedPubId: u256,
// uint256[] referrerProfileIds;
// uint256[] referrerPubIds;
// bytes referenceModuleData;
// address[] actionModules;
// bytes[] actionModulesInitDatas;
// address referenceModule;
// bytes referenceModuleInitData;
}
9 changes: 7 additions & 2 deletions src/interfaces/IProfile.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use starknet::ContractAddress;
use karst::base::types::Profile;
// *************************************************************************
// INTERFACE of KARST PROFILE
// *************************************************************************
Expand All @@ -19,6 +20,10 @@ pub trait IKarstProfile<TState> {
// GETTERS
// *************************************************************************
fn get_user_profile_address(self: @TState, user: ContractAddress) -> ContractAddress;
fn get_profile(self: @TState, profile_id: ContractAddress) -> ByteArray;
fn get_profile_owner_by_id(self: @TState, profile_id: ContractAddress) -> ContractAddress;
fn get_profile_metadata(self: @TState, user: ContractAddress) -> ByteArray;
fn get_profile_owner(self: @TState, user: ContractAddress) -> ContractAddress;
fn get_profile_details(
self: @TState, profile_address: ContractAddress
) -> (u256, ByteArray, ContractAddress, ContractAddress);
fn get_profile(self: @TState, profile_address: ContractAddress) -> Profile;
}
2 changes: 2 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ pub mod profile;
pub mod base;
pub mod follownft;
pub mod mocks;
pub mod publication;

62 changes: 35 additions & 27 deletions src/profile/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ mod KarstProfile {
use karst::interfaces::IERC721::{IERC721Dispatcher, IERC721DispatcherTrait};
use karst::interfaces::IProfile::IKarstProfile;
use karst::base::errors::Errors::{NOT_PROFILE_OWNER};
use karst::base::types::Profile;

// *************************************************************************
// STORAGE
// *************************************************************************
#[storage]
struct Storage {
profile_address: LegacyMap<
ContractAddress, ContractAddress
>, // mapping of user => profile_address
profile_metadata_uri: LegacyMap<
ContractAddress, ByteArray
>, //mapping of profile_id => metadata_uri
profile_owner: LegacyMap<
ContractAddress, ContractAddress
> // mapping of profile_address => user
profile: LegacyMap<ContractAddress, Profile> //maps user => Profile
}

// *************************************************************************
Expand Down Expand Up @@ -80,44 +73,59 @@ mod KarstProfile {
class_hash: registry_hash.try_into().unwrap()
}
.create_account(implementation_hash, karstnft_contract_address, token_id, salt);
self.profile_address.write(caller, profile_address);
let profile_id = self.profile_address.read(caller);
self.profile_owner.write(profile_id, caller);

let new_profile = Profile {
pubCount: 0,
metadataURI: "",
profile_address: profile_address,
profile_owner: caller
};
self.profile.write(caller, new_profile);
self.emit(CreateProfile { user: caller, token_id, profile_address })
}
/// @notice set profile metadata_uri (`banner_image, description, profile_image` to be uploaded to arweave or ipfs)
/// @params metadata_uri the profile CID
fn set_profile_metadata_uri(ref self: ContractState, metadata_uri: ByteArray) {
let caller = get_caller_address();
let profile_id = self.profile_address.read(caller);
let profile_owner = self.profile_owner.read(profile_id);
let mut profile = self.profile.read(caller);
// assert that caller is the owner of the profile to be updated.
assert(caller == profile_owner, NOT_PROFILE_OWNER);
self.profile_metadata_uri.write(profile_id, metadata_uri);
assert(caller == profile.profile_owner, NOT_PROFILE_OWNER);
profile.metadataURI = metadata_uri;
self.profile.write(caller, profile);
}


// *************************************************************************
// GETTERS
// *************************************************************************
/// @notice returns user profile_id
/// @notice returns user profile_address
/// @params user ContractAddress of user
fn get_user_profile_address(
self: @ContractState, user: ContractAddress
) -> ContractAddress {
self.profile_address.read(user)
self.profile.read(user).profile_address
}
/// @notice returns user metadata
/// @params profile_id profile_id of user
fn get_profile(self: @ContractState, profile_id: ContractAddress) -> ByteArray {
self.profile_metadata_uri.read(profile_id)
/// @params user
fn get_profile_metadata(self: @ContractState, user: ContractAddress) -> ByteArray {
self.profile.read(user).metadataURI
}
/// @notice returns owner of a profile
/// @params profile_id the profile_id_address to query for.
fn get_profile_owner_by_id(
self: @ContractState, profile_id: ContractAddress
) -> ContractAddress {
self.profile_owner.read(profile_id)
/// @params user the user address to query for.
fn get_profile_owner(self: @ContractState, user: ContractAddress) -> ContractAddress {
self.profile.read(user).profile_owner
}

/// @notice returns a profile
/// @params profile_address the profile_id_address to query for.
fn get_profile_details(
self: @ContractState, profile_address: ContractAddress
) -> (u256, ByteArray, ContractAddress, ContractAddress) {
let profile = self.profile.read(profile_address);
(profile.pubCount, profile.metadataURI, profile.profile_address, profile.profile_owner)
}

fn get_profile(self: @ContractState, profile_address: ContractAddress) -> Profile {
self.profile.read(profile_address)
}
}
}
1 change: 1 addition & 0 deletions src/publication.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod Publication;
Loading

0 comments on commit 60234cf

Please sign in to comment.