mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-08 16:33:11 +00:00
* openAPI: StorageRequestCreation: reward => pricePerByte, collateral => collateralPerByte * purchasing: reward => pricePerByte, collateral => collateralPerByte * Updates availabilities and reservations to use totalCollateral, minPricePerByte, and maxCollateralPerByte * Uses correct div operator when operating on UInt256 * proposal updating totalCollateral in availability * makes sure that reading currentCollateral happens before freeing slot * Updates naming * fixes tests: unit and contracts * uses feat/price-per-byte branch for codex-contracts-eth * temporarily disables integration tests on CI * introduces high level <<totalCollateral>> property for a cleaner external interface * updates integration tests * Applies review comments * Updates description of totalCollateral in SalesAvailability * updates codex-contracts-eth (price-per-byte)
40 lines
1.1 KiB
Nim
40 lines
1.1 KiB
Nim
import ../../logutils
|
|
import ../salesagent
|
|
import ../statemachine
|
|
import ./errorhandling
|
|
|
|
logScope:
|
|
topics = "marketplace sales cancelled"
|
|
|
|
type SaleCancelled* = ref object of ErrorHandlingState
|
|
|
|
method `$`*(state: SaleCancelled): string =
|
|
"SaleCancelled"
|
|
|
|
method run*(state: SaleCancelled, machine: Machine): Future[?State] {.async.} =
|
|
let agent = SalesAgent(machine)
|
|
let data = agent.data
|
|
let market = agent.context.market
|
|
|
|
without request =? data.request:
|
|
raiseAssert "no sale request"
|
|
|
|
let slot = Slot(request: request, slotIndex: data.slotIndex)
|
|
debug "Collecting collateral and partial payout",
|
|
requestId = data.requestId, slotIndex = data.slotIndex
|
|
let currentCollateral = await market.currentCollateral(slot.id)
|
|
await market.freeSlot(slot.id)
|
|
|
|
if onClear =? agent.context.onClear and request =? data.request:
|
|
onClear(request, data.slotIndex)
|
|
|
|
if onCleanUp =? agent.onCleanUp:
|
|
await onCleanUp(
|
|
returnBytes = true,
|
|
reprocessSlot = false,
|
|
returnedCollateral = some currentCollateral,
|
|
)
|
|
|
|
warn "Sale cancelled due to timeout",
|
|
requestId = data.requestId, slotIndex = data.slotIndex
|