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