iterate_outdated_kyc_statuses.c (4040B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 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 src/backenddb/iterate_outdated_kyc_statuses.c 18 * @brief Implementation of the iterate_outdated_kyc_statuses function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include <taler/taler_error_codes.h> 23 #include <taler/taler_dbevents.h> 24 #include <taler/taler_pq_lib.h> 25 #include "merchant-database/iterate_outdated_kyc_statuses.h" 26 #include "helper.h" 27 28 /** 29 * Closure for kyc_status_cb(). 30 */ 31 struct KycStatusContext 32 { 33 /** 34 * Function to call with results. 35 */ 36 TALER_MERCHANTDB_KycOutdatedCallback kyc_cb; 37 38 /** 39 * Closure for @e kyc_cb. 40 */ 41 void *kyc_cb_cls; 42 43 /** 44 * Number of results found. 45 */ 46 unsigned int count; 47 48 /** 49 * Set to true on failure(s). 50 */ 51 bool failure; 52 }; 53 54 55 /** 56 * Function to be called with the results of a SELECT statement 57 * that has returned @a num_results results about accounts. 58 * 59 * @param[in,out] cls of type `struct KycStatusContext *` 60 * @param result the postgres result 61 * @param num_results the number of results in @a result 62 */ 63 static void 64 kyc_status_cb (void *cls, 65 PGresult *result, 66 unsigned int num_results) 67 { 68 struct KycStatusContext *ksc = cls; 69 70 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 71 "Got %u outdated KYC records\n", 72 num_results); 73 for (unsigned int i = 0; i < num_results; i++) 74 { 75 struct TALER_MerchantWireHashP h_wire; 76 char *exchange_url; 77 char *instance_id; 78 struct GNUNET_PQ_ResultSpec rs[] = { 79 GNUNET_PQ_result_spec_auto_from_type ("out_h_wire", 80 &h_wire), 81 GNUNET_PQ_result_spec_string ("out_exchange_url", 82 &exchange_url), 83 GNUNET_PQ_result_spec_string ("out_merchant_id", 84 &instance_id), 85 GNUNET_PQ_result_spec_end 86 }; 87 88 if (GNUNET_OK != 89 GNUNET_PQ_extract_result (result, 90 rs, 91 i)) 92 { 93 GNUNET_break (0); 94 ksc->failure = true; 95 return; 96 } 97 ksc->count++; 98 ksc->kyc_cb (ksc->kyc_cb_cls, 99 instance_id, 100 exchange_url, 101 &h_wire); 102 GNUNET_PQ_cleanup_result (rs); 103 } 104 } 105 106 107 enum GNUNET_DB_QueryStatus 108 TALER_MERCHANTDB_iterate_outdated_kyc_statuses ( 109 struct TALER_MERCHANTDB_PostgresContext *pg, 110 uint64_t merchant_serial, 111 TALER_MERCHANTDB_KycOutdatedCallback kyc_cb, 112 void *kyc_cb_cls) 113 { 114 struct KycStatusContext ksc = { 115 .kyc_cb = kyc_cb, 116 .kyc_cb_cls = kyc_cb_cls 117 }; 118 struct GNUNET_TIME_Absolute now 119 = GNUNET_TIME_absolute_get (); 120 struct GNUNET_PQ_QueryParam params[] = { 121 GNUNET_PQ_query_param_absolute_time (&now), 122 GNUNET_PQ_query_param_uint64 (&merchant_serial), 123 GNUNET_PQ_query_param_end 124 }; 125 enum GNUNET_DB_QueryStatus qs; 126 127 PREPARE (pg, 128 "iterate_outdated_kyc_statuses", 129 "SELECT" 130 " out_merchant_id" 131 " ,out_h_wire" 132 " ,out_exchange_url" 133 " FROM merchant.account_kyc_get_outdated($1, $2)"); 134 qs = GNUNET_PQ_eval_prepared_multi_select ( 135 pg->conn, 136 "iterate_outdated_kyc_statuses", 137 params, 138 &kyc_status_cb, 139 &ksc); 140 if (ksc.failure) 141 { 142 GNUNET_break (0); 143 return GNUNET_DB_STATUS_HARD_ERROR; 144 } 145 if (0 > qs) 146 return qs; 147 return ksc.count; 148 }