summaryrefslogtreecommitdiff
path: root/sandbox
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-01-13 14:33:45 +0100
committerMS <ms@taler.net>2023-01-13 14:33:45 +0100
commit4acefbd1c6bcf1313be312851abe5a4ecf3f178f (patch)
tree9094dafa634fef67fe319108ea6f53c747acd96d /sandbox
parentcc9fcded04ca7b288a568644ba1edd90c6421159 (diff)
downloadlibeufin-4acefbd1c6bcf1313be312851abe5a4ecf3f178f.tar.gz
libeufin-4acefbd1c6bcf1313be312851abe5a4ecf3f178f.tar.bz2
libeufin-4acefbd1c6bcf1313be312851abe5a4ecf3f178f.zip
Fix debit check on withdrawals.
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt21
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt1
2 files changed, 5 insertions, 17 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 6bfa80d7..e3a9d01d 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -1301,23 +1301,10 @@ val sandboxApp: Application.() -> Unit = {
val amount = parseAmount(req.amount)
if (amount.currency != demobank.currency)
throw badRequest("Currency ${amount.currency} differs from Demobank's: ${demobank.currency}")
- /**
- * Check for debit threshold. That's however also later checked
- * after the /confirm call. Username == null case is handled above.
- */
- val pendingBalance = getBalance(username!!, withPending = true)
- val maxDebt = if (username == "admin") {
- demobank.bankDebtLimit
- } else demobank.usersDebtLimit
- val amountAsNumber = BigDecimal(amount.amount)
- if ((pendingBalance - amountAsNumber).abs() > BigDecimal.valueOf(maxDebt.toLong())) {
- logger.info("User $username would surpass user debit " +
- "threshold of ${demobank.usersDebtLimit}. Rollback Taler withdrawal"
- )
- throw SandboxError(
- HttpStatusCode.Forbidden,
- "Insufficient funds."
- )
+ // Check funds are sufficient.
+ if (maybeDebit(maybeOwnedAccount.label, BigDecimal(amount.amount))) {
+ logger.error("Account ${maybeOwnedAccount.label} would surpass debit threshold. Not withdrawing")
+ throw SandboxError(HttpStatusCode.PreconditionFailed, "Insufficient funds")
}
val wo: TalerWithdrawalEntity = transaction {
TalerWithdrawalEntity.new {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index 50963695..d194178c 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -127,6 +127,7 @@ fun wireTransfer(
pmtInfId: String? = null
): String {
val parsedAmount = parseAmount(amount)
+ // Potential amount to transfer.
val amountAsNumber = BigDecimal(parsedAmount.amount)
if (amountAsNumber == BigDecimal.ZERO)
throw badRequest("Wire transfers of zero not possible.")