HW21: Ticket sale (*)

Problem statement

Implement a smart contract for selling tickets to events.

Example scenario

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.)

Contract interface

Contract skeleton

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
    }

}