Skip to content

Commit

Permalink
Fix IntVoteIntrerface warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
orenyodfat committed Jul 31, 2018
1 parent af5517f commit af24c3a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
46 changes: 28 additions & 18 deletions contracts/VotingMachines/AbsoluteVote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,8 @@ contract AbsoluteVote is IntVoteInterface {
* @return bool true - the proposal has been executed
* false - otherwise.
*/
function execute(bytes32 _proposalId) public votable(_proposalId) returns(bool) {
Proposal storage proposal = proposals[_proposalId];
Reputation reputation = parameters[proposal.paramsHash].reputationSystem;
require(reputation != address(0));
uint totalReputation = reputation.totalSupply();
uint precReq = parameters[proposal.paramsHash].precReq;
// Check if someone crossed the bar:
for (uint cnt = 0; cnt <= proposal.numOfChoices; cnt++) {
if (proposal.votes[cnt] > totalReputation*precReq/100) {
Proposal memory tmpProposal = proposal;
deleteProposal(_proposalId);
emit ExecuteProposal(_proposalId, tmpProposal.avatar, cnt, totalReputation);
(tmpProposal.executable).execute(_proposalId, tmpProposal.avatar, int(cnt));
return true;
}
}
return false;
function execute(bytes32 _proposalId) external votable(_proposalId) returns(bool) {
return _execute(_proposalId);
}

/**
Expand Down Expand Up @@ -300,6 +285,31 @@ contract AbsoluteVote is IntVoteInterface {
delete proposals[_proposalId];
}

/**
* @dev execute check if the proposal has been decided, and if so, execute the proposal
* @param _proposalId the id of the proposal
* @return bool true - the proposal has been executed
* false - otherwise.
*/
function _execute(bytes32 _proposalId) internal votable(_proposalId) returns(bool) {
Proposal storage proposal = proposals[_proposalId];
Reputation reputation = parameters[proposal.paramsHash].reputationSystem;
require(reputation != address(0));
uint totalReputation = reputation.totalSupply();
uint precReq = parameters[proposal.paramsHash].precReq;
// Check if someone crossed the bar:
for (uint cnt = 0; cnt <= proposal.numOfChoices; cnt++) {
if (proposal.votes[cnt] > totalReputation*precReq/100) {
Proposal memory tmpProposal = proposal;
deleteProposal(_proposalId);
emit ExecuteProposal(_proposalId, tmpProposal.avatar, cnt, totalReputation);
(tmpProposal.executable).execute(_proposalId, tmpProposal.avatar, int(cnt));
return true;
}
}
return false;
}

/**
* @dev Vote for a proposal, if the voter already voted, cancel the last vote and set a new one instead
* @param _proposalId id of the proposal
Expand Down Expand Up @@ -336,6 +346,6 @@ contract AbsoluteVote is IntVoteInterface {
emit VoteProposal(_proposalId, proposal.avatar, _voter, _vote, reputation);
emit AVVoteProposal(_proposalId, (_voter != msg.sender));
// execute the proposal if this vote was decisive:
return execute(_proposalId);
return _execute(_proposalId);
}
}
12 changes: 6 additions & 6 deletions contracts/VotingMachines/IntVoteInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ interface IntVoteInterface {
) external returns(bytes32);

// Only owned proposals and only the owner:
function cancelProposal(bytes32 _proposalId) external onlyProposalOwner(_proposalId) votable(_proposalId) returns(bool);
function cancelProposal(bytes32 _proposalId) external returns(bool);

// Only owned proposals and only the owner:
function ownerVote(bytes32 _proposalId, uint _vote, address _voter) external onlyProposalOwner(_proposalId) returns(bool);
function ownerVote(bytes32 _proposalId, uint _vote, address _voter) external returns(bool);

function vote(bytes32 _proposalId, uint _vote) external votable(_proposalId) returns(bool);
function vote(bytes32 _proposalId, uint _vote) external returns(bool);

function voteWithSpecifiedAmounts(
bytes32 _proposalId,
uint _vote,
uint _rep,
uint _token) external votable(_proposalId) returns(bool);
uint _token) external returns(bool);

function cancelVote(bytes32 _proposalId) external votable(_proposalId);
function cancelVote(bytes32 _proposalId) external;

//@dev execute check if the proposal has been decided, and if so, execute the proposal
//@param _proposalId the id of the proposal
//@return bool true - the proposal has been executed
// false - otherwise.
function execute(bytes32 _proposalId) public votable(_proposalId) returns(bool);
function execute(bytes32 _proposalId) external returns(bool);

function getNumberOfChoices(bytes32 _proposalId) external view returns(uint);

Expand Down
15 changes: 11 additions & 4 deletions contracts/VotingMachines/QuorumVote.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
pragma solidity ^0.4.24;

import "../controller/Reputation.sol";
import "./IntVoteInterface.sol";
import "./AbsoluteVote.sol";


contract QuorumVote is IntVoteInterface, AbsoluteVote {
contract QuorumVote is AbsoluteVote {

/**
* @dev check if the proposal has been decided, and if so, execute the proposal
* @param _proposalId the id of the proposal
*/
function execute(bytes32 _proposalId) external votable(_proposalId) returns(bool) {
return _execute(_proposalId);
}

/**
* @dev check if the proposal has been decided, and if so, execute the proposal
* @param _proposalId the id of the proposal
*/
function execute(bytes32 _proposalId) public votable(_proposalId) returns(bool) {
function _execute(bytes32 _proposalId) internal votable(_proposalId) returns(bool) {
Proposal storage proposal = proposals[_proposalId];

uint totalReputation = parameters[proposal.paramsHash].reputationSystem.totalSupply();
Expand Down

0 comments on commit af24c3a

Please sign in to comment.