Created
May 31, 2018 04:17
-
-
Save rounakdatta/ff2cfdf047f87a90ea9b0268166c93de to your computer and use it in GitHub Desktop.
Simple enough escrow contract
This file contains hidden or 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
contract Escrow{ | |
mapping (address => uint) public balances; | |
address public seller; | |
address public buyer; | |
address public escrow; | |
bool sellerApprove; | |
bool buyerApprove; | |
uint public buyerBalance = balances[buyer]; | |
uint public sellerBalance = balances[seller]; | |
uint public totalContractBalance = this.balance; | |
function Escrow() public { | |
escrow = msg.sender; | |
} | |
function setup(address _seller, address _buyer){ | |
if(msg.sender == escrow){ | |
seller = _seller; | |
buyer = _buyer; | |
} | |
} | |
function approve(){ | |
if(msg.sender == buyer) buyerApprove = true; | |
else if(msg.sender == seller) sellerApprove = true; | |
if(sellerApprove && buyerApprove) fee(); | |
} | |
function abort(){ | |
if(msg.sender == buyer) buyerApprove = false; | |
else if (msg.sender == seller) sellerApprove = false; | |
if(!sellerApprove && !buyerApprove) refund(); | |
} | |
function payOut(){ | |
balances[seller] = this.balance; | |
balances[buyer] = 0; | |
seller.send(this.balance); | |
} | |
function deposit() payable { | |
if(msg.sender == buyer) balances[buyer] += msg.value; | |
else throw; | |
} | |
function killContract() internal { | |
selfdestruct(escrow); | |
//kills contract and returns funds to buyer | |
} | |
function refund(){ | |
if(buyerApprove == false && sellerApprove == false) selfdestruct(buyer); | |
//send money back to recipient if both parties agree contract is void | |
} | |
function fee(){ | |
escrow.send(this.balance / 100); //1% fee | |
payOut(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment