-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoList.sol
More file actions
36 lines (31 loc) · 899 Bytes
/
TodoList.sol
File metadata and controls
36 lines (31 loc) · 899 Bytes
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TodoList{
struct Task{
uint id;
string description;
bool completed;
}
Task[] public alltasks;
uint public currentId=1;
function addTask(string memory description)public{
alltasks.push(Task(currentId,description,false));
currentId++;
}
function getTask(uint id) public view returns (Task memory) {
for(uint i=0;i<alltasks.length;i++){
if(alltasks[i].id==id){
return alltasks[i];
}
}
revert("Task not found");
}
function toggleTask(uint TaskId)public{
for(uint i=0;i<alltasks.length;i++){
if(alltasks[i].id == TaskId){
alltasks[i].completed=!alltasks[i].completed;
return;
}
}
}
}