Last active
August 1, 2018 10:13
-
-
Save beeeku/6334f940eac2ea888875d45c9f172483 to your computer and use it in GitHub Desktop.
todo.sol
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
pragma solidity ^0.4.20; | |
contract TodoList { | |
struct Todo { | |
uint256 id; | |
bytes32 content; | |
address owner; | |
bool isCompleted; | |
uint256 timestamp; | |
} | |
uint256 public constant maxAmountOfTodos = 100; | |
// Owner => todos | |
mapping(address => Todo[maxAmountOfTodos]) public todos; | |
// Owner => last todo id | |
mapping(address => uint256) public lastIds; | |
// Add a todo to the list function | |
function addTodo(bytes32 _content) public { | |
Todo memory myNote = Todo(lastIds[msg.sender], _content, msg.sender, false, now); | |
todos[msg.sender][lastIds[msg.sender]] = myNote; | |
if(lastIds[msg.sender] >= maxAmountOfTodos) { | |
lastIds[msg.sender] = 0; | |
} else { | |
lastIds[msg.sender]++; | |
} | |
} | |
// Mark a todo as completed | |
function markTodoAsCompleted(uint256 _todoId) public { | |
require(_todoId < maxAmountOfTodos); | |
require(!todos[msg.sender][_todoId].isCompleted); | |
require(msg.sender == todos[msg.sender][_todoId].owner); | |
todos[msg.sender][_todoId].isCompleted = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment