mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-02-28 14:20:36 +00:00
* fix(statemachine): do not raise from state.run * fix rebase * fix exception handling in SaleProvingSimulated.prove - re-raise CancelledError - don't return State on CatchableError - expect the Proofs_InvalidProof custom error instead of checking a string * asyncSpawn salesagent.onCancelled This was swallowing a KeyError in one of the tests (fixed in the previous commit) * remove error handling states in asyncstatemachine * revert unneeded changes * formatting * PR feedback, logging updates
34 lines
961 B
Nim
34 lines
961 B
Nim
import pkg/metrics
|
|
|
|
import ../statemachine
|
|
import ../../utils/exceptions
|
|
import ../../logutils
|
|
import ./error
|
|
|
|
declareCounter(codex_purchases_finished, "codex purchases finished")
|
|
|
|
logScope:
|
|
topics = "marketplace purchases finished"
|
|
|
|
type PurchaseFinished* = ref object of PurchaseState
|
|
|
|
method `$`*(state: PurchaseFinished): string =
|
|
"finished"
|
|
|
|
method run*(
|
|
state: PurchaseFinished, machine: Machine
|
|
): Future[?State] {.async: (raises: []).} =
|
|
codex_purchases_finished.inc()
|
|
let purchase = Purchase(machine)
|
|
try:
|
|
info "Purchase finished, withdrawing remaining funds",
|
|
requestId = purchase.requestId
|
|
await purchase.market.withdrawFunds(purchase.requestId)
|
|
|
|
purchase.future.complete()
|
|
except CancelledError as e:
|
|
trace "PurchaseFinished.run was cancelled", error = e.msgDetail
|
|
except CatchableError as e:
|
|
error "Error during PurchaseFinished.run", error = e.msgDetail
|
|
return some State(PurchaseErrored(error: e))
|