2023-07-20 09:56:28 +02:00
|
|
|
import pkg/metrics
|
2023-10-19 10:12:49 +02:00
|
|
|
import pkg/chronicles
|
2022-09-27 16:27:40 +02:00
|
|
|
import ../statemachine
|
2023-06-05 10:48:06 +02:00
|
|
|
import ./errorhandling
|
2022-09-27 16:27:40 +02:00
|
|
|
import ./error
|
|
|
|
|
2023-07-20 09:56:28 +02:00
|
|
|
declareCounter(codexPurchasesCancelled, "codex purchases cancelled")
|
|
|
|
|
2023-10-19 10:12:49 +02:00
|
|
|
logScope:
|
|
|
|
topics = "marketplace purchases cancelled"
|
|
|
|
|
2023-06-05 10:48:06 +02:00
|
|
|
type PurchaseCancelled* = ref object of ErrorHandlingState
|
2022-09-27 16:27:40 +02:00
|
|
|
|
2023-06-05 10:48:06 +02:00
|
|
|
method `$`*(state: PurchaseCancelled): string =
|
|
|
|
"cancelled"
|
2022-09-27 16:27:40 +02:00
|
|
|
|
2023-06-05 10:48:06 +02:00
|
|
|
method run*(state: PurchaseCancelled, machine: Machine): Future[?State] {.async.} =
|
2023-07-20 09:56:28 +02:00
|
|
|
codexPurchasesCancelled.inc()
|
2023-06-05 10:48:06 +02:00
|
|
|
let purchase = Purchase(machine)
|
2023-10-19 10:12:49 +02:00
|
|
|
|
|
|
|
warn "Request cancelled, withdrawing remaining funds", requestId = $purchase.requestId
|
2023-06-05 10:48:06 +02:00
|
|
|
await purchase.market.withdrawFunds(purchase.requestId)
|
2023-10-19 10:12:49 +02:00
|
|
|
|
2022-09-27 16:27:40 +02:00
|
|
|
let error = newException(Timeout, "Purchase cancelled due to timeout")
|
2023-10-24 12:12:54 +02:00
|
|
|
purchase.future.fail(error)
|