-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEscrow.sol
46 lines (34 loc) · 1.29 KB
/
Escrow.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Escrow {
address public arbiter;
address public beneficiary;
uint public withdrawalDeadline;
bool public isCancelled;
mapping(uint => bool) public withdrawalRequests;
constructor(address _arbiter, address _beneficiary) payable {
arbiter = _arbiter;
beneficiary = _beneficiary;
withdrawalDeadline = block.timestamp + 6 weeks;
}
function cancel() external {
if(block.timestamp >= withdrawalDeadline) {
isCancelled = true;
}
}
function withdraw(uint amount) external {
require(msg.sender == beneficiary, "Only beneficiary");
require(!isCancelled, "Contract cancelled");
require(withdrawalRequests[amount] == false, "Already withddrawal");
(bool sent,) = beneficiary.call{value: amount}("");
require(sent, "Failed to send Ether");
withdrawalRequests[amount] = true;
}
function approve() external {
require(msg.sender == arbiter, "Only arbiter");
require(!isCancelled, "Contract cancelled");
uint balance = address(this).balance;
(bool sent,) = beneficiary.call{value: balance}("");
require(sent, "Failed to send Ether");
}
}