From d4acc18d9fde136309a2f03deb20e5cb450b10d9 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Mon, 5 Nov 2018 00:26:13 -0700 Subject: [PATCH] server: Add endpoint "POST /transactions/latest" This retrieves the latest transaction id for the given addresses. --- .../app/com/xsn/explorer/services/TransactionService.scala | 5 +++++ server/app/controllers/TransactionsController.scala | 5 +++++ server/conf/routes | 1 + 3 files changed, 11 insertions(+) diff --git a/server/app/com/xsn/explorer/services/TransactionService.scala b/server/app/com/xsn/explorer/services/TransactionService.scala index bd8aa50..3e1efcf 100644 --- a/server/app/com/xsn/explorer/services/TransactionService.scala +++ b/server/app/com/xsn/explorer/services/TransactionService.scala @@ -114,6 +114,11 @@ class TransactionService @Inject() ( result.toFuture } + + def getLatestTransactionBy(addresses: List[Address]): FutureApplicationResult[Map[String, String]] = { + transactionFutureDataHandler.getLatestTransactionBy(addresses) + } + private def getTransactionValue(vin: TransactionVIN): FutureApplicationResult[TransactionValue] = { val valueMaybe = for { value <- vin.value diff --git a/server/app/controllers/TransactionsController.scala b/server/app/controllers/TransactionsController.scala index fa2a7d5..16351b1 100644 --- a/server/app/controllers/TransactionsController.scala +++ b/server/app/controllers/TransactionsController.scala @@ -3,6 +3,7 @@ package controllers import javax.inject.Inject import com.alexitc.playsonify.models.PublicContextWithModel +import com.xsn.explorer.models.Address import com.xsn.explorer.models.request.SendRawTransactionRequest import com.xsn.explorer.services.TransactionService import controllers.common.{MyJsonController, MyJsonControllerComponents} @@ -23,4 +24,8 @@ class TransactionsController @Inject() ( def sendRawTransaction() = publicWithInput { ctx: PublicContextWithModel[SendRawTransactionRequest] => transactionService.sendRawTransaction(ctx.model.hex) } + + def getLatestByAddresses() = publicWithInput { ctx: PublicContextWithModel[List[Address]] => + transactionService.getLatestTransactionBy(ctx.model) + } } diff --git a/server/conf/routes b/server/conf/routes index 23f3a7d..eeedc6c 100644 --- a/server/conf/routes +++ b/server/conf/routes @@ -8,6 +8,7 @@ GET /health controllers.HealthController.check() GET /transactions/:txid controllers.TransactionsController.getTransaction(txid: String) GET /transactions/:txid/raw controllers.TransactionsController.getRawTransaction(txid: String) POST /transactions controllers.TransactionsController.sendRawTransaction() +POST /transactions/latest controllers.TransactionsController.getLatestByAddresses() GET /addresses/:address controllers.AddressesController.getBy(address: String) GET /addresses/:address/transactions controllers.AddressesController.getTransactions(address: String, offset: Int ?= 0, limit: Int ?= 10, orderBy: String ?= "")