Skip to content

Instantly share code, notes, and snippets.

@gwmccubbin gwmccubbin/HotelRoom.sol
Last active May 6, 2020

Embed
What would you like to do?
pragma solidity ^0.6.0;
contract HotelRoom {
enum Statuses { Vacant, Occupied }
Statuses currentStatus;
address payable public owner;
event Occupy(address _occupant, uint _value);
constructor() public {
owner = 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.");
_;
}
receive() external payable onlyWhileVacant costs(2 ether) {
currentStatus = Statuses.Occupied;
owner.transfer(msg.value);
emit Occupy(msg.sender, msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.