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_global_fee.c
18 : * @brief Implementation of the insert_global_fee function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include "taler_error_codes.h"
23 : #include "taler_dbevents.h"
24 : #include "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 19 : 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 19 : struct PostgresClosure *pg = cls;
40 19 : struct GNUNET_PQ_QueryParam params[] = {
41 19 : GNUNET_PQ_query_param_timestamp (&start_date),
42 19 : GNUNET_PQ_query_param_timestamp (&end_date),
43 19 : TALER_PQ_query_param_amount (pg->conn,
44 : &fees->history),
45 19 : TALER_PQ_query_param_amount (pg->conn,
46 : &fees->account),
47 19 : TALER_PQ_query_param_amount (pg->conn,
48 : &fees->purse),
49 19 : GNUNET_PQ_query_param_relative_time (&purse_timeout),
50 19 : GNUNET_PQ_query_param_relative_time (&history_expiration),
51 19 : GNUNET_PQ_query_param_uint32 (&purse_account_limit),
52 19 : 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 19 : 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 19 : if (qs < 0)
74 0 : return qs;
75 19 : if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
76 : {
77 0 : if (0 != GNUNET_memcmp (&sig,
78 : master_sig))
79 : {
80 0 : GNUNET_break (0);
81 0 : return GNUNET_DB_STATUS_HARD_ERROR;
82 : }
83 0 : if (0 !=
84 0 : TALER_global_fee_set_cmp (fees,
85 : &wx))
86 : {
87 0 : GNUNET_break (0);
88 0 : return GNUNET_DB_STATUS_HARD_ERROR;
89 : }
90 0 : if ( (GNUNET_TIME_timestamp_cmp (sd,
91 : !=,
92 0 : start_date)) ||
93 0 : (GNUNET_TIME_timestamp_cmp (ed,
94 : !=,
95 : end_date)) )
96 : {
97 0 : GNUNET_break (0);
98 0 : return GNUNET_DB_STATUS_HARD_ERROR;
99 : }
100 0 : if ( (GNUNET_TIME_relative_cmp (purse_timeout,
101 : !=,
102 0 : pt)) ||
103 0 : (GNUNET_TIME_relative_cmp (history_expiration,
104 : !=,
105 : he)) )
106 : {
107 0 : GNUNET_break (0);
108 0 : return GNUNET_DB_STATUS_HARD_ERROR;
109 : }
110 0 : if (purse_account_limit != pal)
111 : {
112 0 : GNUNET_break (0);
113 0 : return GNUNET_DB_STATUS_HARD_ERROR;
114 : }
115 : /* equal record already exists */
116 0 : return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
117 : }
118 :
119 : /* Used in #postgres_insert_global_fee */
120 19 : 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 19 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
135 : "insert_global_fee",
136 : params);
137 : }
|