forked from bsaepfl/solidity-workshop-lauzhack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicketSeller.sol
39 lines (31 loc) · 918 Bytes
/
TicketSeller.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;
contract TicketSeller {
// how much do people have to pay for the ticket
uint256 public price = 30; // 1 ether is 1e18 wei
address public owner;
// who has a ticket (and who doesn't)
// user -> has a ticket?
mapping(address => bool) public tickets;
constructor(address _owner) {
owner = _owner;
}
modifier onlyOwner() {
if (msg.sender != owner) {
revert("unauthorized");
}
_;
}
function setPrice(uint256 newPrice) onlyOwner external {
price = newPrice;
}
function buyTicket() payable external {
// we can access
// the amount of money sent with msg.value
// the sender (the user) with msg.sender
if (msg.value != price) {
revert("wrong amount");
}
tickets[msg.sender] = true;
}
}