gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 01/02: bank DB: creating cash-out operations.


From: gnunet
Subject: [libeufin] 01/02: bank DB: creating cash-out operations.
Date: Sat, 02 Sep 2023 11:01:24 +0200

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

ms pushed a commit to branch master
in repository libeufin.

commit 6da1ee06fe2bac9c601f3d33df40de6f139e8a34
Author: MS <ms@taler.net>
AuthorDate: Sat Sep 2 09:00:42 2023 +0200

    bank DB: creating cash-out operations.
---
 .../main/kotlin/tech/libeufin/sandbox/Database.kt  | 90 +++++++++++++++++++++-
 sandbox/src/test/kotlin/DatabaseTest.kt            | 21 +++++
 2 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Database.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Database.kt
index dde9d47b..ec6a3196 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Database.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Database.kt
@@ -37,7 +37,11 @@ data class BankAccount(
 )
 
 enum class TransactionDirection {
-    Credit, Debit
+    credit, debit
+}
+
+enum class TanChannel {
+    sms, email, file
 }
 
 data class BankInternalTransaction(
@@ -79,6 +83,25 @@ data class TalerWithdrawalOperation(
     val walletBankAccount: Long
 )
 
+data class Cashout(
+    val cashoutUuid: UUID,
+    val localTransaction: Long? = null,
+    val amountDebit: TalerAmount,
+    val amountCredit: TalerAmount,
+    val buyAtRatio: Int,
+    val buyInFee: TalerAmount,
+    val sellAtRatio: Int,
+    val sellOutFee: TalerAmount,
+    val subject: String,
+    val creationTime: Long,
+    val tanConfirmationTime: Long? = null,
+    val tanChannel: TanChannel,
+    val tanCode: String,
+    val bankAccount: Long,
+    val cashoutAddress: String,
+    val cashoutCurrency: String
+)
+
 class Database(private val dbConfig: String) {
     private var dbConn: PgConnection? = null
     private var dbCtr: Int = 0
@@ -119,7 +142,8 @@ class Database(private val dbConfig: String) {
             stmt.execute()
         } catch (e: SQLException) {
             logger.error(e.message)
-            if (e.errorCode == 0) return false // unique key violation.
+            // NOTE: it seems that _every_ error gets the 0 code.
+            if (e.errorCode == 0) return false
             // rethrowing, not to hide other types of errors.
             throw e
         }
@@ -367,8 +391,8 @@ class Database(private val dbConfig: String) {
                         endToEndId = it.getString("end_to_end_id"),
                         direction = it.getString("direction").run {
                             when(this) {
-                                "credit" -> TransactionDirection.Credit
-                                "debit" -> TransactionDirection.Debit
+                                "credit" -> TransactionDirection.credit
+                                "debit" -> TransactionDirection.debit
                                 else -> throw internalServerError("Wrong 
direction in transaction: $this")
                             }
                         },
@@ -466,6 +490,64 @@ class Database(private val dbConfig: String) {
         stmt.setObject(1, opUUID)
         return myExecute(stmt)
     }
+
+    fun cashoutCreate(op: Cashout): Boolean {
+        reconnect()
+        val stmt = prepare("""
+            INSERT INTO cashout_operations (
+              cashout_uuid
+              ,amount_debit 
+              ,amount_credit 
+              ,buy_at_ratio
+              ,buy_in_fee 
+              ,sell_at_ratio
+              ,sell_out_fee
+              ,subject
+              ,creation_time
+              ,tan_channel
+              ,tan_code
+              ,bank_account
+              ,cashout_address
+              ,cashout_currency
+               )
+            VALUES (
+             ?
+             ,(?,?)::taler_amount
+             ,(?,?)::taler_amount
+             ,?
+             ,(?,?)::taler_amount
+             ,?
+             ,(?,?)::taler_amount
+             ,?
+             ,?
+             ,?::tan_enum
+             ,?
+             ,?
+             ,?
+             ,?
+           );
+        """)
+        stmt.setObject(1, op.cashoutUuid)
+        stmt.setLong(2, op.amountDebit.value)
+        stmt.setInt(3, op.amountDebit.frac)
+        stmt.setLong(4, op.amountCredit.value)
+        stmt.setInt(5, op.amountCredit.frac)
+        stmt.setInt(6, op.buyAtRatio)
+        stmt.setLong(7, op.buyInFee.value)
+        stmt.setInt(8, op.buyInFee.frac)
+        stmt.setInt(9, op.sellAtRatio)
+        stmt.setLong(10, op.sellOutFee.value)
+        stmt.setInt(11, op.sellOutFee.frac)
+        stmt.setString(12, op.subject)
+        stmt.setLong(13, op.creationTime)
+        stmt.setString(14, op.tanChannel.name)
+        stmt.setString(15, op.tanCode)
+        stmt.setLong(16, op.bankAccount)
+        stmt.setString(17, op.cashoutAddress)
+        stmt.setString(18, op.cashoutCurrency)
+        return myExecute(stmt)
+    }
+
     // NOTE: EBICS not needed for BFH and NB.
 
 }
diff --git a/sandbox/src/test/kotlin/DatabaseTest.kt 
b/sandbox/src/test/kotlin/DatabaseTest.kt
index 2ca6aeb3..cbe59d08 100644
--- a/sandbox/src/test/kotlin/DatabaseTest.kt
+++ b/sandbox/src/test/kotlin/DatabaseTest.kt
@@ -215,4 +215,25 @@ class DatabaseTest {
         )
         assert(res.isEmpty())
     }
+    @Test
+    fun cashoutTest() {
+        val db = initDb()
+        val op = Cashout(
+            cashoutUuid = UUID.randomUUID(),
+            amountDebit = TalerAmount(1, 0),
+            amountCredit = TalerAmount(2, 0),
+            bankAccount = 1L,
+            buyAtRatio = 3,
+            buyInFee = TalerAmount(0, 22),
+            sellAtRatio = 2,
+            sellOutFee = TalerAmount(0, 44),
+            cashoutAddress = "IBAN",
+            cashoutCurrency = "KUDOS",
+            creationTime = 3L,
+            subject = "31st",
+            tanChannel = TanChannel.sms,
+            tanCode = "secret",
+        )
+        assert(db.cashoutCreate(op))
+    }
 }
\ No newline at end of file

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