pg_do_check_deposit_idempotent.c (4805B)
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_do_deposit.c 18 * @brief Implementation of the do_deposit function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/platform.h" 22 #include "taler/taler_error_codes.h" 23 #include "taler/taler_dbevents.h" 24 #include "taler/taler_pq_lib.h" 25 #include "pg_do_check_deposit_idempotent.h" 26 #include "pg_helper.h" 27 #include "pg_compute_shard.h" 28 29 30 enum GNUNET_DB_QueryStatus 31 TEH_PG_do_check_deposit_idempotent ( 32 void *cls, 33 const struct TALER_EXCHANGEDB_BatchDeposit *bd, 34 struct GNUNET_TIME_Timestamp *exchange_timestamp, 35 bool *is_idempotent) 36 { 37 struct PostgresClosure *pg = cls; 38 uint64_t deposit_shard = TEH_PG_compute_shard (&bd->merchant_pub); 39 const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)]; 40 const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)]; 41 struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)]; 42 struct TALER_NormalizedPaytoHashP h_normalized_payto; 43 struct GNUNET_PQ_QueryParam params[] = { 44 /* data for batch_deposits */ 45 GNUNET_PQ_query_param_uint64 (&deposit_shard), 46 GNUNET_PQ_query_param_auto_from_type (&bd->merchant_pub), 47 GNUNET_PQ_query_param_timestamp (&bd->wallet_timestamp), 48 GNUNET_PQ_query_param_timestamp (exchange_timestamp), 49 GNUNET_PQ_query_param_timestamp (&bd->refund_deadline), 50 GNUNET_PQ_query_param_timestamp (&bd->wire_deadline), 51 GNUNET_PQ_query_param_auto_from_type (&bd->h_contract_terms), 52 (bd->no_wallet_data_hash) 53 ? GNUNET_PQ_query_param_null () 54 : GNUNET_PQ_query_param_auto_from_type (&bd->wallet_data_hash), 55 GNUNET_PQ_query_param_auto_from_type (&bd->wire_salt), 56 GNUNET_PQ_query_param_auto_from_type (&bd->wire_target_h_payto), 57 (0 == bd->policy_details_serial_id) 58 ? GNUNET_PQ_query_param_null () 59 : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id), 60 GNUNET_PQ_query_param_bool (bd->policy_blocked), 61 /* arrays for coin_deposits */ 62 GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis, 63 coin_pubs, 64 pg->conn), 65 GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis, 66 coin_sigs, 67 pg->conn), 68 TALER_PQ_query_param_array_amount (bd->num_cdis, 69 amounts_with_fee, 70 pg->conn), 71 GNUNET_PQ_query_param_end 72 }; 73 bool no_time; 74 struct GNUNET_PQ_ResultSpec rs[] = { 75 GNUNET_PQ_result_spec_allow_null ( 76 GNUNET_PQ_result_spec_timestamp ("exchange_timestamp", 77 exchange_timestamp), 78 &no_time), 79 GNUNET_PQ_result_spec_bool ("is_idempotent", 80 is_idempotent), 81 GNUNET_PQ_result_spec_end 82 }; 83 enum GNUNET_DB_QueryStatus qs; 84 85 TALER_full_payto_normalize_and_hash (bd->receiver_wire_account, 86 &h_normalized_payto); 87 for (unsigned int i = 0; i < bd->num_cdis; i++) 88 { 89 const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi 90 = &bd->cdis[i]; 91 92 amounts_with_fee[i] = cdi->amount_with_fee; 93 coin_pubs[i] = &cdi->coin.coin_pub; 94 coin_sigs[i] = &cdi->csig; 95 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 96 "Do deposit %u = %s\n", 97 i, 98 TALER_B2S (&cdi->coin.coin_pub)); 99 } 100 PREPARE (pg, 101 "call_check_deposit_idempotent", 102 "SELECT " 103 " out_exchange_timestamp AS exchange_timestamp" 104 ",out_is_idempotent AS is_idempotent" 105 " FROM exchange_do_check_deposit_idempotent" 106 " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15);"); 107 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 108 "call_check_deposit_idempotent", 109 params, 110 rs); 111 GNUNET_PQ_cleanup_query_params_closures (params); 112 return qs; 113 }