Last active
February 24, 2018 06:20
-
-
Save capsulecorplab/fe69cb92608e41f10773cfd869db42ea to your computer and use it in GitHub Desktop.
Smart contract for simulating an escrow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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