Browse Source

fix: post's author shouldn't be able to vote for it

develop
Ezerous 4 years ago
parent
commit
1e6c03a79f
  1. 5
      packages/concordia-contracts/contracts/Forum.sol
  2. 6
      packages/concordia-contracts/contracts/PostVoting.sol

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

@ -171,4 +171,9 @@ contract Forum {
posts[postID].topicID
);
}
function getPostAuthor(uint postID) public view returns (address) {
require(postExists(postID), POST_DOES_NOT_EXIST);
return posts[postID].author;
}
}

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

@ -70,11 +70,13 @@ contract PostVoting {
}
function vote(uint postID, Option option) private {
require(forum.hasUserSignedUp(msg.sender), forum.USER_HAS_NOT_SIGNED_UP());
address voter = msg.sender;
require(forum.hasUserSignedUp(voter), forum.USER_HAS_NOT_SIGNED_UP());
require(forum.postExists(postID), forum.POST_DOES_NOT_EXIST());
address postAuthor = forum.getPostAuthor(postID);
require(voter != postAuthor, "Post's author cannot vote for it.");
PostBallot storage postBallot = postBallots[postID];
address voter = msg.sender;
Option prevOption = postBallot.votes[voter];
if (prevOption == option)

Loading…
Cancel
Save