Skip to content

Commit

Permalink
chore: update community to manually set permissioned addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Jan 16, 2025
1 parent 49d9a56 commit f767608
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
10 changes: 5 additions & 5 deletions scripts/src/contracts/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const create_subscription = async() => {

// execute upgrade
const execute_upgrade = async() => {
let community_id = cairo.uint256(1);
let community_id = cairo.uint256(5);
let community_type = new CairoCustomEnum({ Business: {} });
let erc20_address:string = "0x006e1698dcd0665757dd213a59aff489624bab8c970ce0482c23937a78879b04";
let sub_id: Uint256 = cairo.uint256(
Expand Down Expand Up @@ -265,12 +265,12 @@ const execute_upgrade = async() => {

// execute gatekeep
const execute_gatekeep = async() =>{
let community_id = cairo.uint256(3);
let gatekeep_type = new CairoCustomEnum({ [GateKeepType.PaidGating]: {} });
let community_id = cairo.uint256(4);
let gatekeep_type = new CairoCustomEnum({ [GateKeepType.PermissionedGating]: {} });
let permissioned_address = [1, "0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f"];
let erc20_address:string = "0x006e1698dcd0665757dd213a59aff489624bab8c970ce0482c23937a78879b04";
let amount = cairo.uint256(50);
let erc721_address = "0x036053a7520d7ff5cb1ce8ebec7acaf8b6364130865662937ab1e2a36d4e00c1";
let erc721_address = "0x0000003697660a0981d734780731949ecb2b4a38d6a58fc41629ed611e8defda";
let paid_gating_details = {
"0": erc20_address,
"1": amount
Expand Down Expand Up @@ -299,9 +299,9 @@ const execute_gatekeep = async() =>{

// execute_get_community();
// execute_create_community();
// execute_upgrade()
execute_gatekeep()
// create_subscription()
// execute_upgrade()
// execute_create_channel();
// execute_join_community();
// execute_make_post();
Expand Down
1 change: 1 addition & 0 deletions src/base/constants/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod Errors {
pub const COMMUNITY_DOES_NOT_EXIST: felt252 = 'coloniz: Comm does not exist';
pub const NOT_COMMUNITY_OWNER: felt252 = 'coloniz: Not Community owner';
pub const ONLY_PREMIUM_COMMUNITIES: felt252 = 'coloniz: not premium community';
pub const INVALID_UPGRADE: felt252 = 'coloniz: invalid upgrade type';
pub const NOT_COMMUNITY_MEMBER: felt252 = 'coloniz: Not Community Member';
pub const NOT_COMMUNITY_MOD: felt252 = 'coloniz: Not a community mod';
pub const BANNED_MEMBER: felt252 = 'coloniz: Profile is banned!';
Expand Down
30 changes: 27 additions & 3 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod CommunityComponent {
};
use coloniz::base::constants::errors::Errors::{
ALREADY_MEMBER, NOT_COMMUNITY_OWNER, NOT_COMMUNITY_MEMBER, NOT_COMMUNITY_MOD, BANNED_MEMBER,
UNAUTHORIZED, ONLY_PREMIUM_COMMUNITIES, INVALID_LENGTH
UNAUTHORIZED, ONLY_PREMIUM_COMMUNITIES, INVALID_LENGTH, INVALID_UPGRADE
};

// *************************************************************************
Expand Down Expand Up @@ -313,6 +313,7 @@ pub mod CommunityComponent {
// check community owner is caller
let community_owner = self.communities.read(community_id).community_owner;
assert(community_owner == get_caller_address(), NOT_COMMUNITY_OWNER);
assert(upgrade_type != CommunityType::Free, INVALID_UPGRADE);

self
._upgrade_community(
Expand Down Expand Up @@ -386,14 +387,28 @@ pub mod CommunityComponent {
);
}

/// @notice sets permissioned addresses for a community
/// @param community_id The id of the community
/// /// @param permissioned_addresses array of addresses to set for permissioned gatekeeping
fn set_permissioned_addresses(
ref self: ComponentState<TContractState>, community_id: u256,
permissioned_addresses: Array<ContractAddress>
) {
// check caller is owner
let mut community = self.communities.read(community_id);
assert(community.community_owner == get_caller_address(), UNAUTHORIZED);

// set permissioned addresses
self._permissioned_gatekeeping(community_id, permissioned_addresses);
}

/// @notice set the censorship status of a community
/// @param community_id The id of the community
fn set_community_censorship_status(
ref self: ComponentState<TContractState>, community_id: u256, censorship_status: bool
) {
let mut community = self.communities.read(community_id);

// check caller is owner
let mut community = self.communities.read(community_id);
assert(community.community_owner == get_caller_address(), UNAUTHORIZED);

// update storage
Expand Down Expand Up @@ -513,6 +528,15 @@ pub mod CommunityComponent {

(true, gatekeep_details)
}

/// @notice checks if an address has permissions to join a community
/// @param community_id id of community to check
/// @return bool permissioned status of the address
fn is_permissioned_address(
self: @ComponentState<TContractState>, community_id: u256, address: ContractAddress
) -> bool {
self.gate_keep_permissioned_addresses.read((community_id, address))
}
}

// *************************************************************************
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub trait ICommunity<TState> {
permissioned_addresses: Array<ContractAddress>,
paid_gating_details: (ContractAddress, u256),
);
fn set_permissioned_addresses(
ref self: TState,
community_id: u256,
permissioned_addresses: Array<ContractAddress>
);

// *************************************************************************
// GETTERS
Expand All @@ -64,4 +69,5 @@ pub trait ICommunity<TState> {
fn get_community_fee_address(self: @TState, community_id: u256) -> ContractAddress;
fn is_premium_community(self: @TState, community_id: u256) -> (bool, CommunityType);
fn is_gatekeeped(self: @TState, community_id: u256) -> (bool, CommunityGateKeepDetails);
fn is_permissioned_address(self: @TState, community_id: u256, address: ContractAddress) -> bool;
}

0 comments on commit f767608

Please sign in to comment.