From 7f5310d640b9b7d86a0762481634e50ab28d2164 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 2 Aug 2022 17:50:57 +0200 Subject: [PATCH] [rest api] Allow user to specify amount of hosts --- codex/rest/api.nim | 7 +++---- codex/rest/json.nim | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 8e062db2..d5be7951 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -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, diff --git a/codex/rest/json.nim b/codex/rest/json.nim index 2c0492a6..d142f5f3 100644 --- a/codex/rest/json.nim +++ b/codex/rest/json.nim @@ -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 =