LCOV - code coverage report
Current view: top level - exchangedb - pg_insert_purse_request.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 36 63.9 %
Date: 2025-06-05 21:03:14 Functions: 1 1 100.0 %

          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_insert_purse_request.c
      18             :  * @brief Implementation of the insert_purse_request function for Postgres
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_error_codes.h"
      23             : #include "taler_dbevents.h"
      24             : #include "taler_pq_lib.h"
      25             : #include "pg_insert_purse_request.h"
      26             : #include "pg_get_purse_request.h"
      27             : #include "pg_helper.h"
      28             : 
      29             : 
      30             : enum GNUNET_DB_QueryStatus
      31          24 : TEH_PG_insert_purse_request (
      32             :   void *cls,
      33             :   const struct TALER_PurseContractPublicKeyP *purse_pub,
      34             :   const struct TALER_PurseMergePublicKeyP *merge_pub,
      35             :   struct GNUNET_TIME_Timestamp purse_expiration,
      36             :   const struct TALER_PrivateContractHashP *h_contract_terms,
      37             :   uint32_t age_limit,
      38             :   enum TALER_WalletAccountMergeFlags flags,
      39             :   const struct TALER_Amount *purse_fee,
      40             :   const struct TALER_Amount *amount,
      41             :   const struct TALER_PurseContractSignatureP *purse_sig,
      42             :   bool *in_conflict)
      43             : {
      44          24 :   struct PostgresClosure *pg = cls;
      45             :   enum GNUNET_DB_QueryStatus qs;
      46          24 :   struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
      47          24 :   uint32_t flags32 = (uint32_t) flags;
      48          24 :   bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA
      49          24 :                            == (flags & TALER_WAMF_MERGE_MODE_MASK));
      50          24 :   struct GNUNET_PQ_QueryParam params[] = {
      51          24 :     GNUNET_PQ_query_param_auto_from_type (purse_pub),
      52          24 :     GNUNET_PQ_query_param_auto_from_type (merge_pub),
      53          24 :     GNUNET_PQ_query_param_timestamp (&now),
      54          24 :     GNUNET_PQ_query_param_timestamp (&purse_expiration),
      55          24 :     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
      56          24 :     GNUNET_PQ_query_param_uint32 (&age_limit),
      57          24 :     GNUNET_PQ_query_param_uint32 (&flags32),
      58          24 :     GNUNET_PQ_query_param_bool (in_reserve_quota),
      59          24 :     TALER_PQ_query_param_amount (pg->conn,
      60             :                                  amount),
      61          24 :     TALER_PQ_query_param_amount (pg->conn,
      62             :                                  purse_fee),
      63          24 :     GNUNET_PQ_query_param_auto_from_type (purse_sig),
      64             :     GNUNET_PQ_query_param_end
      65             :   };
      66             : 
      67          24 :   *in_conflict = false;
      68          24 :   PREPARE (pg,
      69             :            "insert_purse_request",
      70             :            "INSERT INTO purse_requests"
      71             :            "  (purse_pub"
      72             :            "  ,merge_pub"
      73             :            "  ,purse_creation"
      74             :            "  ,purse_expiration"
      75             :            "  ,h_contract_terms"
      76             :            "  ,age_limit"
      77             :            "  ,flags"
      78             :            "  ,in_reserve_quota"
      79             :            "  ,amount_with_fee"
      80             :            "  ,purse_fee"
      81             :            "  ,purse_sig"
      82             :            "  ) VALUES "
      83             :            "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)"
      84             :            "  ON CONFLICT DO NOTHING;");
      85          24 :   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      86             :                                            "insert_purse_request",
      87             :                                            params);
      88          24 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
      89          24 :     return qs;
      90             :   {
      91             :     struct TALER_PurseMergePublicKeyP merge_pub2;
      92             :     struct GNUNET_TIME_Timestamp purse_expiration2;
      93             :     struct TALER_PrivateContractHashP h_contract_terms2;
      94             :     uint32_t age_limit2;
      95             :     struct TALER_Amount amount2;
      96             :     struct TALER_Amount balance;
      97             :     struct TALER_PurseContractSignatureP purse_sig2;
      98             : 
      99           0 :     qs = TEH_PG_get_purse_request (pg,
     100             :                                    purse_pub,
     101             :                                    &merge_pub2,
     102             :                                    &purse_expiration2,
     103             :                                    &h_contract_terms2,
     104             :                                    &age_limit2,
     105             :                                    &amount2,
     106             :                                    &balance,
     107             :                                    &purse_sig2);
     108           0 :     if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
     109             :     {
     110           0 :       GNUNET_break (0);
     111           0 :       return GNUNET_DB_STATUS_HARD_ERROR;
     112             :     }
     113           0 :     if ( (age_limit2 == age_limit) &&
     114           0 :          (0 == TALER_amount_cmp (amount,
     115           0 :                                  &amount2)) &&
     116           0 :          (0 == GNUNET_memcmp (&h_contract_terms2,
     117           0 :                               h_contract_terms)) &&
     118           0 :          (0 == GNUNET_memcmp (&merge_pub2,
     119             :                               merge_pub)) )
     120             :     {
     121           0 :       return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     122             :     }
     123           0 :     *in_conflict = true;
     124           0 :     return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
     125             :   }
     126             : }

Generated by: LCOV version 1.16