donau

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

do_insert_receipt_issued.c (3279B)


      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/do_insert_receipt_issued.c
     18  * @brief Implementation of the do_insert_receipt_issued function for Postgres
     19  * @author Johannes Casaburi
     20  * @author Lukas Matyja
     21  */
     22 #include <donau_config.h>
     23 #include <gnunet/gnunet_pq_lib.h>
     24 #include <taler/taler_error_codes.h>
     25 #include <taler/taler_dbevents.h>
     26 #include <taler/taler_pq_lib.h>
     27 #include "do_insert_receipt_issued.h"
     28 #include "helper.h"
     29 #include "donau_service.h"
     30 #include "donau_pq_lib.h"
     31 
     32 enum GNUNET_DB_QueryStatus
     33 DONAUDB_do_insert_receipt_issued (
     34   struct DONAUDB_PostgresContext *ctx,
     35   uint32_t year,
     36   size_t num_blinded_sig,
     37   const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig],
     38   uint64_t charity_id,
     39   const struct DONAU_DonationReceiptHashP *h_receipt,
     40   const struct TALER_Amount *amount_receipts_request,
     41   bool *smaller_than_max_per_year,
     42   bool *charity_unknown)
     43 {
     44   struct GNUNET_PQ_QueryParam params[] = {
     45     GNUNET_PQ_query_param_uint64 (&charity_id),
     46     DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig,
     47                                                           signatures,
     48                                                           ctx->conn),
     49     GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash),
     50     TALER_PQ_query_param_amount (ctx->conn,
     51                                  amount_receipts_request),
     52     GNUNET_PQ_query_param_uint32 (&year),
     53     GNUNET_PQ_query_param_end
     54   };
     55   struct GNUNET_PQ_ResultSpec rs[] = {
     56     GNUNET_PQ_result_spec_bool ("smaller_than_max_per_year",
     57                                 smaller_than_max_per_year),
     58     GNUNET_PQ_result_spec_bool ("charity_unknown",
     59                                 charity_unknown),
     60     GNUNET_PQ_result_spec_end
     61   };
     62 
     63   enum GNUNET_DB_QueryStatus qs;
     64   PREPARE (ctx,
     65            "do_insert_receipt_issued",
     66            "SELECT "
     67            " out_smaller_than_max_per_year AS smaller_than_max_per_year"
     68            ",out_charity_unknown AS charity_unknown"
     69            " FROM do_insert_issued_receipts"
     70            "($1,$2,$3,$4,$5);");
     71 
     72   qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
     73                                                  "do_insert_receipt_issued",
     74                                                  params,
     75                                                  rs);
     76   GNUNET_PQ_cleanup_query_params_closures (params);
     77   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
     78     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     79                 "Is the new receipts_to_day smaller than the max_per_year (1 = true): %d\n",
     80                 (*smaller_than_max_per_year));
     81   return qs;
     82 }