From 29b8b0fd1895c6dbc3f164172bdc05151692cd14 Mon Sep 17 00:00:00 2001 From: ccellado Date: Wed, 4 Oct 2023 15:59:54 +0300 Subject: [PATCH] #2039 Add bulk endpoint for full block by header ids fetch --- src/main/resources/api/openapi.yaml | 6 +++--- .../scala/org/ergoplatform/http/api/BlocksApiRoute.scala | 8 ++++---- .../org/ergoplatform/http/routes/BlocksApiRouteSpec.scala | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/resources/api/openapi.yaml b/src/main/resources/api/openapi.yaml index 236698d71e..b9d86e56aa 100644 --- a/src/main/resources/api/openapi.yaml +++ b/src/main/resources/api/openapi.yaml @@ -2703,10 +2703,10 @@ paths: schema: $ref: '#/components/schemas/ApiError' - /blocks/headerIdsList: + /blocks/headerIds: get: summary: Get the list of full block info by given header ids - operationId: getFullBlockByIdsList + operationId: getFullBlockByIds tags: - blocks requestBody: @@ -2719,7 +2719,7 @@ paths: type: string responses: '200': - description: List of block objects representing the full block data + description: Full blocks corresponding to ids provided content: application/json: schema: diff --git a/src/main/scala/org/ergoplatform/http/api/BlocksApiRoute.scala b/src/main/scala/org/ergoplatform/http/api/BlocksApiRoute.scala index 751d8246bd..ebf82586d8 100644 --- a/src/main/scala/org/ergoplatform/http/api/BlocksApiRoute.scala +++ b/src/main/scala/org/ergoplatform/http/api/BlocksApiRoute.scala @@ -38,7 +38,7 @@ case class BlocksApiRoute(viewHolderRef: ActorRef, readersHolder: ActorRef, ergo getChainSliceR ~ getBlockIdsAtHeightR ~ getBlockHeaderByHeaderIdR ~ - getFullBlockByHeaderIdsListR ~ + getFullBlockByHeaderIdsR ~ getBlockTransactionsByHeaderIdR ~ getProofForTxR ~ getFullBlockByHeaderIdR ~ @@ -70,7 +70,7 @@ case class BlocksApiRoute(viewHolderRef: ActorRef, readersHolder: ActorRef, ergo history.typedModifierById[Header](headerId).flatMap(history.getFullBlock) } - private def getFullBlockByHeaderIdsList(headerIds: Seq[ModifierId]): Future[Seq[ErgoFullBlock]] = + private def getFullBlockByHeaderIds(headerIds: Seq[ModifierId]): Future[Seq[ErgoFullBlock]] = getHistory.map { history => headerIds.flatMap(headerId => history.typedModifierById[Header](headerId).flatMap(history.getFullBlock)) } @@ -183,8 +183,8 @@ case class BlocksApiRoute(viewHolderRef: ActorRef, readersHolder: ActorRef, ergo ApiResponse(getFullBlockByHeaderId(id)) } - def getFullBlockByHeaderIdsListR: Route = (post & path("headerIdsList") & modifierIds) { ids => - ApiResponse(getFullBlockByHeaderIdsList(ids)) + def getFullBlockByHeaderIdsR: Route = (post & path("headerIds") & modifierIds) { ids => + ApiResponse(getFullBlockByHeaderIds(ids)) } } diff --git a/src/test/scala/org/ergoplatform/http/routes/BlocksApiRouteSpec.scala b/src/test/scala/org/ergoplatform/http/routes/BlocksApiRouteSpec.scala index 5e4d824292..ab7efade11 100644 --- a/src/test/scala/org/ergoplatform/http/routes/BlocksApiRouteSpec.scala +++ b/src/test/scala/org/ergoplatform/http/routes/BlocksApiRouteSpec.scala @@ -100,7 +100,7 @@ class BlocksApiRouteSpec val headerIdsBytes = history.lastHeaders(10).headers val headerIdsString: Seq[String] = headerIdsBytes.map(h => Algos.encode(h.id)) - Post(prefix + "/headerIdsList", headerIdsString.asJson) ~> route ~> check { + Post(prefix + "/headerIds", headerIdsString.asJson) ~> route ~> check { status shouldBe StatusCodes.OK val expected = headerIdsBytes