do_recoup.c (3923B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 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/do_recoup.c 18 * @brief Implementation of the do_recoup function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "taler/taler_pq_lib.h" 23 #include "exchange-database/do_recoup.h" 24 #include "helper.h" 25 26 27 enum GNUNET_DB_QueryStatus 28 TALER_EXCHANGEDB_do_recoup ( 29 struct TALER_EXCHANGEDB_PostgresContext *pg, 30 const struct TALER_ReservePublicKeyP *reserve_pub, 31 uint64_t withdraw_id, 32 uint32_t coin_index, 33 const union GNUNET_CRYPTO_BlindingSecretP *coin_bks, 34 const struct TALER_CoinSpendPublicKeyP *coin_pub, 35 uint64_t known_coin_id, 36 const struct TALER_CoinSpendSignatureP *coin_sig, 37 struct GNUNET_TIME_Timestamp *recoup_timestamp, 38 struct TALER_Amount *recoup_amount, 39 bool *recoup_ok, 40 bool *internal_failure) 41 { 42 struct GNUNET_TIME_Timestamp reserve_gc 43 = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time); 44 struct GNUNET_TIME_Timestamp reserve_expiration 45 = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time); 46 struct GNUNET_PQ_QueryParam params[] = { 47 GNUNET_PQ_query_param_auto_from_type (reserve_pub), 48 GNUNET_PQ_query_param_uint64 (&withdraw_id), 49 GNUNET_PQ_query_param_uint32 (&coin_index), 50 GNUNET_PQ_query_param_auto_from_type (coin_bks), 51 GNUNET_PQ_query_param_auto_from_type (coin_pub), 52 GNUNET_PQ_query_param_uint64 (&known_coin_id), 53 GNUNET_PQ_query_param_auto_from_type (coin_sig), 54 GNUNET_PQ_query_param_timestamp (&reserve_gc), 55 GNUNET_PQ_query_param_timestamp (&reserve_expiration), 56 GNUNET_PQ_query_param_timestamp (recoup_timestamp), 57 GNUNET_PQ_query_param_end 58 }; 59 bool is_null; 60 bool amount_is_null; 61 struct GNUNET_PQ_ResultSpec rs[] = { 62 GNUNET_PQ_result_spec_allow_null ( 63 GNUNET_PQ_result_spec_timestamp ("recoup_timestamp", 64 recoup_timestamp), 65 &is_null), 66 GNUNET_PQ_result_spec_allow_null ( 67 TALER_PQ_result_spec_amount ("recoup_amount", 68 pg->currency, 69 recoup_amount), 70 &amount_is_null), 71 GNUNET_PQ_result_spec_bool ("recoup_ok", 72 recoup_ok), 73 GNUNET_PQ_result_spec_bool ("internal_failure", 74 internal_failure), 75 GNUNET_PQ_result_spec_end 76 }; 77 78 79 PREPARE (pg, 80 "do_recoup", 81 "SELECT " 82 " out_recoup_timestamp AS recoup_timestamp" 83 ",out_recoup_amount AS recoup_amount" 84 ",out_recoup_ok AS recoup_ok" 85 ",out_internal_failure AS internal_failure" 86 " FROM exchange_do_recoup_to_reserve" 87 " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);"); 88 { 89 enum GNUNET_DB_QueryStatus qs; 90 91 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 92 "do_recoup", 93 params, 94 rs); 95 if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) || 96 amount_is_null) 97 GNUNET_assert (GNUNET_OK == 98 TALER_amount_set_zero (pg->currency, 99 recoup_amount)); 100 return qs; 101 } 102 }