Browse Source

server: Persist the block extraction method while synchronizing the blocks

master
Alexis Hernandez 6 years ago
parent
commit
a926191a77
  1. 4
      server/app/com/xsn/explorer/models/transformers/package.scala
  2. 4
      server/app/com/xsn/explorer/services/LedgerSynchronizerService.scala
  3. 2
      server/test/com/xsn/explorer/helpers/Converters.scala
  4. 3
      server/test/com/xsn/explorer/services/LedgerSynchronizerServiceSpec.scala

4
server/app/com/xsn/explorer/models/transformers/package.scala

@ -9,10 +9,10 @@ import io.scalaland.chimney.dsl._
*/
package object transformers {
def toPersistedBlock(rpcBlock: rpc.Block): persisted.Block = {
def toPersistedBlock(rpcBlock: rpc.Block, extractionMethod: BlockExtractionMethod): persisted.Block = {
rpcBlock
.into[Block]
.withFieldConst(_.extractionMethod, BlockExtractionMethod.ProofOfWork) // TODO: Get proper method
.withFieldConst(_.extractionMethod, extractionMethod)
.transform
}

4
server/app/com/xsn/explorer/services/LedgerSynchronizerService.scala

@ -18,6 +18,7 @@ class LedgerSynchronizerService @Inject() (
xsnService: XSNService,
transactionService: TransactionService,
transactionRPCService: TransactionRPCService,
blockService: BlockService,
ledgerDataHandler: LedgerFutureDataHandler,
blockDataHandler: BlockFutureDataHandler)(
implicit ec: ExecutionContext) {
@ -161,8 +162,9 @@ class LedgerSynchronizerService @Inject() (
private def getRPCBlock(blockhash: Blockhash): FutureApplicationResult[(Block, List[Transaction.HasIO])] = {
val result = for {
rpcBlock <- xsnService.getBlock(blockhash).toFutureOr
extractionMethod <- blockService.extractionMethod(rpcBlock).toFutureOr
transactions <- transactionRPCService.getTransactions(rpcBlock.transactions).toFutureOr
} yield (toPersistedBlock(rpcBlock), transactions)
} yield (toPersistedBlock(rpcBlock, extractionMethod), transactions)
result.toFuture
}

2
server/test/com/xsn/explorer/helpers/Converters.scala

@ -7,6 +7,6 @@ import scala.language.implicitConversions
object Converters {
implicit def toPersistedBlock(rpcBlock: rpc.Block): persisted.Block = {
transformers.toPersistedBlock(rpcBlock)
transformers.toPersistedBlock(rpcBlock, BlockExtractionMethod.ProofOfWork)
}
}

3
server/test/com/xsn/explorer/services/LedgerSynchronizerServiceSpec.scala

@ -11,6 +11,7 @@ import com.xsn.explorer.helpers._
import com.xsn.explorer.models.rpc.Block
import com.xsn.explorer.models.values.{Blockhash, Height}
import com.xsn.explorer.parsers.TransactionOrderingParser
import com.xsn.explorer.services.logic.{BlockLogic, TransactionLogic}
import org.scalactic.{Bad, Good, One, Or}
import org.scalatest.BeforeAndAfter
import org.scalatest.concurrent.ScalaFutures
@ -214,11 +215,13 @@ class LedgerSynchronizerServiceSpec extends PostgresDataHandlerSpec with BeforeA
new TransactionOrderingParser,
new TransactionFutureDataHandler(transactionDataHandler)(Executors.databaseEC))
val blockService = new BlockService(xsnService, new BlockLogic, new TransactionLogic)
val transactionRPCService = new TransactionRPCService(xsnService)
new LedgerSynchronizerService(
xsnService,
transactionService,
transactionRPCService,
blockService,
new LedgerFutureDataHandler(dataHandler)(Executors.databaseEC),
new BlockFutureDataHandler(blockDataHandler)(Executors.databaseEC))
}

Loading…
Cancel
Save