Skip to content

Commit

Permalink
feat : implemented is_owner_of_profile function
Browse files Browse the repository at this point in the history
  • Loading branch information
AkankshaAttavar committed May 31, 2024
1 parent b0ffd33 commit 7d8165c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/core/libraries.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod clone;
mod errors;
pub mod errors;
4 changes: 2 additions & 2 deletions src/core/libraries/errors.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use starknet::{ContractAddress, contract_address_const};

mod Errors {
pub mod Errors {
/// Throws as an general error when input / data is invalid.
const INVALID: felt252 = 'Data is invalid';
/// Thrown when mismatch in decoding data.
const MISMATCH: felt252 = 'Mismatch in decoding data';
/// 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
// const ZERO_ADDRESS : ContractAddress = contract_address_const::<'0'>();
/// Thrown when the function is not implemented
Expand Down
96 changes: 62 additions & 34 deletions src/core/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,38 @@ 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;
// ==========================
// === 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 {}
struct Storage {
profiles_by_id: LegacyMap<u256, Profile>,
}

/// ======================
/// ======= Events =======
Expand All @@ -57,35 +78,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
// 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. #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. #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. #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. #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. #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
// 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 @@ -134,17 +160,19 @@ 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#L331

fn _checkOnlyProfileOwner(_profileId: u256) {
assert(_isOwnerOfProfile(_profileId, get_caller_address()), Errors::UNAUTHORIZED);
}
// 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. #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
// 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 7d8165c

Please sign in to comment.