Skip to content

Commit

Permalink
server: Extract the BlockExtractionMethod from the persisted block
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Feb 18, 2019
1 parent fc0696a commit 469c241
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions server/app/com/xsn/explorer/models/BlockExtractionMethod.scala
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 17 deletions server/app/com/xsn/explorer/models/persisted/Block.scala
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 1 addition & 5 deletions server/test/com/xsn/explorer/helpers/Converters.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 469c241

Please sign in to comment.