Skip to content

Instantly share code, notes, and snippets.

@beeeku
Last active August 1, 2018 10:13
Show Gist options
  • Save beeeku/6334f940eac2ea888875d45c9f172483 to your computer and use it in GitHub Desktop.
Save beeeku/6334f940eac2ea888875d45c9f172483 to your computer and use it in GitHub Desktop.
todo.sol
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