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_purse_merge.c
18 : * @brief Implementation of the do_purse_merge 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_purse_merge.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 5 : TEH_PG_do_purse_merge (
31 : void *cls,
32 : const struct TALER_PurseContractPublicKeyP *purse_pub,
33 : const struct TALER_PurseMergeSignatureP *merge_sig,
34 : const struct GNUNET_TIME_Timestamp merge_timestamp,
35 : const struct TALER_ReserveSignatureP *reserve_sig,
36 : const char *partner_url,
37 : const struct TALER_ReservePublicKeyP *reserve_pub,
38 : bool *no_partner,
39 : bool *no_balance,
40 : bool *in_conflict)
41 : {
42 5 : struct PostgresClosure *pg = cls;
43 : struct TALER_NormalizedPaytoHashP h_payto;
44 : struct GNUNET_TIME_Timestamp expiration
45 5 : = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
46 5 : struct GNUNET_PQ_QueryParam params[] = {
47 5 : GNUNET_PQ_query_param_auto_from_type (purse_pub),
48 5 : GNUNET_PQ_query_param_auto_from_type (merge_sig),
49 5 : GNUNET_PQ_query_param_timestamp (&merge_timestamp),
50 5 : GNUNET_PQ_query_param_auto_from_type (reserve_sig),
51 : (NULL == partner_url)
52 5 : ? GNUNET_PQ_query_param_null ()
53 5 : : GNUNET_PQ_query_param_string (partner_url),
54 5 : GNUNET_PQ_query_param_auto_from_type (reserve_pub),
55 5 : GNUNET_PQ_query_param_auto_from_type (&h_payto),
56 5 : GNUNET_PQ_query_param_timestamp (&expiration),
57 : GNUNET_PQ_query_param_end
58 : };
59 5 : struct GNUNET_PQ_ResultSpec rs[] = {
60 5 : GNUNET_PQ_result_spec_bool ("no_partner",
61 : no_partner),
62 5 : GNUNET_PQ_result_spec_bool ("no_balance",
63 : no_balance),
64 5 : GNUNET_PQ_result_spec_bool ("conflict",
65 : in_conflict),
66 : GNUNET_PQ_result_spec_end
67 : };
68 :
69 : {
70 : struct TALER_NormalizedPayto payto_uri;
71 :
72 5 : payto_uri = TALER_reserve_make_payto (pg->exchange_url,
73 : reserve_pub);
74 5 : TALER_normalized_payto_hash (payto_uri,
75 : &h_payto);
76 5 : GNUNET_free (payto_uri.normalized_payto);
77 : }
78 5 : PREPARE (pg,
79 : "call_purse_merge",
80 : "SELECT"
81 : " out_no_partner AS no_partner"
82 : ",out_no_balance AS no_balance"
83 : ",out_conflict AS conflict"
84 : " FROM exchange_do_purse_merge"
85 : " ($1, $2, $3, $4, $5, $6, $7, $8);");
86 :
87 5 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
88 : "call_purse_merge",
89 : params,
90 : rs);
91 : }
|