Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // solhint-disable-next-line
  2. pragma solidity ^0.4.4;
  3.  
  4. import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
  5. import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
  6.  
  7.  
  8. contract RevenueSplit is Ownable {
  9.  
  10.     address[] public beneficiaries;
  11.  
  12.     // solhint-disable-next-line no-empty-blocks
  13.     function () public payable {}
  14.  
  15.     /**
  16.      * Withdraw tokens to beneficiaries
  17.      * @param _token Address of the Token to withdraw
  18.      */
  19.     function withdrawToken(address _token) external { //anyone can call, funds go to beneficiaries anyway
  20.         uint256 totalTokens = ERC20(_token).balanceOf(this);
  21.  
  22.         for (uint256 i = 0; i < beneficiaries.length; i++) {
  23.             // solhint-disable-next-line max-line-length
  24.             ERC20(_token).transfer(beneficiaries[i], totalTokens / beneficiaries.length); //splits equal portion to every beneficiary
  25.         }
  26.     }
  27.  
  28.     /**
  29.      * Withdraw Ether to beneficiaries
  30.      */
  31.     function withdrawEther() external { //anyone can call, ether goes to beneficiaries
  32.         uint256 totalEther = address(this).balance;
  33.  
  34.         for (uint256 i = 0; i < beneficiaries.length; i++) {
  35.             beneficiaries[i].transfer(totalEther / beneficiaries.length); //splits equal portion to every beneficiary
  36.         }
  37.     }
  38.  
  39.     /**
  40.      * Add a beneficiary. Can only be called by the owner
  41.      * @param _newBeneficiary Beneficiary to add
  42.      */
  43.     function addBeneficiary(address _newBeneficiary) external onlyOwner {
  44.         beneficiaries.push(_newBeneficiary);
  45.     }
  46.  
  47.     /**
  48.      * Remove a beneficiary. Can only be called by the owner
  49.      * @param _index Index of the beneficiary to remove
  50.      */
  51.     function removeBeneficiary(uint256 _index) external onlyOwner {
  52.         if (_index != beneficiaries.length - 1) {//only replace last if index is smaller than last
  53.             beneficiaries[_index] = beneficiaries[beneficiaries.length - 1];
  54.         }
  55.         beneficiaries.length = beneficiaries.length-1;
  56.     }
  57.  
  58.     /**
  59.      * Get the beneficiaries
  60.      * @return An array of the beneficiaries
  61.      */
  62.     function getBeneficiaries() public view returns(address[]) {
  63.         return beneficiaries;
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement