solidity/test/compilationTests/zeppelin/ownership/HasNoEther.sol

45 lines
1.3 KiB
Solidity
Raw Normal View History

2017-07-05 10:28:15 +00:00
pragma solidity ^0.4.11;
import "./Ownable.sol";
/**
2017-07-05 10:28:15 +00:00
* @title Contracts that should not own Ether
* @author Remco Bloemen <remco@2π.com>
* @dev This tries to block incoming ether to prevent accidental loss of Ether. Should Ether end up
* in the contract, it will allow the owner to reclaim this ether.
* @notice Ether can still be send to this contract by:
* calling functions labeled `payable`
* `selfdestruct(contract_address)`
* mining directly to the contract address
*/
contract HasNoEther is Ownable {
/**
* @dev Constructor that rejects incoming Ether
* @dev The `payable` flag is added so we can access `msg.value` without compiler warning. If we
* leave out payable, then Solidity will allow inheriting contracts to implement a payable
* constructor. By doing it this way we prevent a payable constructor from working. Alternatively
2017-07-05 10:28:15 +00:00
* we could use assembly to access msg.value.
*/
2018-07-04 17:20:51 +00:00
constructor() public payable {
2017-07-05 10:28:15 +00:00
if(msg.value > 0) {
revert();
2017-07-05 10:28:15 +00:00
}
}
/**
* @dev Disallows direct send by settings a default function without the `payable` flag.
*/
function() external {
}
/**
* @dev Transfer all Ether held by the contract to the owner.
*/
function reclaimEther() external onlyOwner {
2018-07-05 12:32:32 +00:00
if(!owner.send(address(this).balance)) {
revert();
2017-07-05 10:28:15 +00:00
}
}
}