insert_sanction_list_hit.c (3374B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2025 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/insert_sanction_list_hit.c 18 * @brief Implementation of the insert_sanction_list_hit function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "exchange-database/insert_sanction_list_hit.h" 23 #include "helper.h" 24 25 26 enum GNUNET_DB_QueryStatus 27 TALER_EXCHANGEDB_insert_sanction_list_hit ( 28 struct TALER_EXCHANGEDB_PostgresContext *pg, 29 const struct TALER_NormalizedPaytoHashP *h_payto, 30 uint64_t kyc_attributes_serial_id, 31 bool to_investigate, 32 const json_t *new_rules, 33 const json_t *account_properties, 34 unsigned int num_events, 35 const char **events) 36 { 37 struct GNUNET_TIME_Timestamp never 38 = GNUNET_TIME_UNIT_FOREVER_TS; 39 struct GNUNET_TIME_Timestamp now 40 = GNUNET_TIME_timestamp_get (); 41 struct TALER_EXCHANGEDB_KycCompletedEventP rep = { 42 .header.size = htons (sizeof (rep)), 43 .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED), 44 .h_payto = *h_payto 45 }; 46 char *notify_s 47 = GNUNET_PQ_get_event_notify_channel (&rep.header); 48 struct GNUNET_PQ_QueryParam params[] = { 49 GNUNET_PQ_query_param_auto_from_type (h_payto), 50 GNUNET_PQ_query_param_timestamp (&now), 51 GNUNET_PQ_query_param_timestamp (&never), 52 GNUNET_PQ_query_param_uint64 (&kyc_attributes_serial_id), 53 NULL != account_properties 54 ? TALER_PQ_query_param_json (account_properties) 55 : GNUNET_PQ_query_param_null (), 56 NULL != new_rules 57 ? TALER_PQ_query_param_json (new_rules) 58 : GNUNET_PQ_query_param_null (), 59 GNUNET_PQ_query_param_bool (to_investigate), 60 GNUNET_PQ_query_param_string (notify_s), 61 GNUNET_PQ_query_param_array_ptrs_string (num_events, 62 events, 63 pg->conn), 64 GNUNET_PQ_query_param_end 65 }; 66 uint64_t outcome_serial_id; 67 struct GNUNET_PQ_ResultSpec rs[] = { 68 GNUNET_PQ_result_spec_uint64 ("outcome_serial_id", 69 &outcome_serial_id), 70 GNUNET_PQ_result_spec_end 71 }; 72 enum GNUNET_DB_QueryStatus qs; 73 74 PREPARE (pg, 75 "insert_sanction_list_hit", 76 "SELECT" 77 " out_outcome_serial_id AS outcome_serial_id" 78 " FROM exchange_do_insert_sanction_list_hit" 79 "($1,$2,$3,$4,$5::TEXT::JSONB,$6::TEXT::JSONB,$7,$8,$9);"); 80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 81 "Inserting LEGI OUTCOME from sanction list hit\n"); 82 qs = GNUNET_PQ_eval_prepared_singleton_select ( 83 pg->conn, 84 "insert_sanction_list_hit", 85 params, 86 rs); 87 (void) outcome_serial_id; 88 GNUNET_PQ_cleanup_query_params_closures (params); 89 GNUNET_free (notify_s); 90 GNUNET_PQ_event_do_poll (pg->conn); 91 return qs; 92 }