Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Mirror Function #27

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct ReferencePubParams {
// * @param pointed_profile_id The profile address to point the mirror to.
// * @param pointed_pub_id The publication ID to point the mirror to.
// */
#[derive(Drop, Serde, starknet::Store)]
#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct MirrorParams {
profile_address: ContractAddress,
metadata_URI: ByteArray,
Expand Down
7 changes: 6 additions & 1 deletion src/interfaces/IPublication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// INTERFACE of KARST PUBLICATIONS
// *************************************************************************
use starknet::ContractAddress;
use karst::base::types::{PostParams, ReferencePubParams, PublicationType, Publication};
use karst::base::types::{
PostParams, MirrorParams, ReferencePubParams, PublicationType, Publication
};

#[starknet::interface]
pub trait IKarstPublications<T> {
Expand All @@ -23,6 +25,9 @@ pub trait IKarstPublications<T> {
pointed_pub_id: u256,
profile_contract_address: ContractAddress,
) -> u256;
fn mirror(
ref self: T, mirrorParams: MirrorParams, profile_contract_address: ContractAddress
) -> u256;

// *************************************************************************
// GETTERS
Expand Down
64 changes: 59 additions & 5 deletions src/publication/publication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use karst::base::types::{
PostParams, PublicationType, CommentParams, ReferencePubParams, Publication, MirrorParams,
QuoteParams
};

use karst::interfaces::IProfile::{IKarstProfileDispatcher, IKarstProfileDispatcherTrait};
use core::option::OptionTrait;

mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -31,7 +32,9 @@ pub trait IKarstPublications<T> {
pointed_pub_id: u256,
profile_contract_address: ContractAddress,
) -> u256;
fn mirror(ref self: T, mirrorParams: MirrorParams) -> u256;
fn mirror(
ref self: T, mirrorParams: MirrorParams, profile_contract_address: ContractAddress
) -> u256;
fn quote(ref self: T, quoteParams: QuoteParams) -> u256;
////// Getters//////
fn get_publication(self: @T, user: ContractAddress, pubIdAssigned: u256) -> Publication;
Expand All @@ -48,7 +51,7 @@ pub mod Publications {
// *************************************************************************
// IMPORTS
// *************************************************************************
use starknet::{ContractAddress, get_contract_address, get_caller_address};
use starknet::{ContractAddress, get_contract_address, get_caller_address, get_block_timestamp};
use karst::base::types::{
PostParams, Publication, PublicationType, ReferencePubParams, CommentParams, QuoteParams,
MirrorParams
Expand All @@ -75,6 +78,7 @@ pub mod Publications {
#[derive(Drop, starknet::Event)]
pub enum Event {
Post: Post,
MirrorCreated: MirrorCreated,
}

// *************************************************************************
Expand All @@ -89,6 +93,14 @@ pub mod Publications {
pub block_timestamp: u256,
}

#[derive(Drop, starknet::Event)]
pub struct MirrorCreated {
pub mirrorParams: MirrorParams,
pub publication_id: u256,
pub transaction_executor: ContractAddress,
pub block_timestamp: u64,
}


// *************************************************************************
// CONSTRUCTOR
Expand All @@ -103,7 +115,6 @@ pub mod Publications {
// *************************************************************************
// PUBLISHING FUNCTIONS
// *************************************************************************

fn post(
ref self: ContractState,
contentURI: ByteArray,
Expand Down Expand Up @@ -159,9 +170,52 @@ pub mod Publications {
// *
// * @return uint256 The created publication's pubId.
// */
fn mirror(ref self: ContractState, mirrorParams: MirrorParams) -> u256 {
fn mirror(
ref self: ContractState,
mirrorParams: MirrorParams,
profile_contract_address: ContractAddress
) -> u256 {
// logic here
0

assert!(
profile_contract_address.into() != 0, "Contract Profile Address cannot be zero"
);

self._validatePointedPub(mirrorParams.profile_address, mirrorParams.pointed_pub_id);
self
.validateNotBlocked(
mirrorParams.profile_address, mirrorParams.pointed_profile_address, false
);
let ref_mirrorParams = mirrorParams.clone();
// _processMirrorIfNeeded is not needed
let profileDispatcher = IKarstProfileDispatcher {
contract_address: profile_contract_address
};
let pub_id_assigned = profileDispatcher
.get_user_publication_count(mirrorParams.profile_address);
let publication = self
.get_publication(mirrorParams.pointed_profile_address, mirrorParams.pointed_pub_id);

self
._fillRefeferencePublicationStorage(
mirrorParams.profile_address,
publication.content_URI,
mirrorParams.pointed_profile_address,
mirrorParams.pointed_pub_id,
PublicationType::Mirror,
profile_contract_address,
);
self
.emit(
MirrorCreated {
mirrorParams: ref_mirrorParams,
publication_id: pub_id_assigned,
transaction_executor: mirrorParams.profile_address,
block_timestamp: get_block_timestamp(),
}
);

pub_id_assigned
}

fn quote(ref self: ContractState, quoteParams: QuoteParams) -> u256 {
Expand Down
Loading
Loading