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 backenddb/pg_store_wire_fee_by_exchange.c 18 : * @brief Implementation of the store_wire_fee_by_exchange function for Postgres 19 : * @author Christian Grothoff 20 : */ 21 : #include "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_store_wire_fee_by_exchange.h" 26 : #include "pg_helper.h" 27 : 28 : 29 : enum GNUNET_DB_QueryStatus 30 36 : TMH_PG_store_wire_fee_by_exchange ( 31 : void *cls, 32 : const struct TALER_MasterPublicKeyP *master_pub, 33 : const struct GNUNET_HashCode *h_wire_method, 34 : const struct TALER_WireFeeSet *fees, 35 : struct GNUNET_TIME_Timestamp start_date, 36 : struct GNUNET_TIME_Timestamp end_date, 37 : const struct TALER_MasterSignatureP *master_sig) 38 : { 39 36 : struct PostgresClosure *pg = cls; 40 36 : struct GNUNET_PQ_QueryParam params[] = { 41 36 : GNUNET_PQ_query_param_auto_from_type (master_pub), 42 36 : GNUNET_PQ_query_param_auto_from_type (h_wire_method), 43 36 : TALER_PQ_query_param_amount_with_currency (pg->conn, 44 : &fees->wire), 45 36 : TALER_PQ_query_param_amount_with_currency (pg->conn, 46 : &fees->closing), 47 36 : GNUNET_PQ_query_param_timestamp (&start_date), 48 36 : GNUNET_PQ_query_param_timestamp (&end_date), 49 36 : GNUNET_PQ_query_param_auto_from_type (master_sig), 50 : GNUNET_PQ_query_param_end 51 : }; 52 : 53 : /* no preflight check here, run in its own transaction by the caller */ 54 36 : PREPARE (pg, 55 : "insert_wire_fee", 56 : "INSERT INTO merchant_exchange_wire_fees" 57 : "(master_pub" 58 : ",h_wire_method" 59 : ",wire_fee" 60 : ",closing_fee" 61 : ",start_date" 62 : ",end_date" 63 : ",master_sig)" 64 : " VALUES " 65 : "($1, $2, $3, $4, $5, $6, $7)" 66 : " ON CONFLICT DO NOTHING"); 67 36 : check_connection (pg); 68 36 : GNUNET_log (GNUNET_ERROR_TYPE_INFO, 69 : "Storing wire fee for %s starting at %s of %s\n", 70 : TALER_B2S (master_pub), 71 : GNUNET_TIME_timestamp2s (start_date), 72 : TALER_amount2s (&fees->wire)); 73 36 : return GNUNET_PQ_eval_prepared_non_select (pg->conn, 74 : "insert_wire_fee", 75 : params); 76 : }