Skip to content

Commit

Permalink
[purchasing] add expiry to storage request via REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
markspanbroek committed May 19, 2022
1 parent 8086dda commit a87986c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dagger/node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion dagger/rest/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion dagger/rest/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit a87986c

Please sign in to comment.