Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2024 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/persist_kyc_attributes.c
18 : * @brief Implementation of the persist_kyc_attributes function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_pq_lib.h"
22 : #include "exchange-database/persist_kyc_attributes.h"
23 : #include "helper.h"
24 :
25 :
26 : enum GNUNET_DB_QueryStatus
27 10 : TALER_EXCHANGEDB_persist_kyc_attributes (
28 : struct TALER_EXCHANGEDB_PostgresContext *pg,
29 : uint64_t process_row,
30 : const struct TALER_NormalizedPaytoHashP *h_payto,
31 : const char *provider_name,
32 : const char *provider_account_id,
33 : const char *provider_legitimization_id,
34 : uint32_t birthday,
35 : struct GNUNET_TIME_Absolute expiration_time,
36 : const char *form_name,
37 : size_t enc_attributes_size,
38 : const void *enc_attributes)
39 : {
40 : struct GNUNET_TIME_Timestamp collection_time
41 10 : = GNUNET_TIME_timestamp_get ();
42 : struct GNUNET_TIME_Timestamp expiration
43 10 : = GNUNET_TIME_absolute_to_timestamp (expiration_time);
44 10 : struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
45 10 : .header.size = htons (sizeof (rep)),
46 10 : .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
47 : .h_payto = *h_payto
48 : };
49 : char *kyc_completed_notify_s
50 10 : = GNUNET_PQ_get_event_notify_channel (&rep.header);
51 10 : struct GNUNET_PQ_QueryParam params[] = {
52 10 : (0 == process_row)
53 0 : ? GNUNET_PQ_query_param_null ()
54 10 : : GNUNET_PQ_query_param_uint64 (&process_row),
55 10 : GNUNET_PQ_query_param_auto_from_type (h_payto),
56 10 : GNUNET_PQ_query_param_uint32 (&birthday),
57 10 : GNUNET_PQ_query_param_string (provider_name),
58 : (NULL == provider_account_id)
59 1 : ? GNUNET_PQ_query_param_null ()
60 10 : : GNUNET_PQ_query_param_string (provider_account_id),
61 : (NULL == provider_legitimization_id)
62 1 : ? GNUNET_PQ_query_param_null ()
63 10 : : GNUNET_PQ_query_param_string (provider_legitimization_id),
64 10 : GNUNET_PQ_query_param_timestamp (&collection_time),
65 10 : GNUNET_PQ_query_param_absolute_time (&expiration_time),
66 10 : GNUNET_PQ_query_param_timestamp (&expiration),
67 : (NULL == enc_attributes)
68 0 : ? GNUNET_PQ_query_param_null ()
69 10 : : GNUNET_PQ_query_param_fixed_size (enc_attributes,
70 : enc_attributes_size),
71 10 : GNUNET_PQ_query_param_string (kyc_completed_notify_s),
72 : (NULL == form_name)
73 0 : ? GNUNET_PQ_query_param_null ()
74 10 : : GNUNET_PQ_query_param_string (form_name),
75 : GNUNET_PQ_query_param_end
76 : };
77 : bool ok;
78 10 : struct GNUNET_PQ_ResultSpec rs[] = {
79 10 : GNUNET_PQ_result_spec_bool ("out_ok",
80 : &ok),
81 : GNUNET_PQ_result_spec_end
82 : };
83 : enum GNUNET_DB_QueryStatus qs;
84 :
85 10 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
86 : "Inserting KYC attributes, wake up on %s\n",
87 : kyc_completed_notify_s);
88 10 : GNUNET_break (NULL != h_payto);
89 10 : PREPARE (pg,
90 : "persist_kyc_attributes",
91 : "SELECT "
92 : " out_ok"
93 : " FROM exchange_do_persist_kyc_attributes "
94 : "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
95 10 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
96 : "persist_kyc_attributes",
97 : params,
98 : rs);
99 10 : GNUNET_PQ_cleanup_query_params_closures (params);
100 10 : GNUNET_free (kyc_completed_notify_s);
101 10 : GNUNET_PQ_event_do_poll (pg->conn);
102 10 : return qs;
103 : }
|