exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

select_all_purse_deletions_above_serial_id.c (4139B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 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 exchangedb/select_all_purse_deletions_above_serial_id.c
     18  * @brief Implementation of the select_all_purse_deletions_above_serial_id function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_pq_lib.h"
     22 #include "exchange-database/select_all_purse_deletions_above_serial_id.h"
     23 #include "helper.h"
     24 
     25 
     26 /**
     27  * Closure for #all_purse_deletion_serial_helper_cb().
     28  */
     29 struct AllPurseDeletionSerialContext
     30 {
     31 
     32   /**
     33    * Callback to call.
     34    */
     35   TALER_EXCHANGEDB_AllPurseDeletionsCallback cb;
     36 
     37   /**
     38    * Closure for @e cb.
     39    */
     40   void *cb_cls;
     41 
     42   /**
     43    * Plugin context.
     44    */
     45   struct TALER_EXCHANGEDB_PostgresContext *pg;
     46 
     47   /**
     48    * Status code, set to #GNUNET_SYSERR on hard errors.
     49    */
     50   enum GNUNET_GenericReturnValue status;
     51 };
     52 
     53 
     54 /**
     55  * Helper function to be called with the results of a SELECT statement
     56  * that has returned @a num_results results.
     57  *
     58  * @param cls closure of type `struct PurseRefundSerialContext`
     59  * @param result the postgres result
     60  * @param num_results the number of results in @a result
     61  */
     62 static void
     63 all_purse_deletion_serial_helper_cb (void *cls,
     64                                      PGresult *result,
     65                                      unsigned int num_results)
     66 {
     67   struct AllPurseDeletionSerialContext *dsc = cls;
     68 
     69   for (unsigned int i = 0; i<num_results; i++)
     70   {
     71     struct TALER_PurseContractPublicKeyP purse_pub;
     72     struct TALER_PurseContractSignatureP purse_sig;
     73     uint64_t rowid;
     74     struct GNUNET_PQ_ResultSpec rs[] = {
     75       GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
     76                                             &purse_pub),
     77       GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
     78                                             &purse_sig),
     79       GNUNET_PQ_result_spec_uint64 ("purse_deletion_serial_id",
     80                                     &rowid),
     81       GNUNET_PQ_result_spec_end
     82     };
     83     enum GNUNET_GenericReturnValue ret;
     84 
     85     if (GNUNET_OK !=
     86         GNUNET_PQ_extract_result (result,
     87                                   rs,
     88                                   i))
     89     {
     90       GNUNET_break (0);
     91       dsc->status = GNUNET_SYSERR;
     92       return;
     93     }
     94     ret = dsc->cb (dsc->cb_cls,
     95                    rowid,
     96                    &purse_pub,
     97                    &purse_sig);
     98     GNUNET_PQ_cleanup_result (rs);
     99     if (GNUNET_OK != ret)
    100       break;
    101   }
    102 }
    103 
    104 
    105 enum GNUNET_DB_QueryStatus
    106 TALER_EXCHANGEDB_select_all_purse_deletions_above_serial_id (
    107   struct TALER_EXCHANGEDB_PostgresContext *pg,
    108   uint64_t serial_id,
    109   TALER_EXCHANGEDB_AllPurseDeletionsCallback cb,
    110   void *cb_cls)
    111 {
    112   struct GNUNET_PQ_QueryParam params[] = {
    113     GNUNET_PQ_query_param_uint64 (&serial_id),
    114     GNUNET_PQ_query_param_end
    115   };
    116   struct AllPurseDeletionSerialContext dsc = {
    117     .cb = cb,
    118     .cb_cls = cb_cls,
    119     .pg = pg,
    120     .status = GNUNET_OK
    121   };
    122   enum GNUNET_DB_QueryStatus qs;
    123 
    124   PREPARE (pg,
    125            "audit_select_all_purse_deletions_above_serial_id",
    126            "SELECT"
    127            " purse_pub"
    128            ",purse_sig"
    129            ",purse_deletion_serial_id"
    130            " FROM purse_deletion"
    131            " WHERE purse_deletion_serial_id>=$1"
    132            " ORDER BY purse_deletion_serial_id ASC;");
    133   qs = GNUNET_PQ_eval_prepared_multi_select (
    134     pg->conn,
    135     "audit_select_all_purse_deletions_above_serial_id",
    136     params,
    137     &all_purse_deletion_serial_helper_cb,
    138     &dsc);
    139   if (GNUNET_OK != dsc.status)
    140     return GNUNET_DB_STATUS_HARD_ERROR;
    141   return qs;
    142 }