-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathHotel.sol
42 lines (31 loc) · 1.07 KB
/
Hotel.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
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HotelRoom {
enum Statuses { Vacant, Occupied }
Statuses public currentStatus;
event Occupy(address _occupant, uint _value);
address payable public owner;
uint public roomPrice;
constructor(uint _roomPrice) {
owner = payable(msg.sender);
currentStatus = Statuses.Vacant;
roomPrice = _roomPrice;
}
modifier onlyWhileVacant {
require(currentStatus == Statuses.Vacant, "Room is currently occupied.");
_;
}
modifier costs(uint _amount) {
require(msg.value >= _amount, "Not enough Ether provided.");
_;
}
function bookRoom() public payable onlyWhileVacant costs(roomPrice) {
currentStatus = Statuses.Occupied;
owner.transfer(msg.value);
emit Occupy(msg.sender, msg.value);
}
function changeRoomPrice(uint _newPrice) public {
require(msg.sender == owner, "Only the owner can change the room price.");
roomPrice = _newPrice;
}
}