diff --git a/src/core/registry.cairo b/src/core/registry.cairo index c96217d..f0fcc0f 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -6,7 +6,6 @@ struct Metadata { pointer: ByteArray, } - // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⢿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ @@ -23,13 +22,20 @@ 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 { fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool; + fn is_member_of_profile( + self: @TContractState, profile_id: u256, member: ContractAddress + ) -> bool; + fn is_owner_or_member_of_profile( + self: @TContractState, profile_id: u256, account: ContractAddress + ) -> bool; fn update_profile_pending_owner( ref self: TContractState, profile_id: u256, pending_owner: ContractAddress ); @@ -75,6 +81,7 @@ pub mod Registry { metadata: Metadata, } + #[derive(Drop, Serde, starknet::Store)] pub struct Profile { id: u256, @@ -85,6 +92,7 @@ pub mod Registry { anchor: ContractAddress, } + #[derive(Drop, starknet::Event)] struct ProfilePendingOwnerUpdated { #[key] @@ -142,7 +150,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); @@ -195,6 +203,14 @@ pub mod Registry { // 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#L229 + fn is_owner_or_member_of_profile( + self: @ContractState, profile_id: u256, account: ContractAddress + ) -> bool { + return self._is_owner_of_profile(profile_id, account) + || self._is_member_of_profile(profile_id, account); + } + + // Issue no. #3 Implement the functionality of isOwnerOfProfile // 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#L245 @@ -208,6 +224,12 @@ pub mod Registry { // 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#L245 + fn is_member_of_profile( + self: @ContractState, profile_id: u256, member: ContractAddress + ) -> bool { + return self._is_member_of_profile(profile_id, member); + } + // Issue no. #9 Implement the functionality of UpdateProfilePendingOwner // 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#L253 @@ -243,12 +265,12 @@ pub mod Registry { i += 1; } } - // Issue no. #6 Implement the functionality of removeMembers + // 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 + // 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 @@ -261,10 +283,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 @@ -293,9 +318,15 @@ pub mod Registry { ) -> bool { return self.profiles_by_id.read(_profile_id).owner == _owner; } - // 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 - + // 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 + fn _is_member_of_profile( + self: @ContractState, _profile_id: u256, _owner: ContractAddress + ) -> bool { + let _profile_id: felt252 = _profile_id.try_into().unwrap(); + return self.accessControl.has_role(_profile_id, _owner); + } } } +