gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: filter invalid transactions in Taler W


From: gnunet
Subject: [libeufin] branch master updated: filter invalid transactions in Taler Wire Gateway API
Date: Sat, 30 Sep 2023 22:49:22 +0200

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

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 9317a014 filter invalid transactions in Taler Wire Gateway API
9317a014 is described below

commit 9317a014bd8e1aca5d19d1dada908d732a4981f1
Author: Florian Dold <florian@dold.me>
AuthorDate: Sat Sep 30 22:49:27 2023 +0200

    filter invalid transactions in Taler Wire Gateway API
    
    We don't bounce yet, but at least don't report invalid reserve_pub 
transactions
---
 .../tech/libeufin/bank/WireGatewayApiHandlers.kt   | 29 ++++++++++++++++------
 bank/src/test/kotlin/TalerApiTest.kt               | 13 +++++++---
 build-system/taler-build-scripts                   |  2 +-
 contrib/wallet-core                                |  2 +-
 4 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApiHandlers.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApiHandlers.kt
index 8833177c..ebfe0ec6 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApiHandlers.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApiHandlers.kt
@@ -27,9 +27,14 @@ import io.ktor.server.request.*
 import io.ktor.server.response.*
 import io.ktor.server.routing.*
 import net.taler.common.errorcodes.TalerErrorCode
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import tech.libeufin.util.extractReservePubFromSubject
 import tech.libeufin.util.stripIbanPayto
 import java.time.Instant
 
+private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
+
 fun Routing.talerWireGatewayHandlers(db: Database, ctx: 
BankApplicationContext) {
     get("/taler-wire-gateway/config") {
         call.respond(TWGConfigResponse(currency = ctx.currency))
@@ -57,15 +62,23 @@ fun Routing.talerWireGatewayHandlers(db: Database, ctx: 
BankApplicationContext)
         }
         val resp = IncomingHistory(credit_account = 
bankAccount.internalPaytoUri)
         history.forEach {
-            resp.incoming_transactions.add(
-                IncomingReserveTransaction(
-                    row_id = it.expectRowId(),
-                    amount = it.amount,
-                    date = TalerProtocolTimestamp(it.transactionDate),
-                    debit_account = it.debtorPaytoUri,
-                    reserve_pub = it.subject
+            val reservePub = extractReservePubFromSubject(it.subject)
+            if (reservePub == null) {
+                // This should usually not happen in the first place,
+                // because transactions to the exchange without a valid
+                // reserve pub should be bounced.
+                logger.warn("exchange account ${c.login} contains invalid 
incoming transaction ${it.expectRowId()}")
+            } else {
+                resp.incoming_transactions.add(
+                    IncomingReserveTransaction(
+                        row_id = it.expectRowId(),
+                        amount = it.amount,
+                        date = TalerProtocolTimestamp(it.transactionDate),
+                        debit_account = it.debtorPaytoUri,
+                        reserve_pub = it.subject
+                    )
                 )
-            )
+            }
         }
         call.respond(resp)
         return@get
diff --git a/bank/src/test/kotlin/TalerApiTest.kt 
b/bank/src/test/kotlin/TalerApiTest.kt
index 1e391a9e..cf6404f6 100644
--- a/bank/src/test/kotlin/TalerApiTest.kt
+++ b/bank/src/test/kotlin/TalerApiTest.kt
@@ -129,7 +129,10 @@ class TalerApiTest {
             assert(currencyMismatchResp.status == HttpStatusCode.BadRequest)
         }
     }
-    // Testing the /history/incoming call from the TWG API.
+
+    /**
+     * Testing the /history/incoming call from the TWG API.
+     */
     @Test
     fun historyIncoming() {
         val db = initDb()
@@ -144,8 +147,12 @@ class TalerApiTest {
             TalerAmount(1000, 0, "KUDOS")
         ))
         // Foo pays Bar (the exchange) twice.
-        assert(db.bankTransactionCreate(genTx("withdrawal 1")) == 
Database.BankTransactionResult.SUCCESS)
-        assert(db.bankTransactionCreate(genTx("withdrawal 2")) == 
Database.BankTransactionResult.SUCCESS)
+        val reservePubOne = 
"5ZFS98S1K4Y083W95GVZK638TSRE44RABVASB3AFA3R95VCW17V0"
+        val reservePubTwo = 
"TFBT5NEVT8D2GETZ4DRF7C69XZHKHJ15296HRGB1R5ARNK0SP8A0"
+        assert(db.bankTransactionCreate(genTx(reservePubOne)) == 
Database.BankTransactionResult.SUCCESS)
+        assert(db.bankTransactionCreate(genTx(reservePubTwo)) == 
Database.BankTransactionResult.SUCCESS)
+        // Should not show up in the taler wire gateway API history
+        assert(db.bankTransactionCreate(genTx("bogus foobar")) == 
Database.BankTransactionResult.SUCCESS)
         // Bar pays Foo once, but that should not appear in the result.
         assert(
             db.bankTransactionCreate(genTx("payout", creditorId = 1, debtorId 
= 2)) ==
diff --git a/build-system/taler-build-scripts b/build-system/taler-build-scripts
index 47f14fcf..001f5dd0 160000
--- a/build-system/taler-build-scripts
+++ b/build-system/taler-build-scripts
@@ -1 +1 @@
-Subproject commit 47f14fcf1d03d9dad1bae59987488ea05ecd307b
+Subproject commit 001f5dd081fc8729ff8def90c4a1c3f93eb8689a
diff --git a/contrib/wallet-core b/contrib/wallet-core
index c5a3cd4c..1708d49a 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit c5a3cd4c50676c49fa6c67cbdeb609101c38e764
+Subproject commit 1708d49a2d5da1f325173a030695223e5a24e75c

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