-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotel.sol
37 lines (33 loc) · 1.17 KB
/
Hotel.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-Lisence-Identifier: MIT
import "./Mytoken.sol";
import "hardhat/console.sol";
pragma solidity ^0.8.13;
contract Hotel is MyToken{
uint public counter;
enum Statuses {
Vacant,
Occupied
}
Statuses[5] public rooms = [Statuses.Vacant];
event Occupy(address _occuoant, uint _value);
Statuses currentStatus;
constructor(string memory name, string memory symbol, uint256 initialSupply,uint256 _cap) MyToken(name,symbol,initialSupply,_cap){
currentStatus = Statuses.Vacant;
}
modifier costs(uint _amount) {
require(msg.value == _amount, "Invalid Money."); _;
}
modifier MaxRooms {
require(counter < 5,"Not Room."); _;
}
uint accountBalance = address(this).balance;
receive() external payable costs(0.0001 ether) MaxRooms{ //receive : calldata없이 msg를 받을 때 동작하는 함수 (message ether)
console.log(msg.value);
rooms[counter++] = Statuses.Occupied;
_mint(msg.sender,2*10**uint(decimals()));
emit Occupy(msg.sender, msg.value);
}
function withdraw() public payable onlyOwner{
_transfer(address(this),msg.sender, accountBalance);
}
}