Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement