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