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_get_global_fee.c
18 : * @brief Implementation of the get_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_get_global_fee.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 19 : TEH_PG_get_global_fee (void *cls,
31 : struct GNUNET_TIME_Timestamp date,
32 : struct GNUNET_TIME_Timestamp *start_date,
33 : struct GNUNET_TIME_Timestamp *end_date,
34 : struct TALER_GlobalFeeSet *fees,
35 : struct GNUNET_TIME_Relative *purse_timeout,
36 : struct GNUNET_TIME_Relative *history_expiration,
37 : uint32_t *purse_account_limit,
38 : struct TALER_MasterSignatureP *master_sig)
39 : {
40 19 : struct PostgresClosure *pg = cls;
41 19 : struct GNUNET_PQ_QueryParam params[] = {
42 19 : GNUNET_PQ_query_param_timestamp (&date),
43 : GNUNET_PQ_query_param_end
44 : };
45 19 : struct GNUNET_PQ_ResultSpec rs[] = {
46 19 : GNUNET_PQ_result_spec_timestamp ("start_date",
47 : start_date),
48 19 : GNUNET_PQ_result_spec_timestamp ("end_date",
49 : end_date),
50 19 : TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
51 : &fees->history),
52 19 : TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
53 : &fees->account),
54 19 : TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
55 : &fees->purse),
56 19 : GNUNET_PQ_result_spec_relative_time ("purse_timeout",
57 : purse_timeout),
58 19 : GNUNET_PQ_result_spec_relative_time ("history_expiration",
59 : history_expiration),
60 19 : GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
61 : purse_account_limit),
62 19 : GNUNET_PQ_result_spec_auto_from_type ("master_sig",
63 : master_sig),
64 : GNUNET_PQ_result_spec_end
65 : };
66 :
67 19 : PREPARE (pg,
68 : "get_global_fee",
69 : "SELECT "
70 : " start_date"
71 : ",end_date"
72 : ",history_fee"
73 : ",account_fee"
74 : ",purse_fee"
75 : ",purse_timeout"
76 : ",history_expiration"
77 : ",purse_account_limit"
78 : ",master_sig"
79 : " FROM global_fee"
80 : " WHERE start_date <= $1"
81 : " AND end_date > $1;");
82 19 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
83 : "get_global_fee",
84 : params,
85 : rs);
86 : }
|