Solidity smart contract to simulate buying a transport ticket from BVG.
The smart contract provides funtionality to set and query owners of the contract, set prices of different kind of tickets, and buy and query user's tickets.
The initial owner and tickets prices are set when the contract is deployed, and both can be updated through the public interface.
There are different kind of tickets based on their duration:
- Single (2 hours)
- Daily (24 hours)
- Weekly (7 days)
- Monthly (31 days)
- Yearly (365 days)
Read functions:
- owners: Checks whether an address is an owner or not
- ticketPrices: Gets a ticket price given a ticket type
- users: Gets the tickets from a user given a user adresss and a ticket number
- getBalance(): Gets the balance of the contract
- isTicketExpired(uint _ticketNumber): Checks if the user's ticket has expired given a ticket number
- getUserTicket(uint _ticketNumber): Gets the user's ticket information given a ticket number
- getUserAllTickets(): Gets a list of all user's tickets
Write functions:
- setTicketPrice(TicketType _type, uint _price): Sets the price of a ticket, only owners are allowed to perform this transaction
- addOwner(address _owner): Adds an owner to the list of owners, only owners are allowed to perform this transaction
- withdraw(): Withdraw the total balance to an owner, only owners are allowed to perform this transaction
- buyTicket(TicketType _type): Buys a ticket and returns the ticket number, the ticket hash, and ticket information, any user can perform this transaction
Ticket information:
- blockNumber: block number of the ticket creation
- startTimestamp: the timestamp of the ticket creation
- endTimestamp: the expiry date timestamp
- ticketType: the ticket type {0: single, 1: daily, 2: weekly, 3: monthly, 4: yearly}
- price: the price of the ticket at creation