mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix name shadowing in ballot example contract.
This commit is contained in:
parent
b62d43912b
commit
098033c94a
@ -94,7 +94,11 @@ of votes.
|
|||||||
// called incorrectly. But watch out, this
|
// called incorrectly. But watch out, this
|
||||||
// will currently also consume all provided gas
|
// will currently also consume all provided gas
|
||||||
// (this is planned to change in the future).
|
// (this is planned to change in the future).
|
||||||
require((msg.sender == chairperson) && !voters[voter].voted && (voters[voter].weight == 0));
|
require(
|
||||||
|
(msg.sender == chairperson) &&
|
||||||
|
!voters[voter].voted &&
|
||||||
|
(voters[voter].weight == 0)
|
||||||
|
);
|
||||||
voters[voter].weight = 1;
|
voters[voter].weight = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,15 +130,15 @@ of votes.
|
|||||||
// modifies `voters[msg.sender].voted`
|
// modifies `voters[msg.sender].voted`
|
||||||
sender.voted = true;
|
sender.voted = true;
|
||||||
sender.delegate = to;
|
sender.delegate = to;
|
||||||
Voter storage delegate = voters[to];
|
Voter storage delegate_ = voters[to];
|
||||||
if (delegate.voted) {
|
if (delegate_.voted) {
|
||||||
// If the delegate already voted,
|
// If the delegate already voted,
|
||||||
// directly add to the number of votes
|
// directly add to the number of votes
|
||||||
proposals[delegate.vote].voteCount += sender.weight;
|
proposals[delegate_.vote].voteCount += sender.weight;
|
||||||
} else {
|
} else {
|
||||||
// If the delegate did not vote yet,
|
// If the delegate did not vote yet,
|
||||||
// add to her weight.
|
// add to her weight.
|
||||||
delegate.weight += sender.weight;
|
delegate_.weight += sender.weight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,13 +159,13 @@ of votes.
|
|||||||
/// @dev Computes the winning proposal taking all
|
/// @dev Computes the winning proposal taking all
|
||||||
/// previous votes into account.
|
/// previous votes into account.
|
||||||
function winningProposal() public view
|
function winningProposal() public view
|
||||||
returns (uint winningProposal)
|
returns (uint winningProposal_)
|
||||||
{
|
{
|
||||||
uint winningVoteCount = 0;
|
uint winningVoteCount = 0;
|
||||||
for (uint p = 0; p < proposals.length; p++) {
|
for (uint p = 0; p < proposals.length; p++) {
|
||||||
if (proposals[p].voteCount > winningVoteCount) {
|
if (proposals[p].voteCount > winningVoteCount) {
|
||||||
winningVoteCount = proposals[p].voteCount;
|
winningVoteCount = proposals[p].voteCount;
|
||||||
winningProposal = p;
|
winningProposal_ = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,12 +174,13 @@ of votes.
|
|||||||
// of the winner contained in the proposals array and then
|
// of the winner contained in the proposals array and then
|
||||||
// returns the name of the winner
|
// returns the name of the winner
|
||||||
function winnerName() public view
|
function winnerName() public view
|
||||||
returns (bytes32 winnerName)
|
returns (bytes32 winnerName_)
|
||||||
{
|
{
|
||||||
winnerName = proposals[winningProposal()].name;
|
winnerName_ = proposals[winningProposal()].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Possible Improvements
|
Possible Improvements
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user