Skip to content

Commit

Permalink
chore: fix build with internal functions but fail execution
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Oct 7, 2024
1 parent d25ad28 commit 738f2df
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 101 deletions.
82 changes: 40 additions & 42 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ pub mod CommunityComponent {
};
use karst::interfaces::ICommunity::ICommunity;
use karst::interfaces::ICommunityNft::{ICommunityNftDispatcher, ICommunityNftDispatcherTrait};
// ICommunityNft

// use karst::interfaces::ICommunity::{
// ICommunityDispatcher, ICommunityDispatcherTrait, ICommunityLibraryDispatcher
// };

use karst::base::constants::types::{
CommunityDetails, GateKeepType, CommunityType, CommunityMember, CommunityGateKeepDetails
Expand Down Expand Up @@ -57,7 +53,7 @@ pub mod CommunityComponent {
(u256, ContractAddress), bool
>, // <u256, Array<ContractAddress>>,
hub_address: ContractAddress,
community_nft_classhash: felt252
community_nft_classhash: ClassHash
}

// *************************************************************************
Expand Down Expand Up @@ -126,7 +122,6 @@ pub mod CommunityComponent {
#[derive(Drop, starknet::Event)]
pub struct DeployedCommunityNFT {
pub community_id: u256,
pub profile_address: ContractAddress,
pub community_nft: ContractAddress,
pub block_timestamp: u64,
}
Expand All @@ -145,23 +140,26 @@ pub mod CommunityComponent {
) {
self.community_counter.write(0);
self.hub_address.write(hub_address);
self.community_nft_classhash.write(community_nft_classhash);
self.community_nft_classhash.write(community_nft_classhash.try_into().unwrap());
}
fn create_comminuty(ref self: ComponentState<TContractState>) -> u256 {
fn create_comminuty(ref self: ComponentState<TContractState>, salt: felt252) -> u256 {
let community_owner = get_caller_address();
let community_counter = self.community_counter.read();

let community_id = community_counter + 1;
let karst_hub = self.hub_address.read();
let community_nft_classhash = self.community_nft_classhash.read();

// deploy a new NFT and save the address in community_nft_address
// let community_nft_address = self
// let community_nft_address = self
// ._get_or_deploy_community_nft(
// karst_hub, community_owner, community_id, collect_nft_impl_class_hash, salt
// karst_hub, community_id, community_nft_classhash, salt
// );
let community_details = CommunityDetails {
community_id: community_id,
community_owner: community_owner,
community_metadata_uri: "Community URI",
community_nft_address: community_owner,
community_nft_address: community_owner, // community_nft_address, -- COMING BACK
community_premium_status: false,
community_total_members: 0,
community_type: CommunityType::Free,
Expand Down Expand Up @@ -191,12 +189,12 @@ pub mod CommunityComponent {

// community_token_id
// a token is minted from the comunity token contract address

// let mint_token_id = self._mint_community_nft(community.community_nft_address);
let community_member = CommunityMember {
profile_address: profile,
community_id: community_id,
total_publications: 0,
community_token_id: 1, // COMING BACK TO THIS
community_token_id: 45, //mint_token_id,
ban_status: false
};

Expand All @@ -221,6 +219,7 @@ pub mod CommunityComponent {

assert(community_member == true, NOT_MEMBER);

let community_member_details = self.community_member.read((community_id, profile));
// remove the member_community_id
self.community_membership_status.write((community_id, profile), false);

Expand All @@ -244,6 +243,10 @@ pub mod CommunityComponent {
// this function will also burn the nft on leaving
// call the burn function from the community nft contract

// self
// ._burn_community_nft(
// community.community_nft_address, community_member_details.community_token_id
// );
}
fn set_community_metadata_uri(
ref self: ComponentState<TContractState>, community_id: u256, metadata_uri: ByteArray
Expand Down Expand Up @@ -344,7 +347,7 @@ pub mod CommunityComponent {
assert(community.community_owner == community_owner_address, NOT_COMMUNITY_OWNER);

let community_member = self.community_membership_status.read((community_id, profile));
println!("Before inside leave_community is member: {}", community_member);

assert(community_member == true, NOT_MEMBER);

let community_member = self.community_member.read((community_id, profile));
Expand Down Expand Up @@ -500,35 +503,24 @@ pub mod CommunityComponent {
(true, gate_keep.gate_keep_type)
}
}
// *************************************************************************
// PRIVATE FUNCTIONS
// *************************************************************************

// #[generate_trait]
#[generate_trait]
impl CommunityPrivateImpl<
TContractState, +HasComponent<TContractState>, +Drop<TContractState>,
> of CommunityPrivateTrait<TContractState> {
pub impl Private<
TContractState, +HasComponent<TContractState>
> of PrivateTrait<TContractState> {
fn _get_or_deploy_community_nft(
ref self: ComponentState<TContractState>,
karst_hub: ContractAddress,
community_owner_address: ContractAddress,
community_id: u256,
community_nft_impl_class_hash: felt252,
community_nft_impl_class_hash: ClassHash,
salt: felt252
) -> ContractAddress {
let mut community = self.communities.read(community_id);
let community_nft = community.community_nft_address;
if community_nft.is_zero() {
// Deploy a new Collect NFT contract
let deployed_collect_nft_address = self
._deploy_community_nft(
karst_hub,
community_owner_address,
community_id,
community_nft_impl_class_hash,
salt
);
.nft_test(karst_hub, community_id, community_nft_impl_class_hash, salt);

// Update the community with the deployed Collect NFT address
let updated_community = CommunityDetails {
Expand All @@ -538,32 +530,39 @@ pub mod CommunityComponent {
// Write the updated community with the new Community NFT address
self.communities.write(community_id, updated_community);
}

let community = self.communities.read(community_id);
community.community_nft_address
}

fn nft_test(
ref self: ComponentState<TContractState>,
karst_hub: ContractAddress,
community_id: u256,
community_nft_impl_class_hash: ClassHash,
salt: felt252
) -> ContractAddress {
'Demo'.try_into().unwrap()
}
fn _deploy_community_nft(
ref self: ComponentState<TContractState>,
karst_hub: ContractAddress,
profile_address: ContractAddress,
community_id: u256,
community_nft_impl_class_hash: felt252,
community_nft_impl_class_hash: ClassHash,
salt: felt252
) -> ContractAddress {
let mut constructor_calldata: Array<felt252> = array![
karst_hub.into(),
profile_address.into(),
community_id.low.into(),
community_id.high.into()
karst_hub.into(), community_id.low.into(), community_id.high.into()
];
let class_hash: ClassHash = community_nft_impl_class_hash.try_into().unwrap();
let result = deploy_syscall(class_hash, salt, constructor_calldata.span(), true);
let (account_address, _) = result.unwrap_syscall();

let (account_address, _) = deploy_syscall(
community_nft_impl_class_hash, salt, constructor_calldata.span(), true
)
.unwrap_syscall();

self
.emit(
DeployedCommunityNFT {
community_id: community_id,
profile_address: profile_address,
community_nft: account_address,
block_timestamp: get_block_timestamp()
}
Expand All @@ -578,7 +577,6 @@ pub mod CommunityComponent {
.mint_nft(caller);
token_id
}

fn _burn_community_nft(
ref self: ComponentState<TContractState>,
community_nft_address: ContractAddress,
Expand Down
10 changes: 4 additions & 6 deletions src/communitynft/communitynft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod CommunityNft {
last_minted_id: u256,
mint_timestamp: Map<u256, u64>,
user_token_id: Map<ContractAddress, u256>,
profile_address: ContractAddress,
community_id: u256
}

Expand All @@ -49,12 +48,11 @@ pub mod CommunityNft {
#[constructor]
fn constructor(
ref self: ContractState,
karst_hub: ContractAddress,
profile_address: ContractAddress,
karst_hub: ContractAddress, // profile_address: ContractAddress,
community_id: u256
) {
self.karst_hub.write(karst_hub);
self.profile_address.write(profile_address);

self.community_id.write(community_id);
}

Expand Down Expand Up @@ -105,10 +103,10 @@ pub mod CommunityNft {
/// @notice returns the community name
fn name(self: @ContractState) -> ByteArray {
let mut collection_name = ArrayTrait::<felt252>::new();
let profile_address_felt252: felt252 = self.profile_address.read().into();
// let profile_address_felt252: felt252 = self.profile_address.read().into();
let community_id_felt252: felt252 = self.community_id.read().try_into().unwrap();
collection_name.append('Karst Community | Profile #');
collection_name.append(profile_address_felt252);
// collection_name.append(profile_address_felt252);
collection_name.append('- Community #');
collection_name.append(community_id_felt252);
let collection_name_byte = convert_into_byteArray(ref collection_name);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait ICommunity<TState> {
fn initializer(
ref self: TState, hub_address: ContractAddress, community_nft_classhash: felt252
);
fn create_comminuty(ref self: TState) -> u256;
fn create_comminuty(ref self: TState, salt: felt252) -> u256;
fn join_community(ref self: TState, profile: ContractAddress, community_id: u256);
fn leave_community(ref self: TState, profile: ContractAddress, community_id: u256);
fn set_community_metadata_uri(ref self: TState, community_id: u256, metadata_uri: ByteArray);
Expand Down
Loading

0 comments on commit 738f2df

Please sign in to comment.