select_wire_out_above_serial_id_by_account.c (4581B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022, 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/select_wire_out_above_serial_id_by_account.c 18 * @brief Implementation of the select_wire_out_above_serial_id_by_account function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "exchange-database/select_wire_out_above_serial_id_by_account.h" 23 #include "helper.h" 24 25 /** 26 * Closure for #wire_out_serial_helper_cb(). 27 */ 28 struct WireOutSerialContext 29 { 30 31 /** 32 * Callback to call. 33 */ 34 TALER_EXCHANGEDB_WireTransferOutCallback cb; 35 36 /** 37 * Closure for @e cb. 38 */ 39 void *cb_cls; 40 41 /** 42 * Plugin context. 43 */ 44 struct TALER_EXCHANGEDB_PostgresContext *pg; 45 46 /** 47 * Status code, set to #GNUNET_SYSERR on hard errors. 48 */ 49 int status; 50 }; 51 52 53 /** 54 * Helper function to be called with the results of a SELECT statement 55 * that has returned @a num_results results. 56 * 57 * @param cls closure of type `struct WireOutSerialContext` 58 * @param result the postgres result 59 * @param num_results the number of results in @a result 60 */ 61 static void 62 wire_out_serial_helper_cb (void *cls, 63 PGresult *result, 64 unsigned int num_results) 65 { 66 struct WireOutSerialContext *wosc = cls; 67 struct TALER_EXCHANGEDB_PostgresContext *pg = wosc->pg; 68 69 for (unsigned int i = 0; i<num_results; i++) 70 { 71 uint64_t rowid; 72 struct GNUNET_TIME_Timestamp date; 73 struct TALER_WireTransferIdentifierRawP wtid; 74 struct TALER_FullPayto payto_uri; 75 struct TALER_Amount amount; 76 struct GNUNET_PQ_ResultSpec rs[] = { 77 GNUNET_PQ_result_spec_uint64 ("wireout_uuid", 78 &rowid), 79 GNUNET_PQ_result_spec_timestamp ("execution_date", 80 &date), 81 GNUNET_PQ_result_spec_auto_from_type ("wtid_raw", 82 &wtid), 83 GNUNET_PQ_result_spec_string ("payto_uri", 84 &payto_uri.full_payto), 85 TALER_PQ_RESULT_SPEC_AMOUNT ("amount", 86 &amount), 87 GNUNET_PQ_result_spec_end 88 }; 89 int ret; 90 91 if (GNUNET_OK != 92 GNUNET_PQ_extract_result (result, 93 rs, 94 i)) 95 { 96 GNUNET_break (0); 97 wosc->status = GNUNET_SYSERR; 98 return; 99 } 100 ret = wosc->cb (wosc->cb_cls, 101 rowid, 102 date, 103 &wtid, 104 payto_uri, 105 &amount); 106 GNUNET_PQ_cleanup_result (rs); 107 if (GNUNET_OK != ret) 108 break; 109 } 110 } 111 112 113 enum GNUNET_DB_QueryStatus 114 TALER_TALER_EXCHANGEDB_select_wire_out_above_serial_id_by_account ( 115 struct TALER_EXCHANGEDB_PostgresContext *pg, 116 const char *account_name, 117 uint64_t serial_id, 118 TALER_EXCHANGEDB_WireTransferOutCallback cb, 119 void *cb_cls) 120 { 121 struct GNUNET_PQ_QueryParam params[] = { 122 GNUNET_PQ_query_param_uint64 (&serial_id), 123 GNUNET_PQ_query_param_string (account_name), 124 GNUNET_PQ_query_param_end 125 }; 126 struct WireOutSerialContext wosc = { 127 .cb = cb, 128 .cb_cls = cb_cls, 129 .pg = pg, 130 .status = GNUNET_OK 131 }; 132 enum GNUNET_DB_QueryStatus qs; 133 134 PREPARE (pg, 135 "select_wire_out_above_serial_id_by_account", 136 "SELECT" 137 " wo.wireout_uuid" 138 ",wo.execution_date" 139 ",wo.wtid_raw" 140 ",wt.payto_uri" 141 ",wo.amount" 142 " FROM wire_out wo" 143 " JOIN wire_targets wt" 144 " USING (wire_target_h_payto)" 145 " WHERE wo.wireout_uuid>=$1 " 146 " AND wo.exchange_account_section=$2" 147 " ORDER BY wo.wireout_uuid ASC;"); 148 qs = GNUNET_PQ_eval_prepared_multi_select ( 149 pg->conn, 150 "select_wire_out_above_serial_id_by_account", 151 params, 152 &wire_out_serial_helper_cb, 153 &wosc); 154 if (GNUNET_OK != wosc.status) 155 return GNUNET_DB_STATUS_HARD_ERROR; 156 return qs; 157 }