Created
April 28, 2017 17:13
-
-
Save kingcocomango/2275ce43ee6c80589ce244ee297a609c 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
pragma solidity ^0.4.10; | |
contract splitsender{ | |
address[] public Targets; // will hold array of targets | |
uint public TargetsLength; // will hold how big the array is | |
bool SendLock; // Used to prevent SendSplit from calling itself. | |
function splitsender(){ // constructor. Runs when contract is created | |
TargetsLength=0; // start the length out at 0 explicitely | |
SendLock=false;// start it as false. | |
} | |
function AddTarget(address Target) external{ // used to add a new target | |
Targets[TargetsLength] = Target; // add it to the array | |
TargetsLength +=1; // increment the length | |
} | |
function RemoveTarget(uint TargetPosition) external{ // call it to remove a target from the array | |
Targets[TargetPosition] = Targets[TargetsLength]; // Replace the removed element with the last element in the array | |
TargetsLength -= 1;// decrement the length | |
} | |
function SendSplit() payable external { | |
if(SendLock){ | |
throw; // if its locked, refuse to run | |
} | |
SendLock = true;// lock this function | |
if(TargetsLength==0){ | |
throw; // To prevent a divide by 0 error | |
} | |
uint AmountEach = msg.value/TargetsLength; | |
for(uint i = 0; i < TargetsLength; i++){// goes over each element in the array | |
Targets[i].transfer(AmountEach); | |
} | |
SendLock = false; // we're done so we unlock | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment