commit e61e046ed02b8d58f2e218eb2bf3a9d8f7a9bd13
parent d7caa39d3b6ec3df92765bd66c8272112365069c
Author: Antoine A <>
Date: Tue, 28 Nov 2023 13:08:01 +0000
Remove unused code and improve `passwd` command error message
Diffstat:
3 files changed, 11 insertions(+), 66 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -226,55 +226,6 @@ fun Application.corebankWebApp(db: Database, ctx: BankConfig) {
}
}
-fun durationFromPretty(s: String): Long {
- var durationUs: Long = 0;
- var currentNum = "";
- var parsingNum = true
- for (c in s) {
- if (c >= '0' && c <= '9') {
- if (!parsingNum) {
- throw Error("invalid duration, unexpected number")
- }
- currentNum += c
- continue
- }
- if (c == ' ') {
- if (currentNum != "") {
- parsingNum = false
- }
- continue
- }
- if (currentNum == "") {
- throw Error("invalid duration, missing number")
- }
- val n = currentNum.toInt(10)
- durationUs += when (c) {
- 's' -> {
- n * 1000000
- }
-
- 'm' -> {
- n * 1000000 * 60
- }
-
- 'h' -> {
- n * 1000000 * 60 * 60
- }
-
- 'd' -> {
- n * 1000000 * 60 * 60 * 24
- }
-
- else -> {
- throw Error("invalid duration, unsupported unit '$c'")
- }
- }
- parsingNum = true
- currentNum = ""
- }
- return durationUs
-}
-
class BankDbInit : CliktCommand("Initialize the libeufin-bank database", name = "dbinit") {
private val configFile by option(
"--config", "-c",
@@ -388,11 +339,16 @@ class ChangePw : CliktCommand("Change account password", name = "passwd") {
val dbCfg = cfg.loadDbConfig()
val db = Database(dbCfg.dbConnStr, ctx.regionalCurrency, ctx.fiatCurrency)
runBlocking {
- if (db.account.reconfigPassword(account, password, null) != AccountPatchAuthResult.Success) {
- println("password change failed")
- exitProcess(1)
- } else {
- println("password change succeeded")
+ val res = db.account.reconfigPassword(account, password, null)
+ when (res) {
+ AccountPatchAuthResult.UnknownAccount -> {
+ logger.error("password change for '$account' account failed: unknown account")
+ exitProcess(1)
+ }
+ AccountPatchAuthResult.OldPasswordMismatch -> { /* Can never happen */ }
+ AccountPatchAuthResult.Success -> {
+ logger.info("password change for '$account' account succeeded")
+ }
}
}
}
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/AccountDAO.kt b/bank/src/main/kotlin/tech/libeufin/bank/db/AccountDAO.kt
@@ -136,7 +136,7 @@ class AccountDAO(private val db: Database) {
return@transaction AccountCreationResult.PayToReuse
}
}
- println("$bonus")
+
if (bonus.value != 0L || bonus.frac != 0) {
conn.prepareStatement("""
SELECT out_balance_insufficient
diff --git a/bank/src/test/kotlin/routines.kt b/bank/src/test/kotlin/routines.kt
@@ -119,10 +119,6 @@ inline suspend fun <reified B> ApplicationTestBuilder.historyRoutine(
val nbIgnored = ignored.size
val nbTotal = nbRegistered + nbIgnored
- println(nbRegistered)
-
- println("simple")
-
// Check ignored
history("delta=$nbTotal").assertHistory(nbRegistered)
// Check skip ignored
@@ -140,8 +136,6 @@ inline suspend fun <reified B> ApplicationTestBuilder.historyRoutine(
.assertHistory(nbRegistered)
}
- println("polling")
-
// Check polling
coroutineScope {
val id = latestId()
@@ -158,12 +152,9 @@ inline suspend fun <reified B> ApplicationTestBuilder.historyRoutine(
}
}
delay(100)
- println(registered.size)
registered[0]()
}
- println("triggers")
-
// Test triggers
for (register in registered) {
coroutineScope {
@@ -195,8 +186,6 @@ inline suspend fun <reified B> ApplicationTestBuilder.historyRoutine(
}
}
- println("range")
-
// Testing ranges.
repeat(20) {
registered[0]()