forked from pi-apps/store-on-pi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEscrowService.sol
More file actions
40 lines (34 loc) · 1.11 KB
/
EscrowService.sol
File metadata and controls
40 lines (34 loc) · 1.11 KB
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
pragma solidity ^0.8.0;
contract EscrowService {
address public buyer;
address public seller;
uint256 public amount;
bool public buyerApproved;
bool public sellerApproved;
event EscrowCreated(address indexed buyer, address indexed seller, uint256 amount);
event EscrowCompleted(address indexed buyer, address indexed seller);
constructor(address _seller) {
seller = _seller;
}
function createEscrow() public payable {
require(msg.value > 0, "Amount must be greater than zero");
buyer = msg.sender;
amount = msg.value;
emit EscrowCreated(buyer, seller, amount);
}
function approve() public {
require(msg.sender == buyer || msg.sender == seller, "Not a party to the escrow");
if (msg.sender == buyer) {
buyerApproved = true;
} else {
sellerApproved = true;
}
if (buyerApproved && sellerApproved) {
completeEscrow();
}
}
function completeEscrow() private {
payable(seller).transfer(amount);
emit EscrowCompleted(buyer, seller);
}
}