Commit d3487207 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #832 from holgerd77/fix-example-contract

Example Contract - Fix compiler warnings / reduce static analysis warning
parents ec522a1e 82cdfd45
...@@ -18,21 +18,21 @@ contract Ballot { ...@@ -18,21 +18,21 @@ contract Ballot {
Proposal[] proposals; Proposal[] proposals;
/// Create a new ballot with $(_numProposals) different proposals. /// Create a new ballot with $(_numProposals) different proposals.
function Ballot(uint8 _numProposals) { function Ballot(uint8 _numProposals) public {
chairperson = msg.sender; chairperson = msg.sender;
voters[chairperson].weight = 1; voters[chairperson].weight = 1;
proposals.length = _numProposals; proposals.length = _numProposals;
} }
/// Give $(voter) the right to vote on this ballot. /// Give $(toVoter) the right to vote on this ballot.
/// May only be called by $(chairperson). /// May only be called by $(chairperson).
function giveRightToVote(address voter) { function giveRightToVote(address toVoter) public {
if (msg.sender != chairperson || voters[voter].voted) return; if (msg.sender != chairperson || voters[toVoter].voted) return;
voters[voter].weight = 1; voters[toVoter].weight = 1;
} }
/// Delegate your vote to the voter $(to). /// Delegate your vote to the voter $(to).
function delegate(address to) { function delegate(address to) public {
Voter storage sender = voters[msg.sender]; // assigns reference Voter storage sender = voters[msg.sender]; // assigns reference
if (sender.voted) return; if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
...@@ -47,21 +47,21 @@ contract Ballot { ...@@ -47,21 +47,21 @@ contract Ballot {
delegateTo.weight += sender.weight; delegateTo.weight += sender.weight;
} }
/// Give a single vote to proposal $(proposal). /// Give a single vote to proposal $(toProposal).
function vote(uint8 proposal) { function vote(uint8 toProposal) public {
Voter storage sender = voters[msg.sender]; Voter storage sender = voters[msg.sender];
if (sender.voted || proposal >= proposals.length) return; if (sender.voted || toProposal >= proposals.length) return;
sender.voted = true; sender.voted = true;
sender.vote = proposal; sender.vote = toProposal;
proposals[proposal].voteCount += sender.weight; proposals[toProposal].voteCount += sender.weight;
} }
function winningProposal() constant returns (uint8 _winningProposal) { function winningProposal() public constant returns (uint8 _winningProposal) {
uint256 winningVoteCount = 0; uint256 winningVoteCount = 0;
for (uint8 proposal = 0; proposal < proposals.length; proposal++) for (uint8 prop = 0; prop < proposals.length; prop++)
if (proposals[proposal].voteCount > winningVoteCount) { if (proposals[prop].voteCount > winningVoteCount) {
winningVoteCount = proposals[proposal].voteCount; winningVoteCount = proposals[prop].voteCount;
_winningProposal = proposal; _winningProposal = prop;
} }
} }
}` }`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment