Browse Source

server: Extract the BlockExtractionMethod from the persisted block

master
Alexis Hernandez 6 years ago
parent
commit
469c241931
  1. 2
      server/app/com/xsn/explorer/data/anorm/parsers/BlockParsers.scala
  2. 14
      server/app/com/xsn/explorer/models/BlockExtractionMethod.scala
  3. 20
      server/app/com/xsn/explorer/models/persisted/Block.scala
  4. 2
      server/app/com/xsn/explorer/models/transformers/package.scala
  5. 6
      server/test/com/xsn/explorer/helpers/Converters.scala

2
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)

14
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")
}

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

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

6
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)
}
}

Loading…
Cancel
Save