Skip to content

Commit

Permalink
Add height to /blocks/seq/{from}/{to} API method
Browse files Browse the repository at this point in the history
close #104
  • Loading branch information
catena2w committed Jun 9, 2016
1 parent b9c40ab commit a88adb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Expand Up @@ -135,7 +135,8 @@ case class BlocksApiRoute(override val application: Application)(implicit val co
case blockchain: BlockChain =>
JsArray(
(start to end).map { height =>
blockchain.blockAt(height).map(_.json).getOrElse(Json.obj("error" -> s"No block at height $height"))
blockchain.blockAt(height).map(_.json + ("height" -> Json.toJson(height)))
.getOrElse(Json.obj("error" -> s"No block at height $height"))
})
case _ =>
Json.obj("status" -> "error", "details" -> "Not available for other option than linear blockchain")
Expand Down
Expand Up @@ -14,7 +14,7 @@ class BlockAPISpecification extends FunSuite with Matchers with TransactionTesti
val history = application.blockStorage.history
val genesis = history.genesis

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

test("GET /blocks/last API route") {
Expand Down

0 comments on commit a88adb3

Please sign in to comment.