Skip to content

Commit

Permalink
completed gatekeep type function
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Sep 30, 2024
1 parent f2316e5 commit 1238def
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/base/constants/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ pub struct CommunityMod {
mod_address: ContractAddress,
}

// /**
// * @notice An enum specifically used in a helper function to easily retrieve the publication type for integrations.
// *
// * @param Nonexistent An indicator showing the queried publication does not exist.
// * @param Post A standard post, having an URI, and no pointer to another publication.
// * @param Comment A comment, having an URI, and a pointer to another publication.
// * @param Mirror A mirror, having a pointer to another publication, but no URI.
// */
#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct CommunityGateKeepDetails {
community_id: u256,
gate_keep_type: ByteArray,
community_nft_address: ContractAddress,
}

// // permissioned_addresses: Vec<ContractAddress>,

#[derive(Debug, Drop, Serde, starknet::Store, Clone, PartialEq)]
enum GateKeepType {
Expand Down
53 changes: 45 additions & 8 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod CommunityComponent {
#[storage]
struct Storage {
communities_counts: u256,
communities_owner: LegacyMap<ContractAddress, u256>, // map<owner, community)id>
communities_owner: LegacyMap<ContractAddress, u256>, // map<owner_address, community_id>
communities: LegacyMap<u256, CommunityDetails>, // map <community_id, community_details>
member_community_id: LegacyMap<
ContractAddress, u256
Expand All @@ -34,8 +34,9 @@ mod CommunityComponent {
>, // map <member_address, CommunityMember>
community_mod: LegacyMap<u256, Vec<CommunityMod>>, // map <community id mod_address>
community_gate_keep: LegacyMap<
u256, Vec<GateKeepType>
> // map <community, Vec<GateKeepType>>
u256, CommunityGateKeepDetails
>, // map <community, CommunityGateKeepDetails>
community_gate_keep_permissioned_addresses: LegacyMap<u256, Vec<ContractAddress>>
}

// *************************************************************************
Expand All @@ -48,7 +49,8 @@ mod CommunityComponent {
CommunityModAdded: CommunityModAdded,
CommunityBanStatusUpdated: CommunityBanStatusUpdated,
CommunityModRemoved: CommunityModRemoved,
CommunityUpgraded: CommunityUpgraded
CommunityUpgraded: CommunityUpgraded,
CommunityGateKeep: CommunityGateKeep
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -91,6 +93,14 @@ mod CommunityComponent {
block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct CommunityGateKeep {
community_id: u256,
transaction_executor: ContractAddress,
gatekeepType: GateKeepType,
block_timestamp: u64,
}

// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
Expand Down Expand Up @@ -333,14 +343,41 @@ mod CommunityComponent {
}
);
}
// IN_COMPLET
// IN_COMPLETE
fn gatekeep(
ref self: ComponentState<TContractState>,
community_id: u256,
gatekeep_type: GateKeepType,
gate_keep_type: GateKeepType,
nft_contract_address: ContractAddress,
permissioned_addresses: Array<ContractAddress>
) {}
permissioned_addresses: Vec<ContractAddress>
) {
// only community owner can set gate keep type
let community_owner = get_caller_address();
let comminuty_main_id = self.communities_owner.read(community_owner);
assert(comminuty_main_id == community_id, "Not Community Owner");
let community_details = self.communities.read(community_id);
let community_gate_keep_details = CommunityGateKeepDetails {
community_id: comminuty_main_id,
gate_keep_type: gatekeep_type,
community_nft_address: community_details.community_nft_address,
permissioned_addresses: permissioned_addresses,
};

self.community_gate_keep.write(comminuty_main_id, community_gate_keep_details);
self
.community_gate_keep_permissioned_addresses
.write(community_id, permissioned_addresses)
// emint event
self
.emit(
CommunityGateKeep {
community_id: community_id,
transaction_executor: community_owner,
gatekeepType: gate_keep_type,
block_timestamp: get_block_timestamp()
}
);
}

fn get_community(
self: @ComponentState<TContractState>, community_id: u256
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait ICommunity<TState> {
fn gatekeep(
ref self: TState,
community_id: u256,
gatekeep_type: GateKeepType,
gate_keep_type: GateKeepType,
nft_contract_address: ContractAddress,
permissioned_addresses: Array<ContractAddress>
);
Expand Down

0 comments on commit 1238def

Please sign in to comment.