gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (51300a1a -> 5441ffc3)


From: gnunet
Subject: [libeufin] branch master updated (51300a1a -> 5441ffc3)
Date: Tue, 23 Jan 2024 20:46:50 +0100

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

antoine pushed a change to branch master
in repository libeufin.

    from 51300a1a Share IbanPayto logic and improve full IBAN payto logic
     new 9210b01f Add missing /config endpoints
     new 1d27092d New RevenueApi
     new 5441ffc3 Remove debug println

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 API_CHANGES.md                                     |  3 ++
 .../main/kotlin/tech/libeufin/bank/Constants.kt    |  3 +-
 bank/src/main/kotlin/tech/libeufin/bank/Main.kt    |  2 +-
 .../main/kotlin/tech/libeufin/bank/RevenueApi.kt   | 11 +++++--
 .../main/kotlin/tech/libeufin/bank/TalerMessage.kt | 36 +++++++++++++---------
 .../kotlin/tech/libeufin/bank/WireGatewayApi.kt    | 12 +++-----
 .../main/kotlin/tech/libeufin/bank/db/Database.kt  |  2 +-
 .../kotlin/tech/libeufin/bank/db/ExchangeDAO.kt    | 30 ++----------------
 .../tech/libeufin/bank/db/NotificationWatcher.kt   |  6 ++--
 .../kotlin/tech/libeufin/bank/db/TransactionDAO.kt | 26 +++++++++++++++-
 bank/src/test/kotlin/RevenueApiTest.kt             | 26 +++++++++-------
 bank/src/test/kotlin/WireGatewayApiTest.kt         |  8 +++++
 bank/src/test/kotlin/helpers.kt                    | 10 +++---
 common/src/main/kotlin/TalerCommon.kt              |  1 -
 .../main/kotlin/tech/libeufin/nexus/EbicsFetch.kt  |  1 -
 nexus/src/main/kotlin/tech/libeufin/nexus/Log.kt   |  3 +-
 16 files changed, 101 insertions(+), 79 deletions(-)

diff --git a/API_CHANGES.md b/API_CHANGES.md
index 3379c505..b9e550ba 100644
--- a/API_CHANGES.md
+++ b/API_CHANGES.md
@@ -30,6 +30,9 @@ This files contains all the API changes for the current 
release:
 - POST /cashouts: remove status field
 - PATCH /accounts/USERNAME: add tan_channel
 - GET /accounts/USERNAME: add tan_channel
+- Add GET /accounts/USERNAME/taler-revenue/config
+- Add GET /accounts/USERNAME/taler-wire-gateway/config
+- Change GET /accounts/USERNAME/taler-revenue/history logic and body type
 
 ## bank cli
 
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Constants.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/Constants.kt
index ef647112..c25ea662 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Constants.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Constants.kt
@@ -43,4 +43,5 @@ const val MAX_BODY_LENGTH: Long = 4 * 1024 // 4kB
 const val COREBANK_API_VERSION: String = "4:0:0"
 const val CONVERSION_API_VERSION: String = "0:0:0"
 const val INTEGRATION_API_VERSION: String = "2:0:2"
-const val WIRE_GATEWAY_API_VERSION: String = "0:1:0"
\ No newline at end of file
+const val WIRE_GATEWAY_API_VERSION: String = "0:2:0"
+const val REVENUE_API_VERSION: String = "0:0:0"
\ No newline at end of file
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
index 575efe6c..ceb7927b 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -209,7 +209,7 @@ fun Application.corebankWebApp(db: Database, ctx: 
BankConfig) {
         conversionApi(db, ctx)
         bankIntegrationApi(db, ctx)
         wireGatewayApi(db, ctx)
-        revenueApi(db)
+        revenueApi(db, ctx)
         ctx.spaPath?.let {
             get("/") {
                 call.respondRedirect("/webui/")
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/RevenueApi.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/RevenueApi.kt
index 7200de47..999503d2 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/RevenueApi.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/RevenueApi.kt
@@ -28,17 +28,22 @@ import tech.libeufin.common.*
 import tech.libeufin.bank.auth.*
 import tech.libeufin.bank.db.*
 
-fun Routing.revenueApi(db: Database) { 
+fun Routing.revenueApi(db: Database, ctx: BankConfig) { 
     auth(db, TokenScope.readonly) {
+        get("/accounts/{USERNAME}/taler-revenue/config") {
+            call.respond(RevenueConfig(
+                currency = ctx.regionalCurrency
+            ))
+        }
         get("/accounts/{USERNAME}/taler-revenue/history") {
             val params = HistoryParams.extract(context.request.queryParameters)
             val bankAccount = call.bankInfo(db)
-            val items = db.exchange.revenueHistory(params, 
bankAccount.bankAccountId);
+            val items = db.transaction.revenueHistory(params, 
bankAccount.bankAccountId);
         
             if (items.isEmpty()) {
                 call.respond(HttpStatusCode.NoContent)
             } else {
-                call.respond(MerchantIncomingHistory(items, 
bankAccount.internalPaytoUri))
+                call.respond(RevenueIncomingHistory(items, 
bankAccount.internalPaytoUri))
             }
         }
     }
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
index b4857085..1d7c5efa 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
@@ -304,8 +304,24 @@ data class TalerIntegrationConfigResponse(
     val currency: String,
     val currency_specification: CurrencySpecification
 ) {
-    val name: String = "taler-bank-integration";
-    val version: String = INTEGRATION_API_VERSION;
+    val name: String = "taler-bank-integration"
+    val version: String = INTEGRATION_API_VERSION
+}
+
+@Serializable
+data class WireGatewayConfig(
+    val currency: String
+) {
+    val name: String = "taler-wire-gateway"
+    val version: String = WIRE_GATEWAY_API_VERSION
+}
+
+@Serializable
+data class RevenueConfig(
+    val currency: String
+) {
+    val name: String = "taler-revenue"
+    val version: String = REVENUE_API_VERSION
 }
 
 enum class CreditDebitInfo {
@@ -535,13 +551,6 @@ data class AddIncomingResponse(
     val row_id: Long
 )
 
-@Serializable
-data class TWGConfigResponse(
-    val name: String = "taler-wire-gateway",
-    val version: String = WIRE_GATEWAY_API_VERSION,
-    val currency: String
-)
-
 /**
  * Response of a TWG /history/incoming call.
  */
@@ -587,19 +596,18 @@ data class OutgoingTransaction(
 )
 
 @Serializable
-data class MerchantIncomingHistory(
-    val incoming_transactions : List<MerchantIncomingBankTransaction>,
+data class RevenueIncomingHistory(
+    val incoming_transactions : List<RevenueIncomingBankTransaction>,
     val credit_account: String
 )
 
 @Serializable
-data class MerchantIncomingBankTransaction(
+data class RevenueIncomingBankTransaction(
     val row_id: Long,
     val date: TalerProtocolTimestamp,
     val amount: TalerAmount,
     val debit_account: String,
-    val exchange_url: String,
-    val wtid: ShortHashCode
+    val subject: String
 )
 
 /**
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt
index eba396a1..bfca3d1e 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt
@@ -35,14 +35,12 @@ import tech.libeufin.bank.auth.*
 
 
 fun Routing.wireGatewayApi(db: Database, ctx: BankConfig) {
-    get("/taler-wire-gateway/config") {
-        call.respond(TWGConfigResponse(
-            currency = ctx.regionalCurrency
-        ))
-        
-        return@get
-    }
     auth(db, TokenScope.readwrite) {
+        get("/accounts/{USERNAME}/taler-wire-gateway/config") {
+            call.respond(WireGatewayConfig(
+                currency = ctx.regionalCurrency
+            ))
+        }
         post("/accounts/{USERNAME}/taler-wire-gateway/transfer") {
             val req = call.receive<TransferRequest>()
             ctx.checkRegionalCurrency(req.amount)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt
index a0edbdec..f652c3c5 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt
@@ -160,7 +160,7 @@ class Database(dbConfig: String, internal val bankCurrency: 
String, internal val
         suspend fun load(): List<T> = page(
             params.page, 
             "bank_transaction_id", 
-            "$query WHERE $accountColumn=? AND", 
+            "$query $accountColumn=? AND", 
             {
                 setLong(1, bankAccountId)
                 1
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/ExchangeDAO.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/db/ExchangeDAO.kt
index 3339bae6..474205bc 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/db/ExchangeDAO.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/db/ExchangeDAO.kt
@@ -44,6 +44,7 @@ class ExchangeDAO(private val db: Database) {
             FROM taler_exchange_incoming AS tfr
                 JOIN bank_account_transactions AS txs
                     ON bank_transaction=txs.bank_transaction_id
+            WHERE
         """) {
             IncomingReserveTransaction(
                 row_id = it.getLong("bank_transaction_id"),
@@ -71,6 +72,7 @@ class ExchangeDAO(private val db: Database) {
             FROM taler_exchange_outgoing AS tfr
                 JOIN bank_account_transactions AS txs
                     ON bank_transaction=txs.bank_transaction_id
+            WHERE
         """) {
             OutgoingTransaction(
                 row_id = it.getLong("bank_transaction_id"),
@@ -82,34 +84,6 @@ class ExchangeDAO(private val db: Database) {
             )
         }
 
-    /** Query [merchantId] history of taler outgoing transactions to its 
account */
-    suspend fun revenueHistory(
-        params: HistoryParams, 
-        merchantId: Long
-    ): List<MerchantIncomingBankTransaction> 
-        = db.poolHistory(params, merchantId, 
NotificationWatcher::listenRevenue, """
-            SELECT
-                bank_transaction_id
-                ,transaction_date
-                ,(amount).val AS amount_val
-                ,(amount).frac AS amount_frac
-                ,debtor_payto_uri
-                ,wtid
-                ,exchange_base_url
-            FROM taler_exchange_outgoing AS tfr
-                JOIN bank_account_transactions AS txs
-                    ON bank_transaction=txs.bank_transaction_id
-        """, "creditor_account_id") {
-            MerchantIncomingBankTransaction(
-                row_id = it.getLong("bank_transaction_id"),
-                date = it.getTalerTimestamp("transaction_date"),
-                amount = it.getAmount("amount", db.bankCurrency),
-                debit_account = it.getString("debtor_payto_uri"),
-                wtid = ShortHashCode(it.getBytes("wtid")),
-                exchange_url = it.getString("exchange_base_url")
-            )
-        }
-
     /** Result of taler transfer transaction creation */
     sealed class TransferResult {
         /** Transaction [id] and wire transfer [timestamp] */
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt
index 973423e1..eb6cd879 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt
@@ -75,15 +75,15 @@ internal class NotificationWatcher(private val pgSource: 
PGSimpleDataSource) {
                                         bankTxFlows[creditor]?.run {
                                             flow.emit(creditRow)
                                         }
+                                        revenueTxFlows[creditor]?.run {
+                                            flow.emit(creditRow)
+                                        }
                                     }
                                     "outgoing_tx" -> {
                                         val (account, merchant, debitRow, 
creditRow) = it.parameter.split(' ', limit = 4).map { it.toLong() }
                                         outgoingTxFlows[account]?.run {
                                             flow.emit(debitRow)
                                         }
-                                        revenueTxFlows[merchant]?.run {
-                                            flow.emit(creditRow)
-                                        }
                                     }
                                     "incoming_tx" -> {
                                         val (account, row) = 
it.parameter.split(' ', limit = 2).map { it.toLong() }
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt
index b6038dc5..1b996f5a 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt
@@ -187,7 +187,7 @@ class TransactionDAO(private val db: Database) {
                 ,creditor_payto_uri
                 ,subject
                 ,direction
-            FROM bank_account_transactions
+            FROM bank_account_transactions WHERE
         """) {
             BankAccountTransactionInfo(
                 row_id = it.getLong("bank_transaction_id"),
@@ -200,4 +200,28 @@ class TransactionDAO(private val db: Database) {
             )
         }
     }
+
+    /** Query [accountId] history of incoming transactions to its account */
+    suspend fun revenueHistory(
+        params: HistoryParams, 
+        accountId: Long
+    ): List<RevenueIncomingBankTransaction> 
+        = db.poolHistory(params, accountId, 
NotificationWatcher::listenRevenue, """
+            SELECT
+                bank_transaction_id
+                ,transaction_date
+                ,(amount).val AS amount_val
+                ,(amount).frac AS amount_frac
+                ,debtor_payto_uri
+                ,subject
+            FROM bank_account_transactions WHERE direction='credit' AND
+        """) {
+            RevenueIncomingBankTransaction(
+                row_id = it.getLong("bank_transaction_id"),
+                date = it.getTalerTimestamp("transaction_date"),
+                amount = it.getAmount("amount", db.bankCurrency),
+                debit_account = it.getString("debtor_payto_uri"),
+                subject = it.getString("subject")
+            )
+        }
 }
\ No newline at end of file
diff --git a/bank/src/test/kotlin/RevenueApiTest.kt 
b/bank/src/test/kotlin/RevenueApiTest.kt
index 8f76b216..dfa0e69c 100644
--- a/bank/src/test/kotlin/RevenueApiTest.kt
+++ b/bank/src/test/kotlin/RevenueApiTest.kt
@@ -29,32 +29,36 @@ import org.junit.Test
 import tech.libeufin.bank.*
 
 class RevenueApiTest {
+    // GET /accounts/{USERNAME}/taler-revenue/config
+    @Test
+    fun config() = bankSetup { _ ->
+        authRoutine(HttpMethod.Get, "/accounts/merchant/taler-revenue/config")
+
+        client.getA("/accounts/merchant/taler-revenue/config").assertOk()
+    }
+
     // GET /accounts/{USERNAME}/taler-revenue/history
     @Test
     fun history() = bankSetup {
         setMaxDebt("exchange", "KUDOS:1000000")
         authRoutine(HttpMethod.Get, "/accounts/merchant/taler-revenue/history")
-        historyRoutine<MerchantIncomingHistory>(
+        historyRoutine<RevenueIncomingHistory>(
             url = "/accounts/merchant/taler-revenue/history",
             ids = { it.incoming_transactions.map { it.row_id } },
             registered = listOf(
                 { 
                     // Transactions using clean transfer logic
                     transfer("KUDOS:10")
+                },
+                { 
+                    // Common credit transactions
+                    tx("exchange", "KUDOS:10", "merchant", "ignored")
                 }
             ),
             ignored = listOf(
                 {
-                    // Ignore manual incoming transaction
-                    tx("exchange", "KUDOS:10", "merchant", 
"${randShortHashCode()} http://exchange.example.com/";)
-                },
-                {
-                    // Ignore malformed incoming transaction
-                    tx("merchant", "KUDOS:10", "exchange", "ignored")
-                },
-                {
-                    // Ignore malformed outgoing transaction
-                    tx("exchange", "KUDOS:10", "merchant", "ignored")
+                    // Ignore debit transactions
+                    tx("merchant", "KUDOS:10", "customer")
                 }
             )
         )
diff --git a/bank/src/test/kotlin/WireGatewayApiTest.kt 
b/bank/src/test/kotlin/WireGatewayApiTest.kt
index 150de96a..ed8bdbf9 100644
--- a/bank/src/test/kotlin/WireGatewayApiTest.kt
+++ b/bank/src/test/kotlin/WireGatewayApiTest.kt
@@ -30,6 +30,14 @@ import tech.libeufin.bank.*
 import tech.libeufin.common.*
 
 class WireGatewayApiTest {
+    // GET /accounts/{USERNAME}/taler-wire-gateway/config
+    @Test
+    fun config() = bankSetup { _ ->
+        authRoutine(HttpMethod.Get, 
"/accounts/merchant/taler-wire-gateway/config")
+
+        client.getA("/accounts/merchant/taler-wire-gateway/config").assertOk()
+    }
+
     // Testing the POST /transfer call from the TWG API.
     @Test
     fun transfer() = bankSetup { _ -> 
diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt
index 69c0ede9..c02a7e77 100644
--- a/bank/src/test/kotlin/helpers.kt
+++ b/bank/src/test/kotlin/helpers.kt
@@ -397,19 +397,19 @@ inline suspend fun <reified B> 
HttpResponse.assertHistoryIds(size: Int, ids: (B)
     val params = PageParams.extract(call.request.url.parameters)
 
     // testing the size is like expected.
-    assertEquals(size, history.size)
+    assertEquals(size, history.size, "bad history lenght: $history")
     if (params.delta < 0) {
         // testing that the first id is at most the 'start' query param.
-        assert(history[0] <= params.start)
+        assert(history[0] <= params.start) { "bad history start: $params 
$history" }
         // testing that the id decreases.
         if (history.size > 1)
-            assert(history.windowed(2).all { (a, b) -> a > b })
+            assert(history.windowed(2).all { (a, b) -> a > b }) { "bad history 
order: $history" }
     } else {
         // testing that the first id is at least the 'start' query param.
-        assert(history[0] >= params.start)
+        assert(history[0] >= params.start) { "bad history start: $params 
$history" }
         // testing that the id increases.
         if (history.size > 1)
-            assert(history.windowed(2).all { (a, b) -> a < b })
+            assert(history.windowed(2).all { (a, b) -> a < b }) { "bad history 
order: $history" }
     }
 
     return body
diff --git a/common/src/main/kotlin/TalerCommon.kt 
b/common/src/main/kotlin/TalerCommon.kt
index 76c8d801..4cec44ab 100644
--- a/common/src/main/kotlin/TalerCommon.kt
+++ b/common/src/main/kotlin/TalerCommon.kt
@@ -121,7 +121,6 @@ class IbanPayto: PaytoUri {
     override val receiverName: String?
 
     constructor(raw: String) {
-        println(raw)
         try {
             parsed = URI(raw)
         } catch (e: Exception) {
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
index 55a3e401..2c26ea75 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -424,7 +424,6 @@ class EbicsFetch: CliktCommand("Fetches bank records.  
Defaults to camt.054 noti
      * FIXME: reduce code duplication with the submit subcommand.
      */
     override fun run() = cliCmd(logger, common.log) {
-        println("start $ebicsLog")
         val cfg: EbicsSetupConfig = extractEbicsConfig(common.config)
         val dbCfg = cfg.config.dbConfig()
 
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Log.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Log.kt
index e59b65f4..ffd495f8 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Log.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Log.kt
@@ -36,8 +36,7 @@ class FileLogger(path: String?) {
     private val dir = if (path != null) Path(path) else null
 
     init {
-        println("$path $dir")
-                if (dir != null) {
+        if (dir != null) {
             try {
                 // Create logging directory if missing
                 dir.createDirectories()

-- 
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]