-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoList.sol
More file actions
47 lines (37 loc) · 1.28 KB
/
TodoList.sol
File metadata and controls
47 lines (37 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract TodoList {
struct Task {
string content;
bool completed;
}
Task[] public tasks;
address public owner;
event TaskCreated(uint indexed taskId, string content);
event TaskCompleted(uint indexed taskId, bool completed);
constructor() {
owner = msg.sender;
createTask("My first task!");
}
function createTask(string memory _content) public {
require(bytes(_content).length > 0, "Task cant be empty");
tasks.push(Task({
content: _content,
completed: false
}));
emit TaskCreated(tasks.length - 1, _content);
}
function toggleCompleted(uint _taskId) public {
require(_taskId < tasks.length, "No task with such ID");
tasks[_taskId].completed = !tasks[_taskId].completed;
emit TaskCompleted(_taskId, tasks[_taskId].completed);
}
function getTaskCount() public view returns (uint) {
return tasks.length;
}
function getTask(uint _taskId) public view returns (string memory content, bool completed) {
require(_taskId < tasks.length, "No task with such ID");
Task storage task = tasks[_taskId];
return (task.content, task.completed);
}
}