Support slot queue (#61)
* feat: add request expiry to StorageRequested event * add slot index to SlotFreed event * copy slotIndex before delete for emit * Update tests
This commit is contained in:
parent
6801f2c009
commit
230e7276e2
|
@ -83,7 +83,7 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||||
_marketplaceTotals.received += amount;
|
_marketplaceTotals.received += amount;
|
||||||
_transferFrom(msg.sender, amount);
|
_transferFrom(msg.sender, amount);
|
||||||
|
|
||||||
emit StorageRequested(id, request.ask);
|
emit StorageRequested(id, request.ask, request.expiry);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillSlot(
|
function fillSlot(
|
||||||
|
@ -117,7 +117,7 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||||
|
|
||||||
_addToMySlots(slot.host, slotId);
|
_addToMySlots(slot.host, slotId);
|
||||||
|
|
||||||
emit SlotFilled(requestId, slotIndex, slotId);
|
emit SlotFilled(requestId, slotIndex);
|
||||||
if (context.slotsFilled == request.ask.slots) {
|
if (context.slotsFilled == request.ask.slots) {
|
||||||
context.state = RequestState.Started;
|
context.state = RequestState.Started;
|
||||||
context.startedAt = block.timestamp;
|
context.startedAt = block.timestamp;
|
||||||
|
@ -168,9 +168,10 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||||
|
|
||||||
_removeFromMySlots(slot.host, slotId);
|
_removeFromMySlots(slot.host, slotId);
|
||||||
|
|
||||||
|
uint256 slotIndex = slot.slotIndex;
|
||||||
delete _slots[slotId];
|
delete _slots[slotId];
|
||||||
context.slotsFilled -= 1;
|
context.slotsFilled -= 1;
|
||||||
emit SlotFreed(requestId, slotId);
|
emit SlotFreed(requestId, slotIndex);
|
||||||
_resetMissingProofs(slotId);
|
_resetMissingProofs(slotId);
|
||||||
|
|
||||||
Request storage request = _requests[requestId];
|
Request storage request = _requests[requestId];
|
||||||
|
@ -315,15 +316,17 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||||
require(token.transferFrom(sender, receiver, amount), "Transfer failed");
|
require(token.transferFrom(sender, receiver, amount), "Transfer failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
event StorageRequested(RequestId requestId, Ask ask);
|
event StorageRequested(RequestId requestId, Ask ask, uint256 expiry);
|
||||||
event RequestFulfilled(RequestId indexed requestId);
|
event RequestFulfilled(RequestId indexed requestId);
|
||||||
event RequestFailed(RequestId indexed requestId);
|
event RequestFailed(RequestId indexed requestId);
|
||||||
event SlotFilled(
|
event SlotFilled(
|
||||||
RequestId indexed requestId,
|
RequestId indexed requestId,
|
||||||
uint256 indexed slotIndex,
|
uint256 slotIndex
|
||||||
SlotId slotId
|
);
|
||||||
|
event SlotFreed(
|
||||||
|
RequestId indexed requestId,
|
||||||
|
uint256 slotIndex
|
||||||
);
|
);
|
||||||
event SlotFreed(RequestId indexed requestId, SlotId slotId);
|
|
||||||
event RequestCancelled(RequestId indexed requestId);
|
event RequestCancelled(RequestId indexed requestId);
|
||||||
|
|
||||||
struct MarketplaceTotals {
|
struct MarketplaceTotals {
|
||||||
|
|
|
@ -124,7 +124,7 @@ describe("Marketplace", function () {
|
||||||
await token.approve(marketplace.address, price(request))
|
await token.approve(marketplace.address, price(request))
|
||||||
await expect(marketplace.requestStorage(request))
|
await expect(marketplace.requestStorage(request))
|
||||||
.to.emit(marketplace, "StorageRequested")
|
.to.emit(marketplace, "StorageRequested")
|
||||||
.withArgs(requestId(request), askToArray(request.ask))
|
.withArgs(requestId(request), askToArray(request.ask), request.expiry)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("allows retrieval of request details", async function () {
|
it("allows retrieval of request details", async function () {
|
||||||
|
@ -171,7 +171,7 @@ describe("Marketplace", function () {
|
||||||
it("emits event when slot is filled", async function () {
|
it("emits event when slot is filled", async function () {
|
||||||
await expect(marketplace.fillSlot(slot.request, slot.index, proof))
|
await expect(marketplace.fillSlot(slot.request, slot.index, proof))
|
||||||
.to.emit(marketplace, "SlotFilled")
|
.to.emit(marketplace, "SlotFilled")
|
||||||
.withArgs(slot.request, slot.index, slotId(slot))
|
.withArgs(slot.request, slot.index)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("allows retrieval of host that filled slot", async function () {
|
it("allows retrieval of host that filled slot", async function () {
|
||||||
|
@ -378,7 +378,7 @@ describe("Marketplace", function () {
|
||||||
await waitUntilStarted(marketplace, request, proof, token)
|
await waitUntilStarted(marketplace, request, proof, token)
|
||||||
await expect(await marketplace.freeSlot(id))
|
await expect(await marketplace.freeSlot(id))
|
||||||
.to.emit(marketplace, "SlotFreed")
|
.to.emit(marketplace, "SlotFreed")
|
||||||
.withArgs(slot.request, id)
|
.withArgs(slot.request, slot.index)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue