Skip to content

Instantly share code, notes, and snippets.

@andrejrakic
Created May 7, 2020 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrejrakic/8fd96a8e76b7b47f767f6531a463ccce to your computer and use it in GitHub Desktop.
Save andrejrakic/8fd96a8e76b7b47f767f6531a463ccce to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=
pragma solidity ^0.6.0;
contract HotelRoom {
enum Statuses { Vacant, Occupied }
Statuses currentStatus;
event Occupy(address _occupant, uint _amount);
address payable public owner;
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) {
//require(msg.value >= 2 ether, "Not enough Ether provided");
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