I really enjoy this assignments. Great blog post followed by a good challenge. Hereās my answer:
pragma solidity 0.7.5;
import "./Ownable.sol";
contract Destroyable is Ownable {
function close() public onlyOwner {
selfdestruct(owner);
}
}
The only real roadblock I hit was trying to determine how to make owner
payable in the Ownable.sol
contract. Just a syntax thing, really. Once I got address payable public owner;
figured out then BAM got a nice little self destruct contract.
Cheers yāall!
Edit: Hereās the Ownable.sol
code, 'cause why not.
pragma solidity 0.7.5;
contract Ownable {
address payable public owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
constructor() {
owner = msg.sender;
}
}
@dan-i ā quick question about encapsulation:
I noticed that most other folks are making their owner
variable private
or internal
(as Filip did) in the Ownable.sol
parent contract. Is there an advantage to keeping the scope smaller, or is public
an okay option? I had initially assumed that public
was required for the child contract to access it, but clearly thatās not the case.