diff --git a/server/app/com/xsn/explorer/data/anorm/parsers/BlockParsers.scala b/server/app/com/xsn/explorer/data/anorm/parsers/BlockParsers.scala index 4e9262ce..ba85ffdc 100644 --- a/server/app/com/xsn/explorer/data/anorm/parsers/BlockParsers.scala +++ b/server/app/com/xsn/explorer/data/anorm/parsers/BlockParsers.scala @@ -27,7 +27,7 @@ object BlockParsers { .map { _.getOrElse(throw new RuntimeException("corrupted merkle_root")) } val parseExtractionMethod = str("extraction_method") - .map(Block.ExtractionMethod.withNameInsensitiveOption) + .map(BlockExtractionMethod.withNameInsensitiveOption) .map { _.getOrElse(throw new RuntimeException("corrupted extraction_method")) } val parseSize = int("size").map(Size.apply) diff --git a/server/app/com/xsn/explorer/models/BlockExtractionMethod.scala b/server/app/com/xsn/explorer/models/BlockExtractionMethod.scala new file mode 100644 index 00000000..4e517483 --- /dev/null +++ b/server/app/com/xsn/explorer/models/BlockExtractionMethod.scala @@ -0,0 +1,14 @@ +package com.xsn.explorer.models + +import enumeratum._ + +sealed abstract class BlockExtractionMethod(override val entryName: String) extends EnumEntry + +object BlockExtractionMethod extends Enum[BlockExtractionMethod] { + + val values = findValues + + final case object ProofOfWork extends BlockExtractionMethod("PoW") + final case object ProofOfStake extends BlockExtractionMethod("PoS") + final case object TrustlessProofOfStake extends BlockExtractionMethod("TPoS") +} \ No newline at end of file diff --git a/server/app/com/xsn/explorer/models/persisted/Block.scala b/server/app/com/xsn/explorer/models/persisted/Block.scala index f2edba0a..ffdc721a 100644 --- a/server/app/com/xsn/explorer/models/persisted/Block.scala +++ b/server/app/com/xsn/explorer/models/persisted/Block.scala @@ -1,8 +1,7 @@ package com.xsn.explorer.models.persisted -import com.xsn.explorer.models._ -import com.xsn.explorer.models.values.{Blockhash, Height, Size, TransactionId} -import enumeratum._ +import com.xsn.explorer.models.BlockExtractionMethod +import com.xsn.explorer.models.values._ case class Block( hash: Blockhash, @@ -19,17 +18,4 @@ case class Block( bits: String, chainwork: String, difficulty: BigDecimal, - extractionMethod: Block.ExtractionMethod) - -object Block { - - sealed abstract class ExtractionMethod(override val entryName: String) extends EnumEntry - object ExtractionMethod extends Enum[ExtractionMethod] { - - val values = findValues - - final case object ProofOfWork extends ExtractionMethod("PoW") - final case object ProofOfStake extends ExtractionMethod("PoS") - final case object TrustlessProofOfStake extends ExtractionMethod("TPoS") - } -} + extractionMethod: BlockExtractionMethod) diff --git a/server/app/com/xsn/explorer/models/transformers/package.scala b/server/app/com/xsn/explorer/models/transformers/package.scala index 903f02db..e5f6e7bb 100644 --- a/server/app/com/xsn/explorer/models/transformers/package.scala +++ b/server/app/com/xsn/explorer/models/transformers/package.scala @@ -12,7 +12,7 @@ package object transformers { def toPersistedBlock(rpcBlock: rpc.Block): persisted.Block = { rpcBlock .into[Block] - .withFieldConst(_.extractionMethod, Block.ExtractionMethod.ProofOfWork) // TODO: Get proper method + .withFieldConst(_.extractionMethod, BlockExtractionMethod.ProofOfWork) // TODO: Get proper method .transform } diff --git a/server/test/com/xsn/explorer/helpers/Converters.scala b/server/test/com/xsn/explorer/helpers/Converters.scala index 8c5e4dfc..835e0a3e 100644 --- a/server/test/com/xsn/explorer/helpers/Converters.scala +++ b/server/test/com/xsn/explorer/helpers/Converters.scala @@ -1,16 +1,12 @@ package com.xsn.explorer.helpers import com.xsn.explorer.models._ -import io.scalaland.chimney.dsl._ import scala.language.implicitConversions object Converters { implicit def toPersistedBlock(rpcBlock: rpc.Block): persisted.Block = { - rpcBlock - .into[persisted.Block] - .withFieldConst(_.extractionMethod, persisted.Block.ExtractionMethod.ProofOfWork) // TODO: Detect method - .transform + transformers.toPersistedBlock(rpcBlock) } }