mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-02-14 15:46:35 +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)
38 lines
1.1 KiB
Nim
38 lines
1.1 KiB
Nim
import ../../logutils
|
|
import ../../market
|
|
import ../statemachine
|
|
import ../salesagent
|
|
import ./errorhandling
|
|
import ./cancelled
|
|
import ./failed
|
|
import ./finished
|
|
|
|
logScope:
|
|
topics = "marketplace sales payout"
|
|
|
|
type SalePayout* = ref object of ErrorHandlingState
|
|
|
|
method `$`*(state: SalePayout): string =
|
|
"SalePayout"
|
|
|
|
method onCancelled*(state: SalePayout, request: StorageRequest): ?State =
|
|
return some State(SaleCancelled())
|
|
|
|
method onFailed*(state: SalePayout, request: StorageRequest): ?State =
|
|
return some State(SaleFailed())
|
|
|
|
method run*(state: SalePayout, machine: Machine): Future[?State] {.async.} =
|
|
let data = SalesAgent(machine).data
|
|
let market = SalesAgent(machine).context.market
|
|
|
|
without request =? data.request:
|
|
raiseAssert "no sale request"
|
|
|
|
let slot = Slot(request: request, slotIndex: data.slotIndex)
|
|
debug "Collecting finished slot's reward",
|
|
requestId = data.requestId, slotIndex = data.slotIndex
|
|
let currentCollateral = await market.currentCollateral(slot.id)
|
|
await market.freeSlot(slot.id)
|
|
|
|
return some State(SaleFinished(returnedCollateral: some currentCollateral))
|