Browse Source

server: Remove temporal shift while computing supplies

prometheus-integration
Alexis Hernandez 6 years ago
parent
commit
1c0c271864
  1. 5
      server/app/com/xsn/explorer/data/anorm/dao/StatisticsPostgresDAO.scala
  2. 14
      server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala

5
server/app/com/xsn/explorer/data/anorm/dao/StatisticsPostgresDAO.scala

@ -26,10 +26,7 @@ class StatisticsPostgresDAO {
""".stripMargin
).as(StatisticsParsers.parseStatistics.single)
val shiftBy = BigDecimal(6000000)
val totalSupply = result.totalSupply.map(x => (x - shiftBy) max 0)
val circulatingSupply = result.circulatingSupply.map(x => (x - shiftBy) max 0)
result.copy(totalSupply = totalSupply, circulatingSupply = circulatingSupply)
result
}
}

14
server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala

@ -33,6 +33,7 @@ class StatisticsPostgresDataHandlerSpec extends PostgresDataHandlerSpec {
}
val balance = Balance(hiddenAddress, received = BigDecimal(1000), spent = BigDecimal(500))
setAvailableCoins(balance.available)
balanceDataHandler.upsert(balance).isGood mustEqual true
val result = dataHandler.getStatistics().get
@ -45,10 +46,23 @@ class StatisticsPostgresDataHandlerSpec extends PostgresDataHandlerSpec {
val totalSupply = dataHandler.getStatistics().get.totalSupply.getOrElse(0)
val balance = Balance(burnAddress, received = BigDecimal(1000), spent = BigDecimal(500))
setAvailableCoins(balance.available)
balanceDataHandler.upsert(balance).isGood mustEqual true
val result = dataHandler.getStatistics().get
result.totalSupply.value mustEqual totalSupply
}
}
private def setAvailableCoins(total: BigDecimal) = {
database.withConnection { implicit conn =>
_root_.anorm.SQL(
s"""
|UPDATE aggregated_amounts
|SET value = value + $total
|WHERE name = 'available_coins'
""".stripMargin
).executeUpdate()
}
}
}

Loading…
Cancel
Save