LCOV - code coverage report
Current view: top level - exchangedb - do_refresh.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.5 % 57 51
Test Date: 2026-11-18 17:34:04 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2025 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/do_refresh.c
      18              :  * @brief Implementation of the do_refresh function for Postgres
      19              :  * @author Özgür Kesim
      20              :  */
      21              : #include "exchangedb_lib.h"
      22              : #include "taler/taler_pq_lib.h"
      23              : #include "exchange-database/do_refresh.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28           76 : TALER_EXCHANGEDB_do_refresh (
      29              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      30              :   struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS *refresh,
      31              :   const struct GNUNET_TIME_Timestamp *timestamp,
      32              :   bool *found,
      33              :   uint32_t *noreveal_index,
      34              :   bool *zombie_required,
      35              :   bool *nonce_reuse,
      36              :   bool *balance_ok,
      37              :   struct TALER_Amount *coin_balance)
      38              : {
      39           76 :   uint32_t rc_version = refresh->rc_version;
      40           76 :   struct GNUNET_PQ_QueryParam params[] = {
      41           76 :     GNUNET_PQ_query_param_auto_from_type (&refresh->rc),
      42           76 :     GNUNET_PQ_query_param_timestamp (timestamp),
      43           76 :     GNUNET_PQ_query_param_auto_from_type (&refresh->refresh_seed), /* 3 */
      44           76 :     (TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 == refresh->rc_version)
      45           13 :         ? GNUNET_PQ_query_param_null ()
      46           76 :         : GNUNET_PQ_query_param_array_auto_from_type (refresh->num_coins,
      47              :                                                       refresh->transfer_pubs,
      48              :                                                       pg->conn),
      49           76 :     GNUNET_PQ_query_param_auto_from_type (&refresh->planchets_h),
      50           76 :     TALER_PQ_query_param_amount (pg->conn, /* 6 */
      51           76 :                                  &refresh->amount_with_fee),
      52           76 :     (refresh->no_blinding_seed)
      53           43 :         ? GNUNET_PQ_query_param_null ()
      54           76 :         : GNUNET_PQ_query_param_auto_from_type (&refresh->blinding_seed),
      55           76 :     (0 < refresh->num_cs_r_values)
      56           33 :         ? TALER_PQ_query_param_array_cs_r_pub (refresh->num_cs_r_values,
      57           33 :                                                refresh->cs_r_values,
      58              :                                                pg->conn)
      59           76 :         : GNUNET_PQ_query_param_null (),
      60           76 :     (0 < refresh->num_cs_r_values)
      61           33 :         ? GNUNET_PQ_query_param_uint64 (&refresh->cs_r_choices) /* 9 */
      62           76 :         : GNUNET_PQ_query_param_null (),
      63           76 :     GNUNET_PQ_query_param_auto_from_type (&refresh->selected_h),
      64           76 :     TALER_PQ_query_param_array_blinded_denom_sig (refresh->num_coins,
      65           76 :                                                   refresh->denom_sigs,
      66              :                                                   pg->conn),
      67           76 :     GNUNET_PQ_query_param_array_uint64 (refresh->num_coins, /* 12 */
      68           76 :                                         refresh->denom_serials,
      69              :                                         pg->conn),
      70           76 :     GNUNET_PQ_query_param_auto_from_type (&refresh->coin.coin_pub),
      71           76 :     GNUNET_PQ_query_param_auto_from_type (&refresh->coin_sig),
      72           76 :     GNUNET_PQ_query_param_uint32 (&refresh->noreveal_index), /* 15 */
      73           76 :     GNUNET_PQ_query_param_bool (*zombie_required),
      74           76 :     GNUNET_PQ_query_param_uint32 (&rc_version),
      75              :     GNUNET_PQ_query_param_end
      76              :   };
      77              :   bool coin_found;
      78              :   bool no_noreveal_index;
      79              :   bool no_coin_balance;
      80           76 :   struct GNUNET_PQ_ResultSpec rs[] = {
      81           76 :     GNUNET_PQ_result_spec_bool ("coin_found",
      82              :                                 &coin_found),
      83           76 :     GNUNET_PQ_result_spec_bool ("balance_ok",
      84              :                                 balance_ok),
      85           76 :     GNUNET_PQ_result_spec_bool ("zombie_required",
      86              :                                 zombie_required),
      87           76 :     GNUNET_PQ_result_spec_bool ("nonce_reuse",
      88              :                                 nonce_reuse),
      89           76 :     GNUNET_PQ_result_spec_bool ("found",
      90              :                                 found),
      91           76 :     GNUNET_PQ_result_spec_allow_null (
      92              :       GNUNET_PQ_result_spec_uint32 ("noreveal_index",
      93              :                                     noreveal_index),
      94              :       &no_noreveal_index),
      95           76 :     GNUNET_PQ_result_spec_allow_null (
      96           76 :       TALER_PQ_RESULT_SPEC_AMOUNT ("coin_balance",
      97              :                                    coin_balance),
      98              :       &no_coin_balance),
      99              :     GNUNET_PQ_result_spec_end
     100              :   };
     101              :   enum GNUNET_DB_QueryStatus qs;
     102              : 
     103           76 :   GNUNET_assert ((TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 ==
     104              :                   refresh->rc_version) ==
     105              :                  (NULL == refresh->transfer_pubs));
     106           76 :   PREPARE (pg,
     107              :            "do_refresh",
     108              :            "SELECT "
     109              :            " out_coin_found AS coin_found"
     110              :            ",out_balance_ok AS balance_ok"
     111              :            ",out_zombie_bad AS zombie_required"
     112              :            ",out_nonce_reuse AS nonce_reuse"
     113              :            ",out_idempotent AS found"
     114              :            ",out_noreveal_index AS noreveal_index"
     115              :            ",out_coin_balance AS coin_balance"
     116              :            " FROM exchange_do_refresh"
     117              :            " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);");
     118           76 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     119              :                                                  "do_refresh",
     120              :                                                  params,
     121              :                                                  rs);
     122           76 :   GNUNET_PQ_cleanup_query_params_closures (params);
     123           76 :   if (0 > qs)
     124              :   {
     125            0 :     GNUNET_break (0);
     126            0 :     return qs;
     127              :   }
     128           76 :   if (! coin_found)
     129              :   {
     130            1 :     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     131              :   }
     132           75 :   if (*found && no_noreveal_index)
     133              :   {
     134            0 :     GNUNET_break (0);
     135            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     136              :   }
     137           75 :   if (! (*balance_ok) && no_coin_balance)
     138              :   {
     139            0 :     GNUNET_break (0);
     140            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     141              :   }
     142           75 :   return qs;
     143              : }
        

Generated by: LCOV version 2.0-1