-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store.sol
48 lines (38 loc) · 1.04 KB
/
Store.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
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.7.0 <0.9.0;
contract Todo{
address public owner;
Task[] tasks;
struct Task{
string content;
bool status;
}
constructor(){
owner = msg.sender;
}
modifier isOwner(){
require(owner == msg.sender);
_;
}
function add(string memory _content) public isOwner {
tasks.push(Task(_content, false));
}
function get(uint _id) public isOwner view returns (Task memory){
return tasks[_id];
}
function list() public isOwner view returns (Task[] memory){
return tasks;
}
function update(uint _id, string memory _content) public isOwner {
tasks[_id].content = _content;
}
function toggle(uint _id) public isOwner {
tasks[_id].status = !tasks[_id].status;
}
function remove(uint _id) public isOwner{
for(uint i = _id; i<tasks.length -1; i++){
tasks[i] = tasks[i+1];
}
tasks.pop();
}
}