-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotel.sol
More file actions
43 lines (32 loc) · 1.06 KB
/
hotel.sol
File metadata and controls
43 lines (32 loc) · 1.06 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
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
contract Hotel
{
enum status{
vacant,
occupied
}
status public currentStatus ;
address payable public owner;
event occupy( address occupant, uint paidAmount);
constructor(){
// executer of the smart contract is the owner of hotel
owner = payable(msg.sender);
//initially the room is vacant
currentStatus = status.vacant;
}
modifier checkAmount(uint _amount) {
require(msg.value >= _amount, "Failure insufficient balance ");
_;
}
modifier checkStatus{
require(currentStatus==status.vacant, "Failure hotel already occupied");
_;
}
function book() payable public checkAmount(2 ether) checkStatus{
(bool sent, bytes memory data) = owner.call{value: msg.value}("");
require(sent, "Failure not sufficient amount /n hotel not booked /n transaction reverted");
currentStatus = status.occupied;
emit occupy(msg.sender, msg.value);
}
}