do_recoup.c (3202B)
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 "exchange-database/do_recoup.h" 23 #include "helper.h" 24 25 26 enum GNUNET_DB_QueryStatus 27 TALER_EXCHANGEDB_do_recoup ( 28 struct TALER_EXCHANGEDB_PostgresContext *pg, 29 const struct TALER_ReservePublicKeyP *reserve_pub, 30 uint64_t withdraw_id, 31 const union GNUNET_CRYPTO_BlindingSecretP *coin_bks, 32 const struct TALER_CoinSpendPublicKeyP *coin_pub, 33 uint64_t known_coin_id, 34 const struct TALER_CoinSpendSignatureP *coin_sig, 35 struct GNUNET_TIME_Timestamp *recoup_timestamp, 36 bool *recoup_ok, 37 bool *internal_failure) 38 { 39 struct GNUNET_TIME_Timestamp reserve_gc 40 = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time); 41 struct GNUNET_TIME_Timestamp reserve_expiration 42 = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time); 43 struct GNUNET_PQ_QueryParam params[] = { 44 GNUNET_PQ_query_param_auto_from_type (reserve_pub), 45 GNUNET_PQ_query_param_uint64 (&withdraw_id), 46 GNUNET_PQ_query_param_auto_from_type (coin_bks), 47 GNUNET_PQ_query_param_auto_from_type (coin_pub), 48 GNUNET_PQ_query_param_uint64 (&known_coin_id), 49 GNUNET_PQ_query_param_auto_from_type (coin_sig), 50 GNUNET_PQ_query_param_timestamp (&reserve_gc), 51 GNUNET_PQ_query_param_timestamp (&reserve_expiration), 52 GNUNET_PQ_query_param_timestamp (recoup_timestamp), 53 GNUNET_PQ_query_param_end 54 }; 55 bool is_null; 56 struct GNUNET_PQ_ResultSpec rs[] = { 57 GNUNET_PQ_result_spec_allow_null ( 58 GNUNET_PQ_result_spec_timestamp ("recoup_timestamp", 59 recoup_timestamp), 60 &is_null), 61 GNUNET_PQ_result_spec_bool ("recoup_ok", 62 recoup_ok), 63 GNUNET_PQ_result_spec_bool ("internal_failure", 64 internal_failure), 65 GNUNET_PQ_result_spec_end 66 }; 67 68 69 PREPARE (pg, 70 "call_recoup", 71 "SELECT " 72 " out_recoup_timestamp AS recoup_timestamp" 73 ",out_recoup_ok AS recoup_ok" 74 ",out_internal_failure AS internal_failure" 75 " FROM exchange_do_recoup_to_reserve" 76 " ($1,$2,$3,$4,$5,$6,$7,$8,$9);"); 77 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 78 "call_recoup", 79 params, 80 rs); 81 }