From ff9fc341e26d9d5e3ea46d4eb42ce3e1ccfd29e5 Mon Sep 17 00:00:00 2001 From: lior Date: Sun, 30 Sep 2018 19:41:29 +0300 Subject: [PATCH] made a view for nodes --- app/controllers/NodeController.scala | 50 ++++++++++++++++++++++++++++ app/views/getNodeInfo.scala.html | 19 +++++++++++ build.sbt | 5 ++- conf/routes | 4 ++- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 app/controllers/NodeController.scala create mode 100644 app/views/getNodeInfo.scala.html diff --git a/app/controllers/NodeController.scala b/app/controllers/NodeController.scala new file mode 100644 index 0000000..3b0c3a5 --- /dev/null +++ b/app/controllers/NodeController.scala @@ -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)) + + } + } +} + diff --git a/app/views/getNodeInfo.scala.html b/app/views/getNodeInfo.scala.html new file mode 100644 index 0000000..e77b14d --- /dev/null +++ b/app/views/getNodeInfo.scala.html @@ -0,0 +1,19 @@ +@(info: Seq[String]) + + + + + get nodeInfo + + + +
+ + + + +
name: @info(0)
fullHeight: @info(1)
headersHeight: @info(2)
isMining: @info(3)
+ +
+ + \ No newline at end of file diff --git a/build.sbt b/build.sbt index 0339e6a..d08923a 100644 --- a/build.sbt +++ b/build.sbt @@ -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", "*")) \ No newline at end of file + .map(_ exclude("ch.qos.logback", "*") exclude("ch.qos.logback", "*")) +libraryDependencies ++= Seq( + ws +) \ No newline at end of file diff --git a/conf/routes b/conf/routes index c088631..36cb7c3 100644 --- a/conf/routes +++ b/conf/routes @@ -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) \ No newline at end of file +GET /block/:id controllers.BlockController.findBlockView(id: String) + +GET /nodeinfo/:id controllers.NodeController.nodeinfo(id: Int)