donau

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

pg_lookup_issued_receipts.c (2622B)


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