Skip to content

Commit

Permalink
server: Add endpoint "GET /blocks/estimate-fee"
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Apr 16, 2019
1 parent 092f3b7 commit 3888041
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/app/com/xsn/explorer/services/BlockService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/app/controllers/BlocksController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions server/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3888041

Please sign in to comment.