Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions app/controllers/NodeController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package controllers

import javax.inject.Inject
import play.api.libs.circe.Circe
import play.api.mvc.{AbstractController, ControllerComponents}
import play.api.libs.ws.WSClient
import play.api.libs.json._
import scala.concurrent.ExecutionContext
import views.html.getNodeInfo

class NodeController @Inject()(cc: ControllerComponents, ws: WSClient)
(implicit ex: ExecutionContext) extends AbstractController(cc) with Circe {


def nodeinfo(id: Int) = Action.async {
ws.url(s"http://testnet${if(id!=10) 0 + s"$id" else 10}.encry.ru:9051/info").get().map { response =>
val a: JsValue = Json.parse(response.body)
//val b: Seq[String] = a.toString.split(",")
val name: JsLookupResult = a \ "name"
val fullHeight: JsLookupResult = a \ "fullHeight"
val headersHeight: JsLookupResult = a \ "headersHeight"
val isMining: JsLookupResult = a \ "isMining"
var info: Seq[String] = Seq()

name match {
case JsDefined(name) => info = info :+ s"${name.toString()}"
case undefined: JsUndefined => println(undefined.validationError)
}

fullHeight match {
case JsDefined(fullHeight) => info = info :+ s"${fullHeight.toString()}"
case undefined: JsUndefined => println(undefined.validationError)
}

headersHeight match {
case JsDefined(headersHeight) => info = info :+ s"${headersHeight.toString()}"
case undefined: JsUndefined => println(undefined.validationError)
}

isMining match {
case JsDefined(isMining) => info = info :+ s"${isMining.toString()}"
case undefined: JsUndefined => println(undefined.validationError)
}

Ok(getNodeInfo(info))

}
}
}

19 changes: 19 additions & 0 deletions app/views/getNodeInfo.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@(info: Seq[String])

<html lang="en">
<head>
<meta charset="UTF-8">
<title>get nodeInfo</title>
</head>
<body>

<center> <table width="50%" border="1" rules="all">
<tr><td>name: @info(0)</td></tr>
<tr><td>fullHeight: @info(1)</td></tr>
<tr><td>headersHeight: @info(2)</td></tr>
<tr><td>isMining: @info(3)</td></tr>
</table>

</center>
</body>
</html>
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ libraryDependencies ++= (Seq(
"org.encry" %% "encry-common" % "0.8.3",
"de.heikoseeberger" %% "akka-http-circe" % "1.20.1",
) ++ databaseDependencies ++ apiDependencies ++ testingDependencies ++ loggingDependencies)
.map(_ exclude("ch.qos.logback", "*") exclude("ch.qos.logback", "*"))
.map(_ exclude("ch.qos.logback", "*") exclude("ch.qos.logback", "*"))
libraryDependencies ++= Seq(
ws
)
4 changes: 3 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ GET /api/transactions/block/:modifierId/outputs/unspent control
GET /api/transactions/tx/range/:from/:to controllers.TransactionsController.findTransactionByBlockHeightRangeApi(from: Int, to: Int)

GET /api/block/:id controllers.BlockController.findBlockApi(id: String)
GET /block/:id controllers.BlockController.findBlockView(id: String)
GET /block/:id controllers.BlockController.findBlockView(id: String)

GET /nodeinfo/:id controllers.NodeController.nodeinfo(id: Int)