Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. pragma solidity ^0.4.10;
  2.  
  3.  
  4. contract splitsender{
  5. address[] public Targets; // will hold array of targets
  6. uint public TargetsLength; // will hold how big the array is
  7. bool SendLock; // Used to prevent SendSplit from calling itself.
  8.  
  9. function splitsender(){ // constructor. Runs when contract is created
  10. TargetsLength=0; // start the length out at 0 explicitely
  11. SendLock=false;// start it as false.
  12. }
  13.  
  14. function AddTarget(address Target) external{ // used to add a new target
  15. Targets[TargetsLength] = Target; // add it to the array
  16. TargetsLength +=1; // increment the length
  17. }
  18.  
  19. function RemoveTarget(uint TargetPosition) external{ // call it to remove a target from the array
  20. Targets[TargetPosition] = Targets[TargetsLength]; // Replace the removed element with the last element in the array
  21. TargetsLength -= 1;// decrement the length
  22. }
  23.  
  24. function SendSplit() payable external {
  25. if(SendLock){
  26. throw; // if its locked, refuse to run
  27. }
  28. SendLock = true;// lock this function
  29. if(TargetsLength==0){
  30. throw; // To prevent a divide by 0 error
  31. }
  32. uint AmountEach = msg.value/TargetsLength;
  33. for(uint i = 0; i < TargetsLength; i++){// goes over each element in the array
  34. Targets[i].transfer(AmountEach);
  35. }
  36. SendLock = false; // we're done so we unlock
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement