Skip to content

Instantly share code, notes, and snippets.

@dsiganos
Created January 29, 2019 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsiganos/572a95a5329fdd35936d544eb37cd370 to your computer and use it in GitHub Desktop.
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=
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