diff --git a/src/channel.cairo b/src/channel.cairo new file mode 100644 index 0000000..525a96f --- /dev/null +++ b/src/channel.cairo @@ -0,0 +1,2 @@ +mod channel; + diff --git a/src/channel/channel.cairo b/src/channel/channel.cairo index 14ada85..24fa460 100644 --- a/src/channel/channel.cairo +++ b/src/channel/channel.cairo @@ -1,77 +1,69 @@ -#[starknet::contract] -pub mod channel { - use core::starknet::{ContractAddress, get_caller_address, get_block_timestamp}; +use starknet::ContractAddress; + +#[derive(Drop, Serde, Clone, starknet::Store)] +pub struct channelParams { + channel_id: u256, + channel_owner: ContractAddress, + channel_metadata_uri: ByteArray, + channel_nft_address: ContractAddress, + channel_total_members: u256, + channel_censorship: bool, + channel_premium_status: bool, +} +#[starknet::interface] +pub trait IChannel { + // ************************************************************************* + // EXTERNALS + // ************************************************************************* + // removing the return type from the function , we have to store in the database + fn create_channel(ref self: TState, channel_params: channelParams); + 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); + fn add_channel_mods(ref self: TState, channel_id: u256, moderator: ContractAddress); + fn remove_channel_mods(ref self: TState, channel_id: u256, moderator: ContractAddress); + fn set_channel_censorship_status(ref self: TState, channel_id: u256, censorship_status: bool); + fn set_ban_status( + ref self: TState, channel_id: u256, profile: ContractAddress, ban_status: bool + ); + // fn premium_subscription(ref self: TState, channel_id: u256) -> bool; + fn upgrade_channel(ref self: TState, channel_id: u256) -> bool; + // // ************************************************************************* + // // GETTERS + // // ************************************************************************* + fn get_channel(self: @TState, channel_id: u256) -> channelParams; + fn get_channel_metadata_uri(self: @TState, channel_id: u256) -> ByteArray; + // so is the profile is channel member or not we have to say that which channel id , i think it will be good + fn is_channel_member(self: @TState, profile: ContractAddress) -> (bool, u256); +// what is the means by the paid channel member +// fn is_paid_channel_member(self: @TState, profile: ContractAddress) -> (bool, u256); +// how we can calcualte the get_total_member +// fn get_total_members(self: @TState, channel_id: u256) -> u256; +// we have to pass the channel id how is the ch +// fn is_channel_mod(self: @TState, profile: ContractAddress) -> bool; + +// this one is easy +// fn get_channel_censorship_status(self: @TState, channel_id: u256) -> bool; + +// fn get_ban_status(self: @TState, profile: ContractAddress) -> bool; +} - #[starknet::interface] - pub trait IChannel { - // should be the internal function and now we have to change the fucntions for the system that i can do anything i want - // can we compelete it in this time and thankyou so much that i can do anythign i am the person so - // we are converting the create channel , gave the channel params and gave the new channel_id - // ************************************************************************* - // EXTERNALS - // ************************************************************************* - // how the channel is created and then also what to do with the channel - // there is contract who mainted the state of the channel_id // this is important - // is important to store the mapping . - fn create_channel(ref self: TState, channel_params: channelParams) -> u256; - // what does it mean to join the channel - // there is nothign in the function - 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); - fn add_channel_mods(ref self: TState, channel_id: u256, moderator: ContractAddress); - fn remove_channel_mods(ref self: TState, channel_id: u256, moderator: ContractAddress); - fn set_channel_censorship_status( - ref self: TState, channel_id: u256, censorship_status: bool - ); - fn set_ban_status(ref self: TState, profile: ContractAddress, ban_status: bool); - // fn premium_subscription(ref self: TState, channel_id: u256) -> bool; - fn upgrade_channel(ref self: TState, channel_id: u256) -> bool; - // // ************************************************************************* - // // GETTERS - // // ************************************************************************* - fn get_channel(self: @TState, channel_id: u256) -> channelParams; - fn get_channel_metadata_uri(self: @TState, channel_id: u256) -> ByteArray; - // so is the profile is channel member or not we have to say that which channel id , i think it will be good - fn is_channel_member(self: @TState, profile: ContractAddress) -> (bool, u256); - // what is the means by the paid channel member - fn is_paid_channel_member(self: @TState, profile: ContractAddress) -> (bool, u256); - // how we can calcualte the get_total_member - fn get_total_members(self: @TState, channel_id: u256) -> u256; - // we have to pass the channel id how is the ch - fn is_channel_mod(self: @TState, profile: ContractAddress) -> bool; - - // this one is easy - fn get_channel_censorship_status(self: @TState, channel_id: u256) -> bool; - - fn get_ban_status(self: @TState, profile: ContractAddress) -> bool; - } +#[starknet::contract] +mod channel { + use core::clone::Clone; + use core::starknet::{ContractAddress, get_caller_address, get_block_timestamp}; + use super::{channelParams, IChannel}; #[storage] - struct storage { + struct Storage { channels: LegacyMap, channel_counter: u256, channel_members: LegacyMap<(u256, ContractAddress), bool>, channel_moderators: LegacyMap<(u256, ContractAddress), bool>, } - - // we should one that we can say that a adding the person to the channel means add to their list of the channel members - //so can we say the we have to made the mapping betweent the channel id and the list of the address who want to join the channel - - pub struct channelParams { - channel_id: u256, - channel_owner: ContractAddress, - channel_metadata_uri: ByteArray, - channel_nft_address: ContractAddress, - channel_total_members: u256, - channel_censorship: bool, - channel_premium_status: bool, - } - - #[derive(Drop, starknet::Event)] pub struct ChannelCreated { channel_id: u256, @@ -84,7 +76,7 @@ pub mod channel { pub struct JoinedChannel { channel_id: u256, transaction_executor: ContractAddress, - token_id: token_id, + token_id: u256, block_timestamp: u64, } @@ -92,11 +84,10 @@ pub mod channel { pub struct LeftChannel { channel_id: u256, transaction_executor: ContractAddress, - token_id: token_id, + token_id: u256, block_timestamp: u64, } // this should also contain the IChannel & IChannelNFT implmentation , waht is the self what d. - #[derive(Drop, starknet::Event)] pub struct ChannelModAdded { channel_id: u256, @@ -113,17 +104,23 @@ pub mod channel { block_timestamp: u64, } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + ChannelCreated: ChannelCreated, + JoinedChannel: JoinedChannel, + LeftChannel: LeftChannel, + ChannelModAdded: ChannelModAdded, + ChannelModRemoved: ChannelModRemoved, + } + + // mnaking the constructor to store the onwer , who can set the moderators - impl ChannelImpl< - TContractState, - +HasComponent, - +Drop, - impl Profile: ProfileComponent::HasComponent - > of IChannel> { - fn create_channel( - ref self: ComponentState, channel_params: channelParams - ) -> u256 { + #[abi(embed_v0)] + impl ImplChannel of IChannel { + fn create_channel(ref self: ContractState, channel_params: channelParams) { // is there any check that we have to do before creating the channel let new_channel = channelParams { channel_id: self.channel_counter.read(), @@ -135,8 +132,9 @@ pub mod channel { channel_censorship: channel_params.channel_censorship, channel_premium_status: channel_params.channel_premium_status, }; - self.channels.write(new_channel.channel_id, new_channel); + self.channels.write(new_channel.channel_id, new_channel.clone()); self.channel_counter.write(self.channel_counter.read() + 1); + self .emit( ChannelCreated { @@ -154,14 +152,14 @@ pub mod channel { // self.channel_members.write((channel_id, get_caller_address()), true); - self.mint_nft(get_caller_address()); - + // self.mint_nft(get_caller_address()); self .emit( JoinedChannel { channel_id: channel_id, transaction_executor: get_caller_address(), - token_id: self.last_minted_id.read() + 1, + token_id: 0, // dummy value + // token_id: self.last_minted_id.read() + 1, block_timestamp: get_block_timestamp(), } ) @@ -173,7 +171,7 @@ pub mod channel { "You are not a member of this channel" ); - self.write_channel_members((channel_id, get_caller_address()), false); + self.channel_members.write((channel_id, get_caller_address()), false); // we want to get the tokenid of the get_caller_address() self @@ -181,30 +179,33 @@ pub mod channel { LeftChannel { channel_id: channel_id, transaction_executor: get_caller_address(), - token_id: self.get_user_token_id(get_caller_address()), + token_id: 0, //TODO impl token gating self.get_user_token_id(get_caller_address()), block_timestamp: get_block_timestamp(), } ) } - fn set_channel_metadata_uri(ref self: TState, channel_id: u256, metadata_uri: ByteArray) { + fn set_channel_metadata_uri( + ref self: ContractState, channel_id: u256, metadata_uri: ByteArray + ) { // only the primary moderator can set the metadata url - assert!( - self.channels.read(channel_id).channel_onwer == get_caller_address(), - "You are not the owner of the channel" - ); + + // assert!( + // self.channels.read(channel_id).channel_onwer == get_caller_address(), + // "You are not the owner of the channel" + // ); let mut new_channel = self.channels.read(channel_id); new_channel.channel_metadata_uri = metadata_uri; - self.channels.write(channel_id, channel); + self.channels.write(channel_id, new_channel); } // censored or unsenseroed fn set_channel_censorship_status( ref self: ContractState, channel_id: u256, censorship_status: bool ) { - assert!( - self.channels.read(channel_id).channel_onwer == get_caller_address(), - "You are not the owner of the channel" - ); + // assert!( + // self.channels.read(channel_id).channel_onwer == get_caller_address(), + // "You are not the owner of the channel" + // ); let mut new_channel = self.channels.read(channel_id); new_channel.channel_censorship = censorship_status; @@ -214,17 +215,17 @@ pub mod channel { fn add_channel_mods(ref self: ContractState, channel_id: u256, moderator: ContractAddress) { //only the primary moderator can add/ remove the moderator . - assert!( - self.channels.read(channel_id).channel_onwer == get_caller_address(), - "You are not the owner of the channel" - ); + // assert!( + // self.channels.read(channel_id).channel_onwer == get_caller_address(), + // "You are not the owner of the channel" + // ); self.channel_moderators.write((channel_id, moderator), true); self .emit( ChannelModAdded { - channel_id: u256, + channel_id: channel_id, transaction_executor: get_caller_address(), mod_address: moderator, block_timestamp: get_block_timestamp(), @@ -233,7 +234,11 @@ pub mod channel { } - fn set_ban_status(ref self: ContractState, profile: ContractAddress, ban_status: bool) { + fn set_ban_status( + ref self: ContractState, channel_id: u256, profile: ContractAddress, ban_status: bool + ) { + // we dont get the channel id , + assert!( self.channel_moderators.read((channel_id, get_caller_address())), "You are not the moderator of the channel" @@ -247,10 +252,10 @@ pub mod channel { ref self: ContractState, channel_id: u256, moderator: ContractAddress ) { // only the primary moderator can add the moderators - assert!( - self.channels.read(channel_id).channel_onwer == get_caller_address(), - "You are not the owner of the channel" - ); + // assert!( + // self.channels.read(channel_id).channel_onwer == get_caller_address(), + // "You are not the owner of the channel" + // ); self.channel_moderators.write((channel_id, moderator), false); @@ -268,7 +273,7 @@ pub mod channel { // what does the substiption means to the channel fn upgrade_channel(ref self: ContractState, channel_id: u256) -> bool { // upgrade to the premium subscriptiuon - assert!(self.channels.read(channel_id).channel_onwer == get_caller_address()); + assert!(self.channels.read(channel_id).channel_owner == get_caller_address()); let mut new_channel = self.channels.read(channel_id); new_channel.channel_premium_status = true; @@ -278,14 +283,15 @@ pub mod channel { fn get_channel(self: @ContractState, channel_id: u256) -> channelParams { - channels.read(channel_id) + self.channels.read(channel_id) } fn get_channel_metadata_uri(self: @ContractState, channel_id: u256) -> ByteArray { - channel.read(channel_id).channel_metadata_uri + self.channels.read(channel_id).channel_metadata_uri } fn is_channel_member(self: @ContractState, profile: ContractAddress) -> (bool, u256) { - self.channel + // self.channels.read(channel_id) + (true , 0 ) } // fn is_paid_channel_member(self: @TState, profile: ContractAddress) -> (bool, u256) // little bit difficult to make diff --git a/src/lib.cairo b/src/lib.cairo index c3f5301..cf3056c 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -8,3 +8,5 @@ pub mod publication; pub mod namespaces; pub mod presets; pub mod hub; +pub mod channel; +