LCOV - code coverage report
Current view: top level - exchangedb - do_check_deposit_idempotent.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 41 41
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022-2023 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_deposit.c
      18              :  * @brief Implementation of the do_deposit function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/do_check_deposit_idempotent.h"
      23              : #include "helper.h"
      24              : #include "exchange-database/compute_shard.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28            5 : TALER_EXCHANGEDB_do_check_deposit_idempotent (
      29              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      30              :   const struct TALER_EXCHANGEDB_BatchDeposit *bd,
      31              :   struct GNUNET_TIME_Timestamp *exchange_timestamp,
      32              :   bool *is_idempotent)
      33            5 : {
      34            5 :   uint64_t deposit_shard = TALER_EXCHANGEDB_compute_shard (&bd->merchant_pub);
      35            5 :   const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)];
      36            5 :   const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)];
      37            5 :   struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)];
      38              :   struct TALER_NormalizedPaytoHashP h_normalized_payto;
      39            5 :   struct GNUNET_PQ_QueryParam params[] = {
      40              :     /* data for batch_deposits */
      41            5 :     GNUNET_PQ_query_param_uint64 (&deposit_shard),
      42            5 :     GNUNET_PQ_query_param_auto_from_type (&bd->merchant_pub),
      43            5 :     GNUNET_PQ_query_param_timestamp (&bd->wallet_timestamp),
      44            5 :     GNUNET_PQ_query_param_timestamp (exchange_timestamp),
      45            5 :     GNUNET_PQ_query_param_timestamp (&bd->refund_deadline),
      46            5 :     GNUNET_PQ_query_param_timestamp (&bd->wire_deadline),
      47            5 :     GNUNET_PQ_query_param_auto_from_type (&bd->h_contract_terms),
      48            5 :     (bd->no_wallet_data_hash)
      49            5 :     ? GNUNET_PQ_query_param_null ()
      50            5 :     : GNUNET_PQ_query_param_auto_from_type (&bd->wallet_data_hash),
      51            5 :     GNUNET_PQ_query_param_auto_from_type (&bd->wire_salt),
      52            5 :     GNUNET_PQ_query_param_auto_from_type (&bd->wire_target_h_payto),
      53            5 :     (0 == bd->policy_details_serial_id)
      54            5 :     ? GNUNET_PQ_query_param_null ()
      55            5 :     : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id),
      56            5 :     GNUNET_PQ_query_param_bool (bd->policy_blocked),
      57              :     /* arrays for coin_deposits */
      58            5 :     GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis,
      59              :                                                      coin_pubs,
      60              :                                                      pg->conn),
      61            5 :     GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis,
      62              :                                                      coin_sigs,
      63              :                                                      pg->conn),
      64            5 :     TALER_PQ_query_param_array_amount (bd->num_cdis,
      65              :                                        amounts_with_fee,
      66              :                                        pg->conn),
      67              :     GNUNET_PQ_query_param_end
      68              :   };
      69              :   bool no_time;
      70            5 :   struct GNUNET_PQ_ResultSpec rs[] = {
      71            5 :     GNUNET_PQ_result_spec_allow_null (
      72              :       GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
      73              :                                        exchange_timestamp),
      74              :       &no_time),
      75            5 :     GNUNET_PQ_result_spec_bool ("is_idempotent",
      76              :                                 is_idempotent),
      77              :     GNUNET_PQ_result_spec_end
      78              :   };
      79              :   enum GNUNET_DB_QueryStatus qs;
      80              : 
      81            5 :   TALER_full_payto_normalize_and_hash (bd->receiver_wire_account,
      82              :                                        &h_normalized_payto);
      83           10 :   for (unsigned int i = 0; i < bd->num_cdis; i++)
      84              :   {
      85            5 :     const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi
      86            5 :       = &bd->cdis[i];
      87              : 
      88            5 :     amounts_with_fee[i] = cdi->amount_with_fee;
      89            5 :     coin_pubs[i] = &cdi->coin.coin_pub;
      90            5 :     coin_sigs[i] = &cdi->csig;
      91            5 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      92              :                 "Do deposit %u = %s\n",
      93              :                 i,
      94              :                 TALER_B2S (&cdi->coin.coin_pub));
      95              :   }
      96            5 :   PREPARE (pg,
      97              :            "call_check_deposit_idempotent",
      98              :            "SELECT "
      99              :            " out_exchange_timestamp AS exchange_timestamp"
     100              :            ",out_is_idempotent AS is_idempotent"
     101              :            " FROM exchange_do_check_deposit_idempotent"
     102              :            " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15);");
     103            5 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     104              :                                                  "call_check_deposit_idempotent",
     105              :                                                  params,
     106              :                                                  rs);
     107            5 :   GNUNET_PQ_cleanup_query_params_closures (params);
     108            5 :   return qs;
     109              : }
        

Generated by: LCOV version 2.0-1