2023-08-21 10:26:43 +00:00
|
|
|
import pkg/chronicles
|
|
|
|
import ../../market
|
|
|
|
import ../statemachine
|
|
|
|
import ../salesagent
|
|
|
|
import ./errorhandling
|
|
|
|
import ./cancelled
|
|
|
|
import ./failed
|
|
|
|
import ./finished
|
|
|
|
|
|
|
|
logScope:
|
2023-10-19 08:12:49 +00:00
|
|
|
topics = "marketplace sales payout"
|
2023-08-21 10:26:43 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
SalePayout* = ref object of ErrorHandlingState
|
|
|
|
|
|
|
|
method `$`*(state: SalePayout): string = "SalePayout"
|
|
|
|
|
|
|
|
method onCancelled*(state: SalePayout, request: StorageRequest): ?State =
|
|
|
|
return some State(SaleCancelled())
|
|
|
|
|
|
|
|
method onFailed*(state: SalePayout, request: StorageRequest): ?State =
|
|
|
|
return some State(SaleFailed())
|
|
|
|
|
|
|
|
method run(state: SalePayout, 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 "Collecting finished slot's reward", requestId = $data.requestId, slotIndex
|
|
|
|
await market.freeSlot(slot.id)
|
|
|
|
|
|
|
|
return some State(SaleFinished())
|