Skip to content

Instantly share code, notes, and snippets.

@RCasatta
Last active April 13, 2016 07:53
Show Gist options
  • Save RCasatta/e19ef6fbe11594a5ad600fd58eb441f0 to your computer and use it in GitHub Desktop.
Save RCasatta/e19ef6fbe11594a5ad600fd58eb441f0 to your computer and use it in GitHub Desktop.
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