pg_get_ready_deposit.c (3134B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022, 2023 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_get_ready_deposit.c 18 * @brief Implementation of the get_ready_deposit function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "taler/exchange-database/get_ready_deposit.h" 23 #include "helper.h" 24 25 26 enum GNUNET_DB_QueryStatus 27 TALER_EXCHANGEDB_get_ready_deposit (struct TALER_EXCHANGEDB_PostgresContext *pg, 28 uint64_t start_shard_row, 29 uint64_t end_shard_row, 30 struct TALER_MerchantPublicKeyP * 31 merchant_pub, 32 struct TALER_FullPayto *payto_uri, 33 char **extra_wire_subject_metadata) 34 { 35 struct GNUNET_TIME_Absolute now 36 = GNUNET_TIME_absolute_get (); 37 struct GNUNET_PQ_QueryParam params[] = { 38 GNUNET_PQ_query_param_absolute_time (&now), 39 GNUNET_PQ_query_param_uint64 (&start_shard_row), 40 GNUNET_PQ_query_param_uint64 (&end_shard_row), 41 GNUNET_PQ_query_param_end 42 }; 43 struct GNUNET_PQ_ResultSpec rs[] = { 44 GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", 45 merchant_pub), 46 GNUNET_PQ_result_spec_string ("payto_uri", 47 &payto_uri->full_payto), 48 GNUNET_PQ_result_spec_allow_null ( 49 GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata", 50 extra_wire_subject_metadata), 51 NULL), 52 GNUNET_PQ_result_spec_end 53 }; 54 const char *query = "deposits_get_ready"; 55 56 *extra_wire_subject_metadata = NULL; 57 PREPARE (pg, 58 query, 59 "SELECT" 60 " wts.payto_uri" 61 ",bdep.merchant_pub" 62 ",bdep.extra_wire_subject_metadata" 63 " FROM batch_deposits bdep" 64 " JOIN wire_targets wts" 65 " USING (wire_target_h_payto)" 66 " WHERE NOT (bdep.done OR bdep.policy_blocked)" 67 " AND bdep.wire_deadline<=$1" 68 " AND bdep.shard >= $2" 69 " AND bdep.shard <= $3" 70 " ORDER BY " 71 " bdep.wire_deadline ASC" 72 " ,bdep.shard ASC" 73 " LIMIT 1;"); 74 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 75 query, 76 params, 77 rs); 78 }