insert_issued_receipt.c (3045B)
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_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 "insert_issued_receipt.h" 28 #include "helper.h" 29 #include "donau_service.h" 30 #include "donau_pq_lib.h" 31 32 enum GNUNET_DB_QueryStatus 33 DONAUDB_insert_issued_receipt ( 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 { 43 struct GNUNET_PQ_QueryParam params[] = { 44 GNUNET_PQ_query_param_uint64 (&charity_id), 45 DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, 46 signatures, 47 ctx->conn), 48 GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash), 49 TALER_PQ_query_param_amount (ctx->conn, 50 amount_receipts_request), 51 GNUNET_PQ_query_param_uint32 (&year), 52 GNUNET_PQ_query_param_end 53 }; 54 struct GNUNET_PQ_ResultSpec rs[] = { 55 GNUNET_PQ_result_spec_bool ("smaller_than_max_per_year", 56 smaller_than_max_per_year), 57 GNUNET_PQ_result_spec_end 58 }; 59 60 enum GNUNET_DB_QueryStatus qs; 61 PREPARE (ctx, 62 "insert_issued_receipts_request", 63 "SELECT " 64 " out_smaller_than_max_per_year AS smaller_than_max_per_year" 65 " FROM do_insert_issued_receipts" 66 "($1,$2,$3,$4,$5);"); 67 68 qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 69 "insert_issued_receipts_request", 70 params, 71 rs); 72 GNUNET_PQ_cleanup_query_params_closures (params); 73 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 74 "Is the new receipts_to_day smaller than the max_per_year (1 = true): %d\n", 75 (*smaller_than_max_per_year)); 76 return qs; 77 }