mirror of
https://github.com/codex-storage/codex-contracts-eth.git
synced 2025-02-03 07:03:26 +00:00
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;
|
||||
_transferFrom(msg.sender, amount);
|
||||
|
||||
emit StorageRequested(id, request.ask);
|
||||
emit StorageRequested(id, request.ask, request.expiry);
|
||||
}
|
||||
|
||||
function fillSlot(
|
||||
@ -117,7 +117,7 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||
|
||||
_addToMySlots(slot.host, slotId);
|
||||
|
||||
emit SlotFilled(requestId, slotIndex, slotId);
|
||||
emit SlotFilled(requestId, slotIndex);
|
||||
if (context.slotsFilled == request.ask.slots) {
|
||||
context.state = RequestState.Started;
|
||||
context.startedAt = block.timestamp;
|
||||
@ -168,9 +168,10 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||
|
||||
_removeFromMySlots(slot.host, slotId);
|
||||
|
||||
uint256 slotIndex = slot.slotIndex;
|
||||
delete _slots[slotId];
|
||||
context.slotsFilled -= 1;
|
||||
emit SlotFreed(requestId, slotId);
|
||||
emit SlotFreed(requestId, slotIndex);
|
||||
_resetMissingProofs(slotId);
|
||||
|
||||
Request storage request = _requests[requestId];
|
||||
@ -315,15 +316,17 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||
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 RequestFailed(RequestId indexed requestId);
|
||||
event SlotFilled(
|
||||
RequestId indexed requestId,
|
||||
uint256 indexed slotIndex,
|
||||
SlotId slotId
|
||||
uint256 slotIndex
|
||||
);
|
||||
event SlotFreed(
|
||||
RequestId indexed requestId,
|
||||
uint256 slotIndex
|
||||
);
|
||||
event SlotFreed(RequestId indexed requestId, SlotId slotId);
|
||||
event RequestCancelled(RequestId indexed requestId);
|
||||
|
||||
struct MarketplaceTotals {
|
||||
|
@ -124,7 +124,7 @@ describe("Marketplace", function () {
|
||||
await token.approve(marketplace.address, price(request))
|
||||
await expect(marketplace.requestStorage(request))
|
||||
.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 () {
|
||||
@ -171,7 +171,7 @@ describe("Marketplace", function () {
|
||||
it("emits event when slot is filled", async function () {
|
||||
await expect(marketplace.fillSlot(slot.request, slot.index, proof))
|
||||
.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 () {
|
||||
@ -378,7 +378,7 @@ describe("Marketplace", function () {
|
||||
await waitUntilStarted(marketplace, request, proof, token)
|
||||
await expect(await marketplace.freeSlot(id))
|
||||
.to.emit(marketplace, "SlotFreed")
|
||||
.withArgs(slot.request, id)
|
||||
.withArgs(slot.request, slot.index)
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user