forked from magonicolas/Ethereum-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcert.sol
More file actions
46 lines (36 loc) · 1.05 KB
/
Concert.sol
File metadata and controls
46 lines (36 loc) · 1.05 KB
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
pragma solidity ^0.4.0;
contract Event {
address owner;
uint public tickets;
string public description;
string public website;
uint constant price = 0.01 ether;
mapping (address => uint) public purchasers;
function Event(uint t, string _description, string _webstite) {
owner = msg.sender;
description = _description;
website = _webstite;
tickets = t;
}
function () payable {
buyTickets(1);
}
function buyTickets(uint amount) payable {
if (msg.value != (amount * price) || amount > tickets) {
revert();
}
purchasers[msg.sender] += amount;
tickets -= amount;
if (tickets == 0) {
owner.transfer(this.balance);
}
}
function refund(uint numTickets) {
if (purchasers[msg.sender] < numTickets) {
revert();
}
msg.sender.transfer(numTickets * price);
purchasers[msg.sender] -= numTickets;
tickets += numTickets;
}
}