From 44e19e8dc55435ecf58a1fe9e20f59b57771e440 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Wed, 11 Apr 2018 23:48:34 -0500 Subject: [PATCH] server: Include circulatingSupply on statistics --- .../com/xsn/explorer/models/Statistics.scala | 14 +++++++++++++ .../explorer/services/StatisticsService.scala | 20 +++++++++++++++---- .../controllers/StatisticsController.scala | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 server/app/com/xsn/explorer/models/Statistics.scala diff --git a/server/app/com/xsn/explorer/models/Statistics.scala b/server/app/com/xsn/explorer/models/Statistics.scala new file mode 100644 index 0000000..df9f716 --- /dev/null +++ b/server/app/com/xsn/explorer/models/Statistics.scala @@ -0,0 +1,14 @@ +package com.xsn.explorer.models + +import play.api.libs.json.{Json, Writes} + +case class Statistics( + height: Height, + transactions: Int, + totalSupply: BigDecimal, + circulatingSupply: BigDecimal) + +object Statistics { + + implicit val writes: Writes[Statistics] = Json.writes[Statistics] +} diff --git a/server/app/com/xsn/explorer/services/StatisticsService.scala b/server/app/com/xsn/explorer/services/StatisticsService.scala index 9b26195..3fd507d 100644 --- a/server/app/com/xsn/explorer/services/StatisticsService.scala +++ b/server/app/com/xsn/explorer/services/StatisticsService.scala @@ -3,11 +3,23 @@ package com.xsn.explorer.services import javax.inject.Inject import com.alexitc.playsonify.core.FutureApplicationResult -import com.xsn.explorer.models.rpc.ServerStatistics +import com.alexitc.playsonify.core.FutureOr.Implicits.FutureOps +import com.xsn.explorer.data.async.BalanceFutureDataHandler +import com.xsn.explorer.models.Statistics -class StatisticsService @Inject() (xsnService: XSNService) { +import scala.concurrent.ExecutionContext - def getServerStatistics(): FutureApplicationResult[ServerStatistics] = { - xsnService.getServerStatistics() +class StatisticsService @Inject() ( + xsnService: XSNService, + balanceFutureDataHandler: BalanceFutureDataHandler)( + implicit ec: ExecutionContext) { + + def getStatistics(): FutureApplicationResult[Statistics] = { + val result = for { + server <- xsnService.getServerStatistics().toFutureOr + circulatingSupply <- balanceFutureDataHandler.getCirculatingSupply().toFutureOr + } yield Statistics(server.height, server.transactions, server.totalSupply, circulatingSupply) + + result.toFuture } } diff --git a/server/app/controllers/StatisticsController.scala b/server/app/controllers/StatisticsController.scala index 6e132a1..7ac9923 100644 --- a/server/app/controllers/StatisticsController.scala +++ b/server/app/controllers/StatisticsController.scala @@ -11,6 +11,6 @@ class StatisticsController @Inject() ( extends MyJsonController(cc) { def getStatus() = publicNoInput { _ => - statisticsService.getServerStatistics() + statisticsService.getStatistics() } }