gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: Fixing #6251,


From: gnunet
Subject: [libeufin] branch master updated: Fixing #6251,
Date: Tue, 16 Jun 2020 14:25:14 +0200

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

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new d3d3a52  Fixing #6251,
d3d3a52 is described below

commit d3d3a521b9b5af7f4279d368e51c0cd8c4bf5781
Author: MS <ms@taler.net>
AuthorDate: Tue Jun 16 14:24:20 2020 +0200

    Fixing #6251,
    
    Initiated payments should simply have a incremental numeric id.
---
 cli/libeufin-cli-new                               |  4 ++--
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    | 24 +++-------------------
 .../src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 18 +++++++++-------
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  |  8 ++++----
 4 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/cli/libeufin-cli-new b/cli/libeufin-cli-new
index b658af4..06e6318 100755
--- a/cli/libeufin-cli-new
+++ b/cli/libeufin-cli-new
@@ -167,8 +167,8 @@ def import_bank_accounts(obj, connection_name, 
nexus_user_id, nexus_password, ne
 @click.argument("nexus-base-url")
 @click.pass_obj
 def prepare_payment(obj, account_name, credit_iban, credit_bic, credit_name,
-                    nexus_user_id, nexus_password, nexus_base_url):
-    url = urljoin(nexus_basd_url, 
"/bank-accounts/{}/prepared-payments".format(account_name))
+                    nexus_user_id, nexus_password, nexus_base_url, 
payment_amount, payment_subject):
+    url = urljoin(nexus_base_url, 
"/bank-accounts/{}/prepared-payments".format(account_name))
     body = dict(
         iban=credit_iban,
         bic=credit_bic,
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index 9aac051..f6f326f 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -170,19 +170,8 @@ class RawBankTransactionEntity(id: EntityID<Long>) : 
LongEntity(id) {
 /**
  * Represents a prepared payment.
  */
-object PreparedPaymentsTable : IdTable<String>() {
-    /** the UUID representing this payment in the system */
-    override val id = text("id").entityId()
-    val paymentId = long("paymentId")
-
-    /**
-     * Time when the payment initiation was created.
-     */
+object PreparedPaymentsTable : LongIdTable() {
     val preparationDate = long("preparationDate")
-
-    /**
-     * First time that this payment request has been submitted successfully.
-     */
     val submissionDate = long("submissionDate").nullable()
     val sum = amount("sum")
     val currency = varchar("currency", length = 3).default("EUR")
@@ -194,18 +183,11 @@ object PreparedPaymentsTable : IdTable<String>() {
     val debitorIban = text("debitorIban")
     val debitorBic = text("debitorBic")
     val debitorName = text("debitorName").nullable()
-
-    /**
-     * Indicates whether the PAIN message was sent to the bank.
-     * FIXME(dold): Overlap with submissionDate?!
-     */
     val submitted = bool("submitted").default(false)
 }
 
-class PreparedPaymentEntity(id: EntityID<String>) : Entity<String>(id) {
-    companion object : EntityClass<String, 
PreparedPaymentEntity>(PreparedPaymentsTable)
-
-    var paymentId by PreparedPaymentsTable.paymentId
+class PreparedPaymentEntity(id: EntityID<Long>) : LongEntity(id) {
+    companion object : 
LongEntityClass<PreparedPaymentEntity>(PreparedPaymentsTable)
     var preparationDate by PreparedPaymentsTable.preparationDate
     var submissionDate by PreparedPaymentsTable.submissionDate
     var sum by PreparedPaymentsTable.sum
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index 0494225..d3c0903 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -181,7 +181,6 @@ fun ingestBankMessagesIntoAccount(
     }
 }
 
-
 /**
  * Create a PAIN.001 XML document according to the input data.
  * Needs to be called within a transaction block.
@@ -312,7 +311,7 @@ fun createPain001document(paymentData: 
PreparedPaymentEntity): String {
  * Retrieve prepared payment from database, raising exception
  * if not found.
  */
-fun getPreparedPayment(uuid: String): PreparedPaymentEntity {
+fun getPreparedPayment(uuid: Long): PreparedPaymentEntity {
     return transaction {
         PreparedPaymentEntity.findById(uuid)
     } ?: throw NexusError(
@@ -330,9 +329,8 @@ fun getPreparedPayment(uuid: String): PreparedPaymentEntity 
{
  * by this pain document.
  */
 fun addPreparedPayment(paymentData: Pain001Data, debitorAccount: 
NexusBankAccountEntity): PreparedPaymentEntity {
-    val randomId = Random().nextLong()
     return transaction {
-        PreparedPaymentEntity.new(randomId.toString()) {
+        PreparedPaymentEntity.new {
             subject = paymentData.subject
             sum = paymentData.sum
             debitorIban = debitorAccount.iban
@@ -342,15 +340,21 @@ fun addPreparedPayment(paymentData: Pain001Data, 
debitorAccount: NexusBankAccoun
             creditorBic = paymentData.creditorBic
             creditorIban = paymentData.creditorIban
             preparationDate = Instant.now().toEpochMilli()
-            paymentId = randomId
-            endToEndId = randomId
+            endToEndId = 0
         }
     }
 }
 
 fun ensureNonNull(param: String?): String {
     return param ?: throw NexusError(
-        HttpStatusCode.BadRequest, "Bad ID given"
+        HttpStatusCode.BadRequest, "Bad ID given: ${param}"
+    )
+}
+
+fun ensureLong(param: String?): Long {
+    val asString = ensureNonNull(param)
+    return asString.toLongOrNull() ?: throw NexusError(
+        HttpStatusCode.BadRequest, "Parameter is not a number: ${param}"
     )
 }
 
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 2fd6b9f..80b9e43 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -521,7 +521,7 @@ fun serverMain(dbName: String) {
              * Submit one particular payment to the bank.
              */
             post("/bank-accounts/{accountid}/prepared-payments/{uuid}/submit") 
{
-                val uuid = ensureNonNull(call.parameters["uuid"])
+                val uuid = ensureLong(call.parameters["uuid"])
                 val accountId = ensureNonNull(call.parameters["accountid"])
                 val res = transaction {
                     val user = authenticateRequest(call.request)
@@ -568,7 +568,7 @@ fun serverMain(dbName: String) {
             get("/bank-accounts/{accountid}/prepared-payments/{uuid}") {
                 val res = transaction {
                     val user = authenticateRequest(call.request)
-                    val preparedPayment = 
getPreparedPayment(ensureNonNull(call.parameters["uuid"]))
+                    val preparedPayment = 
getPreparedPayment(ensureLong(call.parameters["uuid"]))
                     return@transaction object {
                         val preparedPayment = preparedPayment
                     }
@@ -576,7 +576,7 @@ fun serverMain(dbName: String) {
                 val sd = res.preparedPayment.submissionDate
                 call.respond(
                     PaymentStatus(
-                        uuid = res.preparedPayment.id.value,
+                        uuid = res.preparedPayment.id.value.toString(),
                         submitted = res.preparedPayment.submitted,
                         creditorName = res.preparedPayment.creditorName,
                         creditorBic = res.preparedPayment.creditorBic,
@@ -621,7 +621,7 @@ fun serverMain(dbName: String) {
                 }
                 call.respond(
                     HttpStatusCode.OK,
-                    PreparedPaymentResponse(uuid = res.uuid)
+                    PreparedPaymentResponse(uuid = res.uuid.toString())
                 )
                 return@post
             }

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