donau

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

lookup_issued_receipts.c (2670B)


      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 
     30 enum GNUNET_DB_QueryStatus
     31 DONAUDB_lookup_issued_receipts (struct DONAUDB_PostgresContext *ctx,
     32                                 struct DONAU_DonationReceiptHashP *h_receipts,
     33                                 struct DONAUDB_IssuedReceiptsMetaData *meta)
     34 {
     35   struct GNUNET_PQ_QueryParam params[] = {
     36     GNUNET_PQ_query_param_auto_from_type (h_receipts),
     37     GNUNET_PQ_query_param_end
     38   };
     39   struct DONAU_BlindedDonationUnitSignature *du_sigs;
     40   size_t num_sigs;
     41   struct GNUNET_PQ_ResultSpec rs[] = {
     42     DONAU_PQ_result_spec_array_blinded_donation_unit_sig (
     43       ctx->conn,
     44       "blinded_sig",
     45       &num_sigs,
     46       &du_sigs),
     47     TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
     48                                  &meta->amount),
     49     GNUNET_PQ_result_spec_uint64 ("charity_id",
     50                                   &meta->charity_id),
     51     GNUNET_PQ_result_spec_end
     52   };
     53   enum GNUNET_DB_QueryStatus qs;
     54 
     55   PREPARE (ctx,
     56            "lookup_issued_receipts",
     57            "SELECT "
     58            " blinded_sig"
     59            " ,amount"
     60            " ,charity_id"
     61            " FROM receipts_issued"
     62            " WHERE receipt_hash=$1;");
     63   qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
     64                                                  "lookup_issued_receipts",
     65                                                  params,
     66                                                  rs);
     67   if (qs > 0)
     68   {
     69     /* prevent the result cleanup from freeing the signatures */
     70     meta->num_sig = num_sigs;
     71     meta->blinded_sigs = du_sigs;
     72     num_sigs = 0;
     73     du_sigs = NULL;
     74   }
     75   GNUNET_PQ_cleanup_result (rs);
     76   return qs;
     77 }