LCOV - code coverage report
Current view: top level - exchangedb - pg_get_refresh.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 74.7 % 75 56
Test Date: 2025-12-28 14:06:02 Functions: 100.0 % 1 1

            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/pg_get_refresh.c
      18              :  * @brief Implementation of the get_refresh function for Postgres
      19              :  * @author get_refresh
      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_get_refresh.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           27 : TEH_PG_get_refresh (void *cls,
      31              :                     const struct TALER_RefreshCommitmentP *rc,
      32              :                     struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS *refresh)
      33              : {
      34           27 :   struct PostgresClosure *pg = cls;
      35           27 :   struct GNUNET_PQ_QueryParam params[] = {
      36           27 :     GNUNET_PQ_query_param_auto_from_type (rc),
      37              :     GNUNET_PQ_query_param_end
      38              :   };
      39              :   bool no_cs_r_values;
      40              :   bool no_cs_r_choices;
      41              :   bool no_transfer_pubs;
      42              :   size_t num_denom_sigs;
      43              :   size_t num_transfer_pubs;
      44           27 :   struct TALER_BlindedDenominationSignature *denom_sigs = NULL;
      45           27 :   struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values = NULL;
      46           27 :   struct TALER_TransferPublicKeyP *transfer_pubs = NULL;
      47           27 :   uint64_t *denom_serials = NULL;
      48           27 :   struct GNUNET_PQ_ResultSpec rs[] = {
      49           27 :     TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
      50              :                                  &refresh->amount_with_fee),
      51           27 :     GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
      52              :                                           &refresh->coin.coin_pub),
      53           27 :     GNUNET_PQ_result_spec_allow_null (
      54           27 :       GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
      55              :                                             &refresh->coin.h_age_commitment),
      56              :       &refresh->coin.no_age_commitment),
      57           27 :     GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
      58              :                                           &refresh->coin_sig),
      59           27 :     GNUNET_PQ_result_spec_auto_from_type ("refresh_seed",
      60              :                                           &refresh->refresh_seed),
      61           27 :     GNUNET_PQ_result_spec_uint32 ("noreveal_index",
      62              :                                   &refresh->noreveal_index),
      63           27 :     GNUNET_PQ_result_spec_allow_null (
      64           27 :       GNUNET_PQ_result_spec_auto_from_type ("blinding_seed",
      65              :                                             &refresh->blinding_seed),
      66              :       &refresh->no_blinding_seed),
      67           27 :     GNUNET_PQ_result_spec_allow_null (
      68              :       TALER_PQ_result_spec_array_cs_r_pub (pg->conn,
      69              :                                            "cs_r_values",
      70              :                                            &refresh->num_cs_r_values,
      71              :                                            &cs_r_values),
      72              :       &no_cs_r_values),
      73           27 :     GNUNET_PQ_result_spec_allow_null (
      74              :       GNUNET_PQ_result_spec_uint64 ("cs_r_choices",
      75              :                                     &refresh->cs_r_choices),
      76              :       &no_cs_r_choices),
      77           27 :     GNUNET_PQ_result_spec_auto_from_type ("planchets_h",
      78              :                                           &refresh->planchets_h),
      79           27 :     GNUNET_PQ_result_spec_auto_from_type ("selected_h",
      80              :                                           &refresh->selected_h),
      81           27 :     GNUNET_PQ_result_spec_allow_null (
      82              :       GNUNET_PQ_result_spec_array_fixed_size (pg->conn,
      83              :                                               "transfer_pubs",
      84              :                                               sizeof(*transfer_pubs),
      85              :                                               &num_transfer_pubs,
      86              :                                               (void **) &transfer_pubs),
      87              :       &no_transfer_pubs),
      88           27 :     GNUNET_PQ_result_spec_array_uint64 (pg->conn,
      89              :                                         "denom_serials",
      90              :                                         &refresh->num_coins,
      91              :                                         &denom_serials),
      92           27 :     TALER_PQ_result_spec_array_blinded_denom_sig (pg->conn,
      93              :                                                   "denom_sigs",
      94              :                                                   &num_denom_sigs,
      95              :                                                   &denom_sigs),
      96           27 :     GNUNET_PQ_result_spec_bool ("revealed",
      97              :                                 &refresh->revealed),
      98              :     GNUNET_PQ_result_spec_end
      99              :   };
     100              :   enum GNUNET_DB_QueryStatus qs;
     101              : 
     102           27 :   memset (&refresh->coin.denom_sig,
     103              :           0,
     104              :           sizeof (refresh->coin.denom_sig));
     105           27 :   PREPARE (pg,
     106              :            "get_refresh",
     107              :            "SELECT"
     108              :            " amount_with_fee"
     109              :            ",old_coin_pub"
     110              :            ",kc.age_commitment_hash AS age_commitment_hash"
     111              :            ",old_coin_sig"
     112              :            ",refresh_seed"
     113              :            ",noreveal_index"
     114              :            ",blinding_seed"
     115              :            ",cs_r_values"
     116              :            ",cs_r_choices"
     117              :            ",planchets_h"
     118              :            ",transfer_pubs"
     119              :            ",selected_h"
     120              :            ",denom_serials"
     121              :            ",denom_sigs"
     122              :            ",revealed"
     123              :            " FROM refresh"
     124              :            " JOIN known_coins kc"
     125              :            " ON (old_coin_pub = kc.coin_pub)"
     126              :            " WHERE rc = $1;"
     127              :            );
     128           27 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     129              :                                                  "get_refresh",
     130              :                                                  params,
     131              :                                                  rs);
     132           27 :   GNUNET_PQ_cleanup_query_params_closures (params);
     133           27 :   if (0 > qs)
     134              :   {
     135            0 :     GNUNET_break (0);
     136            0 :     GNUNET_PQ_cleanup_result (rs);
     137            0 :     return qs;
     138              :   }
     139           27 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     140              :   {
     141           13 :     GNUNET_PQ_cleanup_result (rs);
     142           13 :     return qs;
     143              :   }
     144           14 :   if (refresh->num_coins != num_denom_sigs)
     145              :   {
     146            0 :     GNUNET_break (0);
     147            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     148              :                 "got inconsistent number of entries in refresh from DB: "
     149              :                 "num_coins=%ld, num_denom_sigs=%ld\n",
     150              :                 refresh->num_coins,
     151              :                 num_denom_sigs);
     152            0 :     GNUNET_PQ_cleanup_result (rs);
     153            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     154              :   }
     155           14 :   if (no_transfer_pubs)
     156              :   {
     157            0 :     refresh->is_v27_refresh = true;
     158            0 :     refresh->transfer_pubs = NULL;
     159              :   }
     160              :   else
     161              :   {
     162           14 :     if (num_transfer_pubs != refresh->num_coins)
     163              :     {
     164            0 :       GNUNET_break (0);
     165            0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     166              :                   "got inconsistent number of transfer_pubs in refresh from DB: "
     167              :                   "num_coins=%ld, num_transfer_pubs=%ld\n",
     168              :                   refresh->num_coins,
     169              :                   num_transfer_pubs);
     170            0 :       GNUNET_PQ_cleanup_result (rs);
     171            0 :       return GNUNET_DB_STATUS_HARD_ERROR;
     172              :     }
     173           14 :     refresh->is_v27_refresh = false;
     174           14 :     refresh->transfer_pubs = transfer_pubs;
     175              :   }
     176           14 :   if (refresh->no_blinding_seed != no_cs_r_values)
     177              :   {
     178            0 :     GNUNET_break (0);
     179            0 :     GNUNET_PQ_cleanup_result (rs);
     180            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     181              :   }
     182           14 :   if (no_cs_r_choices != no_cs_r_values)
     183              :   {
     184            0 :     GNUNET_break (0);
     185            0 :     GNUNET_PQ_cleanup_result (rs);
     186            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     187              :   }
     188           14 :   if (no_cs_r_values)
     189              :   {
     190            7 :     refresh->cs_r_values = NULL;
     191            7 :     refresh->num_cs_r_values = 0;
     192              :   }
     193           14 :   if (refresh->coin.no_age_commitment)
     194            6 :     memset (&refresh->coin.h_age_commitment,
     195              :             0,
     196              :             sizeof(refresh->coin.h_age_commitment));
     197           14 :   refresh->rc = *rc;
     198              :   /* move the result arrays */
     199           14 :   refresh->denom_sigs = denom_sigs;
     200           14 :   refresh->denom_serials = denom_serials;
     201           14 :   refresh->cs_r_values = cs_r_values;
     202           14 :   transfer_pubs = NULL;
     203           14 :   denom_sigs = NULL;
     204           14 :   denom_serials = NULL;
     205           14 :   cs_r_values = NULL;
     206           14 :   GNUNET_PQ_cleanup_result (rs);
     207           14 :   return qs;
     208              : }
        

Generated by: LCOV version 2.0-1