-
Notifications
You must be signed in to change notification settings - Fork 0
/
HotelRoom.sol
38 lines (33 loc) · 1.02 KB
/
HotelRoom.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.6;
contract HotelRent
{
address payable public owner;
event Occupy(address _Occupant, uint _value); // Passes a message of room stay and value
enum statuses {Vacant, Occupied} // Enum to get room statuse
statuses currentStatues;
constructor()
{
owner = msg.sender;
currentStatues = statuses.Vacant;
}
//Checks the statues of Room availability
modifier onlyWhileVacant()
{
require(currentStatues == statuses.Vacant, "Currently Occupied");
_;
}
//Checks the cost of room rent
modifier costs(uint _amount)
{
require(msg.value >= _amount, "Required min. Ether to book");
_;
}
// Payable function
receive() external payable onlyWhileVacant costs(2 ether)
{
currentStatues = statuses.Vacant;
owner.transfer(msg.value); // Transfers amount to owner address
emit Occupy(msg.sender, msg.value); //Emit Event
}
}