-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStruct.sol
More file actions
36 lines (28 loc) · 875 Bytes
/
Struct.sol
File metadata and controls
36 lines (28 loc) · 875 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.10;
contract Todos {
struct Todo {
string text;
bool completed;
}
Todo[] public todos;
function create (string memory _text) public {
todos.push(Todo(_text, false));
todos.push(Todo({text: _text, completed: false}));
Todo memory todo;
todo.text = _text;
todos.push(todo);
}
function get(uint _index) public view returns (string memory text, bool completed) {
Todo storage todo = todos[_index];
return (todo.text, todo.completed);
}
function update(uint _index, string memory _text) public {
Todo storage todo = todos[_index];
todo.text = _text;
}
function toggleCompleted(uint _index) public {
Todo storage todo = todos[_index];
todo.completed = !todo.completed;
}
}