pg_insert_transfer.c (2949B)
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 backenddb/pg_insert_transfer.c 18 * @brief Implementation of the insert_transfer 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_insert_transfer.h" 26 #include "pg_helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 TMH_PG_insert_transfer ( 31 void *cls, 32 const char *instance_id, 33 const char *exchange_url, 34 const struct TALER_WireTransferIdentifierRawP *wtid, 35 const struct TALER_Amount *credit_amount, 36 struct TALER_FullPayto payto_uri, 37 uint64_t bank_serial_id, 38 bool *no_instance, 39 bool *no_account, 40 bool *conflict) 41 { 42 struct PostgresClosure *pg = cls; 43 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 44 struct GNUNET_PQ_QueryParam params[] = { 45 GNUNET_PQ_query_param_string (instance_id), 46 GNUNET_PQ_query_param_string (exchange_url), 47 GNUNET_PQ_query_param_auto_from_type (wtid), 48 TALER_PQ_query_param_amount_with_currency (pg->conn, 49 credit_amount), 50 GNUNET_PQ_query_param_string (payto_uri.full_payto), 51 0 == bank_serial_id 52 ? GNUNET_PQ_query_param_null () 53 : GNUNET_PQ_query_param_uint64 (&bank_serial_id), 54 GNUNET_PQ_query_param_absolute_time (&now), 55 GNUNET_PQ_query_param_end 56 }; 57 struct GNUNET_PQ_ResultSpec rs[] = { 58 GNUNET_PQ_result_spec_bool ("no_instance", 59 no_instance), 60 GNUNET_PQ_result_spec_bool ("no_account", 61 no_account), 62 GNUNET_PQ_result_spec_bool ("conflict", 63 conflict), 64 GNUNET_PQ_result_spec_end 65 }; 66 67 check_connection (pg); 68 PREPARE (pg, 69 "insert_transfer", 70 "SELECT " 71 " out_no_instance AS no_instance" 72 " ,out_no_account AS no_account" 73 " ,out_conflict AS conflict" 74 " FROM merchant_do_insert_transfer" 75 " ($1, $2, $3, $4, $5, $6, $7);"); 76 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 77 "insert_transfer", 78 params, 79 rs); 80 }