Implement a smart contract for selling tickets to events.
The A38 concert venue organizes a concert. For this, they create an instance of this contract for 200 tickets, setting the price at the wei equivalent of 2000HUF.
Alice buys a ticket through the contract for the wei equivalent of 2000HUF, her ticket's id is 72
. Unfortunately, she finds out she cannot attend, so she decides to sell the ticket. She submits a sale-offer with the wei equivalent of 2400HUF as the price. Bob really wants to attend the concert, but all the tickets are sold already, so he decides to accept Alice's offer. Bob transfers the wei equivalent of 2400HUF to the contract, which is forwarded to Alice, and from this point on, Bob owns the ticket.
On the day of the event, the A38 staff scan Bob's QR code (representing his Ethereum address) and check if Bob has a ticket.
(Note: This is a good way to control the secondary market of tickets. Using this system, the only way to illegally sell tickets is to sell the associated Ethereum private keys.)
constructor: function TicketSale(uint16 numTickets, uint256 basePrice)
numTickets
tickets, sold for basePrice
.msg.sender
) is the owner.validate: function validate(address person) view returns (bool)
true
if person
has a ticket, false
otherwise.buy ticket: function buyTicket() payable
msg.sender
) buys one ticket for the base price.uint16
).get ticket id: function getTicketOf(address person) view returns (uint16)
person
.person
has a ticket.submit offer: function submitOffer(uint16 ticketId, uint256 price)
msg.sender
) submits an offer for selling their ticket (ticketId
) for price
wei.ticketId
.accept offer: function acceptOffer(uint16 ticketId) payable
ticketId
.ticketId
belongs to the buyer, and the offer is destroyed.withdraw: function withdraw()
pragma solidity ^0.4.21;
contract TicketSale {
// <contract_variables>
// </contract_variables>
function TicketSale(uint16 numTickets, uint256 basePrice) public {
// TODO
}
function validate(address person) public view returns (bool) {
// TODO
}
function buyTicket() public payable {
// TODO
}
function getTicketOf(address person) public view returns (uint16) {
// TODO
}
function submitOffer(uint16 ticketId, uint256 price) public {
// TODO
}
function acceptOffer(uint16 ticketId) public payable {
// TODO
}
function withdraw() public {
// TODO
}
}