Skip to content

Instantly share code, notes, and snippets.

@diegofcornejo
Last active February 6, 2022 05:36
Show Gist options
  • Save diegofcornejo/2a99c8c3a3837664592c605bf76fa792 to your computer and use it in GitHub Desktop.
Save diegofcornejo/2a99c8c3a3837664592c605bf76fa792 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: MIT
pragma solidity >=0.8.0 <0.9.0;
contract RandomTestContract{
string text;
function write(string calldata _text) public{
text = _text;
}
function read() public view returns(string memory){
return text;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
contract RandomToDoList {
struct Task {
uint id;
string title;
address owner;
}
Task[] tasks;
function getTasksLen() internal view returns(uint){
return tasks.length;
}
function isOwner(address _owner) internal view returns(bool){
if(_owner == msg.sender || _owner == tx.origin){
return true;
}
revert("You are not the owner");
}
function createTask(string memory _name) public {
uint nextId = getTasksLen();
tasks.push(Task(nextId, _name, msg.sender));
}
function readTask(uint _id) public view returns (uint, string memory, address) {
// if(isOwner(tasks[_id].owner)){
return (tasks[_id].id, tasks[_id].title, tasks[_id].owner);
// }
// return (0, "You are not the owner", msg.sender);
}
function updateTask(uint _id, string memory _title) public {
if(isOwner(tasks[_id].owner)){
tasks[_id].title = _title;
}
}
function deleteTask(uint _id) public {
if(isOwner(tasks[_id].owner)){
delete tasks[_id];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment