-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotelRoomSmartContract.sol
40 lines (33 loc) · 983 Bytes
/
HotelRoomSmartContract.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
contract HotelRoom{
address payable public owner;
enum AvailabilityStatus{
Occupied,
Vacant
}
AvailabilityStatus public isRoomAvailable;
constructor(){
owner = payable(msg.sender);
isRoomAvailable = AvailabilityStatus.Vacant;
}
modifier checkEther(uint _ether){
require(msg.value >= _ether, "Not Enough ether provided.");
_;
}
modifier checkAvailability(){
require(isRoomAvailable == AvailabilityStatus.Vacant, "Room already occupied");
_;
}
function bookRoom() public payable checkAvailability checkEther(2 ether){
owner.transfer(msg.value);
isRoomAvailable = AvailabilityStatus.Occupied;
}
function changeOwner(address _add) public verifyOwner{
owner = payable(_add);
}
modifier verifyOwner(){
require(msg.sender == owner, "Only owner");
_;
}
}