-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotelRoom.sol
37 lines (30 loc) · 931 Bytes
/
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
// 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;
constructor() {
owner = payable(msg.sender);
currentStatus = Statuses.Vacant;
}
modifier checkPrice(uint _amount) {
require(msg.value >= _amount, "Mablag yetarli emas.");
_;
}
modifier checkStatus() {
require(currentStatus == Statuses.Vacant, "Hona bo'sh emas!");
_;
}
function book() public payable checkStatus checkPrice(2 ether) {
currentStatus = Statuses.Occupied;
owner.transfer(msg.value);
(bool sent, bytes memory data) = owner.call{value: msg.value}("");
require(true, "Tranzaksiya amalga oshmadi!");
emit Occupy(msg.sender, msg.value);
}
}