From c1d3d267cdee7d44c190e7635156ce67346ad51f Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Wed, 11 Apr 2018 18:53:33 -0500 Subject: [PATCH] server: Add BlockFutureDataHandler --- .../data/async/BlockFutureDataHandler.scala | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 server/app/com/xsn/explorer/data/async/BlockFutureDataHandler.scala diff --git a/server/app/com/xsn/explorer/data/async/BlockFutureDataHandler.scala b/server/app/com/xsn/explorer/data/async/BlockFutureDataHandler.scala new file mode 100644 index 0000000..2ce5250 --- /dev/null +++ b/server/app/com/xsn/explorer/data/async/BlockFutureDataHandler.scala @@ -0,0 +1,37 @@ +package com.xsn.explorer.data.async + +import javax.inject.Inject + +import com.alexitc.playsonify.core.FutureApplicationResult +import com.xsn.explorer.data.{BlockBlockingDataHandler, BlockDataHandler} +import com.xsn.explorer.executors.DatabaseExecutionContext +import com.xsn.explorer.models.Blockhash +import com.xsn.explorer.models.rpc.Block + +import scala.concurrent.Future + +class BlockFutureDataHandler @Inject() ( + blockBlockingDataHandler: BlockBlockingDataHandler)( + implicit ec: DatabaseExecutionContext) + extends BlockDataHandler[FutureApplicationResult] { + + def upsert(block: Block): FutureApplicationResult[Block] = Future { + blockBlockingDataHandler.upsert(block) + } + + def getBy(blockhash: Blockhash): FutureApplicationResult[Block] = Future { + blockBlockingDataHandler.getBy(blockhash) + } + + def delete(blockhash: Blockhash): FutureApplicationResult[Block] = Future { + blockBlockingDataHandler.delete(blockhash) + } + + def getLatestBlock(): FutureApplicationResult[Block] = Future { + blockBlockingDataHandler.getLatestBlock() + } + + def getFirstBlock(): FutureApplicationResult[Block] = Future { + blockBlockingDataHandler.getFirstBlock() + } +}