Skip to content

Instantly share code, notes, and snippets.

@ZakriaJanjua
Created January 31, 2022 10:46
Show Gist options
  • Save ZakriaJanjua/a0a0ee6e3c0615fa58ac50c0b82f88dd to your computer and use it in GitHub Desktop.
Save ZakriaJanjua/a0a0ee6e3c0615fa58ac50c0b82f88dd to your computer and use it in GitHub Desktop.
payments receiving in solidity
pragma solidity >=0.7.0 <0.9.0;
contract Hotel {
enum Status { Vacant, Occupied }
Status currentStatus;
event Occupy(address _occupant, uint _value);
address payable public owner;
constructor() {
owner = payable(msg.sender);
currentStatus = Status.Vacant;
}
modifier onlyWhileVacant {
require(currentStatus == Status.Vacant, "Currently Occupied");
_;
}
modifier rightAmount(uint _amount) {
require(msg.value >= _amount, "Not the right amount");
_;
}
receive() external payable onlyWhileVacant rightAmount( 2 ether ) {
currentStatus = Status.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