-
Notifications
You must be signed in to change notification settings - Fork 0
/
messaging_contract.sol
86 lines (69 loc) · 2.73 KB
/
messaging_contract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
pragma solidity ^0.4.15;
contract DexNS {
function addressOf(string _name) constant returns (address _addr);
}
contract ClassicEtherWallet_Messages {
DexNS dexns = DexNS(0x28fc417c046d409c14456cec0fc6f9cde46cc9f3);
struct message
{
address from;
string text;
}
struct public_key_struct
{
string key;
string key_type;
}
mapping (address => uint256) public last_msg_index;
mapping (address => mapping (uint256 => message)) public messages;
mapping (address => public_key_struct) public keys;
function sendMessage(address _to, string _text)
{
messages[_to][last_msg_index[_to]].from = msg.sender;
messages[_to][last_msg_index[_to]].text = _text;
last_msg_index[_to]++;
}
function lastIndex(address _owner) constant returns (uint256)
{
return last_msg_index[_owner];
}
function getLastMessage(address _who) constant returns (address, string)
{
return (messages[_who][last_msg_index[_who]].from, messages[_who][last_msg_index[_who]].text);
}
function getIndexedMessage(address _who, uint256 _index) constant returns (address, string)
{
return (messages[_who][_index].from, messages[_who][_index].text);
}
function getPublicKey(address _who) constant returns (string _key, string _key_type)
{
return (keys[_who].key, keys[_who].key_type);
}
function setPublicKey(string _key, string _type)
{
keys[msg.sender].key = _key;
keys[msg.sender].key_type = _type;
}
function getPublicKeyByName(string _name) constant returns (string _key, string _key_type)
{
return (keys[dexns.addressOf(_name)].key, keys[dexns.addressOf(_name)].key_type);
}
function sendMessageByName(string _name, string _text)
{
messages[dexns.addressOf(_name)][last_msg_index[dexns.addressOf(_name)]].from = msg.sender;
messages[dexns.addressOf(_name)][last_msg_index[dexns.addressOf(_name)]].text = _text;
last_msg_index[dexns.addressOf(_name)]++;
}
function getLastMessageByName(string _name) constant returns (address, string)
{
return (messages[dexns.addressOf(_name)][last_msg_index[dexns.addressOf(_name)]].from, messages[dexns.addressOf(_name)][last_msg_index[dexns.addressOf(_name)]].text);
}
function lastIndex(string _name) constant returns (uint256)
{
return last_msg_index[dexns.addressOf(_name)];
}
function getIndexedMessageByName(string _name, uint256 _index) constant returns (address, string)
{
return (messages[dexns.addressOf(_name)][_index].from, messages[dexns.addressOf(_name)][_index].text);
}
}