logos-storage-contracts-eth/contracts/SlotReservations.sol
Eric d2ba8693e7
Remove return value for reserveSlot
Not needed, as a slot that cannot be added due to already being included would revert anyway.
2024-09-19 14:25:41 +10:00

28 lines
828 B
Solidity

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./Requests.sol";
contract SlotReservations {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(SlotId => EnumerableSet.AddressSet) internal _reservations;
uint8 private constant _MAX_RESERVATIONS = 3;
function reserveSlot(SlotId slotId) public {
address host = msg.sender;
require(canReserveSlot(slotId), "Reservation not allowed");
_reservations[slotId].add(host);
}
function canReserveSlot(SlotId slotId) public view returns (bool) {
address host = msg.sender;
return
// TODO: add in check for address inside of expanding window
(_reservations[slotId].length() < _MAX_RESERVATIONS) &&
(!_reservations[slotId].contains(host));
}
}