-
Notifications
You must be signed in to change notification settings - Fork 11
/
TodoList.sol
32 lines (26 loc) · 971 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract TodoList {
struct Todo {
string text;
bool completed;
}
Todo[] public todos;
function create(string calldata _text) external {
Todo memory todo = Todo({text: _text, completed: false});
todos.push(todo);
}
function updateText(uint256 _index, string calldata _text) external {
require(_index >= 0 && _index < todos.length, "index out of range");
todos[_index].text = _text;
}
function toggleCompleted(uint256 _index) external {
require(_index >= 0 && _index < todos.length, "index out of range");
todos[_index].completed = !todos[_index].completed;
}
function get(uint256 _index) external view returns (string memory, bool) {
require(_index >= 0 && _index < todos.length, "index out of range");
Todo memory todo = todos[_index];
return (todo.text, todo.completed);
}
}