gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: code cleanup


From: gnunet
Subject: [libeufin] branch master updated: code cleanup
Date: Sun, 14 Jun 2020 13:48:31 +0200

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

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 547a2f4  code cleanup
547a2f4 is described below

commit 547a2f4740bcc95a6ca34ac01c80f13ed2fbbb78
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Sun Jun 14 17:18:20 2020 +0530

    code cleanup
---
 .../main/kotlin/tech/libeufin/nexus/EbicsClient.kt |  4 +-
 .../src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 26 +++---------
 .../main/kotlin/tech/libeufin/nexus/Iso20022.kt    |  8 ++--
 nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt  |  1 -
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  |  6 +--
 nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 47 +++++++---------------
 nexus/src/main/resources/logback.xml               | 12 +++---
 nexus/src/test/kotlin/Iso20022Test.kt              |  1 -
 8 files changed, 33 insertions(+), 72 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsClient.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsClient.kt
index 830fc52..f23ad84 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsClient.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsClient.kt
@@ -119,7 +119,7 @@ suspend fun doEbicsDownloadTransaction(
 
     // Transfer phase
 
-    for (x in 2..numSegments) {
+    for (x in 2 .. numSegments) {
         val transferReqStr =
             createEbicsRequestForDownloadTransferPhase(subscriberDetails, 
transactionID, x, numSegments)
         val transferResponseStr = 
client.postToBank(subscriberDetails.ebicsUrl, transferReqStr)
@@ -273,4 +273,4 @@ suspend fun doEbicsHpbRequest(
         "Cannot find data in a HPB response"
     )
     return parseEbicsHpbOrder(orderData)
-}
\ No newline at end of file
+}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index 246ad9c..164d98d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -32,21 +32,11 @@ import tech.libeufin.util.*
 import tech.libeufin.util.ebics_h004.EbicsTypes
 import java.security.interfaces.RSAPublicKey
 import java.time.Instant
-import java.time.LocalDateTime
 import java.time.ZoneId
 import java.time.ZonedDateTime
 import java.time.format.DateTimeFormatter
 import java.util.*
 
-fun isProduction(): Boolean {
-    return System.getenv("NEXUS_PRODUCTION") != null
-}
-
-fun calculateRefund(amount: String): Amount {
-    // fixme: must apply refund fees!
-    return Amount(amount)
-}
-
 /**
  * Skip national only-numeric bank account ids, and return the first IBAN in 
list
  */
@@ -194,7 +184,7 @@ fun ingestBankMessagesIntoAccount(
         var lastId = acct.highestSeenBankMessageId
         NexusBankMessageEntity.find {
             (NexusBankMessagesTable.bankConnection eq conn.id) and
-                (NexusBankMessagesTable.id greater 
acct.highestSeenBankMessageId)
+                    (NexusBankMessagesTable.id greater 
acct.highestSeenBankMessageId)
         }.orderBy(Pair(NexusBankMessagesTable.id, SortOrder.ASC)).forEach {
             // FIXME: check if it's CAMT first!
             val doc = 
XMLUtil.parseStringIntoDom(it.message.bytes.toString(Charsets.UTF_8))
@@ -226,8 +216,10 @@ suspend fun fetchEbicsC5x(
         orderParamsJson.toOrderParams()
     )
     when (historyType) {
-        "C52" -> {}
-        "C53" -> {}
+        "C52" -> {
+        }
+        "C53" -> {
+        }
         else -> {
             throw NexusError(HttpStatusCode.BadRequest, "history type 
'$historyType' not supported")
         }
@@ -404,14 +396,6 @@ fun getPreparedPayment(uuid: String): 
PreparedPaymentEntity {
     )
 }
 
-fun getNexusUser(id: String): NexusUserEntity {
-    return transaction {
-        NexusUserEntity.findById(id)
-    } ?: throw NexusError(
-        HttpStatusCode.NotFound,
-        "User '$id' not found"
-    )
-}
 
 /**
  * Insert one row in the database, and leaves it marked as non-submitted.
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt
index e1eb5a7..300cd34 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt
@@ -78,7 +78,7 @@ data class TransactionDetails(
     val unstructuredRemittanceInformation: String
 )
 
-abstract class AccountIdentification() : TypedEntity()
+abstract class AccountIdentification : TypedEntity()
 
 @JsonInclude(JsonInclude.Include.NON_NULL)
 data class AccountIdentificationIban(
@@ -142,7 +142,7 @@ data class BankTransaction(
     JsonSubTypes.Type(value = AccountIdentificationIban::class, name = 
"account-identification-iban"),
     JsonSubTypes.Type(value = AccountIdentificationGeneric::class, name = 
"account-identification-generic")
 )
-abstract class TypedEntity()
+abstract class TypedEntity
 
 @JsonInclude(JsonInclude.Include.NON_NULL)
 class Agent(
@@ -155,7 +155,7 @@ class Party(
     val name: String?
 ) : TypedEntity()
 
-abstract class DateOrDateTime() : TypedEntity()
+abstract class DateOrDateTime : TypedEntity()
 
 class Date(
     val date: String
@@ -383,7 +383,7 @@ fun getTransactions(doc: Document): List<BankTransaction> {
     return destructXml(doc) {
         requireRootElement("Document") {
             // Either bank to customer statement or report
-            requireOnlyChild() {
+            requireOnlyChild {
                 when (it.localName) {
                     "BkToCstmrAcctRpt" -> {
                         mapEachChildNamed("Rpt") {
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
index c75efe1..9033829 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -19,7 +19,6 @@
 
 package tech.libeufin.nexus
 
-import com.fasterxml.jackson.annotation.JsonAutoDetect
 import com.fasterxml.jackson.annotation.JsonSubTypes
 import com.fasterxml.jackson.annotation.JsonTypeInfo
 import com.fasterxml.jackson.annotation.JsonTypeName
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 96c2749..3dd1baa 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -62,7 +62,6 @@ import io.ktor.utils.io.jvm.javaio.toInputStream
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.time.delay
-import org.jetbrains.exposed.sql.and
 import org.jetbrains.exposed.sql.statements.api.ExposedBlob
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.slf4j.Logger
@@ -75,7 +74,6 @@ import java.io.PrintWriter
 import java.io.StringWriter
 import java.net.URLEncoder
 import java.time.Duration
-import java.time.LocalDateTime
 import java.util.*
 import java.util.zip.InflaterInputStream
 import javax.crypto.EncryptedPrivateKeyInfo
@@ -257,7 +255,7 @@ fun ApplicationRequest.hasBody(): Boolean {
             val cl = contentLengthHeaderStr.toInt()
             return cl != 0
         } catch (e: NumberFormatException) {
-            return false;
+            return false
         }
     }
     return false
@@ -276,7 +274,7 @@ fun moreFrequentBackgroundTasks(httpClient: HttpClient) {
         while (true) {
             logger.debug("Running more frequent background jobs")
             reportAndIgnoreErrors { 
downloadTalerFacadesTransactions(httpClient, "C53") }
-            reportAndIgnoreErrors { 
downloadTalerFacadesTransactions(httpClient, "C52")  }
+            reportAndIgnoreErrors { 
downloadTalerFacadesTransactions(httpClient, "C52") }
             reportAndIgnoreErrors { ingestTalerTransactions() }
             reportAndIgnoreErrors { submitPreparedPaymentsViaEbics() }
             logger.debug("More frequent background jobs done")
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
index aa5b1a3..33a7153 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -208,29 +208,6 @@ fun customConverter(body: Any): String {
     return jacksonObjectMapper().writeValueAsString(body)
 }
 
-/**
- * This function indicates whether a payment in the raw table was already 
reported
- * by some other EBICS message.  It works for both incoming and outgoing 
payments.
- * Basically, it tries to match all the relevant details with those from the 
records
- * that are already stored in the local "taler" database.
- *
- * @param entry a new raw payment to be checked.
- * @return true if the payment was already "seen" by the Taler layer, false 
otherwise.
- */
-fun duplicatePayment(entry: RawBankTransactionEntity): Boolean {
-    return false
-}
-
-/**
- * This function checks whether the bank didn't accept one exchange's payment 
initiation.
- *
- * @param entry the raw entry to check
- * @return true if the payment failed, false if it was successful.
- */
-fun paymentFailed(entry: RawBankTransactionEntity): Boolean {
-    return false
-}
-
 /**
  * Tries to extract a valid reserve public key from the raw subject line
  */
@@ -249,7 +226,7 @@ fun extractWtidFromSubject(rawSubject: String): String? {
     return result.value.toUpperCase()
 }
 
-fun getTalerFacadeState(fcid: String): TalerFacadeStateEntity {
+private fun getTalerFacadeState(fcid: String): TalerFacadeStateEntity {
     val facade = FacadeEntity.find { FacadesTable.id eq fcid }.firstOrNull() 
?: throw NexusError(
         HttpStatusCode.NotFound,
         "Could not find facade '${fcid}'"
@@ -263,7 +240,7 @@ fun getTalerFacadeState(fcid: String): 
TalerFacadeStateEntity {
     return facadeState
 }
 
-fun getTalerFacadeBankAccount(fcid: String): NexusBankAccountEntity {
+private fun getTalerFacadeBankAccount(fcid: String): NexusBankAccountEntity {
     val facade = FacadeEntity.find { FacadesTable.id eq fcid }.firstOrNull() 
?: throw NexusError(
         HttpStatusCode.NotFound,
         "Could not find facade '${fcid}'"
@@ -282,8 +259,10 @@ fun getTalerFacadeBankAccount(fcid: String): 
NexusBankAccountEntity {
     return bankAccount
 }
 
-// /taler/transfer
-suspend fun talerTransfer(call: ApplicationCall) {
+/**
+ * Handle a Taler Wire Gateway /transfer request.
+ */
+private suspend fun talerTransfer(call: ApplicationCall) {
     val transferRequest = call.receive<TalerTransferRequest>()
     val amountObj = parseAmount(transferRequest.amount)
     val creditorObj = parsePayto(transferRequest.credit_account)
@@ -347,7 +326,7 @@ suspend fun talerTransfer(call: ApplicationCall) {
 }
 
 // /taler/admin/add-incoming
-suspend fun talerAddIncoming(call: ApplicationCall): Unit {
+private suspend fun talerAddIncoming(call: ApplicationCall): Unit {
     val addIncomingData = call.receive<TalerAdminAddIncoming>()
     val debtor = parsePayto(addIncomingData.debit_account)
     val res = transaction {
@@ -443,7 +422,7 @@ suspend fun submitPreparedPaymentsViaEbics() {
     }
     val httpClient = HttpClient()
     workQueue.forEach {
-        println("submitting prepared payment via EBICS");
+        println("submitting prepared payment via EBICS")
         doEbicsUploadTransaction(
             httpClient,
             it.subscriberDetails,
@@ -564,7 +543,7 @@ fun ingestTalerTransactions() {
     }
 }
 
-suspend fun historyOutgoing(call: ApplicationCall): Unit {
+private suspend fun historyOutgoing(call: ApplicationCall): Unit {
     val param = call.expectUrlParameter("delta")
     val delta: Int = try {
         param.toInt()
@@ -609,8 +588,10 @@ suspend fun historyOutgoing(call: ApplicationCall): Unit {
     )
 }
 
-// /taler/history/incoming
-suspend fun historyIncoming(call: ApplicationCall): Unit {
+/**
+ * taler/history/incoming
+ */
+private suspend fun historyIncoming(call: ApplicationCall): Unit {
     val param = call.expectUrlParameter("delta")
     val delta: Int = try {
         param.toInt()
@@ -667,4 +648,4 @@ fun talerFacadeRoutes(route: Route) {
         call.respondText("Hello, this is Taler Facade")
         return@get
     }
-}
\ No newline at end of file
+}
diff --git a/nexus/src/main/resources/logback.xml 
b/nexus/src/main/resources/logback.xml
index 669cea3..2d6c01f 100644
--- a/nexus/src/main/resources/logback.xml
+++ b/nexus/src/main/resources/logback.xml
@@ -14,14 +14,14 @@
         </encoder>
     </appender>
 
-    <logger name="tech.libeufin" level="TRACE" />
-    <logger name="io.netty" level="WARN" />
-    <logger name="ktor" level="WARN" />
-    <logger name="Exposed" level="WARN" />
+    <logger name="tech.libeufin" level="TRACE"/>
+    <logger name="io.netty" level="WARN"/>
+    <logger name="ktor" level="WARN"/>
+    <logger name="Exposed" level="WARN"/>
 
     <root level="WARN">
-        <appender-ref ref="STDOUT" />
-        <appender-ref ref="NEXUS-FILE" />
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="NEXUS-FILE"/>
     </root>
 
 </configuration>
\ No newline at end of file
diff --git a/nexus/src/test/kotlin/Iso20022Test.kt 
b/nexus/src/test/kotlin/Iso20022Test.kt
index 79a2e13..9720e51 100644
--- a/nexus/src/test/kotlin/Iso20022Test.kt
+++ b/nexus/src/test/kotlin/Iso20022Test.kt
@@ -1,5 +1,4 @@
 package tech.libeufin.nexus
-import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import org.junit.Test
 import org.w3c.dom.Document

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