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]) + + +
+ +| name: @info(0) |
| fullHeight: @info(1) |
| headersHeight: @info(2) |
| isMining: @info(3) |