Skip to content

Commit 140292c

Browse files
authored
Merge pull request #71 from davidmelendez/feat-fn-create_task
feat(protocol): implement create_task function
2 parents a733a96 + c4dfeaa commit 140292c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/mods/interfaces/Iprotocol.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait IProtocol<TState> {
1010
fn create_protocol_campaign(ref self: TState, protocol_id: u256) -> u256;
1111
fn join_protocol_campaign(ref self: TState, campaign_user: ContractAddress, protocol_id: u256);
1212
fn set_protocol_matadata_uri(ref self: TState, protocol_id: u256, matadata_uri: ByteArray);
13-
fn create_task(ref self: TState, task_id: u256) -> u256;
13+
fn create_task(ref self: TState, task_id: u256, task_description: ByteArray) -> u256;
1414

1515

1616
fn is_task_complete(ref self: TState, campaign_user: ContractAddress, task_id: u256) -> bool;

src/mods/protocol/protocolcomponent.cairo

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,23 @@ pub mod ProtocolCampagin {
170170
}
171171

172172

173-
fn create_task(ref self: ComponentState<TContractState>, task_id: u256) -> u256 {
173+
fn create_task(
174+
ref self: ComponentState<TContractState>, task_id: u256, task_description: ByteArray
175+
) -> u256 {
174176
// Get the caller as the protocol owner by using the get_caller_address()
177+
let protocol_owner = get_caller_address();
175178

176179
// Check if the task_id exist by reading from state i.e tasks_initialized
177180
// and also assert if it exist Errors::TASK_ALREADY_EXIST
181+
let task_exists = self.tasks_initialized.read(task_id);
182+
assert(!task_exists, Errors::TASK_ALREADY_EXIST);
183+
184+
let protocol_id = self.protocol_id.read();
185+
let protocol_owner_stored = self.protocol_owner.read(protocol_id);
186+
assert(protocol_owner == protocol_owner_stored, Errors::UNAUTHORIZED);
178187

179188
// call the internal function _create_task
189+
self._create_task(protocol_id, task_id, task_description, protocol_owner);
180190

181191
return task_id;
182192
}

0 commit comments

Comments
 (0)