LCOV - code coverage report
Current view: top level - exchangedb - pg_do_reserve_purse.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 25 25
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_do_reserve_purse.c
      18              :  * @brief Implementation of the do_reserve_purse function for Postgres
      19              :  * @author Christian Grothoff
      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_do_reserve_purse.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : /**
      30              :  * Function called insert request to merge a purse into a reserve by the
      31              :  * respective purse merge key. The purse must not have been merged into a
      32              :  * different reserve.
      33              :  *
      34              :  * @param cls the @e cls of this struct with the plugin-specific state
      35              :  * @param purse_pub purse to merge
      36              :  * @param merge_sig signature affirming the merge
      37              :  * @param merge_timestamp time of the merge
      38              :  * @param reserve_sig signature of the reserve affirming the merge
      39              :  * @param purse_fee amount to charge the reserve for the purse creation, NULL to use the quota
      40              :  * @param reserve_pub public key of the reserve to credit
      41              :  * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
      42              :  * @param[out] no_reserve set to true if @a reserve_pub is not a known reserve
      43              :  * @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse
      44              :  * @return transaction status code
      45              :  */
      46              : enum GNUNET_DB_QueryStatus
      47           13 : TEH_PG_do_reserve_purse (
      48              :   void *cls,
      49              :   const struct TALER_PurseContractPublicKeyP *purse_pub,
      50              :   const struct TALER_PurseMergeSignatureP *merge_sig,
      51              :   const struct GNUNET_TIME_Timestamp merge_timestamp,
      52              :   const struct TALER_ReserveSignatureP *reserve_sig,
      53              :   const struct TALER_Amount *purse_fee,
      54              :   const struct TALER_ReservePublicKeyP *reserve_pub,
      55              :   bool *in_conflict,
      56              :   bool *no_reserve,
      57              :   bool *insufficient_funds)
      58              : {
      59           13 :   struct PostgresClosure *pg = cls;
      60              :   struct TALER_Amount zero_fee;
      61              :   struct TALER_NormalizedPaytoHashP h_payto;
      62              :   struct GNUNET_TIME_Timestamp reserve_expiration
      63           13 :     = GNUNET_TIME_absolute_to_timestamp (
      64              :         GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
      65              :                                   pg->idle_reserve_expiration_time));
      66              :   struct GNUNET_TIME_Timestamp reserve_gc
      67           13 :     = GNUNET_TIME_absolute_to_timestamp (
      68              :         GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
      69              :                                   pg->legal_reserve_expiration_time));
      70              : 
      71           13 :   struct GNUNET_PQ_QueryParam params[] = {
      72           13 :     GNUNET_PQ_query_param_auto_from_type (purse_pub),
      73           13 :     GNUNET_PQ_query_param_auto_from_type (merge_sig),
      74           13 :     GNUNET_PQ_query_param_timestamp (&merge_timestamp),
      75           13 :     GNUNET_PQ_query_param_timestamp (&reserve_expiration),
      76           13 :     GNUNET_PQ_query_param_timestamp (&reserve_gc),
      77           13 :     GNUNET_PQ_query_param_auto_from_type (reserve_sig),
      78           13 :     GNUNET_PQ_query_param_bool (NULL == purse_fee),
      79           13 :     TALER_PQ_query_param_amount (pg->conn,
      80              :                                  NULL == purse_fee
      81              :                                         ? &zero_fee
      82              :                                         : purse_fee),
      83           13 :     GNUNET_PQ_query_param_auto_from_type (reserve_pub),
      84           13 :     GNUNET_PQ_query_param_auto_from_type (&h_payto),
      85              :     GNUNET_PQ_query_param_end
      86              :   };
      87           13 :   struct GNUNET_PQ_ResultSpec rs[] = {
      88           13 :     GNUNET_PQ_result_spec_bool ("insufficient_funds",
      89              :                                 insufficient_funds),
      90           13 :     GNUNET_PQ_result_spec_bool ("conflict",
      91              :                                 in_conflict),
      92           13 :     GNUNET_PQ_result_spec_bool ("no_reserve",
      93              :                                 no_reserve),
      94              :     GNUNET_PQ_result_spec_end
      95              :   };
      96              : 
      97              :   {
      98              :     struct TALER_NormalizedPayto payto_uri;
      99              : 
     100           13 :     payto_uri = TALER_reserve_make_payto (pg->exchange_url,
     101              :                                           reserve_pub);
     102           13 :     TALER_normalized_payto_hash (payto_uri,
     103              :                                  &h_payto);
     104           13 :     GNUNET_free (payto_uri.normalized_payto);
     105              :   }
     106           13 :   GNUNET_assert (GNUNET_OK ==
     107              :                  TALER_amount_set_zero (pg->currency,
     108              :                                         &zero_fee));
     109           13 :   PREPARE (pg,
     110              :            "call_reserve_purse",
     111              :            "SELECT"
     112              :            " out_no_funds AS insufficient_funds"
     113              :            ",out_no_reserve AS no_reserve"
     114              :            ",out_conflict AS conflict"
     115              :            " FROM exchange_do_reserve_purse"
     116              :            "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
     117              : 
     118           13 :   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     119              :                                                    "call_reserve_purse",
     120              :                                                    params,
     121              :                                                    rs);
     122              : }
        

Generated by: LCOV version 2.0-1