[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Endpoint to GET withdrawal details.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Endpoint to GET withdrawal details. |
Date: |
Tue, 19 Sep 2023 15:29:55 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 9e836fd0 Endpoint to GET withdrawal details.
9e836fd0 is described below
commit 9e836fd04bf792b2f6b87c17a9ab71c194a9d523
Author: MS <ms@taler.net>
AuthorDate: Tue Sep 19 15:29:34 2023 +0200
Endpoint to GET withdrawal details.
---
.../kotlin/tech/libeufin/bank/talerWebHandlers.kt | 34 ++++++++++++++++++++--
bank/src/main/kotlin/tech/libeufin/bank/types.kt | 11 +++++++
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt
b/bank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt
index bf06f21f..d3bc8e71 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt
@@ -25,10 +25,12 @@
package tech.libeufin.bank
import io.ktor.server.application.*
+import io.ktor.server.plugins.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import net.taler.common.errorcodes.TalerErrorCode
+import net.taler.wallet.crypto.Base32Crockford
import tech.libeufin.util.getBaseUrl
import java.util.*
@@ -67,7 +69,7 @@ fun Routing.talerWebHandlers() {
throw internalServerError("Bank failed at creating the withdraw
operation.")
val bankBaseUrl = call.request.getBaseUrl()
- ?: throw internalServerError("Bank could not find its base URL")
+ ?: throw internalServerError("Bank could not find its own base
URL")
call.respond(BankAccountCreateWithdrawalResponse(
withdrawal_id = opId.toString(),
taler_withdraw_uri = getTalerWithdrawUri(bankBaseUrl,
opId.toString())
@@ -75,7 +77,35 @@ fun Routing.talerWebHandlers() {
return@post
}
get("/accounts/{USERNAME}/withdrawals/{W_ID}") {
- throw NotImplementedError()
+ val c = call.myAuth(TokenScope.readonly) ?: throw unauthorized()
+ val accountName = call.expectUriComponent("USERNAME")
+ // Admin allowed to see the details
+ if (c.login != accountName && c.login != "admin") throw forbidden()
+ // Permissions passed, get the information.
+ val opIdParam: String = call.request.queryParameters.get("W_ID") ?:
throw
+ MissingRequestParameterException("withdrawal_id")
+ val opId = try {
+ UUID.fromString(opIdParam)
+ } catch (e: Exception) {
+ logger.error(e.message)
+ throw badRequest("withdrawal_id query parameter was malformed")
+ }
+ val op = db.talerWithdrawalGet(opId)
+ ?: throw notFound(
+ hint = "Withdrawal operation ${opIdParam} not found",
+ talerEc = TalerErrorCode.TALER_EC_END
+ )
+ call.respond(BankAccountGetWithdrawalResponse(
+ amount = op.amount.toString(),
+ aborted = op.aborted,
+ confirmation_done = op.confirmationDone,
+ selection_done = op.selectionDone,
+ selected_exchange_account = op.selectedExchangePayto,
+ selected_reserve_pub = if (op.reservePub != null) {
+ Base32Crockford.encode(op.reservePub)
+ } else null
+ ))
+ return@get
}
post("/accounts/{USERNAME}/withdrawals/abort") {
throw NotImplementedError()
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/types.kt
b/bank/src/main/kotlin/tech/libeufin/bank/types.kt
index ebbb0f1e..cfe58476 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/types.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/types.kt
@@ -395,3 +395,14 @@ data class BankAccountCreateWithdrawalResponse(
val withdrawal_id: String,
val taler_withdraw_uri: String
)
+
+// Taler withdrawal details response
+@Serializable
+data class BankAccountGetWithdrawalResponse(
+ val amount: String,
+ val aborted: Boolean,
+ val confirmation_done: Boolean,
+ val selection_done: Boolean,
+ val selected_reserve_pub: String? = null,
+ val selected_exchange_account: String? = null
+)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Endpoint to GET withdrawal details.,
gnunet <=