LCOV - code coverage report
Current view: top level - exchangedb - pg_insert_wire_fee.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 50.0 % 28 14
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_insert_wire_fee.c
      18              :  * @brief Implementation of the insert_wire_fee 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_insert_wire_fee.h"
      26              : #include "pg_helper.h"
      27              : #include "pg_get_wire_fee.h"
      28              : 
      29              : 
      30              : enum GNUNET_DB_QueryStatus
      31           21 : TEH_PG_insert_wire_fee (void *cls,
      32              :                         const char *type,
      33              :                         struct GNUNET_TIME_Timestamp start_date,
      34              :                         struct GNUNET_TIME_Timestamp end_date,
      35              :                         const struct TALER_WireFeeSet *fees,
      36              :                         const struct TALER_MasterSignatureP *master_sig)
      37              : {
      38           21 :   struct PostgresClosure *pg = cls;
      39           21 :   struct GNUNET_PQ_QueryParam params[] = {
      40           21 :     GNUNET_PQ_query_param_string (type),
      41           21 :     GNUNET_PQ_query_param_timestamp (&start_date),
      42           21 :     GNUNET_PQ_query_param_timestamp (&end_date),
      43           21 :     TALER_PQ_query_param_amount (pg->conn,
      44              :                                  &fees->wire),
      45           21 :     TALER_PQ_query_param_amount (pg->conn,
      46              :                                  &fees->closing),
      47           21 :     GNUNET_PQ_query_param_auto_from_type (master_sig),
      48              :     GNUNET_PQ_query_param_end
      49              :   };
      50              :   struct TALER_WireFeeSet wx;
      51              :   struct TALER_MasterSignatureP sig;
      52              :   struct GNUNET_TIME_Timestamp sd;
      53              :   struct GNUNET_TIME_Timestamp ed;
      54              :   enum GNUNET_DB_QueryStatus qs;
      55              :   uint64_t rowid;
      56              : 
      57           21 :   qs = TEH_PG_get_wire_fee (pg,
      58              :                             type,
      59              :                             start_date,
      60              :                             &rowid,
      61              :                             &sd,
      62              :                             &ed,
      63              :                             &wx,
      64              :                             &sig);
      65           21 :   if (qs < 0)
      66            0 :     return qs;
      67           21 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
      68              :   {
      69            0 :     if (0 != GNUNET_memcmp (&sig,
      70              :                             master_sig))
      71              :     {
      72            0 :       GNUNET_break (0);
      73            0 :       return GNUNET_DB_STATUS_HARD_ERROR;
      74              :     }
      75            0 :     if (0 !=
      76            0 :         TALER_wire_fee_set_cmp (fees,
      77              :                                 &wx))
      78              :     {
      79            0 :       GNUNET_break (0);
      80            0 :       return GNUNET_DB_STATUS_HARD_ERROR;
      81              :     }
      82            0 :     if ( (GNUNET_TIME_timestamp_cmp (sd,
      83              :                                      !=,
      84            0 :                                      start_date)) ||
      85            0 :          (GNUNET_TIME_timestamp_cmp (ed,
      86              :                                      !=,
      87              :                                      end_date)) )
      88              :     {
      89            0 :       GNUNET_break (0);
      90            0 :       return GNUNET_DB_STATUS_HARD_ERROR;
      91              :     }
      92              :     /* equal record already exists */
      93            0 :     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
      94              :   }
      95              : 
      96           21 :   PREPARE (pg,
      97              :            "insert_wire_fee",
      98              :            "INSERT INTO wire_fee "
      99              :            "(wire_method"
     100              :            ",start_date"
     101              :            ",end_date"
     102              :            ",wire_fee"
     103              :            ",closing_fee"
     104              :            ",master_sig"
     105              :            ") VALUES "
     106              :            "($1, $2, $3, $4, $5, $6);");
     107           21 :   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     108              :                                              "insert_wire_fee",
     109              :                                              params);
     110              : }
        

Generated by: LCOV version 2.0-1