Last active
April 29, 2018 15:25
-
-
Save vvsotnikov/61f22fbe3112d93f718ff7afad43536b to your computer and use it in GitHub Desktop.
Simple Ethereum smart contract for sending text messages.
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.0; | |
contract Messenger { | |
struct MsgDB { | |
uint totalMessages; | |
mapping (uint => string) message; | |
} | |
struct Message { | |
string text; | |
string date; | |
} | |
mapping (address => mapping (address => MsgDB)) dialogues; | |
function IsBigger (address x, address y) private returns (bool) { | |
return (x > y); | |
} | |
function Send(address addr, string text) { | |
address x; | |
address y; | |
if (IsBigger(addr, msg.sender)) { | |
x = addr; | |
y = msg.sender; | |
} | |
else { | |
x = msg.sender; | |
y = addr; | |
} | |
// if (dialogues[x][y] == 0) { | |
// dialogues[x][y] = MsgDB; | |
//} | |
var i = ++dialogues[x][y].totalMessages; | |
dialogues[x][y].message[i] = text; | |
} | |
function Receive(address addr, uint i) returns (string) { | |
address x; | |
address y; | |
if (IsBigger(addr, msg.sender)) { | |
x = addr; | |
y = msg.sender; | |
} | |
else { | |
x = msg.sender; | |
y = addr; | |
} | |
if (i > dialogues[x][y].totalMessages) { | |
i = dialogues[x][y].totalMessages; | |
} | |
return dialogues[x][y].message[i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment