-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20_Event.sol
40 lines (35 loc) · 1.09 KB
/
20_Event.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
pragma solidity ^0.4.0;
contract Event {
address owner;
uint public tickets;
uint constant public price = 1 ether;
string public description;
string public website;
mapping(address => uint) public purchasers;
function Event(uint _tickets, string _description, string _website) {
owner = msg.sender;
tickets = _tickets;
description = _description;
website = _website;
}
function buyTickets(uint amount) payable {
if (msg.value != (amount * price) || amount > tickets) {
revert();
} else {
purchasers[msg.sender] += amount;
tickets -= amount;
if (tickets == 0) {
owner.transfer(this.balance);
}
}
}
function refund(uint numTickets) {
if (purchasers[msg.sender] < numTickets) {
revert();
} else {
msg.sender.transfer(numTickets * price);
purchasers[msg.sender] -= numTickets;
tickets += numTickets;
}
}
}