donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

pg_insert_submitted_receipts.c (3832B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2023 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file donaudb/pg_insert_submitted_receipts.c
     18  * @brief Implementation of the insert_submitted_receipts function for Postgres
     19  * @author Johannes Casaburi
     20  */
     21 #include <donau_config.h>
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "pg_insert_submitted_receipts.h"
     26 #include "pg_helper.h"
     27 #include "donau_service.h"
     28 #include "donau_pq_lib.h"
     29 
     30 
     31 enum GNUNET_DB_QueryStatus
     32 DH_PG_insert_submitted_receipts (
     33   void *cls,
     34   struct DONAU_HashDonorTaxId *h_donor_tax_id,
     35   size_t num_dr,
     36   const struct DONAU_DonationReceipt donation_receipts[static num_dr],
     37   uint64_t donation_year)
     38 {
     39   struct PostgresClosure *pg = cls;
     40   struct GNUNET_HashCode h_donation_unit_pubs[GNUNET_NZL (num_dr)];
     41   struct DONAU_UniqueDonorIdentifierNonce nonces[GNUNET_NZL (num_dr)];
     42   struct DONAU_DonationUnitSignature donation_unit_sigs[GNUNET_NZL (num_dr)];
     43   struct GNUNET_PQ_QueryParam params[] = {
     44     GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id),
     45     GNUNET_PQ_query_param_array_auto_from_type (num_dr,
     46                                                 h_donation_unit_pubs,
     47                                                 pg->conn),
     48     GNUNET_PQ_query_param_array_auto_from_type (num_dr,
     49                                                 nonces,
     50                                                 pg->conn),
     51     DONAU_PQ_query_param_array_donation_unit_sig (num_dr,
     52                                                   donation_unit_sigs,
     53                                                   pg->conn),
     54     GNUNET_PQ_query_param_uint64 (&donation_year),
     55     GNUNET_PQ_query_param_end
     56   };
     57   bool *conflicted = NULL;
     58   struct GNUNET_PQ_ResultSpec rs[] = {
     59     GNUNET_PQ_result_spec_array_bool (pg->conn,
     60                                       "conflicted",
     61                                       &num_dr,
     62                                       &conflicted),
     63     GNUNET_PQ_result_spec_end
     64   };
     65   enum GNUNET_DB_QueryStatus qs;
     66 
     67   for (unsigned int i = 0; i < num_dr; i++)
     68   {
     69     const struct DONAU_DonationReceipt *dr = &donation_receipts[i];
     70 
     71     h_donation_unit_pubs[i] = dr->h_donation_unit_pub.hash;
     72     nonces[i] = dr->nonce;
     73     donation_unit_sigs[i] = dr->donation_unit_sig;
     74     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     75                 "Do insert submitted receipt\n");
     76   }
     77 
     78   PREPARE (pg,
     79            "call_insert_submitted_receipts",
     80            "SELECT "
     81            " out_conflict AS conflicted"
     82            " FROM do_insert_submitted_receipts"
     83            "($1,$2,$3,$4,$5);");
     84   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     85                                                  "call_insert_submitted_receipts",
     86                                                  params,
     87                                                  rs);
     88   GNUNET_PQ_cleanup_query_params_closures (params);
     89 
     90   for (size_t i = 0; i < num_dr; i++)
     91   {
     92     if (conflicted[i])
     93     {
     94       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     95                   "Submitted donation receipt at index %ld already present!\n",
     96                   i);
     97     }
     98   }
     99   GNUNET_free (conflicted);
    100   GNUNET_PQ_cleanup_result (rs);
    101   return qs;
    102 }