diff --git a/src/mods/errors.cairo b/src/mods/errors.cairo index e841697..e1980f9 100644 --- a/src/mods/errors.cairo +++ b/src/mods/errors.cairo @@ -1,6 +1,7 @@ pub mod Errors { pub const USER_ALREADY_REGISTERED: felt252 = 'USER_ALREADY_REGISTERED'; pub const USER_NOT_REGISTERED: felt252 = 'USER_NOT_REGISTERED'; + pub const PROTOCOL_NOT_REGISTERED: felt252 = 'PROTOCOL_NOT_REGISTERED'; pub const TASK_ALREADY_EXISTS: felt252 = 'TASK_ALREADY_EXISTS'; pub const TASK_NOT_EXISTS: felt252 = 'TASK_NOT_EXISTS'; pub const PROTOCOL_ALREADY_REGISTERED: felt252 = 'PROTOCOL_ALREADY_REGISTERED'; diff --git a/src/mods/events.cairo b/src/mods/events.cairo index 010662d..d73ab92 100644 --- a/src/mods/events.cairo +++ b/src/mods/events.cairo @@ -3,6 +3,7 @@ use starknet::{ClassHash, ContractAddress}; #[derive(Copy, Drop, Debug, PartialEq, starknet::Event)] pub struct Upgraded { + #[key] pub implementation: ClassHash, } diff --git a/src/mods/interfaces/Iprotocol.cairo b/src/mods/interfaces/Iprotocol.cairo index 7f94992..362ed07 100644 --- a/src/mods/interfaces/Iprotocol.cairo +++ b/src/mods/interfaces/Iprotocol.cairo @@ -16,6 +16,7 @@ pub trait IProtocol { fn set_protocol_matadata_uri(ref self: TState, protocol_id: u256, matadata_uri: ByteArray); fn create_task(ref self: TState, task_description: ByteArray) -> u256; fn protocol_register(ref self: TState, protocol_Details: ByteArray); + fn verfify_protocol(ref self: TState, protocol_address: ContractAddress); // ************************************************************************* diff --git a/src/mods/protocol/protocolcomponent.cairo b/src/mods/protocol/protocolcomponent.cairo index 74df316..135106e 100644 --- a/src/mods/protocol/protocolcomponent.cairo +++ b/src/mods/protocol/protocolcomponent.cairo @@ -57,6 +57,7 @@ pub mod ProtocolCampagin { protocol_register: Map< ContractAddress, ProtocolInfo >, // map the protocol owner to the protocol info + owner: ContractAddress, // The owner of the contract } @@ -170,6 +171,33 @@ pub mod ProtocolCampagin { } + /// @notice verify protocols after registeration, this is done by the admin + + fn verfify_protocol( + ref self: ComponentState, protocol_address: ContractAddress + ) { + let caller = get_caller_address(); + assert(caller == self.owner.read(), Errors::UNAUTHORIZED); + + let protocol_info = self.protocol_register.read(protocol_address); + assert(protocol_info.registered, Errors::PROTOCOL_NOT_REGISTERED); + + self + .protocol_register + .write(protocol_address, ProtocolInfo { verified: true, ..protocol_info }); + + self + .emit( + ProtocolRegistered { + protocol_id: protocol_info.protocol_id, + protocol_owner: get_caller_address(), + event_type: UserEventType::Verify, + block_timestamp: get_block_timestamp() + } + ); + } + + /// @notice Create a new protocol campaign fn create_protocol_campaign( ref self: ComponentState, protocol_id: u256, protocol_info: ByteArray