gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 02/07: Polishing Sandbox.


From: gnunet
Subject: [libeufin] 02/07: Polishing Sandbox.
Date: Fri, 31 Mar 2023 14:28:06 +0200

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

ms pushed a commit to branch master
in repository libeufin.

commit 9fa7dbec7ada36d55893a80db8bd1eb71e72d10a
Author: MS <ms@taler.net>
AuthorDate: Fri Mar 31 13:57:33 2023 +0200

    Polishing Sandbox.
    
    Renaming the internal representation of a transaction
    and avoiding using free strings to express constants
---
 sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt          |  1 +
 .../kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt     | 12 ++++++------
 sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt     |  9 +++++----
 sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt        |  8 ++++----
 sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt |  2 ++
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 00688082..b0654950 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -423,6 +423,7 @@ object BankAccountTransactionsTable : LongIdTable() {
     // Amount is a BigDecimal in String form.
     val amount = text("amount")
     val currency = text("currency")
+    // Milliseconds since the Epoch.
     val date = long("date")
     // Unique ID for this payment within the bank account.
     val accountServicerReference = text("accountServicerReference")
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 051d1a09..d02ff7c3 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -235,7 +235,7 @@ fun <T> expectNonNull(x: T?): T {
     return x;
 }
 
-private fun getRelatedParty(branch: XmlElementBuilder, payment: RawPayment) {
+private fun getRelatedParty(branch: XmlElementBuilder, payment: 
XLibeufinBankTransaction) {
     val otherParty = object {
         var ibanPath = "CdtrAcct/Id/IBAN"
         var namePath = "Cdtr/Nm"
@@ -244,7 +244,7 @@ private fun getRelatedParty(branch: XmlElementBuilder, 
payment: RawPayment) {
         var bicPath = "CdtrAgt/FinInstnId/BIC"
         var bic = payment.creditorBic
     }
-    if (payment.direction == "CRDT") {
+    if (payment.direction == XLibeufinBankDirection.CREDIT) {
         otherParty.iban = payment.debtorIban
         otherParty.ibanPath = "DbtrAcct/Id/IBAN"
         otherParty.namePath = "Dbtr/Nm"
@@ -279,7 +279,7 @@ private fun getCreditDebitInd(balance: BigDecimal): String {
 fun buildCamtString(
     type: Int,
     subscriberIban: String,
-    history: MutableList<RawPayment>,
+    history: MutableList<XLibeufinBankTransaction>,
     balancePrcd: BigDecimal, // Balance up to freshHistory (excluded).
     balanceClbd: BigDecimal,
     currency: String
@@ -521,7 +521,7 @@ private fun constructCamtResponse(
     if (type == 52) {
         if (dateRange != null)
             throw EbicsOrderParamsIgnored("C52 does not support date ranges.")
-        val history = mutableListOf<RawPayment>()
+        val history = mutableListOf<XLibeufinBankTransaction>()
         transaction {
             BankAccountFreshTransactionEntity.all().forEach {
                 if (it.transactionRef.account.label == bankAccount.label) {
@@ -545,8 +545,8 @@ private fun constructCamtResponse(
             var base = prcdBalance
             history.forEach { tx ->
                 when (tx.direction) {
-                    "DBIT" -> base -= parseDecimal(tx.amount)
-                    "CRDT" -> base += parseDecimal(tx.amount)
+                    XLibeufinBankDirection.DEBIT -> base -= 
parseDecimal(tx.amount)
+                    XLibeufinBankDirection.CREDIT -> base += 
parseDecimal(tx.amount)
                     else -> {
                         logger.error("Transaction with subject '${tx.subject}' 
is " +
                                 "inconsistent: neither DBIT nor CRDT")
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
index 8fe70541..5d492914 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -215,8 +215,8 @@ fun getOrderTypeFromTransactionId(transactionID: String): 
String {
     return uploadTransaction.orderType
 }
 
-fun getHistoryElementFromTransactionRow(dbRow: BankAccountTransactionEntity): 
RawPayment {
-    return RawPayment(
+fun getHistoryElementFromTransactionRow(dbRow: BankAccountTransactionEntity): 
XLibeufinBankTransaction {
+    return XLibeufinBankTransaction(
         subject = dbRow.subject,
         creditorIban = dbRow.creditorIban,
         creditorBic = dbRow.creditorBic,
@@ -231,7 +231,8 @@ fun getHistoryElementFromTransactionRow(dbRow: 
BankAccountTransactionEntity): Ra
         // and dbRow makes the document invalid!
         // uid = "${dbRow.pmtInfId}-${it.msgId}"
         uid = dbRow.accountServicerReference,
-        direction = dbRow.direction,
+        // Eventually, the _database_ should contain the direction enum:
+        direction = 
XLibeufinBankDirection.convertCamtDirectionToXLibeufin(dbRow.direction),
         pmtInfId = dbRow.pmtInfId
     )
 }
@@ -256,7 +257,7 @@ fun printConfig(demobank: DemobankConfigEntity) {
 
 fun getHistoryElementFromTransactionRow(
     dbRow: BankAccountFreshTransactionEntity
-): RawPayment {
+): XLibeufinBankTransaction {
     return getHistoryElementFromTransactionRow(dbRow.transactionRef)
 }
 
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 0d2a80d0..a1a4d70b 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -225,7 +225,7 @@ class Camt053Tick : CliktCommand(
         val dbConnString = getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME)
         Database.connect(dbConnString)
         dbCreateTables(dbConnString)
-        val newStatements = mutableMapOf<String, MutableList<RawPayment>>()
+        val newStatements = mutableMapOf<String, 
MutableList<XLibeufinBankTransaction>>()
         /**
          * For each bank account, extract the latest statement and
          * include all the later transactions in a new statement.
@@ -1336,8 +1336,8 @@ val sandboxApp: Application.() -> Unit = {
                     val baseUrl = URL(call.request.getBaseUrl())
                     val withdrawUri = url {
                         protocol = URLProtocol(
-                            "taler".plus(if (baseUrl.protocol.lowercase() == 
"http") "+http" else ""),
-                            -1
+                            name = "taler".plus(if 
(baseUrl.protocol.lowercase() == "http") "+http" else ""),
+                            defaultPort = -1
                         )
                         host = "withdraw"
                         val pathSegments = mutableListOf(
@@ -1492,7 +1492,7 @@ val sandboxApp: Application.() -> Unit = {
                     if (fromMs < 0) throw badRequest("'from_ms' param is less 
than 0")
                     val untilMs = 
expectLong(call.request.queryParameters["until_ms"] ?: 
Long.MAX_VALUE.toString())
                     if (untilMs < 0) throw badRequest("'until_ms' param is 
less than 0")
-                    val ret = mutableListOf<RawPayment>()
+                    val ret = mutableListOf<XLibeufinBankTransaction>()
                     /**
                      * Case where page number wasn't given,
                      * therefore the results starts from the last transaction.
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index 2361b876..2ebe5fc2 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -6,6 +6,8 @@ import org.jetbrains.exposed.sql.transactions.transaction
 import tech.libeufin.util.*
 import java.math.BigDecimal
 
+
+
 /**
  * Check whether the given bank account would surpass the
  * debit threshold, in case the potential amount gets transferred.

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