From a87986cdd6bc337133b10081e4702c2b3c0249f7 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 18 May 2022 13:28:34 +0200 Subject: [PATCH] [purchasing] add expiry to storage request via REST API --- dagger/node.nim | 6 ++++-- dagger/rest/api.nim | 3 ++- dagger/rest/json.nim | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dagger/node.nim b/dagger/node.nim index 202b607e3..8a40baaf4 100644 --- a/dagger/node.nim +++ b/dagger/node.nim @@ -212,7 +212,8 @@ proc requestStorage*(self: DaggerNodeRef, duration: UInt256, nodes: uint, tolerance: uint, - maxPrice: UInt256): Future[?!array[32, byte]] {.async.} = + maxPrice: UInt256, + expiry = UInt256.none): Future[?!array[32, byte]] {.async.} = ## Initiate a request for storage sequence, this might ## be a multistep procedure. ## @@ -280,7 +281,8 @@ proc requestStorage*(self: DaggerNodeRef, publicKey: @[], # TODO: PoR setup name: @[] # TODO: PoR setup ) - ) + ), + expiry: expiry |? 0.u256 ) let purchase = contracts.purchasing.purchase(request) diff --git a/dagger/rest/api.nim b/dagger/rest/api.nim index 7cce37293..d0aef0ae2 100644 --- a/dagger/rest/api.nim +++ b/dagger/rest/api.nim @@ -208,7 +208,8 @@ proc initRestApi*(node: DaggerNodeRef, conf: DaggerConf): RestRouter = params.duration, nodes, tolerance, - params.maxPrice), error: + params.maxPrice, + params.expiry), error: return RestApiResponse.error(Http500, error.msg) return RestApiResponse.response(purchaseId.toHex) diff --git a/dagger/rest/json.nim b/dagger/rest/json.nim index 2c1d12497..49c6cbb94 100644 --- a/dagger/rest/json.nim +++ b/dagger/rest/json.nim @@ -9,6 +9,7 @@ type StorageRequestParams* = object duration*: UInt256 maxPrice*: UInt256 + expiry*: ?UInt256 proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability = let json = ?catch parseJson(string.fromBytes(bytes)) @@ -22,7 +23,12 @@ proc fromJson*(_: type StorageRequestParams, let json = ?catch parseJson(string.fromBytes(bytes)) let duration = ?catch UInt256.fromHex(json["duration"].getStr) let maxPrice = ?catch UInt256.fromHex(json["maxPrice"].getStr) - success StorageRequestParams(duration: duration, maxPrice: maxPrice) + let expiry = UInt256.fromHex(json["expiry"].getStr).catch.option + success StorageRequestParams( + duration: duration, + maxPrice: maxPrice, + expiry: expiry + ) func `%`*(address: Address): JsonNode = % $address