|
@ -15,8 +15,8 @@ contract Forum { |
|
|
mapping (address => User) users; |
|
|
mapping (address => User) users; |
|
|
mapping (string => address) userAddresses; |
|
|
mapping (string => address) userAddresses; |
|
|
|
|
|
|
|
|
event USER_SIGNED_UP(string username, address userAddress); |
|
|
event UserSignedUp(string username, address userAddress); |
|
|
event USERNAME_UPDATED(string newName, string oldName, address userAddress); |
|
|
event UsernameUpdated(string newName, string oldName, address userAddress); |
|
|
|
|
|
|
|
|
function signUp(string memory username) public returns (bool) { |
|
|
function signUp(string memory username) public returns (bool) { |
|
|
require (!hasUserSignedUp(msg.sender), "User has already signed up."); |
|
|
require (!hasUserSignedUp(msg.sender), "User has already signed up."); |
|
@ -24,7 +24,7 @@ contract Forum { |
|
|
users[msg.sender] = User(username, |
|
|
users[msg.sender] = User(username, |
|
|
new uint[](0), new uint[](0), block.timestamp, true); |
|
|
new uint[](0), new uint[](0), block.timestamp, true); |
|
|
userAddresses[username] = msg.sender; |
|
|
userAddresses[username] = msg.sender; |
|
|
emit USER_SIGNED_UP(username, msg.sender); |
|
|
emit UserSignedUp(username, msg.sender); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -35,7 +35,7 @@ contract Forum { |
|
|
delete userAddresses[users[msg.sender].username]; |
|
|
delete userAddresses[users[msg.sender].username]; |
|
|
users[msg.sender].username = newUsername; |
|
|
users[msg.sender].username = newUsername; |
|
|
userAddresses[newUsername] = msg.sender; |
|
|
userAddresses[newUsername] = msg.sender; |
|
|
emit USERNAME_UPDATED(newUsername, oldUsername, msg.sender); |
|
|
emit UsernameUpdated(newUsername, oldUsername, msg.sender); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -95,8 +95,8 @@ contract Forum { |
|
|
mapping (uint => Topic) topics; |
|
|
mapping (uint => Topic) topics; |
|
|
mapping (uint => Post) posts; |
|
|
mapping (uint => Post) posts; |
|
|
|
|
|
|
|
|
event TOPIC_CREATED(uint topicID, uint postID); |
|
|
event TopicCreated(uint topicID, uint postID); |
|
|
event POST_CREATED(uint postID, uint topicID); |
|
|
event PostCreated(uint postID, uint topicID); |
|
|
|
|
|
|
|
|
function createTopic() public returns (uint, uint) { |
|
|
function createTopic() public returns (uint, uint) { |
|
|
require(hasUserSignedUp(msg.sender)); // Only registered users can create topics |
|
|
require(hasUserSignedUp(msg.sender)); // Only registered users can create topics |
|
@ -111,7 +111,7 @@ contract Forum { |
|
|
topics[topicID].postIDs.push(postID); |
|
|
topics[topicID].postIDs.push(postID); |
|
|
users[msg.sender].postIDs.push(postID); |
|
|
users[msg.sender].postIDs.push(postID); |
|
|
|
|
|
|
|
|
emit TOPIC_CREATED(topicID, postID); |
|
|
emit TopicCreated(topicID, postID); |
|
|
return (topicID, postID); |
|
|
return (topicID, postID); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -122,7 +122,7 @@ contract Forum { |
|
|
posts[postID] = Post(postID, msg.sender, block.timestamp, topicID); |
|
|
posts[postID] = Post(postID, msg.sender, block.timestamp, topicID); |
|
|
topics[topicID].postIDs.push(postID); |
|
|
topics[topicID].postIDs.push(postID); |
|
|
users[msg.sender].postIDs.push(postID); |
|
|
users[msg.sender].postIDs.push(postID); |
|
|
emit POST_CREATED(postID, topicID); |
|
|
emit PostCreated(postID, topicID); |
|
|
return postID; |
|
|
return postID; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|