Last active
April 13, 2016 07:53
-
-
Save RCasatta/e19ef6fbe11594a5ad600fd58eb441f0 to your computer and use it in GitHub Desktop.
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
contract MyContract { | |
/* Constructor */ | |
function MyContract() { | |
} | |
bool public dividendDistribution; // if true dividend distribution is happening | |
uint public last; // if a dividend operation was happening but did not finish it stores the next index to iterate | |
uint public dividendBalance; // balance to share for dividends | |
function dividend() { | |
uint start; | |
if(!dividendDistribution) { | |
dividendDistribution = true; | |
dividendBalance = this.balance; | |
start = 0; | |
} else { | |
start = last; | |
} | |
for(var i=start ; i< 1000;i++) { | |
if(msg.gas<300000) { // if I am running out of gas, I am saving status and exiting | |
last = i; | |
return; | |
} | |
address(i+1000).send(dividendBalance/1000); | |
} | |
dividendBalance = 0; | |
dividendDistribution=false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment