selfdestructs(owner)
refunds Eth to owner
. However, it does not transfer any tokens the contract may own. These would get permanently lost.
Would something like the following work? Is there a better approach?
contract Owned {
address owner;
function Owned() {
owner = msg.sender;
}
modifier owner_only() {
if (msg.sender == owner) {
_;
}
}
function terminate(address tokens[]) owner_only {
// Transfer tokens to owner (TODO: error handling)
for(uint i = 0; i < tokens.length; i++)) {
address addr = tokens[i];
ERC20Token token = ERC20Token(addr);
uint256 balance = token.balanceOf(this);
token.transfer(owner, balance);
}
// Transfer Eth to owner and terminate contract
selfdestruct(owner);
}
}