Last active
October 31, 2022 10:32
-
-
Save shobhitic/080f4624eba28024ef3657b879ab6796 to your computer and use it in GitHub Desktop.
TodoList Backend in Solidity - https://www.youtube.com/watch?v=20ktZBancco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
contract TodoList { | |
struct TodoItem { | |
string task; | |
bool isCompleted; | |
} | |
mapping (uint256 => TodoItem) public list; | |
uint256 public count = 0; | |
address public owner; | |
event TaskCompleted(uint256 indexed id); | |
constructor () { | |
owner = msg.sender; | |
} | |
function addTask(string calldata task) onlyOwner public { | |
TodoItem memory item = TodoItem({ task: task, isCompleted: false }); | |
list[count] = item; | |
count++; | |
} | |
function completeTask(uint256 id) onlyOwner public { | |
if (!list[id].isCompleted) { | |
list[id].isCompleted = true; | |
emit TaskCompleted(id); | |
} | |
} | |
modifier onlyOwner() { | |
require(owner == msg.sender, "Only owner can call this"); | |
_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment