Browse Source

server: Include circulatingSupply on statistics

scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
44e19e8dc5
  1. 14
      server/app/com/xsn/explorer/models/Statistics.scala
  2. 20
      server/app/com/xsn/explorer/services/StatisticsService.scala
  3. 2
      server/app/controllers/StatisticsController.scala

14
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]
}

20
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
}
}

2
server/app/controllers/StatisticsController.scala

@ -11,6 +11,6 @@ class StatisticsController @Inject() (
extends MyJsonController(cc) {
def getStatus() = publicNoInput { _ =>
statisticsService.getServerStatistics()
statisticsService.getStatistics()
}
}

Loading…
Cancel
Save