Skip to content

Commit

Permalink
Merge pull request #144 from horuslabsio/feat/token-uris
Browse files Browse the repository at this point in the history
chore: update community and channel creation flow
  • Loading branch information
Darlington02 authored Feb 6, 2025
2 parents 3d0394d + 82c9894 commit d5476dc
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 367 deletions.
140 changes: 70 additions & 70 deletions coverage/coverage_report/tests/test_channel.cairo.gcov.html

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions coverage/coverage_report/tests/test_community.cairo.gcov.html

Large diffs are not rendered by default.

108 changes: 54 additions & 54 deletions coverage/coverage_report/tests/test_publication.cairo.gcov.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions scripts/src/contracts/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const execute_create_community = async() =>{
}

const execute_create_channel = async() =>{
let community_id = cairo.uint256(3);
let community_id = cairo.uint256(7);

let call: Call = {
to: coloniz_HUB_CONTRACT_ADDRESS, //coloniz_HUB_CONTRACT_ADDRESS,
Expand Down Expand Up @@ -306,13 +306,13 @@ const execute_gatekeep = async() =>{
}

// execute_get_community();
// execute_create_community();
// execute_create_community(123);
// execute_upgrade()
// execute_gatekeep()
// set_fee_address()
// set_permissioned_address()
// create_subscription()
// execute_create_channel();
execute_create_channel();
// execute_join_community();
// execute_make_post();
// execute_add_comment()
Expand Down
2 changes: 2 additions & 0 deletions src/base/constants/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub mod Errors {
pub const ALREADY_REACTED: felt252 = 'coloniz: already react to post!';
pub const ALREADY_MEMBER: felt252 = 'coloniz: already a Member';
pub const COMMUNITY_DOES_NOT_EXIST: felt252 = 'coloniz: Comm does not exist';
pub const COMMUNITY_ALREADY_EXISTS: felt252 = 'coloniz: Comm already exists';
pub const CHANNEL_ALREADY_EXISTS: felt252 = 'coloniz: channel already exists';
pub const NOT_COMMUNITY_OWNER: felt252 = 'coloniz: Not Community owner';
pub const ONLY_PREMIUM_COMMUNITIES: felt252 = 'coloniz: not premium community';
pub const INVALID_UPGRADE: felt252 = 'coloniz: invalid upgrade type';
Expand Down
16 changes: 11 additions & 5 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ pub mod ChannelComponent {
ContractAddress, contract_address_const, get_caller_address, get_block_timestamp
};
use starknet::storage::{
StoragePointerReadAccess, StoragePointerWriteAccess, Map, StorageMapReadAccess,
StorageMapWriteAccess
StoragePointerWriteAccess, Map, StorageMapReadAccess, StorageMapWriteAccess
};
use openzeppelin_access::ownable::OwnableComponent;

Expand All @@ -20,7 +19,7 @@ pub mod ChannelComponent {
constants::errors::Errors::{
NOT_CHANNEL_OWNER, ALREADY_MEMBER, NOT_CHANNEL_MEMBER, NOT_COMMUNITY_MEMBER,
BANNED_FROM_CHANNEL, CHANNEL_HAS_NO_MEMBER, UNAUTHORIZED, INVALID_LENGTH,
COMMUNITY_DOES_NOT_EXIST, NOT_CHANNEL_MODERATOR
COMMUNITY_DOES_NOT_EXIST, NOT_CHANNEL_MODERATOR, CHANNEL_ALREADY_EXISTS
},
constants::types::{ChannelDetails, ChannelMember}
};
Expand All @@ -32,6 +31,7 @@ pub mod ChannelComponent {
pub struct Storage {
channels: Map<u256, ChannelDetails>,
channel_counter: u256,
channel_initialized: Map<u256, bool>, // tracks if a channel id has been used or not
channel_members: Map<(u256, ContractAddress), ChannelMember>,
channel_moderators: Map<(u256, ContractAddress), bool>,
channel_ban_status: Map<(u256, ContractAddress), bool>,
Expand Down Expand Up @@ -114,10 +114,15 @@ pub mod ChannelComponent {
impl Ownable: OwnableComponent::HasComponent<TContractState>
> of IChannel<ComponentState<TContractState>> {
/// @notice creates a new channel
fn create_channel(ref self: ComponentState<TContractState>, community_id: u256) -> u256 {
let channel_id = self.channel_counter.read() + 1;
fn create_channel(
ref self: ComponentState<TContractState>, channel_id: u256, community_id: u256
) -> u256 {
let channel_owner = get_caller_address();

// check channel id does not already exist
let channel_initialized = self.channel_initialized.read(channel_id);
assert(channel_initialized == false, CHANNEL_ALREADY_EXISTS);

// check that community exists
let community_instance = get_dep_component!(@self, Community);
let _community_id = community_instance.get_community(community_id).community_id;
Expand All @@ -138,6 +143,7 @@ pub mod ChannelComponent {

// update storage
self.channels.write(channel_id, new_channel.clone());
self.channel_initialized.write(channel_id, true);
self.channel_counter.write(channel_id);

// include channel owner as first member
Expand Down
12 changes: 9 additions & 3 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub mod CommunityComponent {
};
use coloniz::base::constants::errors::Errors::{
ALREADY_MEMBER, NOT_COMMUNITY_OWNER, NOT_COMMUNITY_MEMBER, NOT_COMMUNITY_MOD, BANNED_MEMBER,
UNAUTHORIZED, ONLY_PREMIUM_COMMUNITIES, INVALID_LENGTH, INVALID_UPGRADE
UNAUTHORIZED, ONLY_PREMIUM_COMMUNITIES, INVALID_LENGTH, INVALID_UPGRADE,
COMMUNITY_ALREADY_EXISTS
};

// *************************************************************************
Expand All @@ -36,6 +37,7 @@ pub mod CommunityComponent {
pub struct Storage {
community_owner: Map<u256, ContractAddress>, // map<owner_address, community_id>
communities: Map<u256, CommunityDetails>, // map <community_id, community_details>
community_initialized: Map<u256, bool>, // tracks if a community id has been used or not
community_member: Map<
(u256, ContractAddress), CommunityMember
>, // map<(community_id, member address), Member_details>
Expand Down Expand Up @@ -157,10 +159,13 @@ pub mod CommunityComponent {
impl Ownable: OwnableComponent::HasComponent<TContractState>
> of ICommunity<ComponentState<TContractState>> {
/// @notice creates a new community
fn create_community(ref self: ComponentState<TContractState>) -> u256 {
fn create_community(ref self: ComponentState<TContractState>, community_id: u256) -> u256 {
let community_owner = get_caller_address();
let community_nft_classhash = self.community_nft_classhash.read();
let community_id = self.community_counter.read() + 1;

// check community id does not already exist
let community_initialized = self.community_initialized.read(community_id);
assert(community_initialized == false, COMMUNITY_ALREADY_EXISTS);

// deploy community nft - use community_id as salt since its unique
let community_nft_address = self
Expand Down Expand Up @@ -588,6 +593,7 @@ pub mod CommunityComponent {
};

self.communities.write(community_id, community_details);
self.community_initialized.write(community_id, true);
self.community_owner.write(community_id, community_owner);
self.community_gate_keep.write(community_id, gate_keep_details);
self.community_counter.write(community_id);
Expand Down
11 changes: 1 addition & 10 deletions src/community/communitynft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod CommunityNFT {
// *************************************************************************
// IMPORTS
// *************************************************************************
use starknet::{ContractAddress, ClassHash, get_block_timestamp};
use starknet::{ContractAddress, get_block_timestamp};
use core::num::traits::zero::Zero;
use openzeppelin_introspection::src5::SRC5Component;
use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl};
Expand Down Expand Up @@ -117,15 +117,6 @@ pub mod CommunityNFT {
self.user_token_id.write(user_address, 0);
}

/// @notice upgrades the nft contract
/// @param new_class_hash classhash to upgrade to
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();

// Replace the class hash upgrading the contract
self.upgradeable.upgrade(new_class_hash);
}

// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
11 changes: 1 addition & 10 deletions src/follownft/follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod Follow {
// IMPORT
// *************************************************************************
use starknet::{
ContractAddress, ClassHash, get_block_timestamp,
ContractAddress, get_block_timestamp,
storage::{
StoragePointerWriteAccess, StoragePointerReadAccess, Map, StorageMapReadAccess,
StorageMapWriteAccess
Expand Down Expand Up @@ -244,15 +244,6 @@ pub mod Follow {
return true;
}

/// @notice upgrades the nft contract
/// @param new_class_hash classhash to upgrade to
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();

// Replace the class hash upgrading the contract
self.upgradeable.upgrade(new_class_hash);
}

// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IChannel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub trait IChannel<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn create_channel(ref self: TState, community_id: u256) -> u256;
fn create_channel(ref self: TState, channel_id: u256, community_id: u256) -> u256;
fn join_channel(ref self: TState, channel_id: u256);
fn leave_channel(ref self: TState, channel_id: u256);
fn set_channel_metadata_uri(ref self: TState, channel_id: u256, metadata_uri: ByteArray);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub trait ICommunity<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn create_community(ref self: TState) -> u256;
fn create_community(ref self: TState, community_id: u256) -> u256;
fn join_community(ref self: TState, community_id: u256);
fn leave_community(ref self: TState, community_id: u256);
fn set_community_metadata_uri(ref self: TState, community_id: u256, metadata_uri: ByteArray);
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/ICustomNFT.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use starknet::{ContractAddress, ClassHash};
use starknet::ContractAddress;

// *************************************************************************
// INTERFACE of ICommunity NFT
Expand All @@ -11,7 +11,6 @@ pub trait ICustomNFT<TState> {

fn mint_nft(ref self: TState, user_address: ContractAddress) -> u256;
fn burn_nft(ref self: TState, user_address: ContractAddress, token_id: u256);
fn upgrade(ref self: TState, new_class_hash: ClassHash);

// *************************************************************************
// GETTERS
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/IFollowNFT.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use starknet::{ContractAddress, ClassHash};
use starknet::ContractAddress;
use coloniz::base::constants::types::FollowData;

// *************************************************************************
Expand All @@ -13,7 +13,6 @@ pub trait IFollowNFT<TState> {
fn unfollow(ref self: TState, unfollower_profile_address: ContractAddress);
fn process_block(ref self: TState, follower_profile_address: ContractAddress) -> bool;
fn process_unblock(ref self: TState, follower_profile_address: ContractAddress) -> bool;
fn upgrade(ref self: TState, new_class_hash: ClassHash);
// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/mocks/interfaces/IChannelComposable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait IChannelComposable<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn create_channel(ref self: TState, community_id: u256) -> u256;
fn create_channel(ref self: TState, channel_id: u256, community_id: u256) -> u256;
fn join_channel(ref self: TState, channel_id: u256);
fn leave_channel(ref self: TState, channel_id: u256);
fn set_channel_metadata_uri(ref self: TState, channel_id: u256, metadata_uri: ByteArray);
Expand Down Expand Up @@ -47,7 +47,7 @@ pub trait IChannelComposable<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn create_community(ref self: TState) -> u256;
fn create_community(ref self: TState, community_id: u256) -> u256;
fn join_community(ref self: TState, community_id: u256);
fn leave_community(ref self: TState, community_id: u256);
fn set_community_metadata_uri(ref self: TState, community_id: u256, metadata_uri: ByteArray);
Expand Down
Loading

0 comments on commit d5476dc

Please sign in to comment.