-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShortSNS.sol
58 lines (45 loc) · 1.43 KB
/
ShortSNS.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
pragma solidity ^0.5.0;
contract noncense {
struct post {
address author;
uint32 time;
string contents;
MsgState state;
}
post[] public posts;
event AlertPost (
address indexed author,
uint indexed id,
MsgState indexed state
);
enum MsgState {
Delete,
New,
Update
}
function getNumPost() public view returns(uint){
return posts.length;
}
function newPost(string memory contents) public {
posts.push(post({
author : msg.sender,
time : uint32(now),
contents : contents,
state : MsgState.New
}));
emit AlertPost(msg.sender, posts.length - 1 , MsgState.New);
}
function updatePost(uint id, string memory contents) public {
require(posts[id].author == msg.sender, "Only author can modify this post");
require(posts[id].state != MsgState.Delete, "This is delete post");
posts[id].time = uint32(now);
posts[id].contents = contents;
posts[id].state = MsgState.Update;
emit AlertPost(msg.sender, id, MsgState.Update);
}
function deletePost(uint id) public {
require(posts[id].author == msg.sender, "Only author can modify this post");
delete posts[id];
emit AlertPost(msg.sender, id, MsgState.Delete);
}
}