Created
January 9, 2018 04:51
-
-
Save noman-land/9aacd2d89ebcd2cb8048f9131e750b32 to your computer and use it in GitHub Desktop.
This file contains 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.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