Guest User

Untitled

a guest
Dec 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. pragma solidity ^0.4.25;
  2.  
  3. contract Escrow {
  4.  
  5. enum State {AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE, REFUNDED}
  6. State public currentState;
  7.  
  8. modifier buyerOnly() { require(msg.sender == buyer || msg.sender == arbiter); _; }
  9. modifier sellerOnly() { require(msg.sender == seller || msg.sender == arbiter); _; }
  10. modifier inState(State expectedState) { require(currentState == expectedState); _; }
  11.  
  12. address public buyer;
  13. address public seller;
  14. address public arbiter;
  15.  
  16. constructor(address _buyer, address _seller, address _arbiter) public {
  17. buyer = _buyer;
  18. seller = _seller;
  19. arbiter = _arbiter;
  20. }
  21.  
  22. function sendPayment() public payable buyerOnly inState(State.AWAITING_PAYMENT) {
  23. currentState = State.AWAITING_DELIVERY;
  24. }
  25.  
  26. function confirmDelivery() public buyerOnly inState(State.AWAITING_DELIVERY) {
  27. seller.transfer(address(this).balance);
  28. currentState = State.COMPLETE;
  29. }
  30.  
  31. function refundBuyer() public sellerOnly inState(State.AWAITING_DELIVERY) {
  32. buyer.transfer(address(this).balance);
  33. currentState = State.REFUNDED;
  34. }
  35. }
Add Comment
Please, Sign In to add comment