insert_issued_receipt.c (2997B)
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 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 GNUNET_PQ_ResultSpec rs[] = { 43 GNUNET_PQ_result_spec_bool ("smaller_than_max_per_year", 44 smaller_than_max_per_year), 45 GNUNET_PQ_result_spec_end 46 }; 47 48 struct GNUNET_PQ_QueryParam params[] = { 49 GNUNET_PQ_query_param_uint64 (&charity_id), 50 DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, 51 signatures, 52 ctx->conn), 53 GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash), 54 TALER_PQ_query_param_amount (ctx->conn, 55 amount_receipts_request), 56 GNUNET_PQ_query_param_end 57 }; 58 59 enum GNUNET_DB_QueryStatus qs; 60 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);"); 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 }