list active sales

This commit is contained in:
Eric Mastro 2022-11-04 11:38:34 +11:00 committed by markspanbroek
parent a4057d712f
commit 5b6187afc4

View File

@ -19,6 +19,7 @@ contract Marketplace is Collateral, Proofs {
mapping(RequestId => RequestContext) private requestContexts;
mapping(SlotId => Slot) private slots;
mapping(address => EnumerableSet.Bytes32Set) private activeRequests;
mapping(address => EnumerableSet.Bytes32Set) private activeSlots;
constructor(
IERC20 _token,
@ -38,6 +39,10 @@ contract Marketplace is Collateral, Proofs {
return _toRequestIds(activeRequests[msg.sender].values());
}
function mySlots() public view returns (SlotId[] memory) {
return _toSlotIds(activeSlots[msg.sender].values());
}
function requestStorage(Request calldata request)
public
marketplaceInvariant
@ -89,6 +94,7 @@ contract Marketplace is Collateral, Proofs {
slot.requestId = requestId;
RequestContext storage context = _context(requestId);
context.slotsFilled += 1;
activeSlots[request.client].add(SlotId.unwrap(slotId));
emit SlotFilled(requestId, slotIndex, slotId);
if (context.slotsFilled == request.ask.slots) {
context.state = RequestState.Started;
@ -347,6 +353,17 @@ contract Marketplace is Collateral, Proofs {
}
}
function _toSlotIds(bytes32[] memory array)
private
pure
returns (SlotId[] memory result)
{
// solhint-disable-next-line no-inline-assembly
assembly {
result := array
}
}
function _toSlotId(RequestId requestId, uint256 slotIndex)
internal
pure