Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2022-2023 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/select_batch_deposits_missing_wire.c
18 : * @brief Implementation of the select_batch_deposits_missing_wire function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_pq_lib.h"
22 : #include "exchange-database/select_batch_deposits_missing_wire.h"
23 : #include "helper.h"
24 :
25 : /**
26 : * Closure for #missing_wire_cb().
27 : */
28 : struct MissingWireContext
29 : {
30 : /**
31 : * Function to call per result.
32 : */
33 : TALER_EXCHANGEDB_WireMissingCallback cb;
34 :
35 : /**
36 : * Closure for @e cb.
37 : */
38 : void *cb_cls;
39 :
40 : /**
41 : * Plugin context.
42 : */
43 : struct TALER_EXCHANGEDB_PostgresContext *pg;
44 :
45 : /**
46 : * Set to #GNUNET_SYSERR on error.
47 : */
48 : enum GNUNET_GenericReturnValue status;
49 : };
50 :
51 :
52 : /**
53 : * Invoke the callback for each result.
54 : *
55 : * @param cls a `struct MissingWireContext *`
56 : * @param result SQL result
57 : * @param num_results number of rows in @a result
58 : */
59 : static void
60 0 : missing_wire_cb (void *cls,
61 : PGresult *result,
62 : unsigned int num_results)
63 : {
64 0 : struct MissingWireContext *mwc = cls;
65 0 : struct TALER_EXCHANGEDB_PostgresContext *pg = mwc->pg;
66 :
67 0 : for (unsigned int i = 0; i<num_results; i++)
68 : {
69 : uint64_t batch_deposit_serial_id;
70 : struct GNUNET_TIME_Timestamp deadline;
71 : struct TALER_FullPaytoHashP wire_target_h_payto;
72 : struct TALER_Amount total_amount;
73 0 : struct GNUNET_PQ_ResultSpec rs[] = {
74 0 : GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
75 : &batch_deposit_serial_id),
76 0 : GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
77 : &wire_target_h_payto),
78 0 : GNUNET_PQ_result_spec_timestamp ("deadline",
79 : &deadline),
80 0 : TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
81 : &total_amount),
82 : GNUNET_PQ_result_spec_end
83 : };
84 :
85 0 : if (GNUNET_OK !=
86 0 : GNUNET_PQ_extract_result (result,
87 : rs,
88 : i))
89 : {
90 0 : GNUNET_break (0);
91 0 : mwc->status = GNUNET_SYSERR;
92 0 : return;
93 : }
94 0 : mwc->cb (mwc->cb_cls,
95 : batch_deposit_serial_id,
96 : &total_amount,
97 : &wire_target_h_payto,
98 : deadline);
99 0 : GNUNET_PQ_cleanup_result (rs);
100 : }
101 : }
102 :
103 :
104 : enum GNUNET_DB_QueryStatus
105 0 : TALER_EXCHANGEDB_select_batch_deposits_missing_wire (
106 : struct TALER_EXCHANGEDB_PostgresContext *pg,
107 : uint64_t min_batch_deposit_serial_id,
108 : TALER_EXCHANGEDB_WireMissingCallback cb,
109 : void *cb_cls)
110 : {
111 0 : struct GNUNET_PQ_QueryParam params[] = {
112 0 : GNUNET_PQ_query_param_uint64 (&min_batch_deposit_serial_id),
113 : GNUNET_PQ_query_param_end
114 : };
115 0 : struct MissingWireContext mwc = {
116 : .cb = cb,
117 : .cb_cls = cb_cls,
118 : .pg = pg,
119 : .status = GNUNET_OK
120 : };
121 : enum GNUNET_DB_QueryStatus qs;
122 :
123 0 : PREPARE (pg,
124 : "deposits_get_deposits_missing_wire",
125 : "SELECT"
126 : " batch_deposit_serial_id"
127 : ",wire_target_h_payto"
128 : ",deadline"
129 : ",total_amount"
130 : " FROM exchange_do_select_deposits_missing_wire"
131 : " ($1);");
132 0 : qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
133 : "deposits_get_deposits_missing_wire",
134 : params,
135 : &missing_wire_cb,
136 : &mwc);
137 0 : if (GNUNET_OK != mwc.status)
138 0 : return GNUNET_DB_STATUS_HARD_ERROR;
139 0 : return qs;
140 : }
|