Skip to content

Commit

Permalink
Merge pull request #22 from AkankshaAttavar/main
Browse files Browse the repository at this point in the history
added is_owner_of_profile function
  • Loading branch information
Akashneelesh authored Jul 18, 2024
2 parents ead6e9f + a278782 commit efd3059
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/core/libraries/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod Errors {
/// Thrown when not enough funds are available
const NOT_ENOUGH_FUNDS: felt252 = 'Not enough funds available';
/// Thrown when user is not authorized
const UNAUTHORIZED: felt252 = 'Not authorized';
pub const UNAUTHORIZED: felt252 = 'Not authorized';
// // /// Thrown when address is the zero address
pub const ZERO_ADDRESS: felt252 = 'Address is Zero';
/// Thrown when the function is not implemented
Expand Down
138 changes: 84 additions & 54 deletions src/core/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use starknet::{ContractAddress, get_caller_address, get_contract_address, contra
/// Registry contract interface
/// Interface for the Registry contract.
#[starknet::interface]
pub trait IRegistry<TContractState> {}

pub trait IRegistry<TContractState> {
fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool;
}
#[starknet::contract]
pub mod Registry {
use starknet::ContractAddress;
Expand All @@ -46,12 +47,31 @@ pub mod Registry {
AccessControlComponent::AccessControlImpl<ContractState>;
impl AccessControlComponentInternalImpl = AccessControlComponent::InternalImpl<ContractState>;

// ==========================
// === Structs ==============
// ==========================

#[derive(Drop, Serde, starknet::Store)]
struct Metadata {
protocol: u256,
pointer: ByteArray,
}

#[derive(Drop, Serde, starknet::Store)]
struct Profile {
id: u256,
nonce: u256,
name: ByteArray,
metadata: Metadata,
owner: ContractAddress,
anchor: ContractAddress,
}
// ==========================
// === Storage Variables ====
// ==========================
#[storage]
struct Storage {
profiles_by_id: LegacyMap<u256, Profile>,
#[substorage(v0)]
SRC5_supported_interfaces: SRC5Component::Storage,
#[substorage(v0)]
Expand Down Expand Up @@ -89,35 +109,40 @@ pub mod Registry {
impl Registry of super::IRegistry<
ContractState
> { // 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

// Issue no. #14 Implement the functionality to retrieve profile by anchor
// 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#L102

// Issue no. #13 Implement the functionality of createProfile
// 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#L118C5-L125C18

// Issue no. #12 Implement the functionality of updateProfileName
// 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#L182C14-L182C31

// Issue no. #11 Implement the functionality of updateProfileMetadata
// 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#L214C14-L214C35

// Issue no. #10 Implement the functionality of isOwnerOrMemberOfProfile
// 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#L229

// 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

// 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

// Issue no. #14 Implement the functionality to retrieve profile by anchor
// 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#L102

// Issue no. #13 Implement the functionality of createProfile
// 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#L118C5-L125C18

// Issue no. #12 Implement the functionality of updateProfileName
// 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#L182C14-L182C31

// Issue no. #11 Implement the functionality of updateProfileMetadata
// 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#L214C14-L214C35

// Issue no. #10 Implement the functionality of isOwnerOrMemberOfProfile
// 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#L229

// 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

fn is_owner_of_profile(
self: @ContractState, profile_id: u256, owner: ContractAddress
) -> bool {
return self._is_owner_of_profile(profile_id, owner);
}
// Issue no. #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#L245
Expand Down Expand Up @@ -151,29 +176,34 @@ pub mod Registry {
/// ====================================
#[generate_trait]
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

// Issue no. #18 Implement the functionality of _generateAnchor
// Internal function to create a _generateAnchor
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L340

// Issue no. #17 Implement the functionality of _checkOnlyProfileOwner
// 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#L331

// Issue no. #4 Implement the functionality of _generateProfileId
// 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#L375C14-L375C31

// 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#L375C14-L375C31

// 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

// Issue no. #18 Implement the functionality of _generateAnchor
// Internal function to create a _generateAnchor
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L340

// Issue no. #17 Implement the functionality of _checkOnlyProfileOwner
// 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#L331

// Issue no. #4 Implement the functionality of _generateProfileId
// 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#L375C14-L375C31

// 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#L375C14-L375C31

fn _is_owner_of_profile(
self: @ContractState, _profile_id: u256, _owner: ContractAddress
) -> 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
Expand Down

0 comments on commit efd3059

Please sign in to comment.