diff --git a/server/app/com/xsn/explorer/models/transformers/package.scala b/server/app/com/xsn/explorer/models/transformers/package.scala new file mode 100644 index 0000000..d960f3f --- /dev/null +++ b/server/app/com/xsn/explorer/models/transformers/package.scala @@ -0,0 +1,18 @@ +package com.xsn.explorer.models + +import com.xsn.explorer.models.persisted.Block +import io.scalaland.chimney.dsl._ + +/** + * The package is a bridge between model domains, for example, sometimes you will have a rpc.Block but need a + * persisted.Block, this is where the transormation logic lives. + */ +package object transformers { + + def toPersistedBlock(rpcBlock: rpc.Block): persisted.Block = { + rpcBlock + .into[Block] + .withFieldConst(_.extractionMethod, Block.ExtractionMethod.ProofOfWork) // TODO: Get proper method + .transform + } +} diff --git a/server/app/com/xsn/explorer/services/LedgerSynchronizerService.scala b/server/app/com/xsn/explorer/services/LedgerSynchronizerService.scala index 5bb2eaa..02c1349 100644 --- a/server/app/com/xsn/explorer/services/LedgerSynchronizerService.scala +++ b/server/app/com/xsn/explorer/services/LedgerSynchronizerService.scala @@ -5,9 +5,9 @@ import com.alexitc.playsonify.core.FutureOr.Implicits.{FutureOps, OptionOps} import com.xsn.explorer.data.async.{BlockFutureDataHandler, LedgerFutureDataHandler} import com.xsn.explorer.errors.BlockNotFoundError import com.xsn.explorer.models.persisted.Block +import com.xsn.explorer.models.transformers._ import com.xsn.explorer.models.{Blockhash, Height, Transaction} import com.xsn.explorer.util.Extensions.FutureOrExt -import io.scalaland.chimney.dsl._ import javax.inject.Inject import org.scalactic.Good import org.slf4j.LoggerFactory @@ -162,11 +162,7 @@ class LedgerSynchronizerService @Inject() ( val result = for { rpcBlock <- xsnService.getBlock(blockhash).toFutureOr transactions <- transactionRPCService.getTransactions(rpcBlock.transactions).toFutureOr - block = rpcBlock - .into[Block] - .withFieldConst(_.extractionMethod, Block.ExtractionMethod.ProofOfWork) // TODO: Get proper method - .transform - } yield (block, transactions) + } yield (toPersistedBlock(rpcBlock), transactions) result.toFuture }