Skip to content

Commit

Permalink
chore: scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Oct 11, 2024
1 parent 2cf634b commit 627f48d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/channel.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod channel;
pub mod channelNFT;
pub mod channelNFT;
67 changes: 26 additions & 41 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,15 +114,13 @@ pub mod ChannelComponent {
// *************************************************************************
#[embeddable_as(KarstChannel)]
impl ChannelImpl<
TContractState,
+HasComponent<TContractState>,
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
impl Community: CommunityComponent::HasComponent<TContractState>
> of IChannel<ComponentState<TContractState>> {
/// @notice creates a new channel
fn create_channel(
ref self: ComponentState<TContractState>, community_id: u256
) -> u256 {
fn create_channel(ref self: ComponentState<TContractState>, community_id: u256) -> u256 {
let channel_id = self.channel_counter.read() + 1;
let channel_owner = get_caller_address();

Expand Down Expand Up @@ -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<TContractState>, channel_id: u256) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<moderator> The address of the moderator
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -393,16 +382,14 @@ pub mod ChannelComponent {
// *************************************************************************
#[generate_trait]
pub impl InternalImpl<
TContractState,
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
impl Community: CommunityComponent::HasComponent<TContractState>
> of InternalTrait<TContractState> {
/// @notice initalizes channel component
/// @param channel_nft_classhash classhash of channel NFT
fn _initializer(
ref self: ComponentState<TContractState>, channel_nft_classhash: felt252
) {
fn _initializer(ref self: ComponentState<TContractState>, channel_nft_classhash: felt252) {
self.channel_counter.write(0);
self.channel_nft_classhash.write(channel_nft_classhash.try_into().unwrap());
}
Expand All @@ -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<TContractState>,
profile: ContractAddress,
channel_id: u256
ref self: ComponentState<TContractState>, 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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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;
};
}
Expand Down Expand Up @@ -611,4 +596,4 @@ pub mod ChannelComponent {
.burn_nft(get_caller_address(), token_id);
}
}
}
}
6 changes: 4 additions & 2 deletions src/interfaces/IChannel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub trait IChannel<TState> {
fn remove_channel_mods(ref self: TState, channel_id: u256, moderators: Array<ContractAddress>);
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<ContractAddress>,
ref self: TState,
channel_id: u256,
profiles: Array<ContractAddress>,
ban_statuses: Array<bool>
);
// *************************************************************************
Expand All @@ -27,4 +29,4 @@ pub trait IChannel<TState> {
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;
}
}
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub mod hub;
pub mod jolt;
pub mod collectnft;
pub mod community;
pub mod channel;
pub mod channel;
2 changes: 1 addition & 1 deletion src/presets.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod profile;
pub mod publication;
pub mod community;
pub mod channel;
pub mod channel;
2 changes: 1 addition & 1 deletion src/presets/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 4 additions & 11 deletions tests/test_channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// EventSpyAssertionsTrait, ContractClassTrait, DeclareResultTrait, EventSpy
// };


// use karst::channel::channel::ChannelComponent::{
// Event as ChannelEvent, ChannelCreated, JoinedChannel, LeftChannel, ChannelModAdded,
// ChannelModRemoved, ChannelBanStatusUpdated
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -147,7 +144,6 @@
// );
// }


// #[test]
// #[should_panic(expected: ('Channel: not channel owner',))]
// fn test_add_channel_mods_not_owner() {
Expand Down Expand Up @@ -303,7 +299,6 @@
// );
// }


// // set censorship to test
// #[test]
// fn test_set_channel_censorship_status_owner() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -383,7 +377,6 @@
// );
// }


// #[test]
// #[should_panic(expected: ('Channel: not channel member',))]
// fn test_leave_channel_not_member() {
Expand All @@ -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() {
Expand Down

0 comments on commit 627f48d

Please sign in to comment.