-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscrow.sol
40 lines (34 loc) · 1.26 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Escrow {
address public depositor;
address public beneficiary;
address public arbiter;
bool public isApproved;
uint256 public deadline;
constructor(address _beneficiary, address _arbiter, uint256 _deadline) payable {
depositor = msg.sender;
beneficiary = _beneficiary;
arbiter = _arbiter;
deadline = block.timestamp + _deadline;
}
function approve() public {
require(msg.sender == arbiter, "Only arbiter can approve");
isApproved = true;
payable(beneficiary).transfer(address(this).balance);
}
function refund() public {
require(msg.sender == arbiter, "Only arbiter can cancel");
isApproved = false;
payable(depositor).transfer(address(this).balance);
}
function replaceArbiter(address newArbiter) public {
require(msg.sender == depositor, "Only depositor can replace arbiter");
arbiter = newArbiter;
}
function checkDeadline() public {
require(block.timestamp >= deadline, "Deadline not reached");
require(!isApproved, "Already approved");
payable(depositor).transfer(address(this).balance);
}
}