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

feat/accept-profile-ownership #43

Open
wants to merge 1 commit 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
30 changes: 29 additions & 1 deletion src/core/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub trait IRegistry<TContractState> {
fn add_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;
fn accept_profile_ownership(ref self: TContractState, profile_id: u256);
}
#[starknet::contract]
pub mod Registry {
Expand Down Expand Up @@ -92,6 +93,13 @@ pub mod Registry {
pending_owner: ContractAddress,
}

#[derive(Drop, starknet::Event)]
struct ProfileOwnerUpdated {
#[key]
profile_id: u256,
owner: ContractAddress,
}

// ==========================
// === Storage Variables ====
// ==========================
Expand All @@ -118,7 +126,8 @@ pub mod Registry {
#[flat]
AccessControlComponentEvent: AccessControlComponent::Event,
ProfilePendingOwnerUpdated: ProfilePendingOwnerUpdated,
ProfileMetadataUpdated: ProfileMetadataUpdated
ProfileMetadataUpdated: ProfileMetadataUpdated,
ProfileOwnerUpdated: ProfileOwnerUpdated
}


Expand Down Expand Up @@ -224,6 +233,25 @@ pub mod Registry {
// 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
fn accept_profile_ownership(ref self: ContractState, profile_id: u256) {
// Read the profile from storage
let mut profile = self.profiles_by_id.read(profile_id);

// Ensure the caller is the pending owner of the profile
let caller = get_caller_address();
let new_owner = self.profile_id_to_pending_owner.read(profile_id);
assert(new_owner == caller, 'Not profile pending owner');

// Clear the pending owner
self.profile_id_to_pending_owner.write(profile_id, contract_address_const::<0>());

// Update the profile's owner
profile.owner = new_owner;
self.profiles_by_id.write(profile_id, profile);

// ProfileOwnerUpdated Event Emit
self.emit(ProfileOwnerUpdated { profile_id, owner: new_owner });
}

// Issue no. #7 Implement the functionality of addMembers
// Use u256 instead of bytes32
Expand Down
Loading