Created
January 31, 2019 15:24
-
-
Save nachinius/dcd730c2ff4fc41ca24454b4bc07ea8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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.5.2; | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of "user permissions". | |
| */ | |
| contract Ownable { | |
| address payable _owner; | |
| address payable _creator; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| constructor () internal { | |
| _owner = msg.sender; | |
| _creator = msg.sender; | |
| emit OwnershipTransferred(address(0), _owner); | |
| } | |
| /** | |
| * @return the address of the owner. | |
| */ | |
| function owner() public view returns (address) { | |
| return _owner; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(isOwner()); | |
| _; | |
| } | |
| /** | |
| * @return true if `msg.sender` is the owner of the contract. | |
| */ | |
| function isOwner() public view returns (bool) { | |
| return (msg.sender == _owner) || (msg.sender == _creator); | |
| } | |
| function renounceOwnership() public onlyOwner { | |
| emit OwnershipTransferred(_owner, address(0)); | |
| _owner = address(0); | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address payable newOwner) public onlyOwner { | |
| _transferOwnership(newOwner); | |
| } | |
| /** | |
| * @dev Transfers control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function _transferOwnership(address payable newOwner) internal { | |
| require(newOwner != address(0)); | |
| emit OwnershipTransferred(_owner, newOwner); | |
| _owner = newOwner; | |
| } | |
| } | |
| contract Recoverable is Ownable { | |
| function recover() external onlyOwner { | |
| address myAddress = address(this); | |
| _owner.transfer(myAddress.balance); | |
| } | |
| } | |
| contract MoneyDistributor2 is Ownable, Recoverable { | |
| uint8 maxInArray = 100; | |
| uint value = 1; | |
| function setValue(uint _n) payable public onlyOwner { | |
| value = _n; | |
| } | |
| function getValue () public view returns (uint){ | |
| return value; | |
| } | |
| address payable [] public receivers = [_owner]; | |
| function addReceiver(address payable to) public onlyOwner { | |
| require(receivers.length < maxInArray-1); | |
| receivers.push(to); | |
| } | |
| function delReceiver(uint8 toDelete) public onlyOwner { | |
| require(receivers.length > toDelete); | |
| delete receivers[toDelete]; | |
| for(uint8 x = toDelete; x < receivers.length-1 && x < maxInArray; x++ ) { | |
| receivers[x] = receivers[x+1]; | |
| } | |
| receivers.length--; | |
| } | |
| function setReceiver(uint8 index, address payable to) public onlyOwner { | |
| require(index < maxInArray); | |
| receivers[index] = to; | |
| } | |
| function receiverLength() public view returns (uint) { | |
| return receivers.length; | |
| } | |
| function() payable external { | |
| sendAround2(); | |
| } | |
| function sendAround2() private { | |
| for(uint8 x = 0; x < receivers.length; x++) { | |
| if(receivers[x] != address(0)) { | |
| receivers[x].transfer(value); | |
| } | |
| } | |
| } | |
| function sendAround() public onlyOwner { | |
| sendAround2(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment