diff --git a/src/channel.cairo b/src/channel.cairo index 4852e47..480cc64 100644 --- a/src/channel.cairo +++ b/src/channel.cairo @@ -1,2 +1,2 @@ pub mod channel; -pub mod channelNFT; \ No newline at end of file +pub mod channelNFT; diff --git a/src/channel/channel.cairo b/src/channel/channel.cairo index 68275e2..85f13ad 100644 --- a/src/channel/channel.cairo +++ b/src/channel/channel.cairo @@ -5,11 +5,12 @@ pub mod ChannelComponent { // ************************************************************************* use core::clone::Clone; use core::starknet::{ - ContractAddress, contract_address_const, get_caller_address, get_block_timestamp, ClassHash, syscalls::deploy_syscall, SyscallResultTrait + ContractAddress, contract_address_const, get_caller_address, get_block_timestamp, ClassHash, + syscalls::deploy_syscall, SyscallResultTrait }; use starknet::storage::{ - StoragePointerReadAccess, StoragePointerWriteAccess, Map, - StorageMapReadAccess, StorageMapWriteAccess + StoragePointerReadAccess, StoragePointerWriteAccess, Map, StorageMapReadAccess, + StorageMapWriteAccess }; use karst::interfaces::IChannel::IChannel; use karst::interfaces::ICommunity::ICommunity; @@ -113,15 +114,13 @@ pub mod ChannelComponent { // ************************************************************************* #[embeddable_as(KarstChannel)] impl ChannelImpl< - TContractState, - +HasComponent, + TContractState, + +HasComponent, +Drop, impl Community: CommunityComponent::HasComponent > of IChannel> { /// @notice creates a new channel - fn create_channel( - ref self: ComponentState, community_id: u256 - ) -> u256 { + fn create_channel(ref self: ComponentState, community_id: u256) -> u256 { let channel_id = self.channel_counter.read() + 1; let channel_owner = get_caller_address(); @@ -171,7 +170,6 @@ pub mod ChannelComponent { self._join_channel(profile, channel_id); } - /// @notice removes a member from a channel /// @param channel_id id of channel to be left fn leave_channel(ref self: ComponentState, channel_id: u256) { @@ -187,10 +185,7 @@ pub mod ChannelComponent { assert(total_members > 1, CHANNEL_HAS_NO_MEMBER); // burn user's community token - self - ._burn_channel_nft( - channel.channel_nft_address, channel_member.channel_token_id - ); + self._burn_channel_nft(channel.channel_nft_address, channel_member.channel_token_id); // update storage self @@ -222,7 +217,6 @@ pub mod ChannelComponent { ) } - /// @notice Set the metadata URI of the channel /// @param channel_id The id of the channel /// @param metadata_uri The new metadata URI @@ -241,7 +235,6 @@ pub mod ChannelComponent { self.channels.write(channel_id, channel); } - /// @notice Add a moderator to the channel /// @param channel_id: The id of the channel /// @param Array The address of the moderator @@ -259,7 +252,6 @@ pub mod ChannelComponent { self._add_channel_mods(channel_id, moderators); } - /// @notice Remove a moderator from the channel /// @param channel_id: The id of the channel /// @param moderator: The address of the moderator @@ -285,10 +277,7 @@ pub mod ChannelComponent { let mut channel = self.channels.read(channel_id); // check caller is owner - assert( - channel.channel_owner == get_caller_address(), - NOT_CHANNEL_OWNER - ); + assert(channel.channel_owner == get_caller_address(), NOT_CHANNEL_OWNER); // update storage channel.channel_censorship = censorship_status; @@ -393,16 +382,14 @@ pub mod ChannelComponent { // ************************************************************************* #[generate_trait] pub impl InternalImpl< - TContractState, + TContractState, +HasComponent, +Drop, impl Community: CommunityComponent::HasComponent > of InternalTrait { /// @notice initalizes channel component /// @param channel_nft_classhash classhash of channel NFT - fn _initializer( - ref self: ComponentState, channel_nft_classhash: felt252 - ) { + fn _initializer(ref self: ComponentState, channel_nft_classhash: felt252) { self.channel_counter.write(0); self.channel_nft_classhash.write(channel_nft_classhash.try_into().unwrap()); } @@ -411,15 +398,14 @@ pub mod ChannelComponent { /// @param profile address to add to the channel /// @param channel_id id of the channel to be joined fn _join_channel( - ref self: ComponentState, - profile: ContractAddress, - channel_id: u256 + ref self: ComponentState, profile: ContractAddress, channel_id: u256 ) { let mut channel: ChannelDetails = self.channels.read(channel_id); // check that user is a member of the community this channel belongs to let community_instance = get_dep_component!(@self, Community); - let membership_status = community_instance.is_community_member(profile, channel.community_id); + let membership_status = community_instance + .is_community_member(profile, channel.community_id); assert(membership_status, NOT_MEMBER); let channel_member = ChannelMember { @@ -431,14 +417,13 @@ pub mod ChannelComponent { }; // mint a channel token to new joiner - let minted_token_id = self - ._mint_channel_nft(profile, channel.channel_nft_address); - + let minted_token_id = self._mint_channel_nft(profile, channel.channel_nft_address); + // update storage channel.channel_total_members += 1; self.channels.write(channel_id, channel); self.channel_members.write((channel_id, profile), channel_member); - + // emit events self .emit( @@ -471,14 +456,14 @@ pub mod ChannelComponent { // emit event self - .emit( - ChannelModAdded { - channel_id: channel_id, - transaction_executor: get_caller_address(), - mod_address: moderator, - block_timestamp: get_block_timestamp(), - } - ); + .emit( + ChannelModAdded { + channel_id: channel_id, + transaction_executor: get_caller_address(), + mod_address: moderator, + block_timestamp: get_block_timestamp(), + } + ); index += 1; }; } @@ -611,4 +596,4 @@ pub mod ChannelComponent { .burn_nft(get_caller_address(), token_id); } } -} \ No newline at end of file +} diff --git a/src/interfaces/IChannel.cairo b/src/interfaces/IChannel.cairo index d0f190a..30d12c2 100644 --- a/src/interfaces/IChannel.cairo +++ b/src/interfaces/IChannel.cairo @@ -14,7 +14,9 @@ pub trait IChannel { fn remove_channel_mods(ref self: TState, channel_id: u256, moderators: Array); fn set_channel_censorship_status(ref self: TState, channel_id: u256, censorship_status: bool); fn set_channel_ban_status( - ref self: TState, channel_id: u256, profiles: Array, + ref self: TState, + channel_id: u256, + profiles: Array, ban_statuses: Array ); // ************************************************************************* @@ -27,4 +29,4 @@ pub trait IChannel { fn is_channel_mod(self: @TState, profile: ContractAddress, channel_id: u256) -> bool; fn get_channel_censorship_status(self: @TState, channel_id: u256) -> bool; fn get_channel_ban_status(self: @TState, profile: ContractAddress, channel_id: u256) -> bool; -} \ No newline at end of file +} diff --git a/src/lib.cairo b/src/lib.cairo index c443612..2213bf7 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -11,4 +11,4 @@ pub mod hub; pub mod jolt; pub mod collectnft; pub mod community; -pub mod channel; \ No newline at end of file +pub mod channel; diff --git a/src/presets.cairo b/src/presets.cairo index c99076b..19fc48d 100644 --- a/src/presets.cairo +++ b/src/presets.cairo @@ -1,4 +1,4 @@ pub mod profile; pub mod publication; pub mod community; -pub mod channel; \ No newline at end of file +pub mod channel; diff --git a/src/presets/channel.cairo b/src/presets/channel.cairo index 44f7398..10ec77e 100644 --- a/src/presets/channel.cairo +++ b/src/presets/channel.cairo @@ -2,7 +2,7 @@ pub mod KarstChannel { use karst::channel::channel::ChannelComponent; use karst::community::community::CommunityComponent; - + component!(path: ChannelComponent, storage: channel, event: ChannelEvent); component!(path: CommunityComponent, storage: community, event: CommunityEvent); diff --git a/tests/test_channel.cairo b/tests/test_channel.cairo index 09812e8..2e1296c 100644 --- a/tests/test_channel.cairo +++ b/tests/test_channel.cairo @@ -12,7 +12,6 @@ // EventSpyAssertionsTrait, ContractClassTrait, DeclareResultTrait, EventSpy // }; - // use karst::channel::channel::ChannelComponent::{ // Event as ChannelEvent, ChannelCreated, JoinedChannel, LeftChannel, ChannelModAdded, // ChannelModRemoved, ChannelBanStatusUpdated @@ -86,7 +85,6 @@ // return (channel_contract_address, channel_id, USER_ONE.try_into().unwrap(), metadat_uri); // } - // // writing the test for the set_channel_metadata_uri : // #[test] // fn test_set_channel_metadata_uri_check_owner() { @@ -124,7 +122,6 @@ // stop_cheat_caller_address(channel_contract_address); // } - // // writing the test for the add_channel_mods() // #[test] // fn test_add_channel_mods_owner() { @@ -147,7 +144,6 @@ // ); // } - // #[test] // #[should_panic(expected: ('Channel: not channel owner',))] // fn test_add_channel_mods_not_owner() { @@ -303,7 +299,6 @@ // ); // } - // // set censorship to test // #[test] // fn test_set_channel_censorship_status_owner() { @@ -344,7 +339,6 @@ // assert(ban_status == true, 'invalid ban status'); // } - // #[test] // #[should_panic(expected: ('Karst : Unauthorized access',))] // fn test_set_ban_status_owner_or_moderator() { @@ -383,7 +377,6 @@ // ); // } - // #[test] // #[should_panic(expected: ('Channel: not channel member',))] // fn test_leave_channel_not_member() { @@ -395,21 +388,21 @@ // stop_cheat_caller_address(channel_contract_address); // } - // // joining the channel testing // #[test] // fn test_joining_channel() { // let (channel_contract_address, channel_id, owner, _) = __setup__(); // let dispatcher = IChannelDispatcher { contract_address: channel_contract_address }; -// let is_channel_member = dispatcher.is_channel_member(MEMBER1.try_into().unwrap(), channel_id); +// let is_channel_member = dispatcher.is_channel_member(MEMBER1.try_into().unwrap(), +// channel_id); // assert(is_channel_member == true, 'invalid channel member 1'); -// let is_channel_member = dispatcher.is_channel_member(MEMBER2.try_into().unwrap(), channel_id); +// let is_channel_member = dispatcher.is_channel_member(MEMBER2.try_into().unwrap(), +// channel_id); // assert(is_channel_member == true, 'invalid channel member 2'); // } - // // // counting of the member of the channel . // #[test] // fn test_joining_channel_total_members() {