pg_insert_issued_receipt.c (3007B)
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_issued_receipt.c 18 * @brief Implementation of the insert_issued_receipt 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 "pg_insert_issued_receipt.h" 28 #include "pg_helper.h" 29 #include "donau_service.h" 30 #include "donau_pq_lib.h" 31 32 enum GNUNET_DB_QueryStatus 33 DH_PG_insert_issued_receipt ( 34 void *cls, 35 const size_t num_blinded_sig, 36 const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], 37 const uint64_t charity_id, 38 const struct DONAU_DonationReceiptHashP *h_receipt, 39 const struct TALER_Amount *amount_receipts_request, 40 bool *smaller_than_max_per_year) 41 { 42 struct PostgresClosure *pc = cls; 43 44 struct GNUNET_PQ_ResultSpec rs[] = { 45 GNUNET_PQ_result_spec_bool ("smaller_than_max_per_year", 46 smaller_than_max_per_year), 47 GNUNET_PQ_result_spec_end 48 }; 49 50 struct GNUNET_PQ_QueryParam params[] = { 51 GNUNET_PQ_query_param_uint64 (&charity_id), 52 DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, 53 signatures, 54 pc->conn), 55 GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash), 56 TALER_PQ_query_param_amount (pc->conn, 57 amount_receipts_request), 58 GNUNET_PQ_query_param_end 59 }; 60 61 enum GNUNET_DB_QueryStatus qs; 62 63 PREPARE (pc, 64 "insert_issued_receipts_request", 65 "SELECT " 66 " out_smaller_than_max_per_year AS smaller_than_max_per_year" 67 " FROM do_insert_issued_receipts" 68 "($1,$2,$3,$4);"); 69 70 qs = GNUNET_PQ_eval_prepared_singleton_select (pc->conn, 71 "insert_issued_receipts_request", 72 params, 73 rs); 74 GNUNET_PQ_cleanup_query_params_closures (params); 75 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 76 "Is the new receipts_to_day smaller than the max_per_year (1 = true): %d\n", 77 (*smaller_than_max_per_year)); 78 return qs; 79 }