PR comments

- remove ActiveSlotId type and instead use an additional mapping for readability
- simplify _activeSlotsForHost for readability
This commit is contained in:
Eric Mastro 2022-11-17 12:23:06 +11:00 committed by markspanbroek
parent a99827ed39
commit 74c2d91b69

View File

@ -7,14 +7,11 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./Collateral.sol"; import "./Collateral.sol";
import "./Proofs.sol"; import "./Proofs.sol";
import "hardhat/console.sol";
contract Marketplace is Collateral, Proofs { contract Marketplace is Collateral, Proofs {
using EnumerableSet for EnumerableSet.Bytes32Set; using EnumerableSet for EnumerableSet.Bytes32Set;
type RequestId is bytes32; type RequestId is bytes32;
type SlotId is bytes32; type SlotId is bytes32;
type ActiveSlotId is bytes32;
uint256 public immutable collateral; uint256 public immutable collateral;
MarketplaceFunds private funds; MarketplaceFunds private funds;
@ -22,7 +19,10 @@ contract Marketplace is Collateral, Proofs {
mapping(RequestId => RequestContext) private requestContexts; mapping(RequestId => RequestContext) private requestContexts;
mapping(SlotId => Slot) private slots; mapping(SlotId => Slot) private slots;
mapping(address => EnumerableSet.Bytes32Set) private activeRequests; mapping(address => EnumerableSet.Bytes32Set) private activeRequests;
mapping(RequestId => mapping(ActiveSlotId => EnumerableSet.Bytes32Set)) private activeSlots; mapping(RequestId =>
mapping(address =>
mapping(uint8 =>
EnumerableSet.Bytes32Set))) private activeSlots;
mapping(RequestId => uint8) private activeSlotsIdx; mapping(RequestId => uint8) private activeSlotsIdx;
constructor( constructor(
@ -59,10 +59,8 @@ contract Marketplace is Collateral, Proofs {
view view
returns (EnumerableSet.Bytes32Set storage) returns (EnumerableSet.Bytes32Set storage)
{ {
mapping(ActiveSlotId => EnumerableSet.Bytes32Set) storage activeForReq = uint8 id = activeSlotsIdx[requestId];
activeSlots[requestId]; return activeSlots[requestId][host][id];
ActiveSlotId id = _toActiveSlotId(host, requestId);
return activeForReq[id];
} }
/// @notice Clears active slots for a request /// @notice Clears active slots for a request
@ -409,17 +407,6 @@ contract Marketplace is Collateral, Proofs {
return SlotId.wrap(keccak256(abi.encode(requestId, slotIndex))); return SlotId.wrap(keccak256(abi.encode(requestId, slotIndex)));
} }
function _toActiveSlotId(address host, RequestId requestId)
internal
view
returns (ActiveSlotId)
{
uint8 activeSlotIdx = activeSlotsIdx[requestId];
return ActiveSlotId.wrap(
keccak256(abi.encode(host, activeSlotIdx))
);
}
function _toLockId(RequestId requestId) internal pure returns (LockId) { function _toLockId(RequestId requestId) internal pure returns (LockId) {
return LockId.wrap(RequestId.unwrap(requestId)); return LockId.wrap(RequestId.unwrap(requestId));
} }