2022-11-08 07:10:17 +00:00
|
|
|
import ../statemachine
|
2023-06-05 08:48:06 +00:00
|
|
|
import ./errorhandling
|
2022-11-08 07:10:17 +00:00
|
|
|
import ./submitted
|
|
|
|
import ./started
|
|
|
|
import ./cancelled
|
|
|
|
import ./finished
|
|
|
|
import ./failed
|
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
type PurchaseUnknown* = ref object of ErrorHandlingState
|
2022-11-08 07:10:17 +00:00
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
method `$`*(state: PurchaseUnknown): string =
|
|
|
|
"unknown"
|
2022-11-08 07:10:17 +00:00
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
method run*(state: PurchaseUnknown, machine: Machine): Future[?State] {.async.} =
|
|
|
|
let purchase = Purchase(machine)
|
|
|
|
if (request =? await purchase.market.getRequest(purchase.requestId)) and
|
|
|
|
(requestState =? await purchase.market.requestState(purchase.requestId)):
|
2022-11-08 07:10:17 +00:00
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
purchase.request = some request
|
2022-11-08 07:10:17 +00:00
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
case requestState
|
|
|
|
of RequestState.New:
|
|
|
|
return some State(PurchaseSubmitted())
|
|
|
|
of RequestState.Started:
|
|
|
|
return some State(PurchaseStarted())
|
|
|
|
of RequestState.Cancelled:
|
|
|
|
return some State(PurchaseCancelled())
|
|
|
|
of RequestState.Finished:
|
|
|
|
return some State(PurchaseFinished())
|
|
|
|
of RequestState.Failed:
|
|
|
|
return some State(PurchaseFailed())
|