Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Changed the Zeppelin Destroy functionality fundamentally, to limit lo…
…st ETH sent to 'old' contracts.

In practice any public Ethereum address is a target to receiving ETH.
Often ETH will find its way to a Contract via send (not via a function call), even though the contract was not meant to receive ETH. For this reason all contracts should have a withdrawEther function, even after a contract is meant to retire. For this reason no contract should really ever selfdestruct, instead always only having the withdrawEther function active and disabling all other functions.
  • Loading branch information
Riaan F Venter committed May 4, 2017
commit 1b0f2adc37e585c2afc82f1ff638f66c8974f12f
33 changes: 27 additions & 6 deletions contracts/lifecycle/Destructible.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@ pragma solidity ^0.4.8;

import "../ownership/Ownable.sol";

/*
In practice any public Ethereum address is a target to receiving ETH.
Often ETH will find its way to a Contract via send (not via a function call), even though the contract was not meant to receive ETH. For this reason all contracts should have a withdrawEther function, even after a contract is meant to retire. For this reason no contract should really ever selfdestruct, instead always only having the withdrawEther function active and disabling all other functions.
*/

/*
* Destructible
* Base contract that can be destroyed by owner. All funds in contract will be sent to the owner.
*/
contract Destructible is Ownable {
function destroy() onlyOwner {
selfdestruct(owner);

bool contractActive = true;

/// @notice Set this contract as inactive but do not destroy, withdrawEther
function destroy() onlyOwner destroyable {
contractActive = false;
withdrawEther();
}

/// @notice Withdraw all Ether in this contract
/// @return True if successful
function withdrawEther() payable onlyOwner returns (bool) {
return owner.send(this.balance);
}

/// @notice ALl functions with this modifier will become inaccessible after a call to destroy
modifier destroyable() {
if (!contractActive) {
throw;
}
_;
}
}


3 changes: 2 additions & 1 deletion ethpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "1.0.4",
"description": "Secure Smart Contract library for Solidity",
"authors": [
"Manuel Araoz <[email protected]>"
"Manuel Araoz <[email protected]>",
"Riaan F Venter <[email protected]>"
],
"keywords": [
"solidity",
Expand Down