retreive active slot for sales state restoration

Store slotIndex in slot struct and expose the slot via getActiveSlot. This is to be used when restoring state in the sales module after a node restart.
This commit is contained in:
Eric Mastro 2023-03-30 12:36:19 +11:00
parent fcc28b3931
commit fb76f7d0b2
No known key found for this signature in database
2 changed files with 17 additions and 7 deletions

View File

@ -31,9 +31,15 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
struct Slot {
SlotState state;
RequestId requestId;
uint256 slotIndex;
address host;
}
struct ActiveSlot {
Request request;
uint256 slotIndex;
}
constructor(
IERC20 token,
MarketplaceConfig memory configuration
@ -77,6 +83,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");
@ -216,14 +223,17 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
return _slots[slotId].host;
}
function getRequestFromSlotId(SlotId slotId)
function getActiveSlot(SlotId slotId)
public
view
slotIsNotFree(slotId)
returns (Request memory)
returns (ActiveSlot memory)
{
Slot storage slot = _slots[slotId];
return _requests[slot.requestId];
ActiveSlot memory activeSlot;
activeSlot.request = _requests[slot.requestId];
activeSlot.slotIndex = slot.slotIndex;
return activeSlot;
}
modifier requestIsKnown(RequestId requestId) {

View File

@ -141,16 +141,16 @@ describe("Marketplace", function () {
})
it("fails to retrieve a request of an empty slot", async function () {
expect(marketplace.getRequestFromSlotId(slotId(slot))).to.be.revertedWith(
expect(marketplace.getActiveSlot(slotId(slot))).to.be.revertedWith(
"Slot is free"
)
})
it("allows retrieval of request of a filled slot", async function () {
await marketplace.fillSlot(slot.request, slot.index, proof)
expect(
await marketplace.getRequestFromSlotId(slotId(slot))
).to.be.request(request)
let activeSlot = await marketplace.getActiveSlot(slotId(slot))
expect(activeSlot.request).to.be.request(request)
expect(activeSlot.slotIndex).to.equal(slot.index)
})
it("is rejected when proof is incorrect", async function () {