LCOV - code coverage report
Current view: top level - exchangedb - pg_select_batch_deposits_missing_wire.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 26 0
Test Date: 2025-12-28 14:06:02 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022-2023 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/pg_select_batch_deposits_missing_wire.c
      18              :  * @brief Implementation of the select_batch_deposits_missing_wire function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/platform.h"
      22              : #include "taler/taler_error_codes.h"
      23              : #include "taler/taler_dbevents.h"
      24              : #include "taler/taler_pq_lib.h"
      25              : #include "pg_select_batch_deposits_missing_wire.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : /**
      29              :  * Closure for #missing_wire_cb().
      30              :  */
      31              : struct MissingWireContext
      32              : {
      33              :   /**
      34              :    * Function to call per result.
      35              :    */
      36              :   TALER_EXCHANGEDB_WireMissingCallback cb;
      37              : 
      38              :   /**
      39              :    * Closure for @e cb.
      40              :    */
      41              :   void *cb_cls;
      42              : 
      43              :   /**
      44              :    * Plugin context.
      45              :    */
      46              :   struct PostgresClosure *pg;
      47              : 
      48              :   /**
      49              :    * Set to #GNUNET_SYSERR on error.
      50              :    */
      51              :   enum GNUNET_GenericReturnValue status;
      52              : };
      53              : 
      54              : 
      55              : /**
      56              :  * Invoke the callback for each result.
      57              :  *
      58              :  * @param cls a `struct MissingWireContext *`
      59              :  * @param result SQL result
      60              :  * @param num_results number of rows in @a result
      61              :  */
      62              : static void
      63            0 : missing_wire_cb (void *cls,
      64              :                  PGresult *result,
      65              :                  unsigned int num_results)
      66              : {
      67            0 :   struct MissingWireContext *mwc = cls;
      68            0 :   struct PostgresClosure *pg = mwc->pg;
      69              : 
      70            0 :   for (unsigned int i = 0; i<num_results; i++)
      71              :   {
      72              :     uint64_t batch_deposit_serial_id;
      73              :     struct GNUNET_TIME_Timestamp deadline;
      74              :     struct TALER_FullPaytoHashP wire_target_h_payto;
      75              :     struct TALER_Amount total_amount;
      76            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      77            0 :       GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
      78              :                                     &batch_deposit_serial_id),
      79            0 :       GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
      80              :                                             &wire_target_h_payto),
      81            0 :       GNUNET_PQ_result_spec_timestamp ("deadline",
      82              :                                        &deadline),
      83            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
      84              :                                    &total_amount),
      85              :       GNUNET_PQ_result_spec_end
      86              :     };
      87              : 
      88            0 :     if (GNUNET_OK !=
      89            0 :         GNUNET_PQ_extract_result (result,
      90              :                                   rs,
      91              :                                   i))
      92              :     {
      93            0 :       GNUNET_break (0);
      94            0 :       mwc->status = GNUNET_SYSERR;
      95            0 :       return;
      96              :     }
      97            0 :     mwc->cb (mwc->cb_cls,
      98              :              batch_deposit_serial_id,
      99              :              &total_amount,
     100              :              &wire_target_h_payto,
     101              :              deadline);
     102            0 :     GNUNET_PQ_cleanup_result (rs);
     103              :   }
     104              : }
     105              : 
     106              : 
     107              : enum GNUNET_DB_QueryStatus
     108            0 : TEH_PG_select_batch_deposits_missing_wire (
     109              :   void *cls,
     110              :   uint64_t min_batch_deposit_serial_id,
     111              :   TALER_EXCHANGEDB_WireMissingCallback cb,
     112              :   void *cb_cls)
     113              : {
     114            0 :   struct PostgresClosure *pg = cls;
     115            0 :   struct GNUNET_PQ_QueryParam params[] = {
     116            0 :     GNUNET_PQ_query_param_uint64 (&min_batch_deposit_serial_id),
     117              :     GNUNET_PQ_query_param_end
     118              :   };
     119            0 :   struct MissingWireContext mwc = {
     120              :     .cb = cb,
     121              :     .cb_cls = cb_cls,
     122              :     .pg = pg,
     123              :     .status = GNUNET_OK
     124              :   };
     125              :   enum GNUNET_DB_QueryStatus qs;
     126              : 
     127            0 :   PREPARE (pg,
     128              :            "deposits_get_deposits_missing_wire",
     129              :            "SELECT"
     130              :            " batch_deposit_serial_id"
     131              :            ",wire_target_h_payto"
     132              :            ",deadline"
     133              :            ",total_amount"
     134              :            " FROM exchange_do_select_deposits_missing_wire"
     135              :            " ($1);");
     136            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     137              :                                              "deposits_get_deposits_missing_wire",
     138              :                                              params,
     139              :                                              &missing_wire_cb,
     140              :                                              &mwc);
     141            0 :   if (GNUNET_OK != mwc.status)
     142            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     143            0 :   return qs;
     144              : }
        

Generated by: LCOV version 2.0-1