summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/server
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-01-06 18:50:07 +0100
committerMS <ms@taler.net>2023-01-06 18:50:07 +0100
commitf5995b846492c7b091c09e204f7c6450b5369034 (patch)
tree08020eac48451f0eee7c8e1477b615692726faf5 /nexus/src/main/kotlin/tech/libeufin/nexus/server
parent3365e7dabcb2a6aa37017c71811c37b0073caa3a (diff)
downloadlibeufin-f5995b846492c7b091c09e204f7c6450b5369034.tar.gz
libeufin-f5995b846492c7b091c09e204f7c6450b5369034.tar.bz2
libeufin-f5995b846492c7b091c09e204f7c6450b5369034.zip
Amount representation.
Defer the conversion of amount strings into BigDecimal until the point where they act as numeric operands. This saves resources because in several cases the amount strings do not partecipate in any calculation. For example, an error might occur before the calculation, or the calculation is not carried at all by the function that gets the amount string from the network.
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/server')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt11
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt2
2 files changed, 7 insertions, 6 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
index 17db9166..8f87c0e2 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
@@ -381,7 +381,7 @@ data class Pain001Data(
val creditorIban: String,
val creditorBic: String?,
val creditorName: String,
- val sum: Amount,
+ val sum: String,
val currency: String,
val subject: String
)
@@ -418,7 +418,7 @@ class CurrencyAmountDeserializer(jc: Class<*> = CurrencyAmount::class.java) : St
val s = p.valueAsString
val components = s.split(":")
// FIXME: error handling!
- return CurrencyAmount(components[0], BigDecimal(components[1]))
+ return CurrencyAmount(components[0], components[1])
}
}
@@ -430,19 +430,20 @@ class CurrencyAmountSerializer(jc: Class<CurrencyAmount> = CurrencyAmount::class
if (value == null) {
gen.writeNull()
} else {
- gen.writeString("${value.currency}:${value.value.toPlainString()}")
+ gen.writeString("${value.currency}:${value.value}")
}
}
}
+// FIXME: this type duplicates AmountWithCurrency.
@JsonDeserialize(using = CurrencyAmountDeserializer::class)
@JsonSerialize(using = CurrencyAmountSerializer::class)
data class CurrencyAmount(
val currency: String,
- val value: BigDecimal // allows calculations
+ val value: String // allows calculations
)
fun CurrencyAmount.toPlainString(): String {
- return "${this.currency}:${this.value.toPlainString()}"
+ return "${this.currency}:${this.value}"
}
data class InitiatedPayments(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index b39c72ec..23df07a5 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -208,7 +208,7 @@ val nexusApp: Application.() -> Unit = {
cause.httpStatusCode,
message = ErrorResponse(
code = TalerErrorCode.TALER_EC_LIBEUFIN_NEXUS_GENERIC_ERROR.code,
- hint = "EBICS protocol error",
+ hint = "The EBICS communication with the bank failed: ${cause.ebicsTechnicalCode}",
detail = cause.reason,
)
)