commit cc1bc351553f18fe464935a53e7bd4a2818bf178
parent f6a9023da8868f0f00bfa8c383fbc2b231e387f8
Author: Antoine A <>
Date: Tue, 24 Oct 2023 12:13:03 +0000
Improve /monitor
Diffstat:
2 files changed, 40 insertions(+), 42 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt
@@ -1494,23 +1494,28 @@ class Database(dbConfig: String, private val bankCurrency: String, private val f
stmt.setNull(2, java.sql.Types.INTEGER)
}
stmt.oneOrNull {
- MonitorResponse(
- cashinCount = fiatCurrency?.run { it.getLong("cashin_count") },
- cashinExternalVolume = fiatCurrency?.run {
- TalerAmount(
+ fiatCurrency?.run {
+ MonitorWithCashout(
+ cashinCount = it.getLong("cashin_count"),
+ cashinExternalVolume = TalerAmount(
value = it.getLong("cashin_volume_in_fiat_val"),
frac = it.getInt("cashin_volume_in_fiat_frac"),
currency = this
- )
- },
- cashoutCount = fiatCurrency?.run { it.getLong("cashout_count") },
- cashoutExternalVolume = fiatCurrency?.run {
- TalerAmount(
+ ),
+ cashoutCount = it.getLong("cashout_count"),
+ cashoutExternalVolume = TalerAmount(
value = it.getLong("cashout_volume_in_fiat_val"),
frac = it.getInt("cashout_volume_in_fiat_frac"),
currency = this
+ ),
+ talerPayoutCount = it.getLong("internal_taler_payments_count"),
+ talerPayoutInternalVolume = TalerAmount(
+ value = it.getLong("internal_taler_payments_volume_val"),
+ frac = it.getInt("internal_taler_payments_volume_frac"),
+ currency = bankCurrency
)
- },
+ )
+ } ?: MonitorJustPayouts(
talerPayoutCount = it.getLong("internal_taler_payments_count"),
talerPayoutInternalVolume = TalerAmount(
value = it.getLong("internal_taler_payments_volume_val"),
@@ -1518,30 +1523,8 @@ class Database(dbConfig: String, private val bankCurrency: String, private val f
currency = bankCurrency
)
)
- } ?: MonitorResponse(
- cashinCount = fiatCurrency?.run { 0 },
- cashinExternalVolume = fiatCurrency?.run {
- TalerAmount(
- value = 0,
- frac = 0,
- currency = this
- )
- },
- cashoutCount = fiatCurrency?.run { 0 },
- cashoutExternalVolume = fiatCurrency?.run {
- TalerAmount(
- value = 0,
- frac = 0,
- currency = this
- )
- },
- talerPayoutCount = 0,
- talerPayoutInternalVolume = TalerAmount(
- value = 0,
- frac = 0,
- currency = bankCurrency
- )
- )
+
+ } ?: throw internalServerError("No result from DB procedure stats_get_frame")
}
}
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
@@ -31,6 +31,7 @@ import java.util.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
+import kotlinx.serialization.SerialName
/**
* Allowed lengths for fractional digits in amounts.
@@ -107,14 +108,28 @@ data class TokenRequest(
)
@Serializable
-data class MonitorResponse(
- val cashinCount: Long? = null,
- val cashinExternalVolume: TalerAmount? = null,
- val cashoutCount: Long? = null,
- val cashoutExternalVolume: TalerAmount? = null,
- val talerPayoutCount: Long,
- val talerPayoutInternalVolume: TalerAmount
-)
+sealed class MonitorResponse {
+ abstract val talerPayoutCount: Long
+ abstract val talerPayoutInternalVolume: TalerAmount
+}
+
+@Serializable
+@SerialName("just-payouts")
+data class MonitorJustPayouts(
+ override val talerPayoutCount: Long,
+ override val talerPayoutInternalVolume: TalerAmount
+) : MonitorResponse()
+
+@Serializable
+@SerialName("with-cashout")
+data class MonitorWithCashout(
+ val cashinCount: Long?,
+ val cashinExternalVolume: TalerAmount,
+ val cashoutCount: Long,
+ val cashoutExternalVolume: TalerAmount,
+ override val talerPayoutCount: Long,
+ override val talerPayoutInternalVolume: TalerAmount
+) : MonitorResponse()
/**
* Convenience type to throw errors along the bank activity