nim-codex/codex/purchasing/states/cancelled.nim

25 lines
745 B
Nim
Raw Normal View History

import pkg/metrics
import pkg/chronicles
import ../statemachine
import ./errorhandling
2023-11-03 15:21:54 +00:00
declareCounter(codex_purchases_cancelled, "codex purchases cancelled")
logScope:
topics = "marketplace purchases cancelled"
type PurchaseCancelled* = ref object of ErrorHandlingState
method `$`*(state: PurchaseCancelled): string =
"cancelled"
method run*(state: PurchaseCancelled, machine: Machine): Future[?State] {.async.} =
2023-11-03 15:21:54 +00:00
codex_purchases_cancelled.inc()
let purchase = Purchase(machine)
warn "Request cancelled, withdrawing remaining funds", requestId = $purchase.requestId
await purchase.market.withdrawFunds(purchase.requestId)
let error = newException(Timeout, "Purchase cancelled due to timeout")
purchase.future.fail(error)