Skip to content

Commit

Permalink
feat: update profile metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijofficial committed Aug 21, 2024
1 parent 383a503 commit e517b15
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies = [
name = "allo"
version = "0.0.1"
dependencies = [
"alexandria_bytes",
"alexandria_math",
"openzeppelin",
"snforge_std",
Expand Down
60 changes: 48 additions & 12 deletions src/core/registry.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use starknet::{ContractAddress, get_caller_address, get_contract_address, contract_address_const};

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


// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⢿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Expand Down Expand Up @@ -27,6 +34,7 @@ pub trait IRegistry<TContractState> {
ref self: TContractState, profile_id: u256, pending_owner: ContractAddress
);
fn add_members(ref self: TContractState, profile_Id: u256, members: Array<ContractAddress>);
fn update_profile_metadata(ref self: TContractState, profile_id: u256, metadata: Metadata);
}
#[starknet::contract]
pub mod Registry {
Expand All @@ -39,7 +47,7 @@ pub mod Registry {
use openzeppelin::access::accesscontrol::AccessControlComponent;
use openzeppelin::introspection::src5::SRC5Component;
use starknet::{get_caller_address, contract_address_const};

use super::{Metadata};

component!(path: SRC5Component, storage: SRC5_supported_interfaces, event: SRC5ComponentEvent);

Expand All @@ -59,10 +67,11 @@ pub mod Registry {
// === Structs ==============
// ==========================

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

#[derive(Drop, Serde, starknet::Store)]
Expand Down Expand Up @@ -108,6 +117,7 @@ pub mod Registry {
#[flat]
AccessControlComponentEvent: AccessControlComponent::Event,
ProfilePendingOwnerUpdated: ProfilePendingOwnerUpdated,
ProfileMetadataUpdated: ProfileMetadataUpdated
}


Expand Down Expand Up @@ -149,6 +159,32 @@ 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#L214C14-L214C35

fn update_profile_metadata(ref self: ContractState, profile_id: u256, metadata: Metadata) {
// Get the address of the caller
let caller = get_caller_address();
// Ensure the caller is the owner of the profile
assert(self._is_owner_of_profile(profile_id, caller), 'Not profile owner');

// Read the profile from storage
let mut profile = self.profiles_by_id.read(profile_id);

// Update the profile's metadata with the new protocol and pointer
profile
.metadata =
Metadata {
protocol: metadata.protocol,
pointer: metadata
.pointer
.clone(), //// Clone the pointer to prevent move errors
};

// Write the updated profile back to storage
self.profiles_by_id.write(profile_id, profile);

//ProfileMetaDataUpdated Event Emit
self.emit(ProfileMetadataUpdated { profile_id, metadata });
}

// 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.
Expand Down Expand Up @@ -180,14 +216,14 @@ pub mod Registry {

self.emit(ProfilePendingOwnerUpdated { profile_id, pending_owner, });
}
// Issue no. #8 Implement the functionality of acceptProfileOwnership
// 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#L267
// Issue no. #8 Implement the functionality of acceptProfileOwnership
// 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#L267

// Issue no. #7 Implement the functionality of addMembers
// 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#L289
// Issue no. #7 Implement the functionality of addMembers
// 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#L289
fn add_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());
Expand Down

0 comments on commit e517b15

Please sign in to comment.