Skip to content

Instantly share code, notes, and snippets.

@gwmccubbin
Last active June 14, 2022 05:33
Show Gist options
  • Save gwmccubbin/40a07720fbd56d57e3b4681682f67f09 to your computer and use it in GitHub Desktop.
Save gwmccubbin/40a07720fbd56d57e3b4681682f67f09 to your computer and use it in GitHub Desktop.
// 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