Skip to content

Instantly share code, notes, and snippets.

@noman-land
Created January 9, 2018 04:51
Show Gist options
  • Save noman-land/9aacd2d89ebcd2cb8048f9131e750b32 to your computer and use it in GitHub Desktop.
Save noman-land/9aacd2d89ebcd2cb8048f9131e750b32 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.11;
contract AnsweringMachine {
enum Status {
Here,
Busy,
Away
}
struct AwayStatus {
Status status;
uint updatedAt;
}
struct AwayMessage {
uint messageHash;
uint updatedAt;
}
struct Message {
address sender;
uint messageHash;
uint receivedAt;
}
address public owner;
AwayStatus public awayStatus;
AwayMessage public awayMessage;
Message[] public inbox;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function AnsweringMachine() {
owner = msg.sender;
}
function setStatus(Status newStatus) onlyOwner {
awayStatus.status = newStatus;
awayStatus.updatedAt = block.number;
}
function setAwayMessage(uint newAwayMessage) onlyOwner {
awayMessage.messageHash = newAwayMessage;
awayMessage.updatedAt = block.number;
}
function leaveMessage(uint message) public {
inbox.push(Message(msg.sender, message, block.number));
}
function deleteMessage(uint index) onlyOwner {
inbox[index] = inbox[inbox.length - 1];
inbox.length--;
}
function clearInbox() onlyOwner {
delete inbox;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment