gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: added pg_iterate_submitted_receipts


From: gnunet
Subject: [taler-donau] branch master updated: added pg_iterate_submitted_receipts
Date: Tue, 30 Apr 2024 22:01:43 +0200

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

johannes-casaburi pushed a commit to branch master
in repository donau.

The following commit(s) were added to refs/heads/master by this push:
     new c721f7f  added pg_iterate_submitted_receipts
c721f7f is described below

commit c721f7f2cd7c8d093b7a85b1b8fb4f0830705313
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
AuthorDate: Tue Apr 30 22:01:16 2024 +0200

    added pg_iterate_submitted_receipts
---
 contrib/gana                                |   2 +-
 src/donau/donau-httpd_batch-submit.c        |   8 +-
 src/donaudb/Makefile.am                     |   1 +
 src/donaudb/pg_iterate_submitted_receipts.c | 129 ++++++++++++++++++++++++++++
 src/donaudb/pg_iterate_submitted_receipts.h |  43 ++++++++++
 src/include/donaudb_plugin.h                |  61 +++++++------
 6 files changed, 213 insertions(+), 31 deletions(-)

diff --git a/contrib/gana b/contrib/gana
index e6540cf..63ab2f3 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit e6540cf597091eabaa732826d5ad1185f4bcc5c1
+Subproject commit 63ab2f3c99c86334cc433450d7b99375ebf9d6b1
diff --git a/src/donau/donau-httpd_batch-submit.c 
b/src/donau/donau-httpd_batch-submit.c
index 41bf396..22aa803 100644
--- a/src/donau/donau-httpd_batch-submit.c
+++ b/src/donau/donau-httpd_batch-submit.c
@@ -178,10 +178,6 @@ DH_handler_submit_receipts_post (struct DH_RequestContext 
*rc,
     }
   }
 
-  // FIXME
-  // Fetch donation receipts and join with donation units to get amount
-  // then create donation statement
-
   enum GNUNET_DB_QueryStatus qs;
 
   qs = DH_plugin->insert_submitted_receipts (
@@ -201,6 +197,10 @@ DH_handler_submit_receipts_post (struct DH_RequestContext 
*rc,
                                        "donation_receipts");
   }
 
+  // FIXME
+  // Fetch donation receipts and join with donation units to get amount
+  // then create donation statement
+
   // FIXME
   // Send back DS
 
diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am
index fa843c1..21890f2 100644
--- a/src/donaudb/Makefile.am
+++ b/src/donaudb/Makefile.am
@@ -83,6 +83,7 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \
   pg_iterate_active_signing_keys.c pg_iterate_active_signing_keys.h \
   pg_insert_donation_unit.c pg_insert_donation_unit.h \
   pg_iterate_donation_units.c pg_iterate_donation_units.h \
+  pg_iterate_submitted_receipts.c pg_iterate_submitted_receipts.h \
   pg_get_history.h pg_get_history.c \
   pg_get_charities.h pg_get_charities.c \
   pg_insert_charity.h pg_insert_charity.c \
diff --git a/src/donaudb/pg_iterate_submitted_receipts.c 
b/src/donaudb/pg_iterate_submitted_receipts.c
new file mode 100644
index 0000000..018fb8e
--- /dev/null
+++ b/src/donaudb/pg_iterate_submitted_receipts.c
@@ -0,0 +1,129 @@
+/*
+   This file is part of TALER
+   Copyright (C) 2024 Taler Systems SA
+
+   TALER is free software; you can redistribute it and/or modify it under the
+   terms of the GNU General Public License as published by the Free Software
+   Foundation; either version 3, or (at your option) any later version.
+
+   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file donaudb/pg_iterate_submitted_receipts.c
+ * @brief Implementation of the iterate_submitted_receipts function for 
Postgres
+ * @author Johannes Casaburi
+ */
+#include <taler/platform.h>
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_iterate_submitted_receipts.h"
+#include "pg_helper.h"
+#include "donaudb_plugin.h"
+#include "donau_pq_lib.h"
+
+/**
+ * Closure for #get_submitted_receipts_cb().
+ */
+struct IterateSubmittedReceiptsContext
+{
+  /**
+   * Function to call per result.
+   */
+  DONAUDB_IterateSubmittedReceiptsCallback cb;
+
+  /**
+   * Closure for @e cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Plugin context.
+   */
+  struct PostgresClosure *pg;
+
+};
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+iterate_submitted_receipts_cb (void *cls,
+                               PGresult *result,
+                               unsigned int num_results)
+{
+  struct IterateSubmittedReceiptsContext *ctx = cls;
+  struct PostgresClosure *pg = ctx->pg;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    struct TALER_Amount value;
+    enum GNUNET_GenericReturnValue iret;
+
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      TALER_PQ_RESULT_SPEC_AMOUNT ("value",
+                                   &value),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      return;
+    }
+
+    iret = ctx->cb (ctx->cb_cls,
+                    &value);
+    GNUNET_PQ_cleanup_result (rs);
+    if (GNUNET_OK != iret)
+      break;
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+DH_PG_iterate_submitted_receipts (void *cls,
+                                  const uint64_t donation_year,
+                                  const struct DONAU_HashDonorTaxId *
+                                  h_donor_tax_id,
+                                  DONAUDB_IterateSubmittedReceiptsCallback cb,
+                                  void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_uint64 (&donation_year),
+    GNUNET_PQ_query_param_auto_from_type (&h_donor_tax_id),
+    GNUNET_PQ_query_param_end
+  };
+  struct IterateSubmittedReceiptsContext ctx = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .pg = pg
+  };
+
+  PREPARE (pg,
+           "lookup_submitted_receipts",
+           "SELECT "
+           " value"
+           " FROM receipts_submitted"
+           " JOIN donation_units USING (donation_unit_pub)"
+           " WHERE donation_year=$1"
+           " AND h_tax_number=$2");
+  return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                               "iterate_submitted_receipts",
+                                               params,
+                                               &iterate_submitted_receipts_cb,
+                                               &ctx);
+}
diff --git a/src/donaudb/pg_iterate_submitted_receipts.h 
b/src/donaudb/pg_iterate_submitted_receipts.h
new file mode 100644
index 0000000..a46d470
--- /dev/null
+++ b/src/donaudb/pg_iterate_submitted_receipts.h
@@ -0,0 +1,43 @@
+/*
+   This file is part of TALER
+   Copyright (C) 2024 Taler Systems SA
+
+   TALER is free software; you can redistribute it and/or modify it under the
+   terms of the GNU General Public License as published by the Free Software
+   Foundation; either version 3, or (at your option) any later version.
+
+   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file donaudb/pg_iterate_donation_units.h
+ * @brief implementation of the iterate_donation_units function for Postgres
+ * @author Johannes Casaburi
+ */
+#ifndef PG_ITERATE_SUBMITTED_RECEIPTS_H
+#define PG_ITERATE_SUBMITTED_RECEIPTS_H
+
+#include "donaudb_plugin.h"
+
+/**
+ * Obtain information about the enabled wire accounts of the exchange.
+ *
+ * @param cls closure
+ * @param donation_year donation year
+ * @param h_donor_tax_id hash of donor tax id
+ * @param cb function to call on each account
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+DH_PG_iterate_donation_units (void *cls,
+                              const uint64_t donation_year,
+                              const struct DONAU_HashDonorTaxId 
*h_donor_tax_id,
+                              DONAUDB_IterateSubmittedReceiptsCallback cb,
+                              void *cb_cls);
+
+#endif
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
index cc00739..99500ff 100644
--- a/src/include/donaudb_plugin.h
+++ b/src/include/donaudb_plugin.h
@@ -149,6 +149,15 @@ typedef void
   const struct DONAU_DonauPublicKeyP *donau_pub,
   struct DONAUDB_SignkeyMetaData *meta);
 
+/**
+ * Return value of submitted donation receipts.
+ *
+ * @param cls closure
+ */
+typedef enum GNUNET_GenericReturnValue
+(*DONAUDB_IterateSubmittedReceiptsCallback)(
+  void *cls,
+  struct TALER_Amount *value);
 
 /**
  * Return donation units.
@@ -216,7 +225,7 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
    */
   enum GNUNET_GenericReturnValue
-  (*drop_tables)(void *cls);
+    (*drop_tables)(void *cls);
 
   /**
    * Create the necessary tables if they are not present
@@ -229,7 +238,7 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
    */
   enum GNUNET_GenericReturnValue
-  (*create_tables)(void *cls);
+    (*create_tables)(void *cls);
 
 
   /**
@@ -241,8 +250,8 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK on success
    */
   enum GNUNET_GenericReturnValue
-  (*start)(void *cls,
-           const char *name);
+    (*start)(void *cls,
+             const char *name);
 
 
   /**
@@ -254,8 +263,8 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK on success
    */
   enum GNUNET_GenericReturnValue
-  (*start_read_committed)(void *cls,
-                          const char *name);
+    (*start_read_committed)(void *cls,
+                            const char *name);
 
   /**
    * Start a READ ONLY serializable transaction.
@@ -266,8 +275,8 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK on success
    */
   enum GNUNET_GenericReturnValue
-  (*start_read_only)(void *cls,
-                     const char *name);
+    (*start_read_only)(void *cls,
+                       const char *name);
 
 
   /**
@@ -277,7 +286,7 @@ struct DONAUDB_Plugin
    * @return transaction status
    */
   enum GNUNET_DB_QueryStatus
-  (*commit)(void *cls);
+    (*commit)(void *cls);
 
 
   /**
@@ -291,7 +300,7 @@ struct DONAUDB_Plugin
    *         #GNUNET_SYSERR on hard errors
    */
   enum GNUNET_GenericReturnValue
-  (*preflight)(void *cls);
+    (*preflight)(void *cls);
 
 
   /**
@@ -312,7 +321,7 @@ struct DONAUDB_Plugin
    *         #GNUNET_SYSERR on DB errors
    */
   enum GNUNET_GenericReturnValue
-  (*gc)(void *cls);
+    (*gc)(void *cls);
 
 
   /**
@@ -367,7 +376,7 @@ struct DONAUDB_Plugin
    * @return database transaction status
    */
   enum GNUNET_DB_QueryStatus
-  (*lookup_charity)(
+    (*lookup_charity)(
     void *cls,
     uint64_t charity_id,
     struct DONAUDB_CharityMetaData *meta);
@@ -382,7 +391,7 @@ struct DONAUDB_Plugin
    * @return database transaction status
    */
   enum GNUNET_DB_QueryStatus
-  (*do_charity_delete)(
+    (*do_charity_delete)(
     void *cls,
     uint64_t charity_id);
 
@@ -395,7 +404,7 @@ struct DONAUDB_Plugin
    * @return database transaction status
    */
   enum GNUNET_DB_QueryStatus
-  (*get_charities)(
+    (*get_charities)(
     void *cls,
     DONAUDB_GetCharitiesCallback cb,
     void *cb_cls);
@@ -409,7 +418,7 @@ struct DONAUDB_Plugin
    * @return database transaction status
    */
   enum GNUNET_DB_QueryStatus
-  (*insert_charity)(
+    (*insert_charity)(
     void *cls,
     const struct DONAU_CharityPublicKeyP *charity_pub,
     const char *charity_name,
@@ -428,7 +437,7 @@ struct DONAUDB_Plugin
     * @return database transaction status
     */
   enum GNUNET_DB_QueryStatus
-  (*iterate_donation_units)(
+    (*iterate_donation_units)(
     void *cls,
     DONAUDB_IterateDonationUnitsCallback cb,
     void *cb_cls);
@@ -442,7 +451,7 @@ struct DONAUDB_Plugin
     * @return database transaction status
     */
   enum GNUNET_DB_QueryStatus
-  (*get_history)(
+    (*get_history)(
     void *cls,
     DONAUDB_GetHistoryCallback cb,
     void *cb_cls);
@@ -456,7 +465,7 @@ struct DONAUDB_Plugin
     * @return database transaction status
     */
   enum GNUNET_DB_QueryStatus
-  (*lookup_history_entry)(
+    (*lookup_history_entry)(
     void *cls,
     const unsigned long long charity_id,
     const struct TALER_Amount *final_amount,
@@ -470,7 +479,7 @@ struct DONAUDB_Plugin
     * @return database transaction status
     */
   enum GNUNET_DB_QueryStatus
-  (*insert_donation_unit)(
+    (*insert_donation_unit)(
     void *cls,
     const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
     const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
@@ -487,7 +496,7 @@ struct DONAUDB_Plugin
     * @return transaction status code
     */
   enum GNUNET_DB_QueryStatus
-  (*insert_history_entry)(
+    (*insert_history_entry)(
     void *cls,
     const uint64_t charity_id,
     const struct TALER_Amount *final_amount,
@@ -506,7 +515,7 @@ struct DONAUDB_Plugin
     * @return transaction status code
     */
   enum GNUNET_DB_QueryStatus
-  (*insert_issued_receipt)(
+    (*insert_issued_receipt)(
     void *cls,
     const size_t num_blinded_sig,
     const struct DONAU_BlindedDonationUnitSignature 
signatures[num_blinded_sig],
@@ -527,7 +536,7 @@ struct DONAUDB_Plugin
     * @return transaction status code
     */
   enum GNUNET_DB_QueryStatus
-  (*insert_submitted_receipts)(
+    (*insert_submitted_receipts)(
     void *cls,
     struct DONAU_HashDonorTaxId *h_donor_tax_id,
     size_t num_dr,
@@ -543,7 +552,7 @@ struct DONAUDB_Plugin
   * @return transaction status code
   */
   enum GNUNET_DB_QueryStatus
-  (*lookup_issued_receipts)(
+    (*lookup_issued_receipts)(
     void *cls,
     struct DONAU_DonationReceiptHashP *h_receitps,
     struct DONAUDB_IssuedReceiptsMetaData *meta);
@@ -557,7 +566,7 @@ struct DONAUDB_Plugin
     * @return transaction status code
     */
   enum GNUNET_DB_QueryStatus
-  (*insert_signing_key)(
+    (*insert_signing_key)(
     void *cls,
     const struct DONAU_DonauPublicKeyP *donau_pub,
     struct DONAUDB_SignkeyMetaData *meta);
@@ -571,7 +580,7 @@ struct DONAUDB_Plugin
     * @return transaction status code
     */
   enum GNUNET_DB_QueryStatus
-  (*lookup_signing_key)(
+    (*lookup_signing_key)(
     void *cls,
     const struct DONAU_DonauPublicKeyP *donau_pub,
     struct DONAUDB_SignkeyMetaData *meta);
@@ -585,7 +594,7 @@ struct DONAUDB_Plugin
     * @return database transaction status
     */
   enum GNUNET_DB_QueryStatus
-  (*iterate_active_signing_keys)(
+    (*iterate_active_signing_keys)(
     void *cls,
     DONAUDB_IterateActiveSigningKeysCallback cb,
     void *cb_cls);

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