Created
January 29, 2019 03:57
-
-
Save dsiganos/572a95a5329fdd35936d544eb37cd370 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=false&gist=
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.22 <0.6.0; | |
contract HelloWorld { | |
string greeting = "Hello world"; | |
address last_updater; | |
mapping (address => string[]) public greetings_map; | |
event HelloEvent(string); | |
function hello() public returns (string memory) { | |
emit HelloEvent(greeting); | |
return (greeting); | |
} | |
function updateMessage(string memory _greeting) public { | |
greetings_map[msg.sender].push(_greeting); | |
greeting = _greeting; | |
last_updater = msg.sender; | |
} | |
function getMessage(address user, uint i) public view returns(string memory) { | |
string[] memory greetings = greetings_map[user]; | |
if (i >= greetings.length) { | |
return ""; | |
} | |
return greetings[i]; | |
} | |
function latestMessage() public view returns (string memory, address) { | |
return (greeting, last_updater); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment