LCOV - code coverage report
Current view: top level - exchangedb - iterate_reserve_close_info.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.1 % 32 25
Test Date: 2026-09-11 18:55:36 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022 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 iterate_reserve_close_info.c
      18              :  * @brief Low-level (statement-level) Postgres database access for the exchange
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/iterate_reserve_close_info.h"
      23              : #include "helper.h"
      24              : 
      25              : /**
      26              :  * Closure for #iterate_reserve_close_info_cb()
      27              :  */
      28              : struct IteratorContext
      29              : {
      30              :   /**
      31              :    * Function to call with the results.
      32              :    */
      33              :   TALER_KYCLOGIC_KycAmountCallback cb;
      34              : 
      35              :   /**
      36              :    * Closure to pass to @e cb
      37              :    */
      38              :   void *cb_cls;
      39              : 
      40              :   /**
      41              :    * Plugin context.
      42              :    */
      43              :   struct TALER_EXCHANGEDB_PostgresContext *pg;
      44              : 
      45              :   /**
      46              :    * Flag set to #GNUNET_OK as long as everything is fine.
      47              :    */
      48              :   enum GNUNET_GenericReturnValue status;
      49              : };
      50              : 
      51              : 
      52              : /**
      53              :  * Helper function for #TALER_EXCHANGEDB_iterate_reserve_close_info().
      54              :  * Calls the callback with each denomination key.
      55              :  *
      56              :  * @param cls a `struct IteratorContext`
      57              :  * @param result db results
      58              :  * @param num_results number of results in @a result
      59              :  */
      60              : static void
      61           10 : iterate_reserve_close_info_cb (void *cls,
      62              :                                PGresult *result,
      63              :                                unsigned int num_results)
      64              : {
      65           10 :   struct IteratorContext *ic = cls;
      66           10 :   struct TALER_EXCHANGEDB_PostgresContext *pg = ic->pg;
      67              : 
      68           14 :   for (unsigned int i = 0; i<num_results; i++)
      69              :   {
      70              :     struct TALER_Amount amount;
      71              :     struct GNUNET_TIME_Absolute ts;
      72            5 :     struct GNUNET_PQ_ResultSpec rs[] = {
      73            5 :       GNUNET_PQ_result_spec_absolute_time ("execution_date",
      74              :                                            &ts),
      75            5 :       TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
      76              :                                    &amount),
      77              :       GNUNET_PQ_result_spec_end
      78              :     };
      79              :     enum GNUNET_GenericReturnValue ret;
      80              : 
      81            5 :     if (GNUNET_OK !=
      82            5 :         GNUNET_PQ_extract_result (result,
      83              :                                   rs,
      84              :                                   i))
      85              :     {
      86            0 :       GNUNET_break (0);
      87            0 :       ic->status = GNUNET_SYSERR;
      88            0 :       return;
      89              :     }
      90            5 :     ret = ic->cb (ic->cb_cls,
      91              :                   &amount,
      92              :                   ts);
      93            5 :     switch (ret)
      94              :     {
      95            4 :     case GNUNET_OK:
      96            4 :       continue;
      97            1 :     case GNUNET_NO:
      98            1 :       break;
      99            0 :     case GNUNET_SYSERR:
     100            0 :       ic->status = GNUNET_SYSERR;
     101            0 :       break;
     102              :     }
     103            1 :     break;
     104              :   }
     105              : }
     106              : 
     107              : 
     108              : enum GNUNET_DB_QueryStatus
     109           10 : TALER_EXCHANGEDB_iterate_reserve_close_info (
     110              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
     111              :   const struct TALER_NormalizedPaytoHashP *h_payto,
     112              :   struct GNUNET_TIME_Absolute time_limit,
     113              :   TALER_KYCLOGIC_KycAmountCallback kac,
     114              :   void *kac_cls)
     115              : {
     116           10 :   struct GNUNET_PQ_QueryParam params[] = {
     117           10 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
     118           10 :     GNUNET_PQ_query_param_absolute_time (&time_limit),
     119              :     GNUNET_PQ_query_param_end
     120              :   };
     121           10 :   struct IteratorContext ic = {
     122              :     .cb = kac,
     123              :     .cb_cls = kac_cls,
     124              :     .pg = pg,
     125              :     .status = GNUNET_OK
     126              :   };
     127              :   enum GNUNET_DB_QueryStatus qs;
     128              : 
     129           10 :   PREPARE (pg,
     130              :            "iterate_reserve_close_info",
     131              :            "SELECT amount"
     132              :            "      ,execution_date"
     133              :            "  FROM reserves_close"
     134              :            " WHERE wire_target_h_payto IN ("
     135              :            "   SELECT wire_target_h_payto"
     136              :            "     FROM wire_targets"
     137              :            "    WHERE h_normalized_payto=$1"
     138              :            "   )"
     139              :            "   AND execution_date >= $2"
     140              :            " ORDER BY execution_date DESC");
     141           10 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     142              :     pg->conn,
     143              :     "iterate_reserve_close_info",
     144              :     params,
     145              :     &iterate_reserve_close_info_cb,
     146              :     &ic);
     147           10 :   if (GNUNET_OK != ic.status)
     148            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     149           10 :   return qs;
     150              : }
        

Generated by: LCOV version 2.0-1