LCOV - code coverage report
Current view: top level - exchangedb - do_reserve_purse.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 24 24
Test Date: 2026-09-11 18:55:36 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/do_reserve_purse.c
      18              :  * @brief Implementation of the do_reserve_purse function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/do_reserve_purse.h"
      23              : #include "helper.h"
      24              : 
      25              : 
      26              : enum GNUNET_DB_QueryStatus
      27           17 : TALER_EXCHANGEDB_do_reserve_purse (
      28              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      29              :   const struct TALER_PurseContractPublicKeyP *purse_pub,
      30              :   const struct TALER_PurseMergeSignatureP *merge_sig,
      31              :   const struct GNUNET_TIME_Timestamp merge_timestamp,
      32              :   const struct TALER_ReserveSignatureP *reserve_sig,
      33              :   const struct TALER_Amount *purse_fee,
      34              :   const struct TALER_ReservePublicKeyP *reserve_pub,
      35              :   bool *in_conflict,
      36              :   bool *no_reserve,
      37              :   bool *insufficient_funds)
      38              : {
      39              :   struct TALER_Amount zero_fee;
      40              :   struct TALER_NormalizedPaytoHashP h_payto;
      41              :   struct GNUNET_TIME_Timestamp reserve_expiration
      42           17 :     = GNUNET_TIME_absolute_to_timestamp (
      43              :         GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
      44              :                                   pg->idle_reserve_expiration_time));
      45              :   struct GNUNET_TIME_Timestamp reserve_gc
      46           17 :     = GNUNET_TIME_absolute_to_timestamp (
      47              :         GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
      48              :                                   pg->legal_reserve_expiration_time));
      49              : 
      50           17 :   struct GNUNET_PQ_QueryParam params[] = {
      51           17 :     GNUNET_PQ_query_param_auto_from_type (purse_pub),
      52           17 :     GNUNET_PQ_query_param_auto_from_type (merge_sig),
      53           17 :     GNUNET_PQ_query_param_timestamp (&merge_timestamp),
      54           17 :     GNUNET_PQ_query_param_timestamp (&reserve_expiration),
      55           17 :     GNUNET_PQ_query_param_timestamp (&reserve_gc),
      56           17 :     GNUNET_PQ_query_param_auto_from_type (reserve_sig),
      57           17 :     GNUNET_PQ_query_param_bool (NULL == purse_fee),
      58           17 :     TALER_PQ_query_param_amount (pg->conn,
      59              :                                  NULL == purse_fee
      60              :                                         ? &zero_fee
      61              :                                         : purse_fee),
      62           17 :     GNUNET_PQ_query_param_auto_from_type (reserve_pub),
      63           17 :     GNUNET_PQ_query_param_auto_from_type (&h_payto),
      64              :     GNUNET_PQ_query_param_end
      65              :   };
      66           17 :   struct GNUNET_PQ_ResultSpec rs[] = {
      67           17 :     GNUNET_PQ_result_spec_bool ("insufficient_funds",
      68              :                                 insufficient_funds),
      69           17 :     GNUNET_PQ_result_spec_bool ("conflict",
      70              :                                 in_conflict),
      71           17 :     GNUNET_PQ_result_spec_bool ("no_reserve",
      72              :                                 no_reserve),
      73              :     GNUNET_PQ_result_spec_end
      74              :   };
      75              : 
      76              :   {
      77              :     struct TALER_NormalizedPayto payto_uri;
      78              : 
      79           17 :     payto_uri = TALER_reserve_make_payto (pg->exchange_url,
      80              :                                           reserve_pub);
      81           17 :     TALER_normalized_payto_hash (payto_uri,
      82              :                                  &h_payto);
      83           17 :     GNUNET_free (payto_uri.normalized_payto);
      84              :   }
      85           17 :   GNUNET_assert (GNUNET_OK ==
      86              :                  TALER_amount_set_zero (pg->currency,
      87              :                                         &zero_fee));
      88           17 :   PREPARE (pg,
      89              :            "do_reserve_purse",
      90              :            "SELECT"
      91              :            " out_no_funds AS insufficient_funds"
      92              :            ",out_no_reserve AS no_reserve"
      93              :            ",out_conflict AS conflict"
      94              :            " FROM exchange_do_reserve_purse"
      95              :            "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
      96              : 
      97           17 :   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      98              :                                                    "do_reserve_purse",
      99              :                                                    params,
     100              :                                                    rs);
     101              : }
        

Generated by: LCOV version 2.0-1