gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 01/02: more cash-out data


From: gnunet
Subject: [libeufin] 01/02: more cash-out data
Date: Tue, 14 Feb 2023 15:04:32 +0100

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

ms pushed a commit to branch master
in repository libeufin.

commit f1e8253e6cf202d3ab0bac33cd510a47b94f7e40
Author: MS <ms@taler.net>
AuthorDate: Tue Feb 14 14:40:33 2023 +0100

    more cash-out data
    
    storing the target address and the exchange
    rates and fees upon the creation of a cash-out
    operation
---
 nexus/src/test/kotlin/SandboxCircuitApiTest.kt     |  5 ++++
 .../kotlin/tech/libeufin/sandbox/CircuitApi.kt     | 31 +++++++++++++++++++---
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 10 +++++++
 .../main/kotlin/tech/libeufin/sandbox/Helpers.kt   |  5 +++-
 4 files changed, 47 insertions(+), 4 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..31ba0274 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)
@@ -287,7 +292,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 +376,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 +417,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]