LCOV - code coverage report
Current view: top level - auditordb - get_denomination_pending.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 35 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 "auditor-database/get_denomination_pending.h"
      19              : 
      20              : 
      21              : struct DenominationPendingContext
      22              : {
      23              : 
      24              :   /**
      25              :    * Function to call for each bad sig loss.
      26              :    */
      27              :   TALER_AUDITORDB_DenominationPendingCallback cb;
      28              : 
      29              :   /**
      30              :    * Closure for @e cb
      31              :    */
      32              :   void *cb_cls;
      33              : 
      34              :   /**
      35              :    * Plugin context.
      36              :    */
      37              :   struct TALER_AUDITORDB_PostgresContext *pg;
      38              : 
      39              :   /**
      40              :    * Query status to return.
      41              :    */
      42              :   enum GNUNET_DB_QueryStatus qs;
      43              : };
      44              : 
      45              : 
      46              : /**
      47              :  * Helper function for #TALER_AUDITORDB_get_denomination_pending().
      48              :  * To be called with the results of a SELECT statement
      49              :  * that has returned @a num_results results.
      50              :  *
      51              :  * @param cls closure of type `struct DenominationPendingContext *`
      52              :  * @param result the postgres result
      53              :  * @param num_results the number of results in @a result
      54              :  */
      55              : static void
      56            0 : denomination_pending_cb (void *cls,
      57              :                          PGresult *result,
      58              :                          unsigned int num_results)
      59              : {
      60            0 :   struct DenominationPendingContext *dcc = cls;
      61            0 :   struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
      62              : 
      63            0 :   for (unsigned int i = 0; i < num_results; i++)
      64              :   {
      65              :     uint64_t serial_id;
      66              :     struct TALER_AUDITORDB_DenominationPending dc;
      67            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      68            0 :       GNUNET_PQ_result_spec_uint64 ("row_id",
      69              :                                     &serial_id),
      70            0 :       GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
      71              :                                             &dc.denom_pub_hash),
      72            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance",
      73              :                                    &dc.denom_balance),
      74            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss",
      75              :                                    &dc.denom_loss),
      76            0 :       GNUNET_PQ_result_spec_uint64 ("num_issued",
      77              :                                     &dc.num_issued),
      78            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk",
      79              :                                    &dc.denom_risk),
      80            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss",
      81              :                                    &dc.recoup_loss),
      82              :       GNUNET_PQ_result_spec_end
      83              :     };
      84              :     enum GNUNET_GenericReturnValue rval;
      85              : 
      86            0 :     if (GNUNET_OK !=
      87            0 :         GNUNET_PQ_extract_result (result,
      88              :                                   rs,
      89              :                                   i))
      90              :     {
      91            0 :       GNUNET_break (0);
      92            0 :       dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
      93            0 :       return;
      94              :     }
      95            0 :     dcc->qs = i + 1;
      96            0 :     rval = dcc->cb (dcc->cb_cls,
      97              :                     serial_id,
      98              :                     &dc);
      99            0 :     GNUNET_PQ_cleanup_result (rs);
     100            0 :     if (GNUNET_OK != rval)
     101            0 :       break;
     102              :   }
     103              : }
     104              : 
     105              : 
     106              : enum GNUNET_DB_QueryStatus
     107            0 : TALER_AUDITORDB_get_denomination_pending (
     108              :   struct TALER_AUDITORDB_PostgresContext *pg,
     109              :   int64_t limit,
     110              :   uint64_t offset,
     111              :   TALER_AUDITORDB_DenominationPendingCallback 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_uint64 (&plimit),
     118              :     GNUNET_PQ_query_param_end
     119              :   };
     120            0 :   struct DenominationPendingContext dcc = {
     121              :     .cb = cb,
     122              :     .cb_cls = cb_cls,
     123              :     .pg = pg
     124              :   };
     125              :   enum GNUNET_DB_QueryStatus qs;
     126              : 
     127            0 :   PREPARE (pg,
     128              :            "auditor_denomination_pending_get_desc",
     129              :            "SELECT"
     130              :            " row_id,"
     131              :            " denom_pub_hash,"
     132              :            " denom_balance,"
     133              :            " denom_loss,"
     134              :            " num_issued,"
     135              :            " denom_risk,"
     136              :            " recoup_loss"
     137              :            " FROM auditor_denomination_pending"
     138              :            " WHERE (row_id < $1)"
     139              :            " ORDER BY row_id DESC"
     140              :            " LIMIT $2"
     141              :            );
     142            0 :   PREPARE (pg,
     143              :            "auditor_denomination_pending_get_asc",
     144              :            "SELECT"
     145              :            " row_id,"
     146              :            " denom_pub_hash,"
     147              :            " denom_balance,"
     148              :            " denom_loss,"
     149              :            " num_issued,"
     150              :            " denom_risk,"
     151              :            " recoup_loss"
     152              :            " FROM auditor_denomination_pending"
     153              :            " WHERE (row_id > $1)"
     154              :            " ORDER BY row_id ASC"
     155              :            " LIMIT $2"
     156              :            );
     157            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     158              :     pg->conn,
     159              :     (limit > 0)
     160              :     ? "auditor_denomination_pending_get_asc"
     161              :     : "auditor_denomination_pending_get_desc",
     162              :     params,
     163              :     &denomination_pending_cb,
     164              :     &dcc);
     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