Created
March 24, 2018 10:52
-
-
Save msusur/a581e75a743bb2374f3a581ec6a8ed64 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.21; | |
contract Ownable { | |
address public owner; | |
event OwnerChanged(address oldOwner, address newOwner); | |
function Ownable() { | |
owner = msg.sender; | |
} | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
function changeOwner(address _newOwner) external onlyOwner { | |
address oldOwner = owner; | |
owner = _newOwner; | |
OwnerChanged(oldOwner, _newOwner); | |
} | |
} | |
contract Greeting is Ownable { | |
struct GreetingItem { | |
string greeting; | |
address greeter; | |
} | |
modifier hasNotGreetYet() { | |
require(greetingsMap[msg.sender].greeter == address(0)); | |
_; | |
} | |
mapping(address => GreetingItem) greetingsMap; | |
uint count; | |
address lastGreeterAddress; | |
address owner; | |
event NewGreetingCreated(address newGreeter, string newGreeting); | |
function Greeting() public { | |
} | |
function greet(string _greeting) hasNotGreetYet onlyOwner public { | |
count += 1; | |
GreetingItem memory greetingItem = GreetingItem(_greeting, msg.sender); | |
greetingsMap[msg.sender] = greetingItem; | |
lastGreeterAddress = msg.sender; | |
NewGreetingCreated(msg.sender, _greeting); | |
} | |
function getGreeting() public constant returns (string lastGreeting, address lastGreeter, uint lastCount) { | |
GreetingItem storage greetingItem = greetingsMap[lastGreeterAddress]; | |
return (greetingItem.greeting, greetingItem.greeter, count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment