[purchasing] add expiry to storage request via REST API

This commit is contained in:
Mark Spanbroek 2022-05-18 13:28:34 +02:00 committed by markspanbroek
parent 8086dda3f2
commit a87986cdd6
3 changed files with 13 additions and 4 deletions

View File

@ -212,7 +212,8 @@ proc requestStorage*(self: DaggerNodeRef,
duration: UInt256, duration: UInt256,
nodes: uint, nodes: uint,
tolerance: 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 ## Initiate a request for storage sequence, this might
## be a multistep procedure. ## be a multistep procedure.
## ##
@ -280,7 +281,8 @@ proc requestStorage*(self: DaggerNodeRef,
publicKey: @[], # TODO: PoR setup publicKey: @[], # TODO: PoR setup
name: @[] # TODO: PoR setup name: @[] # TODO: PoR setup
) )
) ),
expiry: expiry |? 0.u256
) )
let purchase = contracts.purchasing.purchase(request) let purchase = contracts.purchasing.purchase(request)

View File

@ -208,7 +208,8 @@ proc initRestApi*(node: DaggerNodeRef, conf: DaggerConf): RestRouter =
params.duration, params.duration,
nodes, nodes,
tolerance, tolerance,
params.maxPrice), error: params.maxPrice,
params.expiry), error:
return RestApiResponse.error(Http500, error.msg) return RestApiResponse.error(Http500, error.msg)
return RestApiResponse.response(purchaseId.toHex) return RestApiResponse.response(purchaseId.toHex)

View File

@ -9,6 +9,7 @@ type
StorageRequestParams* = object StorageRequestParams* = object
duration*: UInt256 duration*: UInt256
maxPrice*: UInt256 maxPrice*: UInt256
expiry*: ?UInt256
proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability = proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
let json = ?catch parseJson(string.fromBytes(bytes)) let json = ?catch parseJson(string.fromBytes(bytes))
@ -22,7 +23,12 @@ proc fromJson*(_: type StorageRequestParams,
let json = ?catch parseJson(string.fromBytes(bytes)) let json = ?catch parseJson(string.fromBytes(bytes))
let duration = ?catch UInt256.fromHex(json["duration"].getStr) let duration = ?catch UInt256.fromHex(json["duration"].getStr)
let maxPrice = ?catch UInt256.fromHex(json["maxPrice"].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 = func `%`*(address: Address): JsonNode =
% $address % $address