gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 03/09: Circuit API.


From: gnunet
Subject: [libeufin] 03/09: Circuit API.
Date: Fri, 20 Jan 2023 16:49:37 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit b28f1511dab120ef2bfeef39801a0058c543138b
Author: MS <ms@taler.net>
AuthorDate: Fri Jan 20 14:49:47 2023 +0100

    Circuit API.
    
    Storing and showing more details about a cash-out
    operation -- used to be only the state.
    
    Avoiding showing accounts not added via the Circuit
    API along its "GET /accounts" response.
---
 .../kotlin/tech/libeufin/sandbox/CircuitApi.kt     | 43 +++++++++++++++++++++-
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    |  2 +
 util/src/main/kotlin/HTTP.kt                       |  1 +
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index 0c43dd29..a6e97778 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
@@ -1,5 +1,6 @@
 package tech.libeufin.sandbox
 
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import io.ktor.server.application.*
 import io.ktor.http.*
 import io.ktor.server.request.*
@@ -262,7 +263,32 @@ fun circuitApi(circuitRoute: Route) {
         }
         if (maybeOperation == null)
             throw notFound("Cash-out operation $operationUuid not found.")
-        call.respond(object { val status = maybeOperation.state })
+        call.respond(object {
+            val status = maybeOperation.state
+            val amount_credit = maybeOperation.amountCredit
+            val amount_debit = maybeOperation.amountDebit
+            val subject = maybeOperation.subject
+            val creation_time = maybeOperation.creationTime.toString()
+            val cashout_address = maybeOperation.tanChannel
+            val account = maybeOperation.account
+        })
+        return@get
+    }
+    // Gets the list of all the cash-out operations.
+    circuitRoute.get("/cashouts") {
+        call.request.basicAuth(onlyAdmin = true)
+        val node = jacksonObjectMapper().createObjectNode()
+        val maybeArray = node.putArray("cashouts")
+        transaction {
+            CashoutOperationEntity.all().forEach {
+                maybeArray.add(it.uuid.toString())
+            }
+        }
+        if (maybeArray.size() == 0) {
+            call.respond(HttpStatusCode.NoContent)
+            return@get
+        }
+        call.respond(node)
         return@get
     }
     // Create a cash-out operation.
@@ -325,8 +351,9 @@ fun circuitApi(circuitRoute: Route) {
         val op = transaction {
             CashoutOperationEntity.new {
                 this.amountDebit = req.amount_debit
+                this.amountCredit = req.amount_credit
                 this.subject = cashoutSubject
-                this.creationTime = getUTCnow().toInstant().epochSecond
+                this.creationTime = getUTCnow().toInstant().toEpochMilli()
                 this.tanChannel = tanChannel
                 this.account = user
                 this.tan = getRandomString(5)
@@ -395,6 +422,11 @@ fun circuitApi(circuitRoute: Route) {
         throwIfInstitutionalName(resourceName)
         allowOwnerOrAdmin(username, resourceName)
         val customer = getCustomer(resourceName)
+        /** FIXME: the following query can 404, but should 500.
+         * The reason is that that's the bank's fault if an existing
+         * customer misses the bank account.  Check other calls too,
+         * for the same error.
+         */
         val bankAccount = getBankAccountFromLabel(resourceName)
         /**
          * Throwing when name or cash-out address aren't found ensures
@@ -420,6 +452,13 @@ fun circuitApi(circuitRoute: Route) {
         val customers = mutableListOf<Any>()
         transaction {
             DemobankCustomerEntity.all().forEach {
+                if (it.cashout_address == null) {
+                    logger.debug("Not listing account '${it.username}', as 
that" +
+                            " misses the cash-out address " +
+                            "and therefore doesn't belong to the Circuit API"
+                    )
+                    return@forEach
+                }
                 customers.add(object {
                     val username = it.username
                     val name = it.name
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index f1eba15a..3adb1a27 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -440,6 +440,7 @@ object CashoutOperationsTable : LongIdTable() {
      * local currency bank account.
      */
     val amountDebit = text("amountDebit")
+    val amountCredit = text("amountCredit")
     val subject = text("subject")
     val creationTime = long("creationTime") // in seconds.
     val tanChannel = text("tanChannel")
@@ -452,6 +453,7 @@ class CashoutOperationEntity(id: EntityID<Long>) : 
LongEntity(id) {
     companion object : 
LongEntityClass<CashoutOperationEntity>(CashoutOperationsTable)
     var uuid by CashoutOperationsTable.uuid
     var amountDebit by CashoutOperationsTable.amountDebit
+    var amountCredit by CashoutOperationsTable.amountCredit
     var subject by CashoutOperationsTable.subject
     var creationTime by CashoutOperationsTable.creationTime
     var tanChannel by CashoutOperationsTable.tanChannel
diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt
index 06884a04..0f70c7e4 100644
--- a/util/src/main/kotlin/HTTP.kt
+++ b/util/src/main/kotlin/HTTP.kt
@@ -4,6 +4,7 @@ import UtilError
 import io.ktor.http.*
 import io.ktor.server.application.*
 import io.ktor.server.request.*
+import io.ktor.server.response.*
 import io.ktor.server.util.*
 import io.ktor.util.*
 import logger

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]