lookup_expected_transfer.c (4126B)
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_pq_lib.h> 23 #include "merchant-database/lookup_expected_transfer.h" 24 #include "helper.h" 25 26 27 enum GNUNET_DB_QueryStatus 28 TALER_MERCHANTDB_lookup_expected_transfer ( 29 struct TALER_MERCHANTDB_PostgresContext *pg, 30 const char *instance_id, 31 uint64_t expected_incoming_serial, 32 struct GNUNET_TIME_Timestamp *expected_time, 33 struct TALER_Amount *expected_credit_amount, 34 struct TALER_WireTransferIdentifierRawP *wtid, 35 struct TALER_FullPayto *payto_uri, 36 char **exchange_url, 37 struct GNUNET_TIME_Timestamp *execution_time, 38 bool *confirmed, 39 struct TALER_MasterPublicKeyP *master_pub) 40 { 41 struct GNUNET_PQ_QueryParam params[] = { 42 GNUNET_PQ_query_param_uint64 (&expected_incoming_serial), 43 GNUNET_PQ_query_param_end 44 }; 45 struct GNUNET_PQ_ResultSpec rs[] = { 46 GNUNET_PQ_result_spec_timestamp ("expected_time", 47 expected_time), 48 GNUNET_PQ_result_spec_bool ("confirmed", 49 confirmed), 50 GNUNET_PQ_result_spec_allow_null ( 51 TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount", 52 expected_credit_amount), 53 NULL), 54 GNUNET_PQ_result_spec_string ("exchange_url", 55 exchange_url), 56 GNUNET_PQ_result_spec_auto_from_type ("wtid", 57 wtid), 58 GNUNET_PQ_result_spec_string ("payto_uri", 59 &payto_uri->full_payto), 60 GNUNET_PQ_result_spec_allow_null ( 61 GNUNET_PQ_result_spec_timestamp ("execution_time", 62 execution_time), 63 NULL), 64 GNUNET_PQ_result_spec_auto_from_type ("master_pub", 65 master_pub), 66 GNUNET_PQ_result_spec_end 67 }; 68 69 GNUNET_assert (NULL != pg->current_merchant_id); 70 GNUNET_assert (0 == strcmp (instance_id, 71 pg->current_merchant_id)); 72 *execution_time = GNUNET_TIME_UNIT_ZERO_TS; 73 memset (expected_credit_amount, 74 0, 75 sizeof (*expected_credit_amount)); 76 check_connection (pg); 77 TMH_PQ_prepare_anon (pg, 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.merchant_exchange_signing_keys esk" 89 " USING (signkey_serial)" 90 " JOIN merchant_accounts ma" 91 " USING (account_serial)" 92 " LEFT JOIN merchant_transfer_signatures mts" 93 " USING (expected_credit_serial)" 94 " WHERE met.expected_credit_serial=$1"); 95 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 96 "", 97 params, 98 rs); 99 }