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 exchangedb/pg_do_recoup.c
18 : * @brief Implementation of the do_recoup function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include "taler_error_codes.h"
23 : #include "taler_dbevents.h"
24 : #include "taler_pq_lib.h"
25 : #include "pg_do_recoup.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 0 : TEH_PG_do_recoup (
31 : void *cls,
32 : const struct TALER_ReservePublicKeyP *reserve_pub,
33 : uint64_t withdraw_id,
34 : const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
35 : const struct TALER_CoinSpendPublicKeyP *coin_pub,
36 : uint64_t known_coin_id,
37 : const struct TALER_CoinSpendSignatureP *coin_sig,
38 : struct GNUNET_TIME_Timestamp *recoup_timestamp,
39 : bool *recoup_ok,
40 : bool *internal_failure)
41 : {
42 0 : struct PostgresClosure *pg = cls;
43 : struct GNUNET_TIME_Timestamp reserve_gc
44 0 : = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
45 : struct GNUNET_TIME_Timestamp reserve_expiration
46 0 : = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
47 0 : struct GNUNET_PQ_QueryParam params[] = {
48 0 : GNUNET_PQ_query_param_auto_from_type (reserve_pub),
49 0 : GNUNET_PQ_query_param_uint64 (&withdraw_id),
50 0 : GNUNET_PQ_query_param_auto_from_type (coin_bks),
51 0 : GNUNET_PQ_query_param_auto_from_type (coin_pub),
52 0 : GNUNET_PQ_query_param_uint64 (&known_coin_id),
53 0 : GNUNET_PQ_query_param_auto_from_type (coin_sig),
54 0 : GNUNET_PQ_query_param_timestamp (&reserve_gc),
55 0 : GNUNET_PQ_query_param_timestamp (&reserve_expiration),
56 0 : GNUNET_PQ_query_param_timestamp (recoup_timestamp),
57 : GNUNET_PQ_query_param_end
58 : };
59 : bool is_null;
60 0 : struct GNUNET_PQ_ResultSpec rs[] = {
61 0 : GNUNET_PQ_result_spec_allow_null (
62 : GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
63 : recoup_timestamp),
64 : &is_null),
65 0 : GNUNET_PQ_result_spec_bool ("recoup_ok",
66 : recoup_ok),
67 0 : GNUNET_PQ_result_spec_bool ("internal_failure",
68 : internal_failure),
69 : GNUNET_PQ_result_spec_end
70 : };
71 :
72 :
73 0 : PREPARE (pg,
74 : "call_recoup",
75 : "SELECT "
76 : " out_recoup_timestamp AS recoup_timestamp"
77 : ",out_recoup_ok AS recoup_ok"
78 : ",out_internal_failure AS internal_failure"
79 : " FROM exchange_do_recoup_to_reserve"
80 : " ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
81 0 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
82 : "call_recoup",
83 : params,
84 : rs);
85 : }
|