lookup_expected_transfer.c (4462B)
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/lookup_expected_transfer.c 18 * @brief Implementation of the lookup_expected_transfer 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/lookup_expected_transfer.h" 26 #include "helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 TALER_MERCHANTDB_lookup_expected_transfer (struct TALER_MERCHANTDB_PostgresContext *pg, 31 const char *instance_id, 32 uint64_t expected_incoming_serial, 33 struct GNUNET_TIME_Timestamp *expected_time, 34 struct TALER_Amount *expected_credit_amount, 35 struct TALER_WireTransferIdentifierRawP *wtid, 36 struct TALER_FullPayto *payto_uri, 37 char **exchange_url, 38 struct GNUNET_TIME_Timestamp *execution_time, 39 bool *confirmed, 40 struct TALER_MasterPublicKeyP *master_pub) 41 { 42 struct GNUNET_PQ_QueryParam params[] = { 43 GNUNET_PQ_query_param_string (instance_id), 44 GNUNET_PQ_query_param_uint64 (&expected_incoming_serial), 45 GNUNET_PQ_query_param_end 46 }; 47 struct GNUNET_PQ_ResultSpec rs[] = { 48 GNUNET_PQ_result_spec_timestamp ("expected_time", 49 expected_time), 50 GNUNET_PQ_result_spec_bool ("confirmed", 51 confirmed), 52 GNUNET_PQ_result_spec_allow_null ( 53 TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount", 54 expected_credit_amount), 55 NULL), 56 GNUNET_PQ_result_spec_string ("exchange_url", 57 exchange_url), 58 GNUNET_PQ_result_spec_auto_from_type ("wtid", 59 wtid), 60 GNUNET_PQ_result_spec_string ("payto_uri", 61 &payto_uri->full_payto), 62 GNUNET_PQ_result_spec_allow_null ( 63 GNUNET_PQ_result_spec_timestamp ("execution_time", 64 execution_time), 65 NULL), 66 GNUNET_PQ_result_spec_auto_from_type ("master_pub", 67 master_pub), 68 GNUNET_PQ_result_spec_end 69 }; 70 71 *execution_time = GNUNET_TIME_UNIT_ZERO_TS; 72 memset (expected_credit_amount, 73 0, 74 sizeof (*expected_credit_amount)); 75 check_connection (pg); 76 PREPARE (pg, 77 "lookup_expected_transfer", 78 "SELECT" 79 " met.expected_time" 80 " ,met.confirmed" 81 " ,met.expected_credit_amount" 82 " ,met.exchange_url" 83 " ,met.wtid" 84 " ,ma.payto_uri" 85 " ,mts.execution_time" 86 " ,esk.master_pub" 87 " FROM merchant_expected_transfers met" 88 " JOIN merchant_exchange_signing_keys esk" 89 " USING (signkey_serial)" 90 " JOIN merchant_accounts ma" 91 " USING (account_serial)" 92 " JOIN merchant_instances inst" 93 " USING (merchant_serial)" 94 " LEFT JOIN merchant_transfer_signatures mts" 95 " USING (expected_credit_serial)" 96 " WHERE inst.merchant_id=$1" 97 " AND met.expected_credit_serial=$2"); 98 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 99 "lookup_expected_transfer", 100 params, 101 rs); 102 }