[rest api] Allow user to specify amount of hosts

This commit is contained in:
Mark Spanbroek 2022-08-02 17:50:57 +02:00 committed by markspanbroek
parent fd6f8a1386
commit 7f5310d640
2 changed files with 10 additions and 5 deletions

View File

@ -194,10 +194,6 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
## duration - the duration of the contract
## reward - the maximum price the client is willing to pay
# TODO: store on multiple nodes
let nodes: uint = 1
let tolerance: uint = 0
without cid =? cid.tryGet.catch, error:
return RestApiResponse.error(Http400, error.msg)
@ -206,6 +202,9 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
without params =? StorageRequestParams.fromJson(body), error:
return RestApiResponse.error(Http400, error.msg)
let nodes = params.nodes |? 1
let tolerance = params.nodes |? 0
without purchaseId =? await node.requestStorage(cid,
params.duration,
nodes,

View File

@ -10,6 +10,8 @@ type
duration*: UInt256
reward*: UInt256
expiry*: ?UInt256
nodes*: ?uint
tolerance*: ?uint
proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
let json = ?catch parseJson(string.fromBytes(bytes))
@ -24,10 +26,14 @@ proc fromJson*(_: type StorageRequestParams,
let duration = ?catch UInt256.fromHex(json["duration"].getStr)
let reward = ?catch UInt256.fromHex(json["reward"].getStr)
let expiry = UInt256.fromHex(json["expiry"].getStr).catch.option
let nodes = strutils.fromHex[uint](json["nodes"].getStr).catch.option
let tolerance = strutils.fromHex[uint](json["tolerance"].getStr).catch.option
success StorageRequestParams(
duration: duration,
reward: reward,
expiry: expiry
expiry: expiry,
nodes: nodes,
tolerance: tolerance
)
func `%`*(address: Address): JsonNode =