Skip to content

Commit a88adb3

Browse files
committed
Add height to /blocks/seq/{from}/{to} API method
close #104
1 parent b9c40ab commit a88adb3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

scorex-transaction/src/main/scala/scorex/api/http/BlocksApiRoute.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ case class BlocksApiRoute(override val application: Application)(implicit val co
135135
case blockchain: BlockChain =>
136136
JsArray(
137137
(start to end).map { height =>
138-
blockchain.blockAt(height).map(_.json).getOrElse(Json.obj("error" -> s"No block at height $height"))
138+
blockchain.blockAt(height).map(_.json + ("height" -> Json.toJson(height)))
139+
.getOrElse(Json.obj("error" -> s"No block at height $height"))
139140
})
140141
case _ =>
141142
Json.obj("status" -> "error", "details" -> "Not available for other option than linear blockchain")

src/test/scala/scorex/lagonaki/integration/api/BlockAPISpecification.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BlockAPISpecification extends FunSuite with Matchers with TransactionTesti
1414
val history = application.blockStorage.history
1515
val genesis = history.genesis
1616

17-
if (history.height() < 2) {
17+
while (history.height() < 3) {
1818
application.blockStorage.appendBlock(genValidBlock())
1919
}
2020
val last = history.lastBlock
@@ -28,6 +28,8 @@ class BlockAPISpecification extends FunSuite with Matchers with TransactionTesti
2828
val response = GET.request(s"/blocks/seq/1/3")
2929
checkGenesis(response(0).as[JsValue])
3030
checkBlock(response(1).as[JsValue])
31+
(response(1) \ "height").as[Int] shouldBe 2
32+
(response(2) \ "height").as[Int] shouldBe 3
3133
}
3234

3335
test("GET /blocks/last API route") {

0 commit comments

Comments
 (0)