Created
May 7, 2020 11:36
-
-
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=
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
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