Skip to content

Instantly share code, notes, and snippets.

@AubreyMayes
Created March 22, 2019 18:33
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 AubreyMayes/161caa00696fb78bd7b05801f98db600 to your computer and use it in GitHub Desktop.
Save AubreyMayes/161caa00696fb78bd7b05801f98db600 to your computer and use it in GitHub Desktop.
painfulDogSale
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