summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-02-24 19:39:20 +0100
committerMS <ms@taler.net>2023-02-24 19:39:20 +0100
commitbb3d2eea0671952b509f16b99f4aba6ef33142fb (patch)
tree18407fcc6895afc6f1844ea9b9431b61194aed56 /sandbox/src/main/kotlin/tech/libeufin
parent8e2097ff41ee020d764cc14a3d14654c71f97906 (diff)
downloadlibeufin-bb3d2eea0671952b509f16b99f4aba6ef33142fb.tar.gz
libeufin-bb3d2eea0671952b509f16b99f4aba6ef33142fb.tar.bz2
libeufin-bb3d2eea0671952b509f16b99f4aba6ef33142fb.zip
Cascade-deleting when deleting a user.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt16
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt17
2 files changed, 25 insertions, 8 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index 4fc1ac48..e3903923 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
@@ -33,13 +33,13 @@ data class CircuitCashoutRequest(
*/
val tan_channel: String?
)
-
+const val FIAT_CURRENCY = "CHF" // FIXME: make configurable.
// Configuration response:
data class ConfigResp(
val name: String = "circuit",
val version: String = SANDBOX_VERSION,
val ratios_and_fees: RatioAndFees,
- val fiat_currency: String = "CHF" // FIXME: make configurable.
+ val fiat_currency: String = FIAT_CURRENCY
)
// After fixing #7527, the values held by this
@@ -370,10 +370,16 @@ fun circuitApi(circuitRoute: Route) {
val amountDebit = parseAmount(req.amount_debit) // amount before rates.
val amountCredit = parseAmount(req.amount_credit) // amount after rates, as expected by the client
val demobank = ensureDemobank(call)
+ // Currency check of the cash-out's circuit part.
if (amountDebit.currency != demobank.currency)
- throw badRequest("The '${req::amount_debit.name}' field has the wrong currency")
- if (amountCredit.currency == demobank.currency)
- throw badRequest("The '${req::amount_credit.name}' field didn't change the currency.")
+ throw badRequest("'${req::amount_debit.name}' (${req.amount_debit})" +
+ " doesn't match the regional currency (${demobank.currency})"
+ )
+ // Currency check of the cash-out's fiat part.
+ if (amountCredit.currency != FIAT_CURRENCY)
+ throw badRequest("'${req::amount_credit.name}' (${req.amount_credit})" +
+ " doesn't match the fiat currency ($FIAT_CURRENCY)."
+ )
// check if TAN is supported. Default to SMS, if that's missing.
val tanChannel = req.tan_channel?.uppercase() ?: SupportedTanChannels.SMS.name
if (!isTanChannelSupported(tanChannel))
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index b6556cb4..3281b67a 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -182,7 +182,11 @@ object EbicsSubscribersTable : IntIdTable() {
val authenticationKey = reference("authorizationKey", EbicsSubscriberPublicKeysTable).nullable()
val nextOrderID = integer("nextOrderID")
val state = enumeration("state", SubscriberState::class)
- val bankAccount = reference("bankAccount", BankAccountsTable).nullable()
+ val bankAccount = reference(
+ "bankAccount",
+ BankAccountsTable,
+ onDelete = ReferenceOption.CASCADE
+ ).nullable()
}
class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) {
@@ -297,7 +301,11 @@ class EbicsUploadTransactionChunkEntity(id: EntityID<String>) : Entity<String>(i
* to the main ledger.
*/
object BankAccountFreshTransactionsTable : LongIdTable() {
- val transactionRef = reference("transaction", BankAccountTransactionsTable)
+ val transactionRef = reference(
+ "transaction",
+ BankAccountTransactionsTable,
+ onDelete = ReferenceOption.CASCADE
+ )
}
class BankAccountFreshTransactionEntity(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<BankAccountFreshTransactionEntity>(BankAccountFreshTransactionsTable)
@@ -331,7 +339,10 @@ object BankAccountTransactionsTable : LongIdTable() {
* Bank account of the party whose 'direction' refers. This version allows
* only both parties to be registered at the running Sandbox.
*/
- val account = reference("account", BankAccountsTable)
+ val account = reference(
+ "account", BankAccountsTable,
+ onDelete = ReferenceOption.CASCADE
+ )
// Redundantly storing the demobank for query convenience.
val demobank = reference("demobank", DemobankConfigsTable)
}