Hi @Stefan_Guse,
@gabba
Just to add… (I’ve also been following this discussion about your particular assignment solution)…
Not necessarily. Your idea to add flexibility, so that someone other than the contract owner can be allowed to destroy the contract, is a good one. This could be a client for whom the contract has been written and deployed, for example.
I think the point here is that this flexibility is fine, as long as it’s only the owner address which is authorised to assign “destruction capability” to a different address. And this is where the setter (restricted to the owner) would be the best solution. And this can be done using the multi-level inheritance: Ownable inherited by Destroyable inherited by HelloWorld. For example:
/* I've tried to keep as much of your original code (variable names,
syntax... etc.) as possible, so that it's easier to see how I've
modified your solution, rather than just rebuilt the whole thing. */
// contract Destroyable
import "./Ownable.sol";
pragma solidity 0.5.12;
contract Destroyable is Ownable {
address private destructor;
function createDestructor(address _destructor) public onlyOwner {
destructor = _destructor;
}
function destroy() public {
require(msg.sender == destructor, 'You cannot do that');
address payable beneficiary = address(uint160(destructor));
selfdestruct(beneficiary);
}
}
// contract HelloWorld
import "./Destroyable.sol";
pragma solidity 0.5.12;
contract HelloWorld is Destroyable {...}
By all means, let’s continue to discuss this, as I think you’ve raised some interesting points that are worth thinking about and exploring further 