-
Notifications
You must be signed in to change notification settings - Fork 3
/
ToDoList.sol
39 lines (31 loc) · 944 Bytes
/
ToDoList.sol
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
pragma solidity ^0.8.0;
contract TaskToDo {
enum TaskStatus {Pending, Finished}
address owner;
struct Task {
string desc;
TaskStatus status;
}
Task[] public tasks;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner, "Not owner");
_;
}
function addTask(string memory _desc) public onlyOwner {
tasks.push(Task(_desc, TaskStatus.Pending));
}
function markAsFinished(uint256 id) public onlyOwner {
require(id < tasks.length, "No task has been added");
tasks[id].status= TaskStatus.Finished;
}
function getAllTasks() public view returns (Task[] memory) {
return tasks;
}
function getTask(uint256 id) public view returns (string memory, TaskStatus) {
require(id < tasks.length, "No task has been added");
return(tasks[id].desc, tasks[id].status);
}
}