HasNoEther.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. pragma solidity ^0.4.11;
  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() payable {
  22. if(msg.value > 0) {
  23. throw;
  24. }
  25. }
  26. /**
  27. * @dev Disallows direct send by settings a default function without the `payable` flag.
  28. */
  29. function() external {
  30. }
  31. /**
  32. * @dev Transfer all Ether held by the contract to the owner.
  33. */
  34. function reclaimEther() external onlyOwner {
  35. if(!owner.send(this.balance)) {
  36. throw;
  37. }
  38. }
  39. }