// SPDX-License-Identifier: MIT pragma solidity 0.8.16; /// @dev The ETH transfer has failed. error ETHTransferFailed(); /// @dev Sends `amount` (in wei) ETH to `to`. /// Reverts upon failure. function safeTransferETH(address to, uint256 amount) { assembly { // Transfer the ETH and check if it succeeded or not. if iszero(call(gas(), to, amount, 0, 0, 0, 0)) { // Store the function selector of `ETHTransferFailed()`. mstore(0x00, 0xb12d13eb) // Revert with (offset, size). revert(0x1c, 0x04) } } } contract Escrow { address public owner; address public claimer; error OnlyOwner(); error OnlyClaimer(); event Claimed(uint256 balance); event ClaimerChanged(address oldClaimer, address newClaimer); event Received(uint256 amount); constructor(address _owner, address _claimer) payable { owner = _owner; claimer = _claimer; } function claim(address recipient) public payable returns (bool) { if (msg.sender != claimer) revert OnlyClaimer(); emit Claimed(address(this).balance); return safeTransferETH(recipient, address(this).balance); } function setClaimer(address _claimer) public payable { if (msg.sender != owner) revert OnlyOwner(); claimer = _claimer; } receive() external payable { emit Received(msg.value); } }