Line data Source code
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/pg_select_all_purse_deletions_above_serial_id.c 18 : * @brief Implementation of the select_all_purse_deletions_above_serial_id function for Postgres 19 : * @author Christian Grothoff 20 : */ 21 : #include "platform.h" 22 : #include "taler_error_codes.h" 23 : #include "taler_dbevents.h" 24 : #include "taler_pq_lib.h" 25 : #include "pg_select_all_purse_deletions_above_serial_id.h" 26 : #include "pg_helper.h" 27 : 28 : 29 : /** 30 : * Closure for #all_purse_deletion_serial_helper_cb(). 31 : */ 32 : struct AllPurseDeletionSerialContext 33 : { 34 : 35 : /** 36 : * Callback to call. 37 : */ 38 : TALER_EXCHANGEDB_AllPurseDeletionsCallback cb; 39 : 40 : /** 41 : * Closure for @e cb. 42 : */ 43 : void *cb_cls; 44 : 45 : /** 46 : * Plugin context. 47 : */ 48 : struct PostgresClosure *pg; 49 : 50 : /** 51 : * Status code, set to #GNUNET_SYSERR on hard errors. 52 : */ 53 : enum GNUNET_GenericReturnValue status; 54 : }; 55 : 56 : 57 : /** 58 : * Helper function to be called with the results of a SELECT statement 59 : * that has returned @a num_results results. 60 : * 61 : * @param cls closure of type `struct PurseRefundSerialContext` 62 : * @param result the postgres result 63 : * @param num_results the number of results in @a result 64 : */ 65 : static void 66 74 : all_purse_deletion_serial_helper_cb (void *cls, 67 : PGresult *result, 68 : unsigned int num_results) 69 : { 70 74 : struct AllPurseDeletionSerialContext *dsc = cls; 71 : 72 74 : for (unsigned int i = 0; i<num_results; i++) 73 : { 74 : struct TALER_PurseContractPublicKeyP purse_pub; 75 : struct TALER_PurseContractSignatureP purse_sig; 76 : uint64_t rowid; 77 0 : struct GNUNET_PQ_ResultSpec rs[] = { 78 0 : GNUNET_PQ_result_spec_auto_from_type ("purse_pub", 79 : &purse_pub), 80 0 : GNUNET_PQ_result_spec_auto_from_type ("purse_sig", 81 : &purse_sig), 82 0 : GNUNET_PQ_result_spec_uint64 ("purse_deletion_serial_id", 83 : &rowid), 84 : GNUNET_PQ_result_spec_end 85 : }; 86 : enum GNUNET_GenericReturnValue ret; 87 : 88 0 : if (GNUNET_OK != 89 0 : GNUNET_PQ_extract_result (result, 90 : rs, 91 : i)) 92 : { 93 0 : GNUNET_break (0); 94 0 : dsc->status = GNUNET_SYSERR; 95 0 : return; 96 : } 97 0 : ret = dsc->cb (dsc->cb_cls, 98 : rowid, 99 : &purse_pub, 100 : &purse_sig); 101 0 : GNUNET_PQ_cleanup_result (rs); 102 0 : if (GNUNET_OK != ret) 103 0 : break; 104 : } 105 : } 106 : 107 : 108 : enum GNUNET_DB_QueryStatus 109 74 : TEH_PG_select_all_purse_deletions_above_serial_id ( 110 : void *cls, 111 : uint64_t serial_id, 112 : TALER_EXCHANGEDB_AllPurseDeletionsCallback cb, 113 : void *cb_cls) 114 : { 115 74 : struct PostgresClosure *pg = cls; 116 74 : struct GNUNET_PQ_QueryParam params[] = { 117 74 : GNUNET_PQ_query_param_uint64 (&serial_id), 118 : GNUNET_PQ_query_param_end 119 : }; 120 74 : struct AllPurseDeletionSerialContext dsc = { 121 : .cb = cb, 122 : .cb_cls = cb_cls, 123 : .pg = pg, 124 : .status = GNUNET_OK 125 : }; 126 : enum GNUNET_DB_QueryStatus qs; 127 : 128 74 : PREPARE (pg, 129 : "audit_select_all_purse_deletions_above_serial_id", 130 : "SELECT" 131 : " purse_pub" 132 : ",purse_sig" 133 : ",purse_deletion_serial_id" 134 : " FROM purse_deletion" 135 : " WHERE purse_deletion_serial_id>=$1" 136 : " ORDER BY purse_deletion_serial_id ASC;"); 137 74 : qs = GNUNET_PQ_eval_prepared_multi_select ( 138 : pg->conn, 139 : "audit_select_all_purse_deletions_above_serial_id", 140 : params, 141 : &all_purse_deletion_serial_helper_cb, 142 : &dsc); 143 74 : if (GNUNET_OK != dsc.status) 144 0 : return GNUNET_DB_STATUS_HARD_ERROR; 145 74 : return qs; 146 : }