Skip to content

Instantly share code, notes, and snippets.

@ArslanKathia
Created February 6, 2023 16:17
Show Gist options
  • Save ArslanKathia/58fbc18ac9b2625f9fb7551354c81764 to your computer and use it in GitHub Desktop.
Save ArslanKathia/58fbc18ac9b2625f9fb7551354c81764 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.7.0 < 0.8.18;
/*Set the owner to the deployer of the contract using the constructor.
Use mapping to keep track of each Task.
Write the modifier onlyOwner() so that only the owner can call certain functions.
Adding a new task to the list.
Fetching (Reading) the task from the list.
Mark the task as completed.*/
contract TODO{
address public owner;
uint public taskNo;
mapping(uint => string) public Tasks;
mapping(uint => bool) public completedTask;
event taskAdded(string task);
event taskCompleted(string task);
constructor(){
owner = msg.sender;
}
modifier onlyOwner(){
require(owner == msg.sender, "Caller is not the owner");
_;
}
function taskAdd(string calldata _task,uint _taskNo) public onlyOwner{
taskNo = _taskNo;
Tasks[taskNo] = _task;
completedTask[taskNo] = false;
emit taskAdded(_task);
}
function completeTask(uint _taskNo) public onlyOwner{
taskNo = _taskNo;
completedTask[taskNo] = true;
string memory task_ = Tasks[taskNo];
emit taskCompleted(task_);
}
function getTasks(uint _taskNo) public view returns(string memory task){
return Tasks[_taskNo];
}
// function totalTasks() public returns{
// return Tasks;
// }
function checkTaskCompleted(uint _taskNo) public returns(bool){
taskNo = _taskNo;
bool status = completedTask[taskNo];
return status;
}
// struct Task{
// uint taskNo;
// string task;
// bool completedTask;
// }
// mapping(uint => Task) public TaskList;
// event taskStructAdd(Task);
// function taskStructAdding(uint _taskNo,string calldata _task) public onlyOwner{
// Task memory sTask = Task(_taskNo,_task,false);
// emit taskStructAdd(sTask);
// }
// function updateTaskStat(uint _taskNo) public onlyOwner{
// taskNo = _taskNo;
// Task memory _sTask;
// _sTask = TaskList[taskNo];
// _sTask.completedTask = true;
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment