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/pg_get_ready_deposit.c
18 : * @brief Implementation of the get_ready_deposit function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/platform.h"
22 : #include "taler/taler_error_codes.h"
23 : #include "taler/taler_dbevents.h"
24 : #include "taler/taler_pq_lib.h"
25 : #include "pg_get_ready_deposit.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 97 : TEH_PG_get_ready_deposit (void *cls,
31 : uint64_t start_shard_row,
32 : uint64_t end_shard_row,
33 : struct TALER_MerchantPublicKeyP *merchant_pub,
34 : struct TALER_FullPayto *payto_uri,
35 : char **extra_wire_subject_metadata)
36 : {
37 97 : struct PostgresClosure *pg = cls;
38 : struct GNUNET_TIME_Absolute now
39 97 : = GNUNET_TIME_absolute_get ();
40 97 : struct GNUNET_PQ_QueryParam params[] = {
41 97 : GNUNET_PQ_query_param_absolute_time (&now),
42 97 : GNUNET_PQ_query_param_uint64 (&start_shard_row),
43 97 : GNUNET_PQ_query_param_uint64 (&end_shard_row),
44 : GNUNET_PQ_query_param_end
45 : };
46 97 : struct GNUNET_PQ_ResultSpec rs[] = {
47 97 : GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
48 : merchant_pub),
49 97 : GNUNET_PQ_result_spec_string ("payto_uri",
50 : &payto_uri->full_payto),
51 97 : GNUNET_PQ_result_spec_allow_null (
52 : GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata",
53 : extra_wire_subject_metadata),
54 : NULL),
55 : GNUNET_PQ_result_spec_end
56 : };
57 97 : const char *query = "deposits_get_ready";
58 :
59 97 : *extra_wire_subject_metadata = NULL;
60 97 : PREPARE (pg,
61 : query,
62 : "SELECT"
63 : " wts.payto_uri"
64 : ",bdep.merchant_pub"
65 : ",bdep.extra_wire_subject_metadata"
66 : " FROM batch_deposits bdep"
67 : " JOIN wire_targets wts"
68 : " USING (wire_target_h_payto)"
69 : " WHERE NOT (bdep.done OR bdep.policy_blocked)"
70 : " AND bdep.wire_deadline<=$1"
71 : " AND bdep.shard >= $2"
72 : " AND bdep.shard <= $3"
73 : " ORDER BY "
74 : " bdep.wire_deadline ASC"
75 : " ,bdep.shard ASC"
76 : " LIMIT 1;");
77 97 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
78 : query,
79 : params,
80 : rs);
81 : }
|