2023-01-10 14:04:16 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.8;
|
|
|
|
|
|
|
|
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
|
|
import "./Requests.sol";
|
|
|
|
|
|
|
|
contract StateRetrieval {
|
|
|
|
using EnumerableSet for EnumerableSet.Bytes32Set;
|
|
|
|
using Requests for bytes32[];
|
|
|
|
|
2023-01-23 10:57:10 +00:00
|
|
|
mapping(address => EnumerableSet.Bytes32Set) private _requestsPerClient;
|
|
|
|
mapping(address => EnumerableSet.Bytes32Set) private _slotsPerHost;
|
2023-01-10 14:04:16 +00:00
|
|
|
|
|
|
|
function myRequests() public view returns (RequestId[] memory) {
|
2023-01-23 10:57:10 +00:00
|
|
|
return _requestsPerClient[msg.sender].values().toRequestIds();
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mySlots() public view returns (SlotId[] memory) {
|
2023-01-23 10:57:10 +00:00
|
|
|
return _slotsPerHost[msg.sender].values().toSlotIds();
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:47:29 +00:00
|
|
|
function _hasSlots(address host) internal view returns (bool) {
|
2023-01-23 10:57:10 +00:00
|
|
|
return _slotsPerHost[host].length() > 0;
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:47:29 +00:00
|
|
|
function _addToMyRequests(address client, RequestId requestId) internal {
|
2023-01-23 10:57:10 +00:00
|
|
|
_requestsPerClient[client].add(RequestId.unwrap(requestId));
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:47:29 +00:00
|
|
|
function _addToMySlots(address host, SlotId slotId) internal {
|
2023-01-23 10:57:10 +00:00
|
|
|
_slotsPerHost[host].add(SlotId.unwrap(slotId));
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:47:29 +00:00
|
|
|
function _removeFromMyRequests(address client, RequestId requestId) internal {
|
2023-01-23 10:57:10 +00:00
|
|
|
_requestsPerClient[client].remove(RequestId.unwrap(requestId));
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:47:29 +00:00
|
|
|
function _removeFromMySlots(address host, SlotId slotId) internal {
|
2023-01-23 10:57:10 +00:00
|
|
|
_slotsPerHost[host].remove(SlotId.unwrap(slotId));
|
2023-01-10 14:04:16 +00:00
|
|
|
}
|
|
|
|
}
|