get_denomination_key_validity_withdraw_inconsistency.c (5331B)
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 #include "taler/taler_pq_lib.h" 17 #include "pg_helper.h" 18 #include \ 19 "auditor-database/get_denomination_key_validity_withdraw_inconsistency.h" 20 21 22 /** 23 * Closure for #denomination_key_validity_withdraw_inconsistency_cb(). 24 */ 25 struct DenominationKeyValidityWithdrawInconsistencyContext 26 { 27 28 /** 29 * Function to call for each denomination key validity... 30 */ 31 TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb; 32 33 /** 34 * Closure for @e cb 35 */ 36 void *cb_cls; 37 38 /** 39 * Plugin context. 40 */ 41 struct TALER_AUDITORDB_PostgresContext *pg; 42 43 /** 44 * Query status to return. 45 */ 46 enum GNUNET_DB_QueryStatus qs; 47 }; 48 49 50 /** 51 * Helper function for #TALER_AUDITORDB_get_deposit_confirmations(). 52 * To be called with the results of a SELECT statement 53 * that has returned @a num_results results. 54 * 55 * @param cls closure of type `struct DepositConfirmationContext *` 56 * @param result the postgres result 57 * @param num_results the number of results in @a result 58 */ 59 static void 60 denomination_key_validity_withdraw_inconsistency_cb ( 61 void *cls, 62 PGresult *result, 63 unsigned int num_results) 64 { 65 struct DenominationKeyValidityWithdrawInconsistencyContext *dcc = cls; 66 67 for (unsigned int i = 0; i < num_results; i++) 68 { 69 struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dc; 70 struct GNUNET_PQ_ResultSpec rs[] = { 71 GNUNET_PQ_result_spec_uint64 ("row_id", 72 &dc.row_id), 73 GNUNET_PQ_result_spec_uint64 ("problem_row_id", 74 &dc.problem_row_id), 75 GNUNET_PQ_result_spec_absolute_time ("execution_date", 76 &dc.execution_date), 77 GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", 78 &dc.reserve_pub), 79 GNUNET_PQ_result_spec_auto_from_type ("denompub_h", 80 &dc.denompub_h), 81 GNUNET_PQ_result_spec_bool ("suppressed", 82 &dc.suppressed), 83 GNUNET_PQ_result_spec_end 84 }; 85 enum GNUNET_GenericReturnValue rval; 86 87 if (GNUNET_OK != 88 GNUNET_PQ_extract_result (result, 89 rs, 90 i)) 91 { 92 GNUNET_break (0); 93 dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; 94 return; 95 } 96 dcc->qs = i + 1; 97 rval = dcc->cb (dcc->cb_cls, 98 &dc); 99 GNUNET_PQ_cleanup_result (rs); 100 if (GNUNET_OK != rval) 101 break; 102 } 103 } 104 105 106 enum GNUNET_DB_QueryStatus 107 TALER_AUDITORDB_get_denomination_key_validity_withdraw_inconsistency ( 108 struct TALER_AUDITORDB_PostgresContext *pg, 109 int64_t limit, 110 uint64_t offset, 111 bool return_suppressed, 112 TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb, 113 void *cb_cls) 114 { 115 uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); 116 struct GNUNET_PQ_QueryParam params[] = { 117 GNUNET_PQ_query_param_uint64 (&offset), 118 GNUNET_PQ_query_param_bool (return_suppressed), 119 GNUNET_PQ_query_param_uint64 (&plimit), 120 GNUNET_PQ_query_param_end 121 }; 122 struct DenominationKeyValidityWithdrawInconsistencyContext dcc = { 123 .cb = cb, 124 .cb_cls = cb_cls, 125 .pg = pg 126 }; 127 enum GNUNET_DB_QueryStatus qs; 128 129 PREPARE (pg, 130 "auditor_denomination_key_validity_withdraw_inconsistency_get_desc", 131 "SELECT" 132 " row_id" 133 ",problem_row_id" 134 ",execution_date" 135 ",reserve_pub" 136 ",denompub_h" 137 ",suppressed" 138 " FROM auditor_denomination_key_validity_withdraw_inconsistency" 139 " WHERE (row_id < $1)" 140 " AND ($2 OR NOT suppressed)" 141 " ORDER BY row_id DESC" 142 " LIMIT $3" 143 ); 144 PREPARE (pg, 145 "auditor_denomination_key_validity_withdraw_inconsistency_get_asc", 146 "SELECT" 147 " row_id" 148 ",problem_row_id" 149 ",execution_date" 150 ",reserve_pub" 151 ",denompub_h" 152 ",suppressed" 153 " FROM auditor_denomination_key_validity_withdraw_inconsistency" 154 " WHERE (row_id > $1)" 155 " AND ($2 OR NOT suppressed)" 156 " ORDER BY row_id ASC" 157 " LIMIT $3" 158 ); 159 qs = GNUNET_PQ_eval_prepared_multi_select ( 160 pg->conn, 161 (limit > 0) 162 ? "auditor_denomination_key_validity_withdraw_inconsistency_get_asc" 163 : "auditor_denomination_key_validity_withdraw_inconsistency_get_desc", 164 params, 165 &denomination_key_validity_withdraw_inconsistency_cb, 166 &dcc); 167 if (qs > 0) 168 return dcc.qs; 169 GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); 170 return qs; 171 }