mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-02-08 21:05:21 +00:00
e5df8c50d3
* style: nph setup * chore: formates codex/ and tests/ folder with nph 0.6.1
36 lines
896 B
Nim
36 lines
896 B
Nim
import pkg/chronos
|
|
|
|
import ../../logutils
|
|
import ../statemachine
|
|
import ../salesagent
|
|
import ./errorhandling
|
|
import ./cancelled
|
|
import ./failed
|
|
|
|
logScope:
|
|
topics = "marketplace sales finished"
|
|
|
|
type SaleFinished* = ref object of ErrorHandlingState
|
|
|
|
method `$`*(state: SaleFinished): string =
|
|
"SaleFinished"
|
|
|
|
method onCancelled*(state: SaleFinished, request: StorageRequest): ?State =
|
|
return some State(SaleCancelled())
|
|
|
|
method onFailed*(state: SaleFinished, request: StorageRequest): ?State =
|
|
return some State(SaleFailed())
|
|
|
|
method run*(state: SaleFinished, machine: Machine): Future[?State] {.async.} =
|
|
let agent = SalesAgent(machine)
|
|
let data = agent.data
|
|
|
|
without request =? data.request:
|
|
raiseAssert "no sale request"
|
|
|
|
info "Slot finished and paid out",
|
|
requestId = data.requestId, slotIndex = data.slotIndex
|
|
|
|
if onCleanUp =? agent.onCleanUp:
|
|
await onCleanUp()
|