Last active
June 14, 2022 05:33
-
-
Save gwmccubbin/40a07720fbd56d57e3b4681682f67f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 owner; | |
constructor() { | |
owner = payable(msg.sender); | |
currentStatus = Statuses.Vacant; | |
} | |
modifier onlyWhileVacant { | |
require(currentStatus == Statuses.Vacant, "Currently occupied."); | |
_; | |
} | |
modifier costs(uint _amount) { | |
require(msg.value >= _amount, "Not enough ether provided."); | |
_; | |
} | |
function book() public payable onlyWhileVacant costs(2 ether) { | |
currentStatus = Statuses.Occupied; | |
(bool sent, bytes memory data) = owner.call{value: msg.value}(""); | |
require(sent); | |
emit Occupy(msg.sender, msg.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment