dagger-contracts/contracts/StateRetrieval.sol
2024-07-25 15:39:28 +10:00

57 lines
1.8 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./Requests.sol";
contract StateRetrieval {
using EnumerableSet for EnumerableSet.Bytes32Set;
using Requests for bytes32[];
mapping(address => EnumerableSet.Bytes32Set) private _requestsPerClient;
mapping(address => EnumerableSet.Bytes32Set) private _slotsPerHost;
mapping(uint16 => EnumerableSet.Bytes32Set) private _slotsPerValidator;
function myRequests() public view returns (RequestId[] memory) {
return _requestsPerClient[msg.sender].values().toRequestIds();
}
function mySlots() public view returns (SlotId[] memory) {
return _slotsPerHost[msg.sender].values().toSlotIds();
}
function validationSlots(
uint16 groupIdx
) public view returns (SlotId[] memory) {
return _slotsPerValidator[groupIdx].values().toSlotIds();
}
function _hasSlots(address host) internal view returns (bool) {
return _slotsPerHost[host].length() > 0;
}
function _addToMyRequests(address client, RequestId requestId) internal {
_requestsPerClient[client].add(RequestId.unwrap(requestId));
}
function _addToMySlots(address host, SlotId slotId) internal {
_slotsPerHost[host].add(SlotId.unwrap(slotId));
}
function _addToValidationSlots(uint16 groupIdx, SlotId slotId) internal {
_slotsPerValidator[groupIdx].add(SlotId.unwrap(slotId));
}
function _removeFromMyRequests(address client, RequestId requestId) internal {
_requestsPerClient[client].remove(RequestId.unwrap(requestId));
}
function _removeFromMySlots(address host, SlotId slotId) internal {
_slotsPerHost[host].remove(SlotId.unwrap(slotId));
}
function _removeFromValidationSlots(uint16 groupIdx, SlotId slotId) internal {
_slotsPerValidator[groupIdx].remove(SlotId.unwrap(slotId));
}
}