mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-02-14 23:57:12 +00:00
* Move to version 2.0.6 * Update nim-confutils submodule to latest version * Update dependencies * Update Nim version to 2.0.12 * Add gcsafe pragma * Add missing import * Update specific conf for Nim 2.x * Fix method signatures * Revert erasure coding attempt to fix bug * More gcsafe pragma * Duplicate code from libp2p because it is not exported anymore * Fix camelcase function names * Use alreadySeen because need is not a bool anymore * newLPStreamReadError does not exist anymore so use another error * Replace ValidIpAddress by IpAddress * Add gcsafe pragma * Restore maintenance parameter deleted by mistake when removing esasure coding fix attempt code * Update method signatures * Copy LPStreamReadError code from libp2p which was removed * Fix camel case * Fix enums in tests * Fix camel case * Extract node components to a variable to make Nim 2 happy * Update the tests using ValidIpAddress to IpAddress * Fix cast for value which is already an option * Set nim version to 2.0.x for CI * Set nim version to 2.0.x for CI * Move to miniupnp version 2.2.4 to avoid symlink error * Set core.symlinks to false for Windows for miniupnp >= 2.2.5 support * Update to Nim 2.0.14 * Update CI nim versions to 2.0.14 * Try with GCC 14 * Replace apt-fast by apt-get * Update ubuntu runner to latest * Use Ubuntu 20.04 for coverage * Disable CI cache for coverage * Add coverage property description * Remove commented test * Check the node value of seen instead of using alreadySeen * Fix the merge. The taskpool work was reverted. * Update nim-ethers submodule * Remove deprecated ValidIpAddress. Fix missing case and imports. * Fix a weird issue where nim-confutils cannot find NatAny * Fix tests and remove useless static keyword
60 lines
1.8 KiB
Nim
60 lines
1.8 KiB
Nim
import pkg/stint
|
|
import ../../logutils
|
|
import ../../market
|
|
import ../statemachine
|
|
import ../salesagent
|
|
import ./errorhandling
|
|
import ./filled
|
|
import ./cancelled
|
|
import ./failed
|
|
import ./ignored
|
|
import ./errored
|
|
|
|
logScope:
|
|
topics = "marketplace sales filling"
|
|
|
|
type
|
|
SaleFilling* = ref object of ErrorHandlingState
|
|
proof*: Groth16Proof
|
|
|
|
method `$`*(state: SaleFilling): string = "SaleFilling"
|
|
|
|
method onCancelled*(state: SaleFilling, request: StorageRequest): ?State =
|
|
return some State(SaleCancelled())
|
|
|
|
method onFailed*(state: SaleFilling, request: StorageRequest): ?State =
|
|
return some State(SaleFailed())
|
|
|
|
method run(state: SaleFilling, machine: Machine): Future[?State] {.async.} =
|
|
let data = SalesAgent(machine).data
|
|
let market = SalesAgent(machine).context.market
|
|
without (fullCollateral =? data.request.?ask.?collateral):
|
|
raiseAssert "Request not set"
|
|
|
|
logScope:
|
|
requestId = data.requestId
|
|
slotIndex = data.slotIndex
|
|
|
|
let slotState = await market.slotState(slotId(data.requestId, data.slotIndex))
|
|
var collateral: UInt256
|
|
|
|
if slotState == SlotState.Repair:
|
|
# When repairing the node gets "discount" on the collateral that it needs to
|
|
let repairRewardPercentage = (await market.repairRewardPercentage).u256
|
|
collateral = fullCollateral - ((fullCollateral * repairRewardPercentage)).div(100.u256)
|
|
else:
|
|
collateral = fullCollateral
|
|
|
|
debug "Filling slot"
|
|
try:
|
|
await market.fillSlot(data.requestId, data.slotIndex, state.proof, collateral)
|
|
except MarketError as e:
|
|
if e.msg.contains "Slot is not free":
|
|
debug "Slot is already filled, ignoring slot"
|
|
return some State( SaleIgnored(reprocessSlot: false, returnBytes: true) )
|
|
else:
|
|
return some State( SaleErrored(error: e) )
|
|
# other CatchableErrors are handled "automatically" by the ErrorHandlingState
|
|
|
|
return some State(SaleFilled())
|