commit 59bda835da5c868f0c8be06df72a30542935d6d8
parent 41db2f5ef6beccd93b270731425ad8597d35a574
Author: ms <ms@taler.net>
Date: Wed, 20 Oct 2021 13:49:02 +0200
Avoid persisting the balance.
Diffstat:
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -171,8 +171,6 @@ object EbicsSubscribersTable : IntIdTable() {
val authenticationKey = reference("authorizationKey", EbicsSubscriberPublicKeysTable).nullable()
val nextOrderID = integer("nextOrderID")
val state = enumeration("state", SubscriberState::class)
- // setting as nullable to integrate this change more seamlessly into the current
- // implementation. Can be removed eventually.
val bankAccount = reference("bankAccount", BankAccountsTable).nullable()
}
@@ -365,7 +363,6 @@ object BankAccountsTable : IntIdTable() {
val label = text("label").uniqueIndex("accountLabelIndex")
val currency = text("currency")
val isDebit = bool("isDebit").default(false)
- val balance = text("balance")
/**
* Allow to assign "admin" - who doesn't have a customer DB entry -
* as the owner. That allows tests using the --no-auth option to go on.
@@ -391,7 +388,6 @@ class BankAccountEntity(id: EntityID<Int>) : IntEntity(id) {
var label by BankAccountsTable.label
var currency by BankAccountsTable.currency
var isDebit by BankAccountsTable.isDebit
- var balance by BankAccountsTable.balance
var owner by BankAccountsTable.owner
var isPublic by BankAccountsTable.isPublic
var demoBank by BankAccountsTable.demoBank
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -19,6 +19,7 @@
package tech.libeufin.sandbox
+import io.ktor.application.*
import io.ktor.http.HttpStatusCode
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
@@ -159,7 +160,11 @@ fun getBankAccountFromSubscriber(subscriber: EbicsSubscriberEntity): BankAccount
}
}
-fun ensureDemobank(name: String): DemobankConfigEntity {
+fun ensureDemobank(call: ApplicationCall): DemobankConfigEntity {
+ return ensureDemobank(call.getUriComponent("demobankid"))
+}
+
+private fun ensureDemobank(name: String): DemobankConfigEntity {
return transaction {
val res = DemobankConfigEntity.find {
DemobankConfigsTable.name eq name
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -994,7 +994,7 @@ val sandboxApp: Application.() -> Unit = {
"Withdrawal operation: $wopid not found"
)
}
- val demobank = ensureDemobank(call.getUriComponent("demobankid"))
+ val demobank = ensureDemobank(call)
val ret = TalerWithdrawalStatus(
selection_done = wo.selectionDone,
transfer_done = wo.transferDone,
@@ -1014,7 +1014,7 @@ val sandboxApp: Application.() -> Unit = {
"Taler withdrawal tried with authentication disabled. " +
"That is impossible, because no bank account can get this operation debited."
)
- val demobank = ensureDemobank(call.getUriComponent("demobankid"))
+ val demobank = ensureDemobank(call)
/**
* Check here if the user has the right over the claimed bank account. After
* this check, the withdrawal operation will be allowed only by providing its
@@ -1075,7 +1075,7 @@ val sandboxApp: Application.() -> Unit = {
subject = wo.reservePub ?: throw internalServerError(
"Cannot transfer funds without reserve public key."
),
- demoBank = ensureDemobank(call.getUriComponent("demobankid"))
+ demoBank = ensureDemobank(call)
)
wo.transferDone = true
}
@@ -1105,9 +1105,11 @@ val sandboxApp: Application.() -> Unit = {
} else {
"credit"
}
+ val balance = balanceForAccount(bankAccount)
+ val demobank = ensureDemobank(call)
call.respond(object {
val balance = {
- val amount = bankAccount.balance
+ val amount = "${demobank.currency}:${balance}"
val credit_debit_indicator = creditDebitIndicator
}
})
@@ -1118,7 +1120,7 @@ val sandboxApp: Application.() -> Unit = {
// (could be merged with GET /accounts/{account_name}
}
get("/accounts/public") {
- val demobank = ensureDemobank(call.getUriComponent("demobankid"))
+ val demobank = ensureDemobank(call)
val ret = object {
val publicAccounts = mutableListOf<PublicAccountInfo>()
}
@@ -1128,9 +1130,10 @@ val sandboxApp: Application.() -> Unit = {
BankAccountsTable.demoBank eq demobank.id
)
}.forEach {
+ val balanceIter = balanceForAccount(it)
ret.publicAccounts.add(
PublicAccountInfo(
- balance = it.balance,
+ balance = "${demobank.currency}:$balanceIter",
iban = it.iban
)
)
@@ -1143,11 +1146,10 @@ val sandboxApp: Application.() -> Unit = {
get("/accounts/public/{account_name}/history") {
// Get transaction history of a public account
}
-
// Keeping the prefix "testing" not to break tests.
post("/testing/register") {
// Check demobank was created.
- val demobank = ensureDemobank(call.getUriComponent("demobankid"))
+ val demobank = ensureDemobank(call)
val req = call.receive<CustomerRegistration>()
val checkExist = transaction {
DemobankCustomerEntity.find {
@@ -1167,7 +1169,6 @@ val sandboxApp: Application.() -> Unit = {
iban = getIban()
label = req.username + "acct" // multiple accounts per username not allowed.
currency = demobank.currency
- balance = "${demobank.currency}:0"
owner = req.username
this.demoBank = demobank.id
}