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/insert_wire_fee.c
18 : * @brief Implementation of the insert_wire_fee function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_pq_lib.h"
22 : #include "exchange-database/insert_wire_fee.h"
23 : #include "helper.h"
24 : #include "exchange-database/get_wire_fee.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 38 : TALER_TALER_EXCHANGEDB_insert_wire_fee (struct
29 : TALER_EXCHANGEDB_PostgresContext *pg,
30 : const char *type,
31 : struct GNUNET_TIME_Timestamp start_date,
32 : struct GNUNET_TIME_Timestamp end_date,
33 : const struct TALER_WireFeeSet *fees,
34 : const struct TALER_MasterSignatureP *
35 : master_sig)
36 : {
37 38 : struct GNUNET_PQ_QueryParam params[] = {
38 38 : GNUNET_PQ_query_param_string (type),
39 38 : GNUNET_PQ_query_param_timestamp (&start_date),
40 38 : GNUNET_PQ_query_param_timestamp (&end_date),
41 38 : TALER_PQ_query_param_amount (pg->conn,
42 : &fees->wire),
43 38 : TALER_PQ_query_param_amount (pg->conn,
44 : &fees->closing),
45 38 : GNUNET_PQ_query_param_auto_from_type (master_sig),
46 : GNUNET_PQ_query_param_end
47 : };
48 : struct TALER_WireFeeSet wx;
49 : struct TALER_MasterSignatureP sig;
50 : struct GNUNET_TIME_Timestamp sd;
51 : struct GNUNET_TIME_Timestamp ed;
52 : enum GNUNET_DB_QueryStatus qs;
53 : uint64_t rowid;
54 :
55 38 : qs = TALER_EXCHANGEDB_get_wire_fee (pg,
56 : type,
57 : start_date,
58 : &rowid,
59 : &sd,
60 : &ed,
61 : &wx,
62 : &sig);
63 38 : if (qs < 0)
64 0 : return qs;
65 38 : if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
66 : {
67 0 : if (0 != GNUNET_memcmp (&sig,
68 : master_sig))
69 : {
70 0 : GNUNET_break (0);
71 0 : return GNUNET_DB_STATUS_HARD_ERROR;
72 : }
73 0 : if (0 !=
74 0 : TALER_wire_fee_set_cmp (fees,
75 : &wx))
76 : {
77 0 : GNUNET_break (0);
78 0 : return GNUNET_DB_STATUS_HARD_ERROR;
79 : }
80 0 : if ( (GNUNET_TIME_timestamp_cmp (sd,
81 : !=,
82 0 : start_date)) ||
83 0 : (GNUNET_TIME_timestamp_cmp (ed,
84 : !=,
85 : end_date)) )
86 : {
87 0 : GNUNET_break (0);
88 0 : return GNUNET_DB_STATUS_HARD_ERROR;
89 : }
90 : /* equal record already exists */
91 0 : return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
92 : }
93 :
94 38 : PREPARE (pg,
95 : "insert_wire_fee",
96 : "INSERT INTO wire_fee "
97 : "(wire_method"
98 : ",start_date"
99 : ",end_date"
100 : ",wire_fee"
101 : ",closing_fee"
102 : ",master_sig"
103 : ") VALUES "
104 : "($1, $2, $3, $4, $5, $6);");
105 38 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
106 : "insert_wire_fee",
107 : params);
108 : }
|