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 pg_do_reserve_open.c
18 : * @brief Low-level (statement-level) Postgres database access for the exchange
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_do_reserve_open.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 6 : TEH_PG_do_reserve_open (
31 : void *cls,
32 : const struct TALER_ReservePublicKeyP *reserve_pub,
33 : const struct TALER_Amount *total_paid,
34 : const struct TALER_Amount *reserve_payment,
35 : uint32_t min_purse_limit,
36 : const struct TALER_ReserveSignatureP *reserve_sig,
37 : struct GNUNET_TIME_Timestamp desired_expiration,
38 : struct GNUNET_TIME_Timestamp now,
39 : const struct TALER_Amount *open_fee,
40 : bool *no_funds,
41 : struct TALER_Amount *reserve_balance,
42 : struct TALER_Amount *open_cost,
43 : struct GNUNET_TIME_Timestamp *final_expiration)
44 : {
45 6 : struct PostgresClosure *pg = cls;
46 6 : struct GNUNET_PQ_QueryParam params[] = {
47 6 : GNUNET_PQ_query_param_auto_from_type (reserve_pub),
48 6 : TALER_PQ_query_param_amount (
49 6 : pg->conn,
50 : total_paid),
51 6 : TALER_PQ_query_param_amount (
52 6 : pg->conn,
53 : reserve_payment),
54 6 : GNUNET_PQ_query_param_uint32 (&min_purse_limit),
55 6 : GNUNET_PQ_query_param_uint32 (&pg->def_purse_limit),
56 6 : GNUNET_PQ_query_param_auto_from_type (reserve_sig),
57 6 : GNUNET_PQ_query_param_timestamp (&desired_expiration),
58 6 : GNUNET_PQ_query_param_relative_time (&pg->legal_reserve_expiration_time),
59 6 : GNUNET_PQ_query_param_timestamp (&now),
60 6 : TALER_PQ_query_param_amount (pg->conn,
61 : open_fee),
62 : GNUNET_PQ_query_param_end
63 : };
64 6 : bool no_reserve = true;
65 6 : struct GNUNET_PQ_ResultSpec rs[] = {
66 6 : TALER_PQ_result_spec_amount ("out_open_cost",
67 6 : pg->currency,
68 : open_cost),
69 6 : TALER_PQ_result_spec_amount ("out_reserve_balance",
70 6 : pg->currency,
71 : reserve_balance),
72 6 : GNUNET_PQ_result_spec_timestamp ("out_final_expiration",
73 : final_expiration),
74 6 : GNUNET_PQ_result_spec_bool ("out_no_reserve",
75 : &no_reserve),
76 6 : GNUNET_PQ_result_spec_bool ("out_no_funds",
77 : no_funds),
78 : GNUNET_PQ_result_spec_end
79 : };
80 : enum GNUNET_DB_QueryStatus qs;
81 :
82 6 : PREPARE (pg,
83 : "do_reserve_open",
84 : "SELECT "
85 : " out_open_cost"
86 : ",out_final_expiration"
87 : ",out_no_funds"
88 : ",out_no_reserve"
89 : ",out_reserve_balance"
90 : " FROM exchange_do_reserve_open"
91 : " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
92 6 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
93 : "do_reserve_open",
94 : params,
95 : rs);
96 6 : if (qs <= 0)
97 0 : return qs;
98 6 : if (no_reserve)
99 0 : return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
100 6 : return qs;
101 : }
|