gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (ed0c2fcc -> 04a78be8)


From: gnunet
Subject: [libeufin] branch master updated (ed0c2fcc -> 04a78be8)
Date: Tue, 14 Feb 2023 15:04:31 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from ed0c2fcc accounts name filter
     new f1e8253e more cash-out data
     new 04a78be8 cash-out checks

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nexus/src/test/kotlin/SandboxCircuitApiTest.kt     |  5 +++
 .../kotlin/tech/libeufin/sandbox/CircuitApi.kt     | 50 ++++++++++++++++++----
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 10 +++++
 .../main/kotlin/tech/libeufin/sandbox/Helpers.kt   |  5 ++-
 4 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/nexus/src/test/kotlin/SandboxCircuitApiTest.kt 
b/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
index 86bd90f0..bfdfbded 100644
--- a/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
+++ b/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
@@ -118,6 +118,11 @@ class SandboxCircuitApiTest {
                         tanChannel = SupportedTanChannels.FILE // change type 
to enum?
                         account = "foo"
                         status = CashoutOperationStatus.PENDING
+                        cashoutAddress = "not used"
+                        buyAtRatio = "not used"
+                        buyInFee = "not used"
+                        sellAtRatio = "not used"
+                        sellOutFee = "not used"
                     }
                 }
                 R = client.get("/demobanks/default/circuit-api/cashouts") {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index 0b655de4..c1768bf2 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
@@ -96,7 +96,12 @@ data class CashoutOperationInfo(
     val creation_time: Long, // milliseconds
     val confirmation_time: Long?, // milliseconds
     val tan_channel: SupportedTanChannels,
-    val account: String
+    val account: String,
+    val cashout_address: String,
+    val buy_in_fee: String,
+    val buy_at_ratio: String,
+    val sell_out_fee: String,
+    val sell_at_ratio: String
 )
 
 data class CashoutConfirmation(val tan: String)
@@ -228,12 +233,6 @@ fun circuitApi(circuitRoute: Route) {
         // 404 if the operation is not found.
         if (op == null)
             throw notFound("Cash-out operation $operationUuid not found")
-        // 412 if the operation got already confirmed.
-        if (op.status == CashoutOperationStatus.CONFIRMED)
-            throw SandboxError(
-                HttpStatusCode.PreconditionFailed,
-                "Cash-out operation $operationUuid was already confirmed."
-            )
         /**
          * Check the TAN.  Give precedence to the TAN found
          * in the environment, for testing purposes.  If that's
@@ -254,7 +253,20 @@ fun circuitApi(circuitRoute: Route) {
          * NOTE: the funds availability got already checked when this operation
          * was created.  On top of that, the 'wireTransfer()' helper does also
          * check for funds availability.  */
+        val customer = maybeGetCustomer(user ?: throw SandboxError(
+            HttpStatusCode.ServiceUnavailable,
+            "This endpoint isn't served when the authentication is disabled."
+        ))
         transaction {
+            if (op.cashoutAddress != customer?.cashout_address) throw conflict(
+                "Inconsistent cash-out address: ${op.cashoutAddress} vs 
${customer?.cashout_address}"
+            )
+            // 412 if the operation got already confirmed.
+            if (op.status == CashoutOperationStatus.CONFIRMED)
+                throw SandboxError(
+                    HttpStatusCode.PreconditionFailed,
+                    "Cash-out operation $operationUuid was already confirmed."
+                )
             wireTransfer(
                 debitAccount = op.account,
                 creditAccount = "admin",
@@ -287,7 +299,13 @@ fun circuitApi(circuitRoute: Route) {
             creation_time = maybeOperation.creationTime,
             confirmation_time = maybeOperation.confirmationTime,
             tan_channel = maybeOperation.tanChannel,
-            account = maybeOperation.account
+            account = maybeOperation.account,
+            cashout_address = maybeOperation.cashoutAddress,
+            buy_at_ratio = maybeOperation.buyAtRatio,
+            buy_in_fee = maybeOperation.buyInFee,
+            sell_at_ratio = maybeOperation.sellAtRatio,
+            sell_out_fee = maybeOperation.sellOutFee
+
         )
         call.respond(ret)
         return@get
@@ -365,7 +383,14 @@ fun circuitApi(circuitRoute: Route) {
                 "TAN channel '$tanChannel' not supported."
             )
         // check if the user contact data would allow the TAN channel.
-        val customer = getCustomer(username = user)
+        val customer: DemobankCustomerEntity? = maybeGetCustomer(username = 
user)
+        if (customer == null) throw internalServerError(
+            "Customer profile '$user' not found after authenticating it."
+        )
+        if (customer.cashout_address == null) throw SandboxError(
+            HttpStatusCode.PreconditionFailed,
+            "Cash-out address not found.  Did the user register via Circuit 
API?"
+        )
         if ((tanChannel == SupportedTanChannels.EMAIL.name) && (customer.email 
== null))
             throw conflict("E-mail address not found for '$user'.  Can't send 
the TAN")
         if ((tanChannel == SupportedTanChannels.SMS.name) && (customer.phone 
== null))
@@ -399,11 +424,18 @@ fun circuitApi(circuitRoute: Route) {
             CashoutOperationEntity.new {
                 this.amountDebit = req.amount_debit
                 this.amountCredit = req.amount_credit
+                this.buyAtRatio = ratiosAndFees.buy_at_ratio.toString()
+                this.buyInFee = ratiosAndFees.buy_in_fee.toString()
+                this.sellAtRatio = ratiosAndFees.sell_at_ratio.toString()
+                this.sellOutFee = ratiosAndFees.sell_out_fee.toString()
                 this.subject = cashoutSubject
                 this.creationTime = getUTCnow().toInstant().toEpochMilli()
                 this.tanChannel = SupportedTanChannels.valueOf(tanChannel)
                 this.account = user
                 this.tan = getRandomString(5)
+                this.cashoutAddress = customer.cashout_address ?: throw 
internalServerError(
+                    "Cash-out address for '$user' not found, after previous 
check succeeded"
+                )
             }
         }
         // Send the TAN.
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index a496cd3e..b6556cb4 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -441,11 +441,16 @@ object CashoutOperationsTable : LongIdTable() {
      */
     val amountDebit = text("amountDebit")
     val amountCredit = text("amountCredit")
+    val buyAtRatio = text("buyAtRatio")
+    val buyInFee = text("buyInFee")
+    val sellAtRatio = text("sellAtRatio")
+    val sellOutFee = text("sellOutFee")
     val subject = text("subject")
     val creationTime = long("creationTime") // in milliseconds.
     val confirmationTime = long("confirmationTime").nullable() // in 
milliseconds.
     val tanChannel = enumeration("tanChannel", SupportedTanChannels::class)
     val account = text("account")
+    val cashoutAddress = text("cashoutAddress")
     val tan = text("tan")
     val status = enumeration("status", 
CashoutOperationStatus::class).default(CashoutOperationStatus.PENDING)
 }
@@ -455,11 +460,16 @@ class CashoutOperationEntity(id: EntityID<Long>) : 
LongEntity(id) {
     var uuid by CashoutOperationsTable.uuid
     var amountDebit by CashoutOperationsTable.amountDebit
     var amountCredit by CashoutOperationsTable.amountCredit
+    var buyAtRatio by CashoutOperationsTable.buyAtRatio
+    var buyInFee by CashoutOperationsTable.buyInFee
+    var sellAtRatio by CashoutOperationsTable.sellAtRatio
+    var sellOutFee by CashoutOperationsTable.sellOutFee
     var subject by CashoutOperationsTable.subject
     var creationTime by CashoutOperationsTable.creationTime
     var confirmationTime by CashoutOperationsTable.confirmationTime
     var tanChannel by CashoutOperationsTable.tanChannel
     var account by CashoutOperationsTable.account
+    var cashoutAddress by CashoutOperationsTable.cashoutAddress
     var tan by CashoutOperationsTable.tan
     var status by CashoutOperationsTable.status
 }
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
index de22bf34..16f1d6b9 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -236,11 +236,14 @@ fun getHistoryElementFromTransactionRow(
  * customer to own multiple bank accounts.
  */
 fun getCustomer(username: String): DemobankCustomerEntity {
+    return maybeGetCustomer(username) ?: throw notFound("Customer 
'${username}' not found")
+}
+fun maybeGetCustomer(username: String): DemobankCustomerEntity? {
     return transaction {
         DemobankCustomerEntity.find {
             DemobankCustomersTable.username eq username
         }.firstOrNull()
-    } ?: throw notFound("Customer '${username}' not found")
+    }
 }
 
 /**

-- 
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]