exchange

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

pg_insert_global_fee.c (4846B)


      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_global_fee.c
     18  * @brief Implementation of the insert_global_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_global_fee.h"
     26 #include "pg_helper.h"
     27 #include "pg_get_global_fee.h"
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TEH_PG_insert_global_fee (void *cls,
     31                           struct GNUNET_TIME_Timestamp start_date,
     32                           struct GNUNET_TIME_Timestamp end_date,
     33                           const struct TALER_GlobalFeeSet *fees,
     34                           struct GNUNET_TIME_Relative purse_timeout,
     35                           struct GNUNET_TIME_Relative history_expiration,
     36                           uint32_t purse_account_limit,
     37                           const struct TALER_MasterSignatureP *master_sig)
     38 {
     39   struct PostgresClosure *pg = cls;
     40   struct GNUNET_PQ_QueryParam params[] = {
     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->history),
     45     TALER_PQ_query_param_amount (pg->conn,
     46                                  &fees->account),
     47     TALER_PQ_query_param_amount (pg->conn,
     48                                  &fees->purse),
     49     GNUNET_PQ_query_param_relative_time (&purse_timeout),
     50     GNUNET_PQ_query_param_relative_time (&history_expiration),
     51     GNUNET_PQ_query_param_uint32 (&purse_account_limit),
     52     GNUNET_PQ_query_param_auto_from_type (master_sig),
     53     GNUNET_PQ_query_param_end
     54   };
     55   struct TALER_GlobalFeeSet wx;
     56   struct TALER_MasterSignatureP sig;
     57   struct GNUNET_TIME_Timestamp sd;
     58   struct GNUNET_TIME_Timestamp ed;
     59   enum GNUNET_DB_QueryStatus qs;
     60   struct GNUNET_TIME_Relative pt;
     61   struct GNUNET_TIME_Relative he;
     62   uint32_t pal;
     63 
     64   qs = TEH_PG_get_global_fee (pg,
     65                               start_date,
     66                               &sd,
     67                               &ed,
     68                               &wx,
     69                               &pt,
     70                               &he,
     71                               &pal,
     72                               &sig);
     73   if (qs < 0)
     74     return qs;
     75   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
     76   {
     77     if (0 != GNUNET_memcmp (&sig,
     78                             master_sig))
     79     {
     80       GNUNET_break (0);
     81       return GNUNET_DB_STATUS_HARD_ERROR;
     82     }
     83     if (0 !=
     84         TALER_global_fee_set_cmp (fees,
     85                                   &wx))
     86     {
     87       GNUNET_break (0);
     88       return GNUNET_DB_STATUS_HARD_ERROR;
     89     }
     90     if ( (GNUNET_TIME_timestamp_cmp (sd,
     91                                      !=,
     92                                      start_date)) ||
     93          (GNUNET_TIME_timestamp_cmp (ed,
     94                                      !=,
     95                                      end_date)) )
     96     {
     97       GNUNET_break (0);
     98       return GNUNET_DB_STATUS_HARD_ERROR;
     99     }
    100     if ( (GNUNET_TIME_relative_cmp (purse_timeout,
    101                                     !=,
    102                                     pt)) ||
    103          (GNUNET_TIME_relative_cmp (history_expiration,
    104                                     !=,
    105                                     he)) )
    106     {
    107       GNUNET_break (0);
    108       return GNUNET_DB_STATUS_HARD_ERROR;
    109     }
    110     if (purse_account_limit != pal)
    111     {
    112       GNUNET_break (0);
    113       return GNUNET_DB_STATUS_HARD_ERROR;
    114     }
    115     /* equal record already exists */
    116     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    117   }
    118 
    119   /* Used in #postgres_insert_global_fee */
    120   PREPARE (pg,
    121            "insert_global_fee",
    122            "INSERT INTO global_fee "
    123            "(start_date"
    124            ",end_date"
    125            ",history_fee"
    126            ",account_fee"
    127            ",purse_fee"
    128            ",purse_timeout"
    129            ",history_expiration"
    130            ",purse_account_limit"
    131            ",master_sig"
    132            ") VALUES "
    133            "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
    134   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    135                                              "insert_global_fee",
    136                                              params);
    137 }