Skip to content

Commit

Permalink
Merge pull request #31 from VictoriaAde/pendingowner
Browse files Browse the repository at this point in the history
Implement the functionality of UpdateProfilePendingOwner
  • Loading branch information
Akashneelesh committed Aug 5, 2024
2 parents efd3059 + 4115993 commit 135a327
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/core/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use starknet::{ContractAddress, get_caller_address, get_contract_address, contra
#[starknet::interface]
pub trait IRegistry<TContractState> {
fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool;
fn update_profile_pending_owner(
ref self: TContractState, profile_id: u256, pending_owner: ContractAddress
);
}
#[starknet::contract]
pub mod Registry {
Expand All @@ -32,6 +35,8 @@ pub mod Registry {
use allo::core::libraries::errors::Errors;
use openzeppelin::access::accesscontrol::AccessControlComponent;
use openzeppelin::introspection::src5::SRC5Component;
use starknet::get_caller_address;


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

Expand Down Expand Up @@ -66,6 +71,14 @@ pub mod Registry {
owner: ContractAddress,
anchor: ContractAddress,
}

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

// ==========================
// === Storage Variables ====
// ==========================
Expand All @@ -76,6 +89,8 @@ pub mod Registry {
SRC5_supported_interfaces: SRC5Component::Storage,
#[substorage(v0)]
accessControl: AccessControlComponent::Storage,
anchor_to_profile_id: LegacyMap<ContractAddress, u256>,
profile_id_to_pending_owner: LegacyMap<u256, ContractAddress>,
}

/// ======================
Expand All @@ -88,6 +103,7 @@ pub mod Registry {
SRC5ComponentEvent: SRC5Component::Event,
#[flat]
AccessControlComponentEvent: AccessControlComponent::Event,
ProfilePendingOwnerUpdated: ProfilePendingOwnerUpdated,
}


Expand Down Expand Up @@ -150,6 +166,16 @@ pub mod Registry {
// 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
fn update_profile_pending_owner(
ref self: ContractState, profile_id: u256, pending_owner: ContractAddress
) {
let caller = get_caller_address();
assert(self._is_owner_of_profile(profile_id, caller), 'Not profile owner');

self.profile_id_to_pending_owner.write(profile_id, pending_owner);

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.
Expand Down Expand Up @@ -209,4 +235,4 @@ pub mod Registry {
// https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32

}
}
}

0 comments on commit 135a327

Please sign in to comment.