Skip to content

Instantly share code, notes, and snippets.

@capsulecorplab
Last active February 24, 2018 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capsulecorplab/fe69cb92608e41f10773cfd869db42ea to your computer and use it in GitHub Desktop.
Save capsulecorplab/fe69cb92608e41f10773cfd869db42ea to your computer and use it in GitHub Desktop.
Smart contract for simulating an escrow
pragma solidity ^0.4.18;
contract Escrow {
enum State {AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE, REFUNDED}
modifier buyerOnly() {
require(msg.sender == buyer);
_;
}
modifier inState(State expectedState) {
require(currentState == expectedState);
_;
}
State public currentState;
address public buyer;
address public seller;
address public arbiter;
function Escrow(address _buyer, address _seller, address _arbiter) {
buyer = _buyer;
seller = _seller;
arbiter = _arbiter;
}
function sendPayment() buyerOnly inState(State.AWAITING_PAYMENT) payable {
currentState = State.AWAITING_DELIVERY;
}
function confirmDelivery() buyerOnly inState(State.AWAITING_DELIVERY){
currentState = State.COMPLETE;
seller.send(this.balance);
}
function refundBuyer() inState(State.AWAITING_DELIVERY){
require(msg.sender == arbiter);
currentState = State.REFUNDED;
buyer.send(this.balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment