From 1e6c03a79f020e704c6dce9497150649e1a85290 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 5 Feb 2021 21:59:06 +0200 Subject: [PATCH] fix: post's author shouldn't be able to vote for it --- packages/concordia-contracts/contracts/Forum.sol | 5 +++++ packages/concordia-contracts/contracts/PostVoting.sol | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/concordia-contracts/contracts/Forum.sol b/packages/concordia-contracts/contracts/Forum.sol index 05d6031..6120530 100644 --- a/packages/concordia-contracts/contracts/Forum.sol +++ b/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; + } } diff --git a/packages/concordia-contracts/contracts/PostVoting.sol b/packages/concordia-contracts/contracts/PostVoting.sol index c6183c7..1b3374a 100644 --- a/packages/concordia-contracts/contracts/PostVoting.sol +++ b/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)