insert_deposit_confirmation.c (6134B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022, 2023, 2024, 2026 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 src/backenddb/insert_deposit_confirmation.c 18 * @brief Implementation of the insert_deposit_confirmation function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include <taler/taler_error_codes.h> 23 #include <taler/taler_dbevents.h> 24 #include <taler/taler_pq_lib.h> 25 #include "merchant-database/insert_deposit_confirmation.h" 26 #include "helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 TALER_MERCHANTDB_insert_deposit_confirmation (struct TALER_MERCHANTDB_PostgresContext *pg, 31 const char *instance_id, 32 struct GNUNET_TIME_Timestamp deposit_timestamp, 33 const struct TALER_PrivateContractHashP * 34 h_contract_terms, 35 const char *exchange_url, 36 struct GNUNET_TIME_Timestamp wire_transfer_deadline, 37 const struct TALER_Amount *total_without_fees, 38 const struct TALER_Amount *wire_fee, 39 const struct TALER_MerchantWireHashP *h_wire, 40 const struct TALER_ExchangeSignatureP *exchange_sig, 41 const struct TALER_ExchangePublicKeyP *exchange_pub, 42 uint64_t *deposit_confirmation_serial_id) 43 { 44 struct GNUNET_TIME_AbsoluteNBO nbo 45 = GNUNET_TIME_absolute_hton (wire_transfer_deadline.abs_time); 46 char *nbo_str 47 = GNUNET_STRINGS_data_to_string_alloc (&nbo, 48 sizeof (nbo)); 49 struct GNUNET_PQ_QueryParam params[] = { 50 GNUNET_PQ_query_param_string (instance_id), 51 GNUNET_PQ_query_param_auto_from_type (h_contract_terms), 52 GNUNET_PQ_query_param_timestamp (&deposit_timestamp), 53 GNUNET_PQ_query_param_string (exchange_url), 54 TALER_PQ_query_param_amount_with_currency (pg->conn, 55 total_without_fees), 56 TALER_PQ_query_param_amount_with_currency (pg->conn, 57 wire_fee), 58 GNUNET_PQ_query_param_auto_from_type (h_wire), /* 7 */ 59 GNUNET_PQ_query_param_auto_from_type (exchange_sig), 60 GNUNET_PQ_query_param_auto_from_type (exchange_pub), 61 GNUNET_PQ_query_param_timestamp (&wire_transfer_deadline), 62 GNUNET_PQ_query_param_string (nbo_str), 63 GNUNET_PQ_query_param_end 64 }; 65 bool no_instance; 66 bool no_order; 67 bool no_account; 68 bool no_signkey; 69 bool conflict; 70 struct GNUNET_PQ_ResultSpec rs[] = { 71 GNUNET_PQ_result_spec_bool ("no_instance", 72 &no_instance), 73 GNUNET_PQ_result_spec_bool ("no_order", 74 &no_order), 75 GNUNET_PQ_result_spec_bool ("no_account", 76 &no_account), 77 GNUNET_PQ_result_spec_bool ("no_signkey", 78 &no_signkey), 79 GNUNET_PQ_result_spec_bool ("conflict", 80 &conflict), 81 GNUNET_PQ_result_spec_uint64 ("deposit_confirmation_serial", 82 deposit_confirmation_serial_id), 83 GNUNET_PQ_result_spec_end 84 }; 85 enum GNUNET_DB_QueryStatus qs; 86 87 /* no preflight check here, run in transaction by caller! */ 88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 89 "Storing deposit confirmation for instance `%s' h_contract_terms `%s', total_without_fees: %s and wire transfer deadline in %s\n", 90 instance_id, 91 GNUNET_h2s (&h_contract_terms->hash), 92 TALER_amount2s (total_without_fees), 93 GNUNET_TIME_relative2s ( 94 GNUNET_TIME_absolute_get_remaining ( 95 wire_transfer_deadline.abs_time), 96 true)); 97 check_connection (pg); 98 PREPARE (pg, 99 "insert_deposit_confirmation", 100 "SELECT " 101 " out_no_instance AS no_instance" 102 " ,out_no_account AS no_account" 103 " ,out_no_order AS no_order" 104 " ,out_no_signkey AS no_signkey" 105 " ,out_conflict AS conflict" 106 " ,out_deposit_confirmation_serial AS deposit_confirmation_serial" 107 " FROM merchant_do_insert_deposit_confirmation" 108 " ($1, $2 ,$3, $4, $5, $6, $7, $8, $9, $10, $11);"); 109 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 110 "insert_deposit_confirmation", 111 params, 112 rs); 113 GNUNET_free (nbo_str); 114 GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs); 115 if (qs < 0) 116 return qs; 117 // FIXME: in the future, return these codes to the client and 118 // return more specific error codes to the client from the API! 119 if (no_instance) 120 { 121 GNUNET_break (0); 122 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 123 } 124 if (no_order) 125 { 126 GNUNET_break (0); 127 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 128 } 129 if (no_account) 130 { 131 GNUNET_break (0); 132 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 133 } 134 if (no_signkey) 135 { 136 GNUNET_break (0); 137 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 138 } 139 if (conflict) 140 { 141 GNUNET_break (0); 142 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 143 } 144 return qs; 145 }