-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathforum.sol
More file actions
102 lines (89 loc) · 2.46 KB
/
Copy pathforum.sol
File metadata and controls
102 lines (89 loc) · 2.46 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import "document.sol";
contract Forum
{
string name;
uint replyCost;
mapping (address => string) titles;
mapping (address => uint) timeStamp;
mapping (string => address[]) tag;
mapping (address => address[]) replies;
mapping (address => string[]) postTags;
mapping (address => address[]) postsByAuthor;
event PostMade
( address _postAddress);
function Forum(string forumName, uint cost)
{
name = forumName;
replyCost = cost;
}
function getReplyCost() constant returns(uint)
{
return replyCost;
}
function makePost(string title, string data)
{
address[] memory authors = new address[] (2);
authors[0] = msg.sender;
authors[1] = address(this);
uint[] memory weights = new uint[] (2);
weights[0] = 75;
weights[1] = 0;
Document newPost = new Document(data, authors, weights);
titles[address(newPost)] = title;
timeStamp[address(newPost)] = now;
postsByAuthor[msg.sender].push(address(newPost));
PostMade(address(newPost));
}
function addTag(address post, string tagToAdd)
{
tag[tagToAdd].push(post);
postTags[post].push(tagToAdd);
}
function makeReply(string title, string data, address replyTo)
{
if(msg.value >= replyCost)
{
if(replyTo.send(msg.value) == false)
{
throw;
}
address[] memory authors = new address[] (2);
authors[0] = msg.sender;
authors[1] = address(this);
uint[] memory weights = new uint[] (2);
weights[0] = 75;
weights[1] = 0;
Document newPost = new Document(data, authors, weights);
titles[address(newPost)] = title;
timeStamp[address(newPost)] = now;
postsByAuthor[msg.sender].push(address(newPost));
PostMade(address(newPost));
replies[replyTo].push(address(newPost));
Document(address(newPost)).addSource(replyTo, 25);
}
}
function getTitle(address post) constant returns(string)
{
return titles[post];
}
function getReplies(address post) constant returns(address[])
{
return replies[post];
}
function getPostsFromTag(string tagName) constant returns(address[])
{
return tag[tagName];
}
function getTagFromPosts(address post, uint i) constant returns(string)
{
return postTags[post][i];
}
function getPostsFromAuthor(address author) constant returns(address[])
{
return postsByAuthor[author];
}
function getNumberOfTags(address post) constant returns(uint)
{
return postTags[post].length;
}
}