Last active
April 18, 2023 04:16
-
-
Save gwmccubbin/e8c3107cbc07417aa941b42c8f7fa04c 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
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); | |
} | |
} |
I second that^^
cool
For anyone getting type error
Solidity 0.8 and onwards ""msg.sender"" is not payable anymore, It needs to be casted in payable first,
owner=msg.sender -> owner=payable(msg.sender)
@neeleshwark17 thanks for the tip
Thnkx
@neeleshwark17 thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ya Da Best