-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicketing_6.sol
72 lines (58 loc) · 1.82 KB
/
Ticketing_6.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pragma solidity ^0.4.25;
/*************************************
* Support for burning a ticket when presented to enter the event
*/
contract Event {
address public manager; //Owner of the Event
string title;
uint price;
address[] private purchasedTickets;
modifier ManagerOnly() {
require(manager == msg.sender);
_;
}
event TicketAddress(address indexed _from, address TicketAddr);
constructor (string name, uint eventPrice) public {
manager = msg.sender;
title = name;
price = eventPrice;
}
function buyTicket() public payable {
require(msg.value == price);
address eventAddr = address(this);
address newTicket = new Ticket(eventAddr, msg.sender, manager);
purchasedTickets.push(newTicket);
emit TicketAddress(msg.sender, newTicket); //Returns the address of the ticket
}
function getTickets() public view ManagerOnly returns (address[]) {
return purchasedTickets;
}
function getBalance() public view ManagerOnly returns (uint){
return address(this).balance;
}
function transferBalance() public ManagerOnly {
manager.transfer(address(this).balance);
}
}
contract Ticket {
address public owner;
address public manager;
address public eventAddress;
bool private burned;
modifier ManagerOnly() {
require(manager == msg.sender);
_;
}
constructor (address _eventAddr, address _buyer, address _manager) public {
owner = _buyer;
manager = _manager;
eventAddress = _eventAddr;
burned = false;
}
function isBurned() public view returns(bool) {
return burned;
}
function burnTicket() public ManagerOnly {
burned = true;
}
}