pg_insert_aml_decision.c (7043B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022, 2023, 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/pg_insert_aml_decision.c 18 * @brief Implementation of the insert_aml_decision 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_insert_aml_decision.h" 26 #include "pg_helper.h" 27 #include <gnunet/gnunet_pq_lib.h> 28 29 30 enum GNUNET_DB_QueryStatus 31 TEH_PG_insert_aml_decision ( 32 void *cls, 33 const struct TALER_FullPayto payto_uri, 34 const struct TALER_NormalizedPaytoHashP *h_payto, 35 struct GNUNET_TIME_Timestamp decision_time, 36 struct GNUNET_TIME_Timestamp expiration_time, 37 const json_t *properties, 38 const json_t *new_rules, 39 bool to_investigate, 40 const char *new_measure_name, 41 const json_t *jmeasures, 42 const char *justification, 43 const struct TALER_AmlOfficerPublicKeyP *decider_pub, 44 const struct TALER_AmlOfficerSignatureP *decider_sig, 45 size_t num_events, 46 const char *events[static num_events], 47 const char *form_name, 48 size_t enc_attributes_size, 49 const void *enc_attributes, 50 struct GNUNET_HashCode *attributes_hash, 51 struct GNUNET_TIME_Timestamp attributes_expiration_time, 52 bool *invalid_officer, 53 bool *unknown_account, 54 struct GNUNET_TIME_Timestamp *last_date, 55 uint64_t *legitimization_measure_serial_id, 56 bool *is_wallet) 57 { 58 struct PostgresClosure *pg = cls; 59 struct TALER_KycCompletedEventP rep = { 60 .header.size = htons (sizeof (rep)), 61 .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED), 62 .h_payto = *h_payto 63 }; 64 struct TALER_FullPaytoHashP h_full_payto; 65 char *notify_s 66 = GNUNET_PQ_get_event_notify_channel (&rep.header); 67 bool account_unknown; 68 struct GNUNET_PQ_QueryParam params[] = { 69 /* $1: in_payto_uri */ 70 NULL == payto_uri.full_payto 71 ? GNUNET_PQ_query_param_null () 72 : GNUNET_PQ_query_param_string (payto_uri.full_payto), 73 /* $2: in_h_normalized_payto */ 74 GNUNET_PQ_query_param_auto_from_type (h_payto), 75 /* $3: in_h_full_payto */ 76 NULL == payto_uri.full_payto 77 ? GNUNET_PQ_query_param_null () 78 : GNUNET_PQ_query_param_auto_from_type (&h_full_payto), 79 /* $4: in_decision_time */ 80 GNUNET_PQ_query_param_timestamp (&decision_time), 81 /* $5: in_expiration_time*/ 82 GNUNET_PQ_query_param_timestamp (&expiration_time), 83 /* $6: in_properties */ 84 NULL != properties 85 ? TALER_PQ_query_param_json (properties) 86 : GNUNET_PQ_query_param_null (), 87 /* $7: in_kyc_attributes_enc */ 88 NULL != enc_attributes 89 ? GNUNET_PQ_query_param_fixed_size (enc_attributes, 90 enc_attributes_size) 91 : GNUNET_PQ_query_param_null (), 92 /* $8: in_kyc_attributes_hash */ 93 NULL != attributes_hash 94 ? GNUNET_PQ_query_param_auto_from_type (attributes_hash) 95 : GNUNET_PQ_query_param_null (), 96 /* $9: in_kyc_attributes_expiration */ 97 GNUNET_PQ_query_param_timestamp (&attributes_expiration_time), 98 /* $10: in_new_rules */ 99 TALER_PQ_query_param_json (new_rules), 100 /* $11: in_to_investigate */ 101 GNUNET_PQ_query_param_bool (to_investigate), 102 /* $12: in_new_measure_name */ 103 NULL != new_measure_name 104 ? GNUNET_PQ_query_param_string (new_measure_name) 105 : GNUNET_PQ_query_param_null (), 106 /* $13: in_jmeasures */ 107 NULL != jmeasures 108 ? TALER_PQ_query_param_json (jmeasures) 109 : GNUNET_PQ_query_param_null (), 110 /* $14: in_justification */ 111 NULL != justification 112 ? GNUNET_PQ_query_param_string (justification) 113 : GNUNET_PQ_query_param_null (), 114 /* $15: in_decider_pub */ 115 NULL != decider_pub 116 ? GNUNET_PQ_query_param_auto_from_type (decider_pub) 117 : GNUNET_PQ_query_param_null (), 118 /* $16: in_decider_sig */ 119 NULL != decider_sig 120 ? GNUNET_PQ_query_param_auto_from_type (decider_sig) 121 : GNUNET_PQ_query_param_null (), 122 /* $17: in_notify_s*/ 123 GNUNET_PQ_query_param_string (notify_s), 124 /* $18: ina_events */ 125 GNUNET_PQ_query_param_array_ptrs_string (num_events, 126 events, 127 pg->conn), 128 (NULL == form_name) 129 ? GNUNET_PQ_query_param_null () 130 : GNUNET_PQ_query_param_string (form_name), 131 GNUNET_PQ_query_param_end 132 }; 133 struct GNUNET_PQ_ResultSpec rs[] = { 134 GNUNET_PQ_result_spec_bool ("out_invalid_officer", 135 invalid_officer), 136 GNUNET_PQ_result_spec_bool ("out_account_unknown", 137 unknown_account), 138 GNUNET_PQ_result_spec_timestamp ("out_last_date", 139 last_date), 140 GNUNET_PQ_result_spec_uint64 ("out_legitimization_measure_serial_id", 141 legitimization_measure_serial_id), 142 GNUNET_PQ_result_spec_allow_null ( 143 GNUNET_PQ_result_spec_bool ("out_is_wallet", 144 is_wallet), 145 &account_unknown), 146 GNUNET_PQ_result_spec_end 147 }; 148 enum GNUNET_DB_QueryStatus qs; 149 150 *is_wallet = false; 151 GNUNET_assert ( ( (NULL == decider_pub) && 152 (NULL == decider_sig) && 153 (NULL == justification) ) || 154 ( (NULL != decider_pub) && 155 (NULL != decider_sig) && 156 (NULL != justification) ) ); 157 158 if (NULL != payto_uri.full_payto) 159 TALER_full_payto_hash (payto_uri, 160 &h_full_payto); 161 PREPARE (pg, 162 "do_insert_aml_decision", 163 "SELECT" 164 " out_invalid_officer" 165 ",out_account_unknown" 166 ",out_last_date" 167 ",out_legitimization_measure_serial_id" 168 ",out_is_wallet" 169 " FROM exchange_do_insert_aml_decision" 170 "($1,$2,$3,$4,$5,$6::TEXT::JSONB,$7,$8,$9,$10::TEXT::JSONB" 171 ",$11,$12,$13::TEXT::JSONB,$14,$15,$16,$17,$18,$19);"); 172 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 173 "do_insert_aml_decision", 174 params, 175 rs); 176 GNUNET_PQ_cleanup_query_params_closures (params); 177 GNUNET_free (notify_s); 178 GNUNET_PQ_event_do_poll (pg->conn); 179 if (qs <= 0) 180 return qs; 181 if (account_unknown) 182 { 183 GNUNET_assert ((*invalid_officer) || (*unknown_account)); 184 } 185 return qs; 186 }