Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to get number of tokens for losing option #44

Open
nickreynolds opened this issue May 14, 2018 · 0 comments
Open

Add functions to get number of tokens for losing option #44

nickreynolds opened this issue May 14, 2018 · 0 comments

Comments

@nickreynolds
Copy link

It is possible to imagine that some use cases of PLCRVoting need access to the number of tokens associated with the losing option. For example, a TCR implementation may have an entity that is able to overturn the result of a challenge (we do this at Civil in our TCR implementation: https://github.com/joincivil/Civil/blob/master/packages/contracts/contracts/tcr/CivilTCR.sol). In order to properly dispense tokens to voters, the TCR contract needs access to both the total number of tokens associated with the losing option, and the number of tokens for a voter of the losing option.

I propose to add the following two functions:

function getNumLosingTokens(address _voter, uint _pollID, uint _salt) public constant returns (uint correctVotes) {
    require(pollEnded(_pollID));
    require(pollMap[_pollID].didReveal[_voter]);

    uint losingChoice = isPassed(_pollID) ? 0 : 1;
    bytes32 loserHash = keccak256(losingChoice, _salt);
    bytes32 commitHash = getCommitHash(_voter, _pollID);

    require(loserHash == commitHash);

    return getNumTokens(_voter, _pollID);
  }

and

function getTotalNumberOfTokensForLosingOption(uint _pollID) constant public returns (uint numTokens) {
    require(pollEnded(_pollID));

    if (isPassed(_pollID))
      return pollMap[_pollID].votesAgainst;
    else
      return pollMap[_pollID].votesFor;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant