Skip to content

Commit

Permalink
OZ Contract added
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Sep 24, 2024
1 parent a8b76e6 commit 7184ee9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions reports/report.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions reports/report.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions tests/contract-playground/src/ContractLocksEther.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,39 @@ contract CanWithdrawChild is CanWithdrawParent {
emit Deposited(msg.sender, msg.value);
}
}

import "../lib/openzeppelin-contracts/contracts/utils/Address.sol";

// GOOD
contract CanWithdrawOZ {
using Address for address payable;

// Event to log deposits
event Deposited(address indexed sender, uint256 indexed amount);

// Event to log transfers
event Transferred(address indexed to, uint256 indexed amount);

// Public payable function to receive Ether
receive() external payable {
emit Deposited(msg.sender, msg.value);
}

// Public payable fallback function to handle any data sent with Ether
fallback() external payable {
emit Deposited(msg.sender, msg.value);
}

// Internal function to send Ether to a given address
function _sendEther(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Insufficient balance");
require(recipient != address(0), "Invalid recipient");
recipient.sendValue(amount);
emit Transferred(recipient, amount);
}

// This function allows for the withdrawal of eth. Hence this contract is a GOOD contract.
function takeEthBack(uint256 amount) external {
_sendEther(payable(msg.sender), amount);
}
}

0 comments on commit 7184ee9

Please sign in to comment.