-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescrow.sol
42 lines (32 loc) · 825 Bytes
/
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
pragma solidity 0.8.0;
contract Escrow {
address payable seller;
address payable buyer;
mapping(address=>uint) TotalAmount;
enum State {
pay,
recieve,
complete
}
State public state;
constructor (address _buyer, address payable _seller) {
buyer= _buyer;
seller = _seller;
state = State.pay;
}
function confirmPayment () external onlyBuyer() checkState(State.pay) payable{
state = State.recieve;
}
function deliver () onlyBuyer() checkState(State.recieve) external payable{
seller.transfer (address(this).balance);
state = State.complete;
}
modifier onlyBuyer() {
require(msg.sender == buyer, "only buyer can call this function");
_;
}
modifier checkState (State currstate) {
require (currstate == state , "Cannot order" );
_;
}
}