gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Balances and GET /accounts.


From: gnunet
Subject: [libeufin] branch master updated: Balances and GET /accounts.
Date: Tue, 07 Mar 2023 19:40:12 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new eb734259 Balances and GET /accounts.
eb734259 is described below

commit eb734259ce107e8850e4f50c881be91847e5778c
Author: MS <ms@taler.net>
AuthorDate: Tue Mar 7 19:37:54 2023 +0100

    Balances and GET /accounts.
    
    Including the max debit allowed per account
    and removing the "GET /accounts" filter for
    the accounts without a cash-out target.
---
 .../src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt  | 12 +++++-------
 sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt    |  5 ++++-
 sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt    |  9 +++++----
 .../src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt | 16 ++++++++++++++++
 4 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index e3903923..2c325ccc 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
@@ -562,16 +562,14 @@ fun circuitApi(circuitRoute: Route) {
                 // like() is case insensitive.
                 DemobankCustomersTable.name.like(filter)
             }.forEach {
-                if (it.cashout_address == null) {
-                    logger.debug("Not listing account '${it.username}', as 
that" +
-                            " misses the cash-out address " +
-                            "and therefore doesn't belong to the Circuit API"
-                    )
-                    return@forEach
-                }
                 customers.add(object {
                     val username = it.username
                     val name = it.name
+                    val balance = getBalanceForJson(
+                        getBalance(it.username),
+                        getDefaultDemobank().currency
+                    )
+                    val debitThreshold = getMaxDebitForUser(it.username)
                 })
             }
         }
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
index 678ccff3..87021146 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
@@ -29,7 +29,10 @@ data class WithdrawalRequest(
      */
     val amount: String // $CURRENCY:X.Y
 )
-
+data class BalanceJson(
+    val amount: String,
+    val credit_debit_indicator: String
+)
 data class Demobank(
     val currency: String,
     val name: String,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index cd52a8f4..70294e80 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -1430,6 +1430,9 @@ val sandboxApp: Application.() -> Unit = {
                             )
                         )
                         val iban = bankAccount.iban
+                        // The Elvis operator helps the --no-auth case,
+                        // where username would be empty
+                        val debitThreshold = getMaxDebitForUser(username ?: 
"admin").toString()
                     })
                     return@get
                 }
@@ -1559,16 +1562,14 @@ val sandboxApp: Application.() -> Unit = {
                     )
                     val balance = getBalance(newAccount.bankAccount, 
withPending = true)
                     call.respond(object {
-                        val balance = object {
-                            val amount = 
"${demobank.currency}:${balance.abs()}"
-                            val credit_debit_indicator = if (balance < 
BigDecimal.ZERO) "DBIT" else "CRDT"
-                        }
+                        val balance = getBalanceForJson(balance, 
demobank.currency)
                         val paytoUri = buildIbanPaytoUri(
                             iban = newAccount.bankAccount.iban,
                             bic = newAccount.bankAccount.bic,
                             receiverName = 
getPersonNameFromCustomer(req.username)
                         )
                         val iban = newAccount.bankAccount.iban
+                        val debitThreshold = 
getMaxDebitForUser(req.username).toString()
                     })
                     return@post
                 }
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index d194178c..5bd45a6f 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -32,6 +32,22 @@ fun maybeDebit(
     return false
 }
 
+fun getMaxDebitForUser(username: String): Int {
+    val bank = getDefaultDemobank()
+    if (username == "admin") return bank.bankDebtLimit
+    return bank.usersDebtLimit
+
+
+}
+
+fun getBalanceForJson(value: BigDecimal, currency: String): BalanceJson {
+    return BalanceJson(
+        amount = "${currency}:${value.abs()}",
+        credit_debit_indicator = if (value < BigDecimal.ZERO) "DBIT" else 
"CRDT"
+    )
+
+}
+
 /**
  * The last balance is the one mentioned in the bank account's
  * last statement.  If the bank account does not have any statement

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]