LCOV - code coverage report
Current view: top level - exchangedb - iterate_denominations.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.7 % 38 36
Test Date: 2026-04-14 15:39:31 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 exchangedb/iterate_denominations.c
      18              :  * @brief Implementation of the iterate_denominations function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_error_codes.h"
      22              : #include "taler/taler_pq_lib.h"
      23              : #include "exchange-database/iterate_denominations.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : /**
      28              :  * Closure for #dominations_cb_helper()
      29              :  */
      30              : struct DenomsIteratorContext
      31              : {
      32              :   /**
      33              :    * Function to call with the results.
      34              :    */
      35              :   TALER_EXCHANGEDB_DenominationsCallback cb;
      36              : 
      37              :   /**
      38              :    * Closure to pass to @e cb
      39              :    */
      40              :   void *cb_cls;
      41              : 
      42              :   /**
      43              :    * Plugin context.
      44              :    */
      45              :   struct TALER_EXCHANGEDB_PostgresContext *pg;
      46              : };
      47              : 
      48              : 
      49              : /**
      50              :  * Helper function for #TALER_EXCHANGEDB_iterate_denominations().
      51              :  * Calls the callback with each denomination key.
      52              :  *
      53              :  * @param cls a `struct DenomsIteratorContext`
      54              :  * @param result db results
      55              :  * @param num_results number of results in @a result
      56              :  */
      57              : static void
      58           41 : dominations_cb_helper (void *cls,
      59              :                        PGresult *result,
      60              :                        unsigned int num_results)
      61              : {
      62           41 :   struct DenomsIteratorContext *dic = cls;
      63           41 :   struct TALER_EXCHANGEDB_PostgresContext *pg = dic->pg;
      64              : 
      65          680 :   for (unsigned int i = 0; i<num_results; i++)
      66              :   {
      67          639 :     struct TALER_EXCHANGEDB_DenominationKeyMetaData meta = {0};
      68          639 :     struct TALER_DenominationPublicKey denom_pub = {0};
      69          639 :     struct TALER_MasterSignatureP master_sig = {0};
      70          639 :     struct TALER_DenominationHashP h_denom_pub = {0};
      71              :     bool revoked;
      72          639 :     struct GNUNET_PQ_ResultSpec rs[] = {
      73          639 :       GNUNET_PQ_result_spec_uint64 ("denominations_serial",
      74              :                                     &meta.serial),
      75          639 :       GNUNET_PQ_result_spec_auto_from_type ("master_sig",
      76              :                                             &master_sig),
      77          639 :       GNUNET_PQ_result_spec_bool ("revoked",
      78              :                                   &revoked),
      79          639 :       GNUNET_PQ_result_spec_timestamp ("valid_from",
      80              :                                        &meta.start),
      81          639 :       GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
      82              :                                        &meta.expire_withdraw),
      83          639 :       GNUNET_PQ_result_spec_timestamp ("expire_deposit",
      84              :                                        &meta.expire_deposit),
      85          639 :       GNUNET_PQ_result_spec_timestamp ("expire_legal",
      86              :                                        &meta.expire_legal),
      87          639 :       TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
      88              :                                    &meta.value),
      89          639 :       TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
      90              :                                    &meta.fees.withdraw),
      91          639 :       TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
      92              :                                    &meta.fees.deposit),
      93          639 :       TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
      94              :                                    &meta.fees.refresh),
      95          639 :       TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
      96              :                                    &meta.fees.refund),
      97          639 :       TALER_PQ_result_spec_denom_pub ("denom_pub",
      98              :                                       &denom_pub),
      99          639 :       GNUNET_PQ_result_spec_uint32 ("age_mask",
     100              :                                     &meta.age_mask.bits),
     101              :       GNUNET_PQ_result_spec_end
     102              :     };
     103              : 
     104          639 :     if (GNUNET_OK !=
     105          639 :         GNUNET_PQ_extract_result (result,
     106              :                                   rs,
     107              :                                   i))
     108              :     {
     109            0 :       GNUNET_break (0);
     110            0 :       return;
     111              :     }
     112              : 
     113              :     /* make sure the mask information is the same */
     114          639 :     denom_pub.age_mask = meta.age_mask;
     115              : 
     116          639 :     TALER_denom_pub_hash (&denom_pub,
     117              :                           &h_denom_pub);
     118          639 :     dic->cb (dic->cb_cls,
     119              :              &denom_pub,
     120              :              &h_denom_pub,
     121              :              &meta,
     122              :              &master_sig,
     123              :              revoked);
     124          639 :     GNUNET_PQ_cleanup_result (rs);
     125              :   }
     126              : }
     127              : 
     128              : 
     129              : enum GNUNET_DB_QueryStatus
     130           41 : TALER_EXCHANGEDB_iterate_denominations (struct
     131              :                                         TALER_EXCHANGEDB_PostgresContext *pg,
     132              :                                         TALER_EXCHANGEDB_DenominationsCallback
     133              :                                         cb,
     134              :                                         void *cb_cls)
     135              : {
     136              :   struct GNUNET_TIME_Absolute now
     137           41 :     = GNUNET_TIME_absolute_get ();
     138           41 :   struct GNUNET_PQ_QueryParam params[] = {
     139           41 :     GNUNET_PQ_query_param_absolute_time (&now),
     140              :     GNUNET_PQ_query_param_end
     141              :   };
     142           41 :   struct DenomsIteratorContext dic = {
     143              :     .cb = cb,
     144              :     .cb_cls = cb_cls,
     145              :     .pg = pg
     146              :   };
     147              : 
     148           41 :   PREPARE (pg,
     149              :            "select_denominations",
     150              :            "SELECT"
     151              :            " denominations_serial"
     152              :            ",denominations.master_sig"
     153              :            ",denom_revocations_serial_id IS NOT NULL AS revoked"
     154              :            ",valid_from"
     155              :            ",expire_withdraw"
     156              :            ",expire_deposit"
     157              :            ",expire_legal"
     158              :            ",coin"              /* value of this denom */
     159              :            ",fee_withdraw"
     160              :            ",fee_deposit"
     161              :            ",fee_refresh"
     162              :            ",fee_refund"
     163              :            ",denom_type"
     164              :            ",age_mask"
     165              :            ",denom_pub"
     166              :            " FROM denominations"
     167              :            " LEFT JOIN "
     168              :            "   denomination_revocations USING (denominations_serial)"
     169              :            " WHERE expire_deposit > $1;");
     170           41 :   return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     171              :                                                "select_denominations",
     172              :                                                params,
     173              :                                                &dominations_cb_helper,
     174              :                                                &dic);
     175              : }
        

Generated by: LCOV version 2.0-1