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

feature: add upvote and downvote function #112

Merged
merged 5 commits into from
Sep 14, 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
3 changes: 3 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.
[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.22.0" }

[sncast.default]
url= "https://starknet-sepolia.public.blastapi.io"

[[target.starknet-contract]]
casm = true
build-external-contracts = ["token_bound_accounts::presets::account::Account"]
Expand Down
1 change: 1 addition & 0 deletions src/base/constants/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pub mod Errors {
pub const UNSUPPORTED_PUB_TYPE: felt252 = 'Karst: unsupported pub type!';
pub const INVALID_PROFILE_ADDRESS: felt252 = 'Karst: invalid profile address!';
pub const SELF_FOLLOWING: felt252 = 'Karst: self follow is forbidden';
pub const ALREADY_REACTED: felt252 = 'Karst: already react to post!';
}
26 changes: 19 additions & 7 deletions src/base/constants/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ pub struct Publication {
content_URI: ByteArray,
pub_Type: PublicationType,
root_profile_address: ContractAddress,
root_pub_id: u256
root_pub_id: u256,
upvote: u256,
downvote: u256,
}

// /**
Expand All @@ -66,15 +68,13 @@ pub struct Publication {
// * @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, Clone, PartialEq)]
enum PublicationType {
Nonexistent,
Post,
Comment,
Mirror,
Quote
Repost,
}

// /**
Expand Down Expand Up @@ -103,7 +103,7 @@ struct CommentParams {
content_URI: ByteArray,
pointed_profile_address: ContractAddress,
pointed_pub_id: u256,
reference_pub_type: PublicationType
reference_pub_type: PublicationType,
}


Expand All @@ -124,10 +124,10 @@ pub struct ReferencePubParams {
// * @param pointed_pub_id The publication ID to point the mirror to.
// */
#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct MirrorParams {
pub struct RepostParams {
profile_address: ContractAddress,
pointed_profile_address: ContractAddress,
pointed_pub_id: u256
pointed_pub_id: u256,
}

// /**
Expand All @@ -146,3 +146,15 @@ pub struct QuoteParams {
pointed_pub_id: u256,
reference_pub_type: PublicationType
}
#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct Upvote {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were meant to be the emitted events on upvote

publication_id: u256,
transaction_executor: ContractAddress,
block_timestamp: u64,
}
#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct Downvote {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was meant to be the emitted event on downvote

publication_id: u256,
transaction_executor: ContractAddress,
block_timestamp: u64,
}
6 changes: 2 additions & 4 deletions src/interfaces/IHub.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use starknet::ContractAddress;
use karst::base::constants::types::{
Profile, PostParams, MirrorParams, CommentParams, PublicationType, Publication, QuoteParams
Profile, PostParams, RepostParams, CommentParams, PublicationType, Publication, QuoteParams
};

// *************************************************************************
Expand Down Expand Up @@ -36,9 +36,7 @@ pub trait IHub<TState> {

fn comment(ref self: TState, comment_params: CommentParams) -> u256;

fn quote(ref self: TState, quote_params: QuoteParams) -> u256;

fn mirror(ref self: TState, mirror_params: MirrorParams) -> u256;
fn repost(ref self: TState, repost_params: RepostParams) -> u256;

fn get_publication(
self: @TState, profile_address: ContractAddress, pub_id_assigned: u256
Expand Down
12 changes: 9 additions & 3 deletions src/interfaces/IPublication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// *************************************************************************
use starknet::ContractAddress;
use karst::base::constants::types::{
PostParams, MirrorParams, CommentParams, PublicationType, Publication, QuoteParams
PostParams, RepostParams, CommentParams, PublicationType, Publication, QuoteParams
};

#[starknet::interface]
Expand All @@ -13,8 +13,11 @@ pub trait IKarstPublications<TState> {
// *************************************************************************
fn post(ref self: TState, post_params: PostParams) -> u256;
fn comment(ref self: TState, comment_params: CommentParams) -> u256;
fn quote(ref self: TState, quote_params: QuoteParams) -> u256;
fn mirror(ref self: TState, mirror_params: MirrorParams) -> u256;
fn repost(ref self: TState, repost_params: RepostParams) -> u256;
fn upvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn downvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn collect(ref self: TState, pub_id: u256) -> bool;

// *************************************************************************
// GETTERS
// *************************************************************************
Expand All @@ -27,4 +30,7 @@ pub trait IKarstPublications<TState> {
fn get_publication_content_uri(
self: @TState, profile_address: ContractAddress, pub_id: u256
) -> ByteArray;
fn has_user_voted(self: @TState, profile_address: ContractAddress, pub_id: u256) -> bool;
fn get_upvote_count(self: @TState, profile_address: ContractAddress, pub_id: u256) -> u256;
fn get_downvote_count(self: @TState, profile_address: ContractAddress, pub_id: u256) -> u256;
}
11 changes: 8 additions & 3 deletions src/mocks/interfaces/IComposable.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use starknet::ContractAddress;
use karst::base::constants::types::{
Profile, PublicationType, Publication, MirrorParams, QuoteParams, PostParams, CommentParams
Profile, PublicationType, Publication, RepostParams, QuoteParams, PostParams, CommentParams
};
// *************************************************************************
// INTERFACE of KARST PROFILE
Expand Down Expand Up @@ -43,8 +43,10 @@ pub trait IComposable<TState> {
fn initialize(ref self: TState, hub_address: ContractAddress);
fn post(ref self: TState, post_params: PostParams) -> u256;
fn comment(ref self: TState, comment_params: CommentParams) -> u256;
fn quote(ref self: TState, quote_params: QuoteParams) -> u256;
fn mirror(ref self: TState, mirror_params: MirrorParams) -> u256;
fn repost(ref self: TState, mirror_params: RepostParams) -> u256;
fn upvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn downvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn collect(ref self: TState, pub_id: u256) -> bool;
// *************************************************************************
// GETTERS
// *************************************************************************
Expand All @@ -57,4 +59,7 @@ pub trait IComposable<TState> {
fn get_publication_content_uri(
self: @TState, profile_address: ContractAddress, pub_id: u256
) -> ByteArray;
fn has_user_voted(self: @TState, profile_address: ContractAddress, pub_id: u256) -> bool;
fn get_upvote_count(self: @TState, profile_address: ContractAddress, pub_id: u256) -> u256;
fn get_downvote_count(self: @TState, profile_address: ContractAddress, pub_id: u256) -> u256;
}
Loading
Loading