lookup_issued_receipts.c (2669B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024, 2025 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/lookup_issued_receipts.c 18 * @brief Implementation of the lookup_issued_receipts function for Postgres 19 * @author Lukas Matyja 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 "lookup_issued_receipts.h" 26 #include "helper.h" 27 #include "donau_pq_lib.h" 28 29 enum GNUNET_DB_QueryStatus 30 DONAUDB_lookup_issued_receipts (struct DONAUDB_PostgresContext *ctx, 31 struct DONAU_DonationReceiptHashP *h_receipts, 32 struct DONAUDB_IssuedReceiptsMetaData *meta) 33 { 34 struct GNUNET_PQ_QueryParam params[] = { 35 GNUNET_PQ_query_param_auto_from_type (h_receipts), 36 GNUNET_PQ_query_param_end 37 }; 38 struct DONAU_BlindedDonationUnitSignature *du_sigs; 39 size_t num_sigs; 40 struct GNUNET_PQ_ResultSpec rs[] = { 41 DONAU_PQ_result_spec_array_blinded_donation_unit_sig ( 42 ctx->conn, 43 "blinded_sig", 44 &num_sigs, 45 &du_sigs), 46 TALER_PQ_RESULT_SPEC_AMOUNT ("amount", 47 &meta->amount), 48 GNUNET_PQ_result_spec_uint64 ("charity_id", 49 &meta->charity_id), 50 GNUNET_PQ_result_spec_end 51 }; 52 enum GNUNET_DB_QueryStatus qs; 53 54 PREPARE (ctx, 55 "lookup_issued_receipts", 56 "SELECT " 57 " blinded_sig" 58 " ,amount" 59 " ,charity_id" 60 " FROM receipts_issued" 61 " WHERE receipt_hash=$1;"); 62 qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 63 "lookup_issued_receipts", 64 params, 65 rs); 66 if (qs > 0) 67 { 68 /* prevent the result cleanup from freeing the signatures */ 69 meta->num_sig = num_sigs; 70 meta->blinded_sigs = du_sigs; 71 num_sigs = 0; 72 du_sigs = NULL; 73 } 74 GNUNET_PQ_cleanup_result (rs); 75 return qs; 76 }