0
pragma solidity ^0.8.7;

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);
    }
}
0

1 Answer 1

1

To convert an address to a payable object you can do

payable(owner)

Not the answer you're looking for? Browse other questions tagged or ask your own question.