exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

pg_insert_wire_fee.c (3695B)


      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 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   struct PostgresClosure *pg = cls;
     39   struct GNUNET_PQ_QueryParam params[] = {
     40     GNUNET_PQ_query_param_string (type),
     41     GNUNET_PQ_query_param_timestamp (&start_date),
     42     GNUNET_PQ_query_param_timestamp (&end_date),
     43     TALER_PQ_query_param_amount (pg->conn,
     44                                  &fees->wire),
     45     TALER_PQ_query_param_amount (pg->conn,
     46                                  &fees->closing),
     47     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   qs = TEH_PG_get_wire_fee (pg,
     58                             type,
     59                             start_date,
     60                             &rowid,
     61                             &sd,
     62                             &ed,
     63                             &wx,
     64                             &sig);
     65   if (qs < 0)
     66     return qs;
     67   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
     68   {
     69     if (0 != GNUNET_memcmp (&sig,
     70                             master_sig))
     71     {
     72       GNUNET_break (0);
     73       return GNUNET_DB_STATUS_HARD_ERROR;
     74     }
     75     if (0 !=
     76         TALER_wire_fee_set_cmp (fees,
     77                                 &wx))
     78     {
     79       GNUNET_break (0);
     80       return GNUNET_DB_STATUS_HARD_ERROR;
     81     }
     82     if ( (GNUNET_TIME_timestamp_cmp (sd,
     83                                      !=,
     84                                      start_date)) ||
     85          (GNUNET_TIME_timestamp_cmp (ed,
     86                                      !=,
     87                                      end_date)) )
     88     {
     89       GNUNET_break (0);
     90       return GNUNET_DB_STATUS_HARD_ERROR;
     91     }
     92     /* equal record already exists */
     93     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     94   }
     95 
     96   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   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    108                                              "insert_wire_fee",
    109                                              params);
    110 }