LCOV - code coverage report
Current view: top level - auditordb - get_reserve_balance_summary_wrong_inconsistency.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 34 0
Test Date: 2026-04-14 15:39:31 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2024 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              : #include "taler/taler_pq_lib.h"
      17              : #include "pg_helper.h"
      18              : #include \
      19              :   "auditor-database/get_reserve_balance_summary_wrong_inconsistency.h"
      20              : 
      21              : 
      22              : struct ReserveBalanceSummaryWrongInconsistencyContext
      23              : {
      24              : 
      25              :   /**
      26              :    * Function to call for each bad sig loss.
      27              :    */
      28              :   TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback cb;
      29              : 
      30              :   /**
      31              :    * Closure for @e cb
      32              :    */
      33              :   void *cb_cls;
      34              : 
      35              :   /**
      36              :    * Plugin context.
      37              :    */
      38              :   struct TALER_AUDITORDB_PostgresContext *pg;
      39              : 
      40              :   /**
      41              :    * Query status to return.
      42              :    */
      43              :   enum GNUNET_DB_QueryStatus qs;
      44              : };
      45              : 
      46              : 
      47              : /**
      48              :  * Helper function for #TALER_AUDITORDB_get_reserve_balance_summary_wrong_inconsistency().
      49              :  * To be called with the results of a SELECT statement
      50              :  * that has returned @a num_results results.
      51              :  *
      52              :  * @param cls closure of type `struct ReserveBalanceSummaryWrongInconsistencyContext *`
      53              :  * @param result the postgres result
      54              :  * @param num_results the number of results in @a result
      55              :  */
      56              : static void
      57            0 : reserve_balance_summary_wrong_inconsistency_cb (void *cls,
      58              :                                                 PGresult *result,
      59              :                                                 unsigned int num_results)
      60              : {
      61            0 :   struct ReserveBalanceSummaryWrongInconsistencyContext *dcc = cls;
      62            0 :   struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
      63              : 
      64            0 :   for (unsigned int i = 0; i < num_results; i++)
      65              :   {
      66              :     struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency dc;
      67            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      68            0 :       GNUNET_PQ_result_spec_uint64 ("row_id",
      69              :                                     &dc.row_id),
      70            0 :       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
      71              :                                             &dc.reserve_pub),
      72            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
      73              :                                    &dc.exchange_amount),
      74            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
      75              :                                    &dc.auditor_amount),
      76            0 :       GNUNET_PQ_result_spec_bool ("suppressed",
      77              :                                   &dc.suppressed),
      78              :       GNUNET_PQ_result_spec_end
      79              :     };
      80              :     enum GNUNET_GenericReturnValue rval;
      81              : 
      82            0 :     if (GNUNET_OK !=
      83            0 :         GNUNET_PQ_extract_result (result,
      84              :                                   rs,
      85              :                                   i))
      86              :     {
      87            0 :       GNUNET_break (0);
      88            0 :       dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
      89            0 :       return;
      90              :     }
      91            0 :     dcc->qs = i + 1;
      92            0 :     rval = dcc->cb (dcc->cb_cls,
      93              :                     &dc);
      94            0 :     GNUNET_PQ_cleanup_result (rs);
      95            0 :     if (GNUNET_OK != rval)
      96            0 :       break;
      97              :   }
      98              : }
      99              : 
     100              : 
     101              : enum GNUNET_DB_QueryStatus
     102            0 : TALER_AUDITORDB_get_reserve_balance_summary_wrong_inconsistency (struct
     103              :                                                                  TALER_AUDITORDB_PostgresContext
     104              :                                                                  *pg,
     105              :                                                                  int64_t limit,
     106              :                                                                  uint64_t offset
     107              :                                                                  ,
     108              :                                                                  bool
     109              :                                                                  return_suppressed,
     110              :                                                                  TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback
     111              :                                                                  cb,
     112              :                                                                  void *cb_cls)
     113              : {
     114            0 :   uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
     115            0 :   struct GNUNET_PQ_QueryParam params[] = {
     116            0 :     GNUNET_PQ_query_param_uint64 (&offset),
     117            0 :     GNUNET_PQ_query_param_bool (return_suppressed),
     118            0 :     GNUNET_PQ_query_param_uint64 (&plimit),
     119              :     GNUNET_PQ_query_param_end
     120              :   };
     121            0 :   struct ReserveBalanceSummaryWrongInconsistencyContext dcc = {
     122              :     .cb = cb,
     123              :     .cb_cls = cb_cls,
     124              :     .pg = pg
     125              :   };
     126              :   enum GNUNET_DB_QueryStatus qs;
     127              : 
     128            0 :   PREPARE (pg,
     129              :            "auditor_reserve_balance_summary_wrong_inconsistency_get_desc",
     130              :            "SELECT"
     131              :            " row_id"
     132              :            ",reserve_pub"
     133              :            ",exchange_amount"
     134              :            ",auditor_amount"
     135              :            ",suppressed"
     136              :            " FROM auditor_reserve_balance_summary_wrong_inconsistency"
     137              :            " WHERE (row_id < $1)"
     138              :            " AND ($2 OR NOT suppressed)"
     139              :            " ORDER BY row_id DESC"
     140              :            " LIMIT $3"
     141              :            );
     142            0 :   PREPARE (pg,
     143              :            "auditor_reserve_balance_summary_wrong_inconsistency_get_asc",
     144              :            "SELECT"
     145              :            " row_id"
     146              :            ",reserve_pub"
     147              :            ",exchange_amount"
     148              :            ",auditor_amount"
     149              :            ",suppressed"
     150              :            " FROM auditor_reserve_balance_summary_wrong_inconsistency"
     151              :            " WHERE (row_id > $1)"
     152              :            " AND ($2 OR NOT suppressed)"
     153              :            " ORDER BY row_id ASC"
     154              :            " LIMIT $3"
     155              :            );
     156            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     157              :     pg->conn,
     158              :     (limit > 0)
     159              :     ? "auditor_reserve_balance_summary_wrong_inconsistency_get_asc"
     160              :     : "auditor_reserve_balance_summary_wrong_inconsistency_get_desc",
     161              :     params,
     162              :     &reserve_balance_summary_wrong_inconsistency_cb,
     163              :     &dcc);
     164              : 
     165            0 :   if (qs > 0)
     166            0 :     return dcc.qs;
     167            0 :   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
     168            0 :   return qs;
     169              : }
        

Generated by: LCOV version 2.0-1