Skip to content

Commit

Permalink
server: Fix scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Oct 30, 2021
1 parent 2f6bf9e commit 5a3a1ef
Show file tree
Hide file tree
Showing 113 changed files with 477 additions and 871 deletions.
5 changes: 1 addition & 4 deletions server/.scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ project.excludeFilters = [
]

maxColumn = 120
docstrings = JavaDoc
assumeStandardLibraryStripMargin = false

continuationIndent.callSite = 2
continuationIndent.defnSite = 4

align = none

newlines.alwaysBeforeTopLevelStatements = true
align.preset = "none"

onTestFailure = "To fix this, run 'sbt scalafmt' from the project directory"
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ trait LedgerSynchronizerConfig {
def parallelSynchronizer: Boolean
}

class LedgerSynchronizerPlayConfig @Inject() (config: Configuration)
extends LedgerSynchronizerConfig {
class LedgerSynchronizerPlayConfig @Inject() (config: Configuration) extends LedgerSynchronizerConfig {

override lazy val enabled: Boolean =
config.getOptional[Boolean]("synchronizer.enabled").getOrElse(false)
Expand Down
6 changes: 1 addition & 5 deletions server/app/com/xsn/explorer/data/BalanceDataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package com.xsn.explorer.data

import com.alexitc.playsonify.core.ApplicationResult
import com.alexitc.playsonify.models.ordering.FieldOrdering
import com.alexitc.playsonify.models.pagination.{
Limit,
PaginatedQuery,
PaginatedResult
}
import com.alexitc.playsonify.models.pagination.{Limit, PaginatedQuery, PaginatedResult}
import com.xsn.explorer.models.fields.BalanceField
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
Expand Down
6 changes: 1 addition & 5 deletions server/app/com/xsn/explorer/data/BlockDataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package com.xsn.explorer.data

import com.alexitc.playsonify.core.ApplicationResult
import com.alexitc.playsonify.models.ordering.{FieldOrdering, OrderingCondition}
import com.alexitc.playsonify.models.pagination.{
Limit,
PaginatedQuery,
PaginatedResult
}
import com.alexitc.playsonify.models.pagination.{Limit, PaginatedQuery, PaginatedResult}
import com.xsn.explorer.models.fields.BlockField
import com.xsn.explorer.models.persisted.{Block, BlockHeader, BlockInfo}
import com.xsn.explorer.models.values.{Blockhash, Height}
Expand Down
13 changes: 5 additions & 8 deletions server/app/com/xsn/explorer/data/LedgerDataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import com.xsn.explorer.models.persisted.Block

import scala.language.higherKinds

/** The ledger could be handled as a stack, we should be able to keep the
* consistency even in the case of reorganizations using just stack operations.
/** The ledger could be handled as a stack, we should be able to keep the consistency even in the case of
* reorganizations using just stack operations.
*/
trait LedgerDataHandler[F[_]] {

/** Append a block to the ledger, the method will succeed only in the
* following scenarios:
/** Append a block to the ledger, the method will succeed only in the following scenarios:
* - The ledger is empty and the block is the genesis one.
* - The ledger has some blocks and the block goes just after the latest
* one.
* - The ledger has some blocks and the block goes just after the latest one.
*/
def push(
block: Block.HasTransactions,
Expand All @@ -25,8 +23,7 @@ trait LedgerDataHandler[F[_]] {
rewards: Option[BlockRewards]
): F[Unit]

/** Remove the latest block from the ledger, it will succeed only if the
* ledger is not empty.
/** Remove the latest block from the ledger, it will succeed only if the ledger is not empty.
*/
def pop(): F[Block]
}
Expand Down
9 changes: 2 additions & 7 deletions server/app/com/xsn/explorer/data/StatisticsDataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package com.xsn.explorer.data
import java.time.Instant
import com.alexitc.playsonify.core.ApplicationResult
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.models.{
AddressesReward,
BlockRewardsSummary,
Statistics
}
import com.xsn.explorer.models.{AddressesReward, BlockRewardsSummary, Statistics}

import scala.language.higherKinds

Expand All @@ -26,5 +22,4 @@ trait StatisticsDataHandler[F[_]] {
def getStakingCoins(): F[BigDecimal]
}

trait StatisticsBlockingDataHandler
extends StatisticsDataHandler[ApplicationResult]
trait StatisticsBlockingDataHandler extends StatisticsDataHandler[ApplicationResult]
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ trait TPoSContractDataHandler[F[_]] {
def getBy(address: Address): F[List[TPoSContract]]
}

trait TPoSContractBlockingDataHandler
extends TPoSContractDataHandler[ApplicationResult]
trait TPoSContractBlockingDataHandler extends TPoSContractDataHandler[ApplicationResult]
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ trait TransactionDataHandler[F[_]] {
): F[List[Transaction.HasIO]]
}

trait TransactionBlockingDataHandler
extends TransactionDataHandler[ApplicationResult]
trait TransactionBlockingDataHandler extends TransactionDataHandler[ApplicationResult]
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ package com.xsn.explorer.data.anorm
import java.sql.Connection

import com.alexitc.playsonify.core.ApplicationResult
import com.xsn.explorer.errors.{
PostgresError,
PostgresForeignKeyViolationError,
UnknownPostgresError
}
import com.xsn.explorer.errors.{PostgresError, PostgresForeignKeyViolationError, UnknownPostgresError}
import org.postgresql.util.PSQLException
import org.scalactic.Bad
import play.api.db.Database

/** Allow us to map a PSQLException to a sub type of PostgresError.
*
* This is helpful to differentiate between errors caused by input data and
* failures that can not be prevented, these failures are thrown.
* This is helpful to differentiate between errors caused by input data and failures that can not be prevented, these
* failures are thrown.
*
* The errors are mapped based on postgres error codes:
* - see: https://www.postgresql.org/docs/9.6/static/errcodes-appendix.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package com.xsn.explorer.data.anorm

import com.alexitc.playsonify.core.ApplicationResult
import com.alexitc.playsonify.models.ordering.FieldOrdering
import com.alexitc.playsonify.models.pagination.{
Limit,
PaginatedQuery,
PaginatedResult
}
import com.alexitc.playsonify.models.pagination.{Limit, PaginatedQuery, PaginatedResult}
import com.xsn.explorer.data.BalanceBlockingDataHandler
import com.xsn.explorer.data.anorm.dao.BalancePostgresDAO
import com.xsn.explorer.errors.BalanceUnknownError
Expand All @@ -33,13 +29,12 @@ class BalancePostgresDataHandler @Inject() (
override def get(
query: PaginatedQuery,
ordering: FieldOrdering[BalanceField]
): ApplicationResult[PaginatedResult[Balance]] = withConnection {
implicit conn =>
val balances = balancePostgresDAO.get(query, ordering)
val total = balancePostgresDAO.count
val result = PaginatedResult(query.offset, query.limit, total, balances)
): ApplicationResult[PaginatedResult[Balance]] = withConnection { implicit conn =>
val balances = balancePostgresDAO.get(query, ordering)
val total = balancePostgresDAO.count
val result = PaginatedResult(query.offset, query.limit, total, balances)

Good(result)
Good(result)
}

override def getBy(address: Address): ApplicationResult[Balance] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package com.xsn.explorer.data.anorm
import com.alexitc.playsonify.core.ApplicationResult
import com.alexitc.playsonify.models.ordering.{FieldOrdering, OrderingCondition}
import com.alexitc.playsonify.models.pagination
import com.alexitc.playsonify.models.pagination.{
PaginatedQuery,
PaginatedResult
}
import com.alexitc.playsonify.models.pagination.{PaginatedQuery, PaginatedResult}
import com.xsn.explorer.data.BlockBlockingDataHandler
import com.xsn.explorer.data.anorm.dao.BlockPostgresDAO
import com.xsn.explorer.errors._
Expand Down Expand Up @@ -38,18 +35,17 @@ class BlockPostgresDataHandler @Inject() (
override def getBy(
paginatedQuery: PaginatedQuery,
ordering: FieldOrdering[BlockField]
): ApplicationResult[PaginatedResult[Block]] = withConnection {
implicit conn =>
val data = blockPostgresDAO.getBy(paginatedQuery, ordering)
val total = blockPostgresDAO.count
val result = PaginatedResult(
paginatedQuery.offset,
paginatedQuery.limit,
total,
data
)

Good(result)
): ApplicationResult[PaginatedResult[Block]] = withConnection { implicit conn =>
val data = blockPostgresDAO.getBy(paginatedQuery, ordering)
val total = blockPostgresDAO.count
val result = PaginatedResult(
paginatedQuery.offset,
paginatedQuery.limit,
total,
data
)

Good(result)
}

override def delete(blockhash: Blockhash): ApplicationResult[Block] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import com.alexitc.playsonify.models.ApplicationError
import com.xsn.explorer.data.LedgerBlockingDataHandler
import com.xsn.explorer.data.anorm.dao._
import com.xsn.explorer.data.anorm.serializers.BlockRewardPostgresSerializer
import com.xsn.explorer.errors.{
PostgresForeignKeyViolationError,
PreviousBlockMissingError,
RepeatedBlockHeightError
}
import com.xsn.explorer.errors.{PostgresForeignKeyViolationError, PreviousBlockMissingError, RepeatedBlockHeightError}
import com.xsn.explorer.gcs.GolombCodedSet
import com.xsn.explorer.models.persisted.{Balance, Block}
import com.xsn.explorer.models.{BlockRewards, TPoSContract}
Expand All @@ -32,9 +28,8 @@ class LedgerPostgresDataHandler @Inject() (
) extends LedgerBlockingDataHandler
with AnormPostgresDataHandler {

/** Push a block into the database chain, note that even if the block is
* supposed to have a next block, we remove the link because that block is
* not stored yet.
/** Push a block into the database chain, note that even if the block is supposed to have a next block, we remove the
* link because that block is not stored yet.
*/
override def push(
block: Block.HasTransactions,
Expand Down Expand Up @@ -68,16 +63,15 @@ class LedgerPostgresDataHandler @Inject() (

/** Pop a block from the database chain (if exists)
*/
override def pop(): ApplicationResult[Block] = withTransaction {
implicit conn =>
val result = for {
block <- blockPostgresDAO.getLatestBlock
_ <- deleteBlockCascade(block)
} yield block
override def pop(): ApplicationResult[Block] = withTransaction { implicit conn =>
val result = for {
block <- blockPostgresDAO.getLatestBlock
_ <- deleteBlockCascade(block)
} yield block

result
.map(Good(_))
.getOrElse(throw new RuntimeException("Unable to pop block"))
result
.map(Good(_))
.getOrElse(throw new RuntimeException("Unable to pop block"))
}

private def upsertBlockCascade(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import com.alexitc.playsonify.core.ApplicationResult
import com.xsn.explorer.data.StatisticsBlockingDataHandler
import com.xsn.explorer.data.anorm.dao.{StatisticsPostgresDAO, TPoSContractDAO}
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.models.{
AddressesReward,
BlockRewardsSummary,
Statistics
}
import com.xsn.explorer.models.{AddressesReward, BlockRewardsSummary, Statistics}

import javax.inject.Inject
import org.scalactic.Good
Expand All @@ -22,10 +18,9 @@ class StatisticsPostgresDataHandler @Inject() (
) extends StatisticsBlockingDataHandler
with AnormPostgresDataHandler {

override def getStatistics(): ApplicationResult[Statistics] = withConnection {
implicit conn =>
val result = statisticsDAO.getStatistics
Good(result)
override def getStatistics(): ApplicationResult[Statistics] = withConnection { implicit conn =>
val result = statisticsDAO.getStatistics
Good(result)
}

override def getRewardsSummary(
Expand Down
Loading

0 comments on commit 5a3a1ef

Please sign in to comment.