Browse Source

Minor reformatting

develop
Ezerous 4 years ago
parent
commit
00510656f1
  1. 12
      packages/concordia-contracts/contracts/Forum.sol
  2. 12
      packages/concordia-contracts/contracts/PostVoting.sol
  3. 10
      packages/concordia-contracts/contracts/Voting.sol

12
packages/concordia-contracts/contracts/Forum.sol

@ -24,7 +24,7 @@ contract Forum {
event UsernameUpdated(string newName, string oldName, address userAddress);
function signUp(string memory username) public returns (bool) {
require (!hasUserSignedUp(msg.sender), USER_HAS_NOT_SIGNED_UP);
require(!hasUserSignedUp(msg.sender), USER_HAS_NOT_SIGNED_UP);
require(!isUserNameTaken(username), USERNAME_TAKEN);
users[msg.sender] = User(username, new uint[](0), new uint[](0), block.timestamp, true);
userAddresses[username] = msg.sender;
@ -33,7 +33,7 @@ contract Forum {
}
function updateUsername(string memory newUsername) public returns (bool) {
require (hasUserSignedUp(msg.sender), USER_HAS_NOT_SIGNED_UP);
require(hasUserSignedUp(msg.sender), USER_HAS_NOT_SIGNED_UP);
require(!isUserNameTaken(newUsername), USERNAME_TAKEN);
string memory oldUsername = getUsername(msg.sender);
delete userAddresses[users[msg.sender].username];
@ -44,7 +44,7 @@ contract Forum {
}
function getUsername(address userAddress) public view returns (string memory) {
require (hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
require(hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
return users[userAddress].username;
}
@ -63,17 +63,17 @@ contract Forum {
}
function getUserTopics(address userAddress) public view returns (uint[] memory) {
require (hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
require(hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
return users[userAddress].topicIDs;
}
function getUserPosts(address userAddress) public view returns (uint[] memory) {
require (hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
require(hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
return users[userAddress].postIDs;
}
function getUserDateOfRegister(address userAddress) public view returns (uint) {
require (hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
require(hasUserSignedUp(userAddress), USER_HAS_NOT_SIGNED_UP);
return users[userAddress].timestamp;
}

12
packages/concordia-contracts/contracts/PostVoting.sol

@ -77,11 +77,11 @@ contract PostVoting {
address voter = msg.sender;
Option prevOption = postBallot.votes[voter];
if(prevOption == option)
if (prevOption == option)
return;
// Remove previous vote if exists
if(prevOption != Option.DEFAULT){
if (prevOption != Option.DEFAULT) {
uint voterIndex = getVoterIndex(postID, voter);
// Swap with last voter address and delete vote
postBallot.voters[prevOption][voterIndex] = postBallot.voters[prevOption][postBallot.voters[prevOption].length - 1];
@ -89,21 +89,21 @@ contract PostVoting {
}
// Add new vote
if(option != Option.DEFAULT)
if (option != Option.DEFAULT)
postBallot.voters[option].push(voter);
postBallot.votes[voter] = option;
emit UserVotedPost(voter, postID, option);
}
function upvote(uint postID) public{
function upvote(uint postID) public {
vote(postID, Option.UP);
}
function downvote(uint postID) public{
function downvote(uint postID) public {
vote(postID, Option.DOWN);
}
function unvote(uint postID) public{
function unvote(uint postID) public {
vote(postID, Option.DEFAULT);
}
}

10
packages/concordia-contracts/contracts/Voting.sol

@ -41,7 +41,7 @@ contract Voting {
function createPoll(uint topicID, uint numOptions, string memory dataHash, bool enableVoteChanges) public returns (uint) {
require(forum.hasUserSignedUp(msg.sender), forum.USER_HAS_NOT_SIGNED_UP());
require(forum.topicExists(topicID), forum.TOPIC_DOES_NOT_EXIST());
require (forum.getTopicAuthor(topicID) == msg.sender, TOPIC_POLL_DIFFERENT_CREATOR);
require(forum.getTopicAuthor(topicID) == msg.sender, TOPIC_POLL_DIFFERENT_CREATOR);
require(!pollExists(topicID), POLL_EXISTS);
Poll storage poll = polls[topicID];
@ -132,21 +132,21 @@ contract Voting {
Poll storage poll = polls[topicID];
address voter = msg.sender;
uint prevOption = poll.votes[voter];
if(prevOption == option)
if (prevOption == option)
return;
// Voter hasn't voted before
if(prevOption == 0){
if (prevOption == 0) {
poll.voters[option].push(voter);
poll.votes[voter] = option;
emit UserVotedPoll(voter, topicID, option);
}
else if (poll.enableVoteChanges){
else if (poll.enableVoteChanges) {
uint voterIndex = getVoterIndex(topicID, voter);
// Swap with last voter address and delete vote
poll.voters[prevOption][voterIndex] = poll.voters[prevOption][poll.voters[prevOption].length - 1];
poll.voters[prevOption].pop();
if(option != 0)
if (option != 0)
poll.voters[option].push(voter);
poll.votes[voter] = option;
emit UserVotedPoll(voter, topicID, option);

Loading…
Cancel
Save