Skip to content
This repository was archived by the owner on May 1, 2026. It is now read-only.
This repository was archived by the owner on May 1, 2026. It is now read-only.

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

@nickreynolds

Description

@nickreynolds

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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions