From 0e02b3adcec7773b2af557dee5cbf61bbba67487 Mon Sep 17 00:00:00 2001 From: destinyae <109734765+destinyae@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:50:53 +0100 Subject: [PATCH] Update Lock.sol You may consider adding access control modifiers to the withdraw function to restrict who can call it. Additionally, you can consider adding event logging for all state changes to make the contract more transparent. Finally, you might want to add error handling to the contract to provide better feedback to users when transactions fail. committed changes: 1. Access control modifier. 2. Event logging for state changes 3. Error handling for transactions Do you mind? --- contracts/Lock.sol | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/contracts/Lock.sol b/contracts/Lock.sol index 37b0e7a..c9308ca 100644 --- a/contracts/Lock.sol +++ b/contracts/Lock.sol @@ -25,4 +25,22 @@ contract Lock { owner.transfer(address(this).balance); } + + modifier onlyOwner { + require(msg.sender == owner, "You are not the owner"); + _; +} + +event LockUpdated(uint newUnlockTime, address indexed updatedBy); +} + +function withdraw() public { + require(block.timestamp >= unlockTime, "You can't withdraw yet"); + require(msg.sender == owner, "You aren't the owner"); + + emit Withdrawal(address(this).balance, block.timestamp); + + (bool success, ) = owner.call{value: address(this).balance}(""); + require(success, "Transfer failed"); +} }