From 3888041470f7ac7eae2acb5dd9a195f40995f8ed Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Tue, 16 Apr 2019 13:35:25 -0600 Subject: [PATCH] server: Add endpoint "GET /blocks/estimate-fee" --- .../app/com/xsn/explorer/services/BlockService.scala | 11 ++++++++++- server/app/controllers/BlocksController.scala | 4 ++++ server/conf/routes | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/app/com/xsn/explorer/services/BlockService.scala b/server/app/com/xsn/explorer/services/BlockService.scala index 95c20ff4..313e6aa0 100644 --- a/server/app/com/xsn/explorer/services/BlockService.scala +++ b/server/app/com/xsn/explorer/services/BlockService.scala @@ -7,7 +7,7 @@ import com.alexitc.playsonify.models.pagination.{Limit, Offset, PaginatedQuery} import com.alexitc.playsonify.validators.PaginatedQueryValidator import com.xsn.explorer.cache.BlockHeaderCache import com.xsn.explorer.data.async.BlockFutureDataHandler -import com.xsn.explorer.errors.BlockRewardsNotFoundError +import com.xsn.explorer.errors.{BlockRewardsNotFoundError, XSNMessageError} import com.xsn.explorer.models._ import com.xsn.explorer.models.persisted.BlockHeader import com.xsn.explorer.models.rpc.{Block, TransactionVIN} @@ -159,6 +159,15 @@ class BlockService @Inject() ( } } + def estimateFee(nBlocks: Int): FutureApplicationResult[JsValue] = { + if (nBlocks >= 1 && nBlocks <= 1000) { + xsnService.estimateSmartFee(nBlocks) + } else { + val error = XSNMessageError("The nBlocks should be between 1 and 1000") + Future.successful(Bad(error).accumulating) + } + } + private def isPoS(block: rpc.Block): FutureApplicationResult[Boolean] = { val result = for { coinbaseTxid <- blockLogic.getCoinbase(block).toFutureOr diff --git a/server/app/controllers/BlocksController.scala b/server/app/controllers/BlocksController.scala index 3dffc80a..a0b731fe 100644 --- a/server/app/controllers/BlocksController.scala +++ b/server/app/controllers/BlocksController.scala @@ -60,6 +60,10 @@ class BlocksController @Inject() ( def getLightTransactionsV2(blockhash: String, limit: Int, lastSeenTxid: Option[String]) = public { _ => transactionService.getLightWalletTransactionsByBlockhash(blockhash, Limit(limit), lastSeenTxid) } + + def estimateFee(nBlocks: Int) = public { _ => + blockService.estimateFee(nBlocks) + } } object BlocksController { diff --git a/server/conf/routes b/server/conf/routes index 28ccbaaa..c51d91e7 100644 --- a/server/conf/routes +++ b/server/conf/routes @@ -18,6 +18,7 @@ GET /addresses/:address/utxos controllers.AddressesContro GET /blocks controllers.BlocksController.getLatestBlocks() GET /blocks/headers controllers.BlocksController.getBlockHeaders(lastSeenHash: Option[String], limit: Int ?= 10, order: String ?= "asc") +GET /blocks/estimate-fee controllers.BlocksController.estimateFee(nBlocks: Int ?= 1) GET /blocks/:query controllers.BlocksController.getDetails(query: String) GET /blocks/:query/raw controllers.BlocksController.getRawBlock(query: String)