do_purse_merge.c (3330B)
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_purse_merge.c 18 * @brief Implementation of the do_purse_merge function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "exchange-database/do_purse_merge.h" 23 #include "helper.h" 24 25 26 enum GNUNET_DB_QueryStatus 27 TALER_EXCHANGEDB_do_purse_merge ( 28 struct TALER_EXCHANGEDB_PostgresContext *pg, 29 const struct TALER_PurseContractPublicKeyP *purse_pub, 30 const struct TALER_PurseMergeSignatureP *merge_sig, 31 const struct GNUNET_TIME_Timestamp merge_timestamp, 32 const struct TALER_ReserveSignatureP *reserve_sig, 33 const char *partner_url, 34 const struct TALER_ReservePublicKeyP *reserve_pub, 35 bool *no_partner, 36 bool *no_balance, 37 bool *in_conflict) 38 { 39 struct TALER_NormalizedPaytoHashP h_payto; 40 struct GNUNET_TIME_Timestamp expiration 41 = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time); 42 struct GNUNET_PQ_QueryParam params[] = { 43 GNUNET_PQ_query_param_auto_from_type (purse_pub), 44 GNUNET_PQ_query_param_auto_from_type (merge_sig), 45 GNUNET_PQ_query_param_timestamp (&merge_timestamp), 46 GNUNET_PQ_query_param_auto_from_type (reserve_sig), 47 (NULL == partner_url) 48 ? GNUNET_PQ_query_param_null () 49 : GNUNET_PQ_query_param_string (partner_url), 50 GNUNET_PQ_query_param_auto_from_type (reserve_pub), 51 GNUNET_PQ_query_param_auto_from_type (&h_payto), 52 GNUNET_PQ_query_param_timestamp (&expiration), 53 GNUNET_PQ_query_param_end 54 }; 55 struct GNUNET_PQ_ResultSpec rs[] = { 56 GNUNET_PQ_result_spec_bool ("no_partner", 57 no_partner), 58 GNUNET_PQ_result_spec_bool ("no_balance", 59 no_balance), 60 GNUNET_PQ_result_spec_bool ("conflict", 61 in_conflict), 62 GNUNET_PQ_result_spec_end 63 }; 64 65 { 66 struct TALER_NormalizedPayto payto_uri; 67 68 payto_uri = TALER_reserve_make_payto (pg->exchange_url, 69 reserve_pub); 70 TALER_normalized_payto_hash (payto_uri, 71 &h_payto); 72 GNUNET_free (payto_uri.normalized_payto); 73 } 74 PREPARE (pg, 75 "call_purse_merge", 76 "SELECT" 77 " out_no_partner AS no_partner" 78 ",out_no_balance AS no_balance" 79 ",out_conflict AS conflict" 80 " FROM exchange_do_purse_merge" 81 " ($1, $2, $3, $4, $5, $6, $7, $8);"); 82 83 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 84 "call_purse_merge", 85 params, 86 rs); 87 }