add slot index to Slot, support retrieval

Adds slotIndex to the Slot struct and allows retrieval via getRequestFromSlotId.
This commit is contained in:
Eric Mastro 2023-02-09 14:19:08 +11:00
parent fcc28b3931
commit 9751b0de5e
No known key found for this signature in database
GPG Key ID: 141E3048D95A4E63
2 changed files with 6 additions and 3 deletions

View File

@ -31,6 +31,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
struct Slot {
SlotState state;
RequestId requestId;
uint256 slotIndex;
address host;
}
@ -77,6 +78,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
SlotId slotId = Requests.slotId(requestId, slotIndex);
Slot storage slot = _slots[slotId];
slot.requestId = requestId;
slot.slotIndex = slotIndex;
require(slotState(slotId) == SlotState.Free, "Slot is not free");
@ -148,6 +150,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
slot.state = SlotState.Free;
slot.host = address(0);
slot.requestId = RequestId.wrap(0);
slot.slotIndex = 0;
context.slotsFilled -= 1;
emit SlotFreed(requestId, slotId);
@ -220,10 +223,10 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
public
view
slotIsNotFree(slotId)
returns (Request memory)
returns (Request memory, uint256 slotIndex)
{
Slot storage slot = _slots[slotId];
return _requests[slot.requestId];
return (_requests[slot.requestId], slot.slotIndex);
}
modifier requestIsKnown(RequestId requestId) {

View File

@ -150,7 +150,7 @@ describe("Marketplace", function () {
await marketplace.fillSlot(slot.request, slot.index, proof)
expect(
await marketplace.getRequestFromSlotId(slotId(slot))
).to.be.request(request)
).to.be.request((request, slot.index))
})
it("is rejected when proof is incorrect", async function () {