-
Notifications
You must be signed in to change notification settings - Fork 4
/
escrow.sol
38 lines (30 loc) · 1.18 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
pragma solidity ^0.4.0;
/*
Simple escrow contract that mediates disputes using a trusted arbiter
*/
contract Escrow {
enum State {AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE, REFUNDED}
State public currentState;
modifier buyerOnly() { require(msg.sender == buyer || msg.sender == arbiter); _; }
modifier sellerOnly() { require(msg.sender == seller || msg.sender == arbiter); _; }
modifier inState(State expectedState) { require(currentState == expectedState); _; }
address public buyer;
address public seller;
address public arbiter;
function Escrow(address _buyer, address _seller, address _arbiter){
buyer = _buyer;
seller = _seller;
arbiter = _arbiter;
}
function confirmPayment() buyerOnly inState(State.AWAITING_PAYMENT) payable {
currentState = State.AWAITING_DELIVERY;
}
function confirmDelivery() buyerOnly inState(State.AWAITING_DELIVERY) {
seller.send(this.balance);
currentState = State.COMPLETE;
}
function refundBuyer() sellerOnly inState(State.AWAITING_DELIVERY) {
buyer.send(this.balance);
currentState = State.REFUNDED;
}
}