Created
April 12, 2022 22:18
-
-
Save CJ42/bd20f58afb81dc1ce257d8f414e98a1d to your computer and use it in GitHub Desktop.
Bad example of loops in storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
/// THIS IS STILL A NEGATIVE EXAMPLE! DO NOT USE! | |
contract Voting { | |
mapping(address => uint) voteWeight; | |
address[] yesVotes; | |
uint requiredWeight; | |
address beneficiary; | |
uint amount; | |
function voteYes() { | |
yesVotes.push(msg.sender); | |
} | |
function tallyVotes() { | |
uint yesVotes; | |
for (uint i = 0; i < yesVotes.length; ++i) | |
yesVotes += voteWeight[yesVotes[i]]; | |
if (yesVotes > requiredWeight) | |
beneficiary.send(amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment