diff --git a/server/app/com/xsn/explorer/services/BlockService.scala b/server/app/com/xsn/explorer/services/BlockService.scala index 95c20ff..313e6aa 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 3dffc80..a0b731f 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 28ccbaa..c51d91e 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)