Hi @0xBrito,
Your code meets the assignment objectives. Your inheritance structure is well coded, but we can make it more streamlined by having Bank explicitly inherit Destroyable only, because it will inherit Ownable implicitly via Destroyable. This will give you a multi-level inheritance structure.
Some additional comments …
(1) In your destroy() function, a concise alternative to using the additional receiver
variable is to just call selfdestruct() with msg.sender
directly…
selfdestruct(msg.sender);
You are using Solidity v0.7.5, and prior to v0.8 msg.sender
is already a payable address by default, and so doesn’t need to be explicitly converted whenever the syntax requires it to reference a payable address e.g. as the payable address argument in the selfdestruct() function call, or as the payable address the transfer
method is called on. However, from Solidity v.0.8 msg.sender
is non-payable by default, which would mean having to explicity convert msg.sender
to a payable address when necessary e.g.
selfdestruct(payable(msg.sender));
Have a look at this post for further details about the use of the additional local variable receiver
in the model solution.
(2) You’ve modified the withdraw function with the onlyOwner modifier, but this means that only the contract owner will be able to withdraw funds while the Bank contract is deployed and operating normally. The contract allows multiple addresses to deposit funds (we are simulating a bank with bank account holders) and so, while the contract is still deployed, it only seems fair that all users should be able to withdraw their funds as well, don’t you think? Your withdraw() function header didn’t include the onlyOwner modifier before. I think during the course we were adding and removing onlyOwner from various functions to demonstrate different scenarios, and I think it might have ended up being left in the withdraw() function in the solution code for this assignment by mistake!
Don’t forget to post your solution to the Events Assignment here, and your answers to the Inheritance Reading Assignment here. The Events Assignment is from the Events video lecture, which is near the end of the Additional Solidity Concepts section of the course. I think you may have missed it out because you are missing a Transfer event in your code, and a corresponding emit statement in the transfer() function. The Inheritance Reading Assignment is at the beginning of the Inheritance & External Contracts section of the course, and in the article you will learn, amongst other things, about the multi-level inheritance structure I’ve mentioned above, as well as other types of inheritance structures.
Let me know if you have any questions.