mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-23 10:08:17 +00:00
- add requestId and slotIndex to Reservation (hopefully these will prove to be useful when we persist Reservations until request are completed, to add back bytes to Availability) - add querying of all reservations, with accompanying tests - change from find to findAvailabilities - move onCleanUp from SalesContext to SalesAgent as it was getting overwritten for each slot processed - remove sales agent AFTER deleting reservation, as this was causing some SIGSEGVs - retrofit testsales and testslotqueue to match updated Reservations module API
38 lines
989 B
Nim
38 lines
989 B
Nim
import pkg/chronos
|
|
import pkg/chronicles
|
|
import ../statemachine
|
|
import ../salesagent
|
|
import ./errorhandling
|
|
import ./cancelled
|
|
import ./failed
|
|
|
|
logScope:
|
|
topics = "marketplace sales finished"
|
|
|
|
type
|
|
SaleFinished* = ref object of ErrorHandlingState
|
|
|
|
method `$`*(state: SaleFinished): string = "SaleFinished"
|
|
|
|
method onCancelled*(state: SaleFinished, request: StorageRequest): ?State =
|
|
return some State(SaleCancelled())
|
|
|
|
method onFailed*(state: SaleFinished, request: StorageRequest): ?State =
|
|
return some State(SaleFailed())
|
|
|
|
method run*(state: SaleFinished, machine: Machine): Future[?State] {.async.} =
|
|
let agent = SalesAgent(machine)
|
|
let data = agent.data
|
|
let context = agent.context
|
|
|
|
without request =? data.request:
|
|
raiseAssert "no sale request"
|
|
|
|
without slotIndex =? data.slotIndex:
|
|
raiseAssert("no slot index assigned")
|
|
|
|
info "Slot finished and paid out", requestId = $data.requestId, slotIndex
|
|
|
|
if onCleanUp =? agent.onCleanUp:
|
|
await onCleanUp()
|