Skip to content

Instantly share code, notes, and snippets.

@therealharpaljadeja
Created August 9, 2022 08:45
Show Gist options
  • Save therealharpaljadeja/a80afd44a30420a20c565adb20ec6732 to your computer and use it in GitHub Desktop.
Save therealharpaljadeja/a80afd44a30420a20c565adb20ec6732 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: Unlicensed
pragma solidity ^0.8.0;
contract Todo {
struct Task {
bool isComplete;
string description;
}
uint256 taskCounter;
mapping(uint256 => Task) public tasks;
event TaskAdded(uint256 indexed taskId);
event TaskCompleted(uint256 indexed taskId);
function addTask(string calldata task) external returns(uint256) {
uint256 taskId = taskCounter;
tasks[taskId].description = task;
emit TaskAdded(taskId);
taskCounter++;
return taskId;
}
function isCompleted(uint256 taskId) view external returns(bool) {
return tasks[taskId].isComplete;
}
function markTaskComplete(uint256 taskId) external {
require(taskId < taskCounter, "No such task exists");
require(!tasks[taskId].isComplete, "Task already complete");
tasks[taskId].isComplete = true;
emit TaskCompleted(taskId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment