Skip to content

Commit

Permalink
#2039 Add bulk endpoint for full block by header ids fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ccellado committed Oct 4, 2023
1 parent fa3d3ca commit 29b8b0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/org/ergoplatform/http/api/BlocksApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ case class BlocksApiRoute(viewHolderRef: ActorRef, readersHolder: ActorRef, ergo
getChainSliceR ~
getBlockIdsAtHeightR ~
getBlockHeaderByHeaderIdR ~
getFullBlockByHeaderIdsListR ~
getFullBlockByHeaderIdsR ~
getBlockTransactionsByHeaderIdR ~
getProofForTxR ~
getFullBlockByHeaderIdR ~
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29b8b0f

Please sign in to comment.