Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove members #49

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions src/core/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ struct Metadata {
pointer: ByteArray,
}


// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⢿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Expand All @@ -23,17 +22,21 @@ struct Metadata {
// allo.gitcoin.co

/// Registry contract
/// Solidity equivalent: https://github.com/allo-protocol/allo-v2/blob/main/contracts/core/Registry.sol
/// Solidity equivalent:
/// https://github.com/allo-protocol/allo-v2/blob/main/contracts/core/Registry.sol

/// Registry contract interface
/// Interface for the Registry contract.
#[starknet::interface]
pub trait IRegistry<TContractState> {
fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool;


fn update_profile_pending_owner(
ref self: TContractState, profile_id: u256, pending_owner: ContractAddress
);
fn add_members(ref self: TContractState, profile_Id: u256, members: Array<ContractAddress>);
fn remove_members(ref self: TContractState, profile_Id: u256, members: Array<ContractAddress>);
fn update_profile_metadata(ref self: TContractState, profile_id: u256, metadata: Metadata);
fn get_profile_by_id(self: @TContractState, profile_id: u256) -> Registry::Profile;
}
Expand Down Expand Up @@ -75,6 +78,7 @@ pub mod Registry {
metadata: Metadata,
}


#[derive(Drop, Serde, starknet::Store)]
pub struct Profile {
id: u256,
Expand All @@ -85,6 +89,7 @@ pub mod Registry {
anchor: ContractAddress,
}


#[derive(Drop, starknet::Event)]
struct ProfilePendingOwnerUpdated {
#[key]
Expand Down Expand Up @@ -142,7 +147,7 @@ pub mod Registry {
> { // Issue no. #15 Implement the functionality to retrieve profile by profileId
// Down below is the function that is to be implemented in the contract but in cairo.
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L94
// Use _profileID as u256
// Use _profileID as u256

fn get_profile_by_id(self: @ContractState, profile_id: u256) -> Profile {
return self.profiles_by_id.read(profile_id);
Expand Down Expand Up @@ -243,12 +248,27 @@ pub mod Registry {
i += 1;
}
}
// Issue no. #6 Implement the functionality of removeMembers
// Use u256 instead of bytes32
// Down below is the function that is to be implemented in the contract but in cairo.
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L311
// Issue no. #6 Implement the functionality of removeMembers
// Use u256 instead of bytes32
// Down below is the function that is to be implemented in the contract but in cairo.
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L311

// Issue no. #16 Implement the functionality of recoverFunds
fn remove_members(
ref self: ContractState, profile_Id: u256, members: Array<ContractAddress>
) {
let profile_id: felt252 = profile_Id.try_into().unwrap();
self.member_length.write(members.len().into());
let mut i = 0;
loop {
if (i >= members.len().into()) {
break;
}
let member: ContractAddress = *members.at(i);
self.accessControl._revoke_role(profile_id, member);
i += 1;
}
}
// Issue no. #16 Implement the functionality of recoverFunds
// Down below is the function that is to be implemented in the contract but in cairo.
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L392C14-L392C26

Expand All @@ -261,10 +281,13 @@ pub mod Registry {
impl RegistryInternalImpl of RegistryInternalTrait { // Issue no. #19 Implement the functionality of _generateProfileId
// Internal function to create a profile
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L366
// Reference on how to implement keccak256(abi.encodePacked)
// Solidity - https://github.com/celestiaorg/blobstream-contracts/blob/0b4bcf69d1ce96df000da7f95fba8c03aa15a45e/src/lib/tree/namespace/TreeHasher.sol#L33
// Cairo - https://github.com/keep-starknet-strange/blobstream-starknet/blob/b74777e5fb479e5b4aa5a1419135e0826343fc37/src/tree/namespace/hasher.cairo#L10
// More about it - https://github.com/keep-starknet-strange/alexandria/tree/main/src/encoding
// Reference on how to implement keccak256(abi.encodePacked)
// Solidity -
// https://github.com/celestiaorg/blobstream-contracts/blob/0b4bcf69d1ce96df000da7f95fba8c03aa15a45e/src/lib/tree/namespace/TreeHasher.sol#L33
// Cairo -
// https://github.com/keep-starknet-strange/blobstream-starknet/blob/b74777e5fb479e5b4aa5a1419135e0826343fc37/src/tree/namespace/hasher.cairo#L10
// More about it -
// https://github.com/keep-starknet-strange/alexandria/tree/main/src/encoding

// Issue no. #18 Implement the functionality of _generateAnchor
// Internal function to create a _generateAnchor
Expand Down Expand Up @@ -293,9 +316,10 @@ pub mod Registry {
) -> bool {
return self.profiles_by_id.read(_profile_id).owner == _owner;
}
// Issue n. #5 Implement the functionality of _isMemberOfProfile
// Issue n. #5 Implement the functionality of _isMemberOfProfile
// Down below is the function that is to be implemented in the contract but in cairo.
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32

}
}

Loading