Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2026 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/insert_aggregation_deferral.c
18 : * @brief Implementation of the insert_aggregation_deferral function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_error_codes.h"
22 : #include "taler/taler_pq_lib.h"
23 : #include "exchange-database/insert_aggregation_deferral.h"
24 : #include "helper.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 10 : TALER_EXCHANGEDB_insert_aggregation_deferral (
29 : struct TALER_EXCHANGEDB_PostgresContext *pg,
30 : const struct TALER_WireTransferIdentifierRawP *wtid,
31 : const struct TALER_FullPaytoHashP *h_payto,
32 : const struct TALER_Amount *amount,
33 : enum TALER_EXCHANGEDB_DeferralReason reason,
34 : uint64_t kyc_requirement_row,
35 : struct GNUNET_TIME_Timestamp deferral_time)
36 : {
37 10 : uint32_t reason32 = (uint32_t) reason;
38 10 : struct GNUNET_PQ_QueryParam params[] = {
39 10 : GNUNET_PQ_query_param_auto_from_type (wtid),
40 10 : GNUNET_PQ_query_param_auto_from_type (h_payto),
41 10 : TALER_PQ_query_param_amount (pg->conn,
42 : amount),
43 10 : GNUNET_PQ_query_param_uint32 (&reason32),
44 10 : GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
45 10 : GNUNET_PQ_query_param_timestamp (&deferral_time),
46 : GNUNET_PQ_query_param_end
47 : };
48 :
49 : /* The deposit we point at is picked here rather than passed in because it
50 : is not a fact about the deferral at all: it exists only so that
51 : exchange_do_main_gc() deleting the aggregate's deposits takes the
52 : deferral with it. Hence the *last* deposit to reach its wire deadline --
53 : that is the one whose collection means the whole aggregate is being aged
54 : out. If the aggregation_tracking rows are not there yet the SELECT is
55 : empty and nothing is inserted, which is why the caller must run after
56 : TALER_EXCHANGEDB_do_aggregate(). */
57 10 : PREPARE (pg,
58 : "insert_aggregation_deferral",
59 : "INSERT INTO aggregation_deferrals"
60 : " (batch_deposit_serial_id"
61 : " ,wtid_raw"
62 : " ,wire_target_h_payto"
63 : " ,amount"
64 : " ,deferral_reason"
65 : " ,legitimization_requirement_serial_id"
66 : " ,deferral_time)"
67 : " SELECT"
68 : " atr.batch_deposit_serial_id"
69 : " ,$1, $2, $3, $4, $5, $6"
70 : " FROM aggregation_tracking atr"
71 : " JOIN batch_deposits bdep"
72 : " USING (batch_deposit_serial_id)"
73 : " WHERE atr.wtid_raw=$1"
74 : " ORDER BY bdep.wire_deadline DESC"
75 : " LIMIT 1;");
76 10 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
77 : "insert_aggregation_deferral",
78 : params);
79 : }
|