Browse Source

server: Add endpoint "GET /blocks/estimate-fee"

bitcoin
Alexis Hernandez 6 years ago
parent
commit
3888041470
  1. 11
      server/app/com/xsn/explorer/services/BlockService.scala
  2. 4
      server/app/controllers/BlocksController.scala
  3. 1
      server/conf/routes

11
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

4
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 {

1
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)

Loading…
Cancel
Save