donau

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

insert_submitted_receipts.c (3989B)


      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 src/donaudb/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 "insert_submitted_receipts.h"
     26 #include "helper.h"
     27 #include "donau_service.h"
     28 #include "donau_pq_lib.h"
     29 
     30 
     31 enum GNUNET_DB_QueryStatus
     32 DONAUDB_insert_submitted_receipts (struct DONAUDB_PostgresContext *ctx,
     33                                    struct DONAU_HashDonorTaxId *h_donor_tax_id,
     34                                    size_t num_dr,
     35                                    const struct DONAU_DonationReceipt
     36                                    donation_receipts[static num_dr],
     37                                    uint64_t donation_year)
     38 {
     39   struct GNUNET_HashCode h_donation_unit_pubs[GNUNET_NZL (num_dr)];
     40   struct DONAU_UniqueDonorIdentifierNonce nonces[GNUNET_NZL (num_dr)];
     41   struct DONAU_DonationUnitSignature donation_unit_sigs[GNUNET_NZL (num_dr)];
     42   struct GNUNET_PQ_QueryParam params[] = {
     43     GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id),
     44     GNUNET_PQ_query_param_array_auto_from_type (num_dr,
     45                                                 h_donation_unit_pubs,
     46                                                 ctx->conn),
     47     GNUNET_PQ_query_param_array_auto_from_type (num_dr,
     48                                                 nonces,
     49                                                 ctx->conn),
     50     DONAU_PQ_query_param_array_donation_unit_sig (num_dr,
     51                                                   donation_unit_sigs,
     52                                                   ctx->conn),
     53     GNUNET_PQ_query_param_uint64 (&donation_year),
     54     GNUNET_PQ_query_param_end
     55   };
     56   bool *conflicted = NULL;
     57   struct GNUNET_PQ_ResultSpec rs[] = {
     58     GNUNET_PQ_result_spec_array_bool (ctx->conn,
     59                                       "conflicted",
     60                                       &num_dr,
     61                                       &conflicted),
     62     GNUNET_PQ_result_spec_end
     63   };
     64   enum GNUNET_DB_QueryStatus qs;
     65 
     66   for (unsigned int i = 0; i < num_dr; i++)
     67   {
     68     const struct DONAU_DonationReceipt *dr = &donation_receipts[i];
     69 
     70     h_donation_unit_pubs[i] = dr->h_donation_unit_pub.hash;
     71     nonces[i] = dr->nonce;
     72     donation_unit_sigs[i] = dr->donation_unit_sig;
     73     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     74                 "Do insert submitted receipt\n");
     75   }
     76 
     77   PREPARE (ctx,
     78            "call_insert_submitted_receipts",
     79            "SELECT "
     80            " out_conflict AS conflicted"
     81            " FROM do_insert_submitted_receipts"
     82            "($1,$2,$3,$4,$5);");
     83   qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
     84                                                  "call_insert_submitted_receipts",
     85                                                  params,
     86                                                  rs);
     87   GNUNET_PQ_cleanup_query_params_closures (params);
     88 
     89   for (size_t i = 0; i < num_dr; i++)
     90   {
     91     if (conflicted[i])
     92     {
     93       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     94                   "Submitted donation receipt at index %ld already present!\n",
     95                   i);
     96     }
     97   }
     98   GNUNET_free (conflicted);
     99   GNUNET_PQ_cleanup_result (rs);
    100   return qs;
    101 }