painfulDogSale
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.5.1; | |
contract DogPurchase { | |
address payable public buyer; | |
address payable public seller; | |
uint cost; | |
bool isDogPurchased; | |
uint currentID; | |
dogBreed dogPurchaseType; | |
enum dogBreed {ChowChow, Lowchen, Rottweiler} | |
event confirmedPurchase(address payable _buy, address payable _seller, uint _paid, uint _timestamp); | |
event sellerPaid ( address payable _buyer, uint _amountRecieved, uint _timestamp); | |
event BuyerRefunded(address payable _buyer, uint _amountRecieved, uint _timestamp); | |
constructor (address payable _buyer, uint _cost) public { | |
seller = msg.sender; | |
buyer = _buyer; | |
cost = _cost; | |
dogPurchaseType = dogBreed.ChowChow; | |
} | |
function FundPurchase() public payable{ | |
require(msg.sender == buyer && | |
msg.value == cost && !isDogPurchased); | |
isDogPurchased = true; | |
emit confirmedPurchase(buyer, seller,cost, now); | |
} | |
function payoutToSell() public { | |
require(msg.sender == buyer); | |
seller.transfer( address(this).balance); | |
emit sellerPaid ( buyer, cost, now); | |
} | |
function refundBuyer() public { | |
require(msg.sender == seller); | |
buyer.transfer(address(this).balance); | |
emit BuyerRefunded (seller, cost, now); | |
} | |
function DogPuchase () public view returns (dogBreed) { | |
return dogPurchaseType; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment