Skip to content

Commit

Permalink
finish TokenizedBallot contract
Browse files Browse the repository at this point in the history
  • Loading branch information
trliner committed Aug 23, 2024
1 parent f9f2186 commit 0b8eb8c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions contracts/TokenizedBallot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract TokenizedBallot {
IMyToken public tokenContract;
Proposal[] public proposals;
uint256 public targetBlockNumber;
mapping (address => uint256) public spentVotePower;

constructor(
bytes32[] memory _proposalNames,
Expand All @@ -22,21 +23,28 @@ contract TokenizedBallot {
) {
tokenContract = IMyToken(_tokenContract);
targetBlockNumber = _targetBlockNumber;
// TODO: Validate if targetBlockNumber is in the past
require(
targetBlockNumber <= block.number,
"TokenizedBallot: targetBlockNumber must be in the past"
);
for (uint i = 0; i < _proposalNames.length; i++) {
proposals.push(Proposal({name: _proposalNames[i], voteCount: 0}));
}
}

function vote(uint256 proposal, uint256 amount) external {
// TODO: Implement vote function
uint256 senderVotingPower = getVotePower(msg.sender);
require(
senderVotingPower >= amount,
"TokenizedBallot: insufficient voting power"
);
spentVotePower[msg.sender] += amount;
proposals[proposal].voteCount += amount;
}

// function getVotePower(address voter ) public view returns (uint voterPower_) {
// votePower_ = 0;

// }
function getVotePower(address voter ) public view returns (uint voterPower_) {
voterPower_ = tokenContract.getPastVotes(voter, targetBlockNumber) - spentVotePower[voter];
}

function winningProposal() public view returns (uint winningProposal_) {
uint winningVoteCount = 0;
Expand Down

0 comments on commit 0b8eb8c

Please sign in to comment.