32 lines
901 B
Nim
32 lines
901 B
Nim
import pkg/chronicles
|
|
import ../salesagent
|
|
import ../statemachine
|
|
import ./errorhandling
|
|
import ./errored
|
|
|
|
logScope:
|
|
topics = "marketplace sales failed"
|
|
|
|
type
|
|
SaleFailed* = ref object of ErrorHandlingState
|
|
SaleFailedError* = object of SaleError
|
|
|
|
method `$`*(state: SaleFailed): string = "SaleFailed"
|
|
|
|
method run*(state: SaleFailed, machine: Machine): Future[?State] {.async.} =
|
|
let data = SalesAgent(machine).data
|
|
let market = SalesAgent(machine).context.market
|
|
|
|
without request =? data.request:
|
|
raiseAssert "no sale request"
|
|
|
|
without slotIndex =? data.slotIndex:
|
|
raiseAssert("no slot index assigned")
|
|
|
|
let slot = Slot(request: request, slotIndex: slotIndex)
|
|
debug "Removing slot from mySlots", requestId = $data.requestId, slotIndex
|
|
await market.freeSlot(slot.id)
|
|
|
|
let error = newException(SaleFailedError, "Sale failed")
|
|
return some State(SaleErrored(error: error))
|