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 : {
36 97 : struct PostgresClosure *pg = cls;
37 : struct GNUNET_TIME_Absolute now
38 97 : = GNUNET_TIME_absolute_get ();
39 97 : struct GNUNET_PQ_QueryParam params[] = {
40 97 : GNUNET_PQ_query_param_absolute_time (&now),
41 97 : GNUNET_PQ_query_param_uint64 (&start_shard_row),
42 97 : GNUNET_PQ_query_param_uint64 (&end_shard_row),
43 : GNUNET_PQ_query_param_end
44 : };
45 97 : struct GNUNET_PQ_ResultSpec rs[] = {
46 97 : GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
47 : merchant_pub),
48 97 : GNUNET_PQ_result_spec_string ("payto_uri",
49 : &payto_uri->full_payto),
50 : GNUNET_PQ_result_spec_end
51 : };
52 97 : const char *query = "deposits_get_ready";
53 :
54 97 : PREPARE (pg,
55 : query,
56 : "SELECT"
57 : " wts.payto_uri"
58 : ",bdep.merchant_pub"
59 : " FROM batch_deposits bdep"
60 : " JOIN wire_targets wts"
61 : " USING (wire_target_h_payto)"
62 : " WHERE NOT (bdep.done OR bdep.policy_blocked)"
63 : " AND bdep.wire_deadline<=$1"
64 : " AND bdep.shard >= $2"
65 : " AND bdep.shard <= $3"
66 : " ORDER BY "
67 : " bdep.wire_deadline ASC"
68 : " ,bdep.shard ASC"
69 : " LIMIT 1;");
70 97 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
71 : query,
72 : params,
73 : rs);
74 : }
|