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/do_trigger_kyc_rule_for_account.c
18 : * @brief Implementation of the do_trigger_kyc_rule_for_account function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_pq_lib.h"
22 : #include "exchange-database/do_trigger_kyc_rule_for_account.h"
23 : #include "helper.h"
24 :
25 :
26 : enum GNUNET_DB_QueryStatus
27 19 : TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (
28 : struct TALER_EXCHANGEDB_PostgresContext *pg,
29 : const struct TALER_FullPayto payto_uri,
30 : const struct TALER_NormalizedPaytoHashP *h_payto,
31 : const union TALER_AccountPublicKeyP *set_account_pub,
32 : const struct TALER_MerchantPublicKeyP *check_merchant_pub,
33 : const json_t *jmeasures,
34 : uint32_t display_priority,
35 : uint64_t *requirement_row,
36 : bool *bad_kyc_auth)
37 : {
38 : struct GNUNET_TIME_Absolute now
39 19 : = GNUNET_TIME_absolute_get ();
40 19 : struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
41 19 : .header.size = htons (sizeof (rep)),
42 19 : .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
43 : .h_payto = *h_payto
44 : };
45 : char *notify_str
46 19 : = GNUNET_PQ_get_event_notify_channel (&rep.header);
47 : struct TALER_FullPaytoHashP h_full_payto;
48 19 : struct GNUNET_PQ_QueryParam params[] = {
49 19 : GNUNET_PQ_query_param_auto_from_type (h_payto),
50 : NULL == set_account_pub
51 11 : ? GNUNET_PQ_query_param_null ()
52 19 : : GNUNET_PQ_query_param_auto_from_type (set_account_pub),
53 : NULL == check_merchant_pub
54 18 : ? GNUNET_PQ_query_param_null ()
55 19 : : GNUNET_PQ_query_param_auto_from_type (check_merchant_pub),
56 19 : NULL == payto_uri.full_payto
57 0 : ? GNUNET_PQ_query_param_null ()
58 19 : : GNUNET_PQ_query_param_string (payto_uri.full_payto),
59 19 : NULL == payto_uri.full_payto
60 0 : ? GNUNET_PQ_query_param_null ()
61 19 : : GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
62 19 : GNUNET_PQ_query_param_absolute_time (&now),
63 19 : TALER_PQ_query_param_json (jmeasures),
64 19 : GNUNET_PQ_query_param_uint32 (&display_priority),
65 19 : GNUNET_PQ_query_param_string (notify_str),
66 : GNUNET_PQ_query_param_end
67 : };
68 19 : struct GNUNET_PQ_ResultSpec rs[] = {
69 19 : GNUNET_PQ_result_spec_uint64 (
70 : "legitimization_measure_serial_id",
71 : requirement_row),
72 19 : GNUNET_PQ_result_spec_bool (
73 : "bad_kyc_auth",
74 : bad_kyc_auth),
75 : GNUNET_PQ_result_spec_end
76 : };
77 : enum GNUNET_DB_QueryStatus qs;
78 :
79 19 : PREPARE (pg,
80 : "do_trigger_kyc_rule_for_account",
81 : "SELECT"
82 : " out_legitimization_measure_serial_id"
83 : " AS legitimization_measure_serial_id"
84 : " ,out_bad_kyc_auth"
85 : " AS bad_kyc_auth"
86 : " FROM exchange_do_trigger_kyc_rule_for_account"
87 : "($1, $2, $3, $4, $5, $6, $7::TEXT::JSONB, $8, $9);");
88 19 : if (NULL != payto_uri.full_payto)
89 19 : TALER_full_payto_hash (payto_uri,
90 : &h_full_payto);
91 19 : qs = GNUNET_PQ_eval_prepared_singleton_select (
92 : pg->conn,
93 : "do_trigger_kyc_rule_for_account",
94 : params,
95 : rs);
96 19 : GNUNET_free (notify_str);
97 19 : return qs;
98 : }
|