-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto-do.sol
39 lines (34 loc) · 1017 Bytes
/
to-do.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract ToDo{
// todo's related data
struct Todo{
uint time;
string text;
bool complated;
}
Todo[] public todos;
// This function can create, changed and get todo's
function create(string calldata _text) external {
todos.push(Todo({
time: block.timestamp,
text: _text,
complated: false
}));
}
// updated todo's text
function update(uint _index, string calldata _text) external {
todos[_index].text = _text;
Todo storage todo = todos[_index];
todo.text = _text;
}
//we can see todo's situation
function get(uint _index) external view returns(string memory, bool) {
Todo memory todo = todos[_index];
return (todo.text, todo.complated);
}
// and we can complated todo
function complatedTodo(uint _index) external {
todos[_index].complated = !todos[_index].complated;
}
}