Skip to content

Instantly share code, notes, and snippets.

@JeffreyBPetersen
Last active June 13, 2016 07:07
Show Gist options
  • Save JeffreyBPetersen/da2a9793ff6ee6628f86be361d3b8c49 to your computer and use it in GitHub Desktop.
Save JeffreyBPetersen/da2a9793ff6ee6628f86be361d3b8c49 to your computer and use it in GitHub Desktop.
Buy a shirt off someone's back using Ethereum
contract BuyThisTshirt {
address currentOwner;
uint price;
bool forSale;
mapping (address => uint) payouts;
function BuyThisTshirt(){
currentOwner = msg.sender;
forSale = true;
}
function buy(){
if(msg.value < price) throw;
payouts[currentOwner] += msg.value;
currentOwner = msg.sender;
forSale = false;
}
function getPayout(){
msg.sender.send(payouts[msg.sender]);
payouts[msg.sender] = 0;
}
function setPrice(uint howMuch){
if(msg.sender != currentOwner) throw;
price = howMuch;
forSale = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment