mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-23 09:09:23 +00:00
f459a2c6f6
Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
41 lines
1.2 KiB
Nim
41 lines
1.2 KiB
Nim
import pkg/chronicles
|
|
import ../statemachine
|
|
import ../salesagent
|
|
import ./errorhandling
|
|
import ./filling
|
|
import ./cancelled
|
|
import ./failed
|
|
|
|
logScope:
|
|
topics = "marketplace sales initial-proving"
|
|
|
|
type
|
|
SaleInitialProving* = ref object of ErrorHandlingState
|
|
|
|
method `$`*(state: SaleInitialProving): string = "SaleInitialProving"
|
|
|
|
method onCancelled*(state: SaleInitialProving, request: StorageRequest): ?State =
|
|
return some State(SaleCancelled())
|
|
|
|
method onFailed*(state: SaleInitialProving, request: StorageRequest): ?State =
|
|
return some State(SaleFailed())
|
|
|
|
method run*(state: SaleInitialProving, machine: Machine): Future[?State] {.async.} =
|
|
let data = SalesAgent(machine).data
|
|
let context = SalesAgent(machine).context
|
|
|
|
without request =? data.request:
|
|
raiseAssert "no sale request"
|
|
|
|
without onProve =? context.onProve:
|
|
raiseAssert "onProve callback not set"
|
|
|
|
without slotIndex =? data.slotIndex:
|
|
raiseAssert("no slot index assigned")
|
|
|
|
debug "Generating initial proof", requestId = $data.requestId
|
|
let proof = await onProve(Slot(request: request, slotIndex: slotIndex))
|
|
debug "Finished proof calculation", requestId = $data.requestId
|
|
|
|
return some State(SaleFilling(proof: proof))
|