HasNoEther.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. pragma solidity ^0.4.21;
  2. import "./Ownable.sol";
  3. /**
  4. * @title Contracts that should not own Ether
  5. * @author Remco Bloemen <remco@2π.com>
  6. * @dev This tries to block incoming ether to prevent accidental loss of Ether. Should Ether end up
  7. * in the contract, it will allow the owner to reclaim this ether.
  8. * @notice Ether can still be send to this contract by:
  9. * calling functions labeled `payable`
  10. * `selfdestruct(contract_address)`
  11. * mining directly to the contract address
  12. */
  13. contract HasNoEther is Ownable {
  14. /**
  15. * @dev Constructor that rejects incoming Ether
  16. * @dev The `payable` flag is added so we can access `msg.value` without compiler warning. If we
  17. * leave out payable, then Solidity will allow inheriting contracts to implement a payable
  18. * constructor. By doing it this way we prevent a payable constructor from working. Alternatively
  19. * we could use assembly to access msg.value.
  20. */
  21. function HasNoEther() public payable {
  22. require(msg.value == 0);
  23. }
  24. /**
  25. * @dev Disallows direct send by settings a default function without the `payable` flag.
  26. */
  27. function() external {
  28. }
  29. /**
  30. * @dev Transfer all Ether held by the contract to the owner.
  31. */
  32. function reclaimEther() external onlyOwner {
  33. // solium-disable-next-line security/no-send
  34. assert(owner.send(address(this).balance));
  35. }
  36. }