-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathSmartContractWorkshop.sol
More file actions
100 lines (79 loc) · 2.38 KB
/
SmartContractWorkshop.sol
File metadata and controls
100 lines (79 loc) · 2.38 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
pragma solidity ^0.4.23;
contract SmartContractWorkshop {
struct Person {
string name;
string email;
bool attendsInPerson;
bool purchased;
}
uint256 baseprice = 0.03 ether;
uint256 priceIncrease = 0.001 ether;
uint256 maxPrice = 0.1 ether;
address owner;
uint256 faceToFaceLimit = 24;
uint256 public ticketsSold;
uint256 public ticketsFaceToFaceSold;
string public eventWebsite;
mapping(address=>Person) public attendants;
address[] allAttendants;
address[] faceToFaceAttendants;
string[] allAttendantsEmail;
string[] faceToFaceAttendantsEmail;
function SmartContractWorkshop (string _eventWebsite) {
owner = msg.sender;
eventWebsite = _eventWebsite;
}
function register(string _name, string _email, bool _attendsInPerson) payable {
require (msg.value == currentPrice() && attendants[msg.sender].purchased == false);
if(_attendsInPerson == true ) {
ticketsFaceToFaceSold++;
require (ticketsFaceToFaceSold <= faceToFaceLimit);
addAttendantAndTransfer(_name, _email, _attendsInPerson);
faceToFaceAttendants.push(msg.sender);
faceToFaceAttendants.push(_email);
} else {
addAttendantAndTransfer(_name, _email, _attendsInPerson);
}
allAttendants.push(msg.sender);
allAttendantsEmail.push(_email);
}
function addAttendantAndTransfer(string _name, string _email, bool _attendsInPerson) internal {
attendants[msg.sender] = Person({
name: _name,
email: _email,
attendsInPerson: _attendsInPerson,
purchased: true
});
ticketsSold++;
owner.transfer(this.balance);
}
function listAllAttendants() external view returns(address[]){
return allAttendants;
}
function listFaceToFaceAttendants() external view returns(address[]){
return faceToFaceAttendants;
}
function listAllAttendantsEmail() external view returns(string[]){
return allAttendantsemail;
}
function listFaceToFaceAttendantsEmail() external view returns(string[]){
return faceToFaceAttendantsEmail;
}
function hasPurchased() public view returns (bool) {
return attendants[msg.sender].purchased;
}
function currentPrice() public view returns (uint256) {
if(baseprice + (ticketsSold * priceIncrease) >= maxPrice) {
return maxPrice;
} else {
return baseprice + (ticketsSold * priceIncrease);
}
}
modifier onlyOwner() {
if(owner != msg.sender) {
revert();
} else {
_;
}
}
}