Created
February 2, 2019 11:40
-
-
Save jecrespo/efb6c640fcae44f8a1518a660cf48dd1 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.0+commit.1d4f565a.js&optimize=false&gist=
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.0; | |
contract Concert { | |
address payable owner; | |
string public concertName; | |
uint public ticketPrice; | |
mapping(address => bool) customer; | |
constructor(string memory _concertName, uint _etherPrice) public{ | |
owner = msg.sender; | |
concertName = _concertName; | |
ticketPrice = _etherPrice * 1 ether; | |
} | |
function buyTicket() public payable { | |
require(msg.value == ticketPrice, "IncorrectPrice"); | |
if (_isCustomer(msg.sender) == false) { | |
_setPurchaseStaus(msg.sender,true); | |
} | |
else { | |
revert("AlreadyClient"); | |
} | |
} | |
function refundTicketToAccount(address payable _to) public { | |
if(_isCustomer(msg.sender) == true) { | |
_to.transfer(ticketPrice); | |
_setPurchaseStaus(msg.sender,false); | |
} | |
else { | |
revert(); | |
} | |
} | |
function _isCustomer(address account) private view returns(bool){ | |
return customer[account]; | |
} | |
function _setPurchaseStaus(address account, bool purchased) private { | |
customer[account] = purchased; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment