[marketplace] Emit RequestFulfilled when all slots are filled
This commit is contained in:
parent
f32974b496
commit
9a76c04d45
|
@ -9,6 +9,7 @@ contract Marketplace is Collateral, Proofs {
|
||||||
uint256 public immutable collateral;
|
uint256 public immutable collateral;
|
||||||
MarketplaceFunds private funds;
|
MarketplaceFunds private funds;
|
||||||
mapping(bytes32 => Request) private requests;
|
mapping(bytes32 => Request) private requests;
|
||||||
|
mapping(bytes32 => RequestState) private requestState;
|
||||||
mapping(bytes32 => Slot) private slots;
|
mapping(bytes32 => Slot) private slots;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -65,8 +66,13 @@ contract Marketplace is Collateral, Proofs {
|
||||||
_expectProofs(slotId, request.ask.proofProbability, request.ask.duration);
|
_expectProofs(slotId, request.ask.proofProbability, request.ask.duration);
|
||||||
_submitProof(slotId, proof);
|
_submitProof(slotId, proof);
|
||||||
|
|
||||||
|
RequestState storage state = requestState[requestId];
|
||||||
slot.host = msg.sender;
|
slot.host = msg.sender;
|
||||||
|
state.slotsFilled += 1;
|
||||||
emit SlotFilled(requestId, slotIndex, slotId);
|
emit SlotFilled(requestId, slotIndex, slotId);
|
||||||
|
if (state.slotsFilled == request.content.erasure.totalNodes) {
|
||||||
|
emit RequestFulfilled(requestId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function payoutSlot(bytes32 requestId, uint256 slotIndex)
|
function payoutSlot(bytes32 requestId, uint256 slotIndex)
|
||||||
|
@ -138,6 +144,10 @@ contract Marketplace is Collateral, Proofs {
|
||||||
bytes name; // random name
|
bytes name; // random name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct RequestState {
|
||||||
|
uint256 slotsFilled;
|
||||||
|
}
|
||||||
|
|
||||||
struct Slot {
|
struct Slot {
|
||||||
address host;
|
address host;
|
||||||
bool hostPaid;
|
bool hostPaid;
|
||||||
|
|
|
@ -231,4 +231,24 @@ describe("Marketplace", function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("fulfilling a request", function () {
|
||||||
|
beforeEach(async function () {
|
||||||
|
switchAccount(client)
|
||||||
|
await token.approve(marketplace.address, request.ask.reward)
|
||||||
|
await marketplace.requestStorage(request)
|
||||||
|
switchAccount(host)
|
||||||
|
await token.approve(marketplace.address, collateral)
|
||||||
|
await marketplace.deposit(collateral)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("emits event when all slots are filled", async function () {
|
||||||
|
const lastSlot = request.content.erasure.totalNodes - 1
|
||||||
|
for (let i = 0; i < lastSlot; i++) {
|
||||||
|
await marketplace.fillSlot(slot.request, i, proof)
|
||||||
|
}
|
||||||
|
await expect(marketplace.fillSlot(slot.request, lastSlot, proof))
|
||||||
|
.to.emit(marketplace, "RequestFulfilled")
|
||||||
|
.withArgs(requestId(request))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue