2023-07-20 07:56:28 +00:00
|
|
|
import pkg/metrics
|
2022-09-27 14:27:40 +00:00
|
|
|
import ../statemachine
|
2023-06-05 08:48:06 +00:00
|
|
|
import ./errorhandling
|
2022-09-27 14:27:40 +00:00
|
|
|
import ./error
|
|
|
|
|
2023-07-20 07:56:28 +00:00
|
|
|
declareCounter(codexPurchasesCancelled, "codex purchases cancelled")
|
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
type PurchaseCancelled* = ref object of ErrorHandlingState
|
2022-09-27 14:27:40 +00:00
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
method `$`*(state: PurchaseCancelled): string =
|
|
|
|
"cancelled"
|
2022-09-27 14:27:40 +00:00
|
|
|
|
2023-06-05 08:48:06 +00:00
|
|
|
method run*(state: PurchaseCancelled, machine: Machine): Future[?State] {.async.} =
|
2023-07-20 07:56:28 +00:00
|
|
|
codexPurchasesCancelled.inc()
|
2023-06-05 08:48:06 +00:00
|
|
|
let purchase = Purchase(machine)
|
|
|
|
await purchase.market.withdrawFunds(purchase.requestId)
|
2022-09-27 14:27:40 +00:00
|
|
|
let error = newException(Timeout, "Purchase cancelled due to timeout")
|
2023-06-05 08:48:06 +00:00
|
|
|
return some State(PurchaseErrored(error: error))
|