[marketplace] support slotIndex no longer optional

Previously, SalesAgent.slotIndex had been moved to not optional. However, there were still many places where optionality was assumed. This commit removes those assumuptions.
This commit is contained in:
Eric Mastro 2023-02-07 17:12:00 +11:00
parent c2a8cea91b
commit f4d5361ca8
No known key found for this signature in database
GPG Key ID: 141E3048D95A4E63
5 changed files with 8 additions and 21 deletions

View File

@ -87,16 +87,15 @@ proc subscribeFailure*(agent: SalesAgent) {.async.} =
proc subscribeSlotFilled*(agent: SalesAgent) {.async.} =
let market = agent.sales.market
without slotIndex =? agent.slotIndex:
raiseAssert "no slot selected"
proc onSlotFilled(requestId: RequestId,
slotIndex: UInt256) {.async.} =
without state =? (agent.state as SaleState):
return
await agent.slotFilled.unsubscribe()
await state.onSlotFilled(requestId, slotIndex)
await state.onSlotFilled(requestId, agent.slotIndex)
agent.slotFilled =
await market.subscribeSlotFilled(agent.requestId, slotIndex, onSlotFilled)
await market.subscribeSlotFilled(agent.requestId,
agent.slotIndex,
onSlotFilled)

View File

@ -34,16 +34,13 @@ method enterAsync(state: SaleDownloading) {.async.} =
without onStore =? agent.sales.onStore:
raiseAssert "onStore callback not set"
without slotIndex =? agent.slotIndex:
raiseAssert "no slot selected"
without request =? agent.request:
raiseAssert "no sale request"
if availability =? agent.availability:
agent.sales.remove(availability)
await onStore(request, slotIndex, agent.availability)
await onStore(request, agent.slotIndex, agent.availability)
await state.switchAsync(SaleProving())
except CancelledError:

View File

@ -24,10 +24,7 @@ method enterAsync(state: SaleFilled) {.async.} =
try:
let market = agent.sales.market
without slotIndex =? agent.slotIndex:
raiseAssert "no slot selected"
let host = await market.getHost(agent.requestId, slotIndex)
let host = await market.getHost(agent.requestId, agent.slotIndex)
let me = await market.getSigner()
if host == me.some:
await state.switchAsync(SaleFinished())

View File

@ -30,10 +30,7 @@ method enterAsync(state: SaleFilling) {.async.} =
try:
let market = agent.sales.market
without slotIndex =? agent.slotIndex:
raiseAssert "no slot selected"
await market.fillSlot(agent.requestId, slotIndex, state.proof)
await market.fillSlot(agent.requestId, agent.slotIndex, state.proof)
except CancelledError:
discard

View File

@ -29,13 +29,10 @@ method enterAsync(state: SaleProving) {.async.} =
without request =? agent.request:
raiseAssert "no sale request"
without slotIndex =? agent.slotIndex:
raiseAssert "no slot selected"
without onProve =? agent.sales.onProve:
raiseAssert "onProve callback not set"
let proof = await onProve(request, slotIndex)
let proof = await onProve(request, agent.slotIndex)
await state.switchAsync(SaleFilling(proof: proof))
except CancelledError: