gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: Collecting currency after amount parsi


From: gnunet
Subject: [libeufin] branch master updated: Collecting currency after amount parsing.
Date: Thu, 14 Sep 2023 16:14:59 +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 77918308 Collecting currency after amount parsing.
77918308 is described below

commit 77918308e35c3cc9ed2f03332ac95b5ec52023eb
Author: MS <ms@taler.net>
AuthorDate: Thu Sep 14 16:14:35 2023 +0200

    Collecting currency after amount parsing.
---
 bank/src/main/kotlin/tech/libeufin/bank/Database.kt | 12 +++++++++++-
 bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt  |  3 ++-
 bank/src/test/kotlin/AmountTest.kt                  |  3 +--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt
index baa1de43..1f676727 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt
@@ -22,9 +22,19 @@ data class Customer(
 )
 fun Customer.expectRowId(): Long = this.dbRowId ?: throw 
internalServerError("Cutsomer '${this.login}' had no DB row ID")
 
+/**
+ * Represents a Taler amount.  This type can be used both
+ * to hold database records and amounts coming from the parser.
+ */
 data class TalerAmount(
     val value: Long,
-    val frac: Int
+    val frac: Int,
+    /**
+     * The currency is likely null when the object is defined
+     * from database records.  It is instead not null when the
+     * object comes from the parsing of serialized amounts.
+     */
+    val currency: String? = null
 )
 
 // BIC got removed, because it'll be expressed in the internal_payto_uri.
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt
index 41684525..22c8e824 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt
@@ -154,6 +154,7 @@ fun parseTalerAmount(
     }
     return TalerAmount(
         value = value,
-        frac = fraction
+        frac = fraction,
+        currency = match.destructured.component1()
     )
 }
\ No newline at end of file
diff --git a/bank/src/test/kotlin/AmountTest.kt 
b/bank/src/test/kotlin/AmountTest.kt
index b8c8f036..bcf066b5 100644
--- a/bank/src/test/kotlin/AmountTest.kt
+++ b/bank/src/test/kotlin/AmountTest.kt
@@ -5,10 +5,9 @@ import tech.libeufin.bank.parseTalerAmount
 class AmountTest {
     @Test
     fun parseTalerAmountTest() {
-        parseTalerAmount("KUDOS:11")
         val one = "EUR:1"
         var obj = parseTalerAmount(one)
-        assert(obj.value == 1L && obj.frac == 0)
+        assert(obj.value == 1L && obj.frac == 0 && obj.currency == "EUR")
         val onePointZero = "EUR:1.00"
         obj = parseTalerAmount(onePointZero)
         assert(obj.value == 1L && obj.frac == 0)

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