diff --git a/codex/purchasing.nim b/codex/purchasing.nim index c7a5f7fe..a53a5150 100644 --- a/codex/purchasing.nim +++ b/codex/purchasing.nim @@ -74,3 +74,10 @@ func getPurchase*(purchasing: Purchasing, id: PurchaseId): ?Purchase = some purchasing.purchases[id] else: none Purchase + +func getPurchaseIds*(purchasing: Purchasing): seq[PurchaseId] = + var pIds: seq[PurchaseId] = @[] + for key in purchasing.purchases.keys: + pIds.add(key) + return pIds + diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 84a7aa40..6f01d564 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -279,6 +279,15 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) = return RestApiResponse.response($json, contentType="application/json") + router.api( + MethodGet, + "/api/codex/v1/storage/purchases") do () -> RestApiResponse: + without contracts =? node.contracts.client: + return RestApiResponse.error(Http503, "Purchasing unavailable") + + let purchaseIds = contracts.purchasing.getPurchaseIds() + return RestApiResponse.response($ %purchaseIds, contentType="application/json") + proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) = router.api( MethodGet, diff --git a/openapi.yaml b/openapi.yaml index 15e87c79..d594e70a 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -412,6 +412,50 @@ paths: "503": description: Sales are unavailable + "/storage/request/{cid}": + post: + summary: "Creates a new Request for storage" + tags: [ Marketplace ] + operationId: createStorageRequest + parameters: + - in: path + name: cid + required: true + schema: + $ref: "#/components/schemas/Cid" + description: CID of the uploaded data that should be stored + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/StorageRequestCreation" + responses: + "200": + description: Returns the Request ID as decimal string + "400": + description: Invalid or missing Request ID + "404": + description: Request ID not found + "503": + description: Purchasing is unavailable + + "/storage/purchases": + get: + summary: "Returns list of purchase IDs" + tags: [ Marketplace ] + operationId: getPurchases + responses: + "200": + description: Gets all purchase IDs stored in node + content: + application/json: + schema: + type: array + items: + type: string + "503": + description: Purchasing is unavailable + "/storage/purchases/{id}": get: summary: "Returns purchase details" @@ -440,33 +484,6 @@ paths: "503": description: Purchasing is unavailable - "/storage/request/{cid}": - post: - summary: "Creates a new Request for storage" - tags: [ Marketplace ] - operationId: createStorageRequest - parameters: - - in: path - name: cid - required: true - schema: - $ref: "#/components/schemas/Cid" - description: CID of the uploaded data that should be stored - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/StorageRequestCreation" - responses: - "200": - description: Returns the Request ID as decimal string - "400": - description: Invalid or missing Request ID - "404": - description: Request ID not found - "503": - description: Purchasing is unavailable - "/debug/chronicles/loglevel": post: summary: "Set log level at run time"