-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomework2.sol
35 lines (30 loc) · 929 Bytes
/
Homework2.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract toDoList{
struct toDo{
bool hasDone;
string job;
}
//29357 gas to view this public data
toDo[] public toDoArr;
function create(string calldata text) external{
toDoArr.push(toDo({
job : text,
hasDone:false
}));
}
function updateToDo(uint index, string calldata newText) external {
toDoArr[index].job = newText;
}
function getToDo(uint index) external view returns (string memory,bool){
//29441 gas to use function
toDo storage todo = toDoArr[index];
return (todo.job,todo.hasDone);
}
function completed(uint index) external {
//46320 gas
//toDoArr[index].hasDone = !toDoArr[index].hasDone;
//26084 gas - as this is more gas efficient I am using this code
toDoArr[index].hasDone = false;
}
}