insert_unclaim_signature.c (3652B)
1 /* 2 This file is part of TALER 3 Copyright (C) 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_unclaim_signature.c 18 * @brief Implementation of the insert_unclaim_signature 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_unclaim_signature.h" 26 #include "helper.h" 27 28 29 static char * 30 get_notify_str (const char *order_id, 31 const struct TALER_MerchantPublicKeyP *merchant_pub) 32 { 33 struct TMH_OrderPayEventP pay_eh = { 34 .header.size = htons (sizeof (pay_eh)), 35 .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_STATUS_CHANGED), 36 .merchant_pub = *merchant_pub 37 }; 38 39 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 40 "Notifying clients about status change of order %s\n", 41 order_id); 42 GNUNET_CRYPTO_hash (order_id, 43 strlen (order_id), 44 &pay_eh.h_order_id); 45 return GNUNET_PQ_get_event_notify_channel (&pay_eh.header); 46 } 47 48 49 enum GNUNET_DB_QueryStatus 50 TALER_MERCHANTDB_insert_unclaim_signature (struct TALER_MERCHANTDB_PostgresContext *pg, 51 const char *instance_id, 52 const struct TALER_MerchantPublicKeyP *merchant_pub, 53 const char *order_id, 54 const struct GNUNET_CRYPTO_EddsaPublicKey *nonce, 55 const struct GNUNET_HashCode *h_contract, 56 const struct GNUNET_CRYPTO_EddsaSignature *nsig) 57 { 58 char *nonce_str = GNUNET_STRINGS_data_to_string_alloc (nonce, 59 sizeof (*nonce)); 60 char *notify_str = get_notify_str (order_id, 61 merchant_pub); 62 struct GNUNET_PQ_QueryParam params[] = { 63 GNUNET_PQ_query_param_string (instance_id), 64 GNUNET_PQ_query_param_string (order_id), 65 GNUNET_PQ_query_param_string (nonce_str), 66 GNUNET_PQ_query_param_string (notify_str), 67 GNUNET_PQ_query_param_auto_from_type (h_contract), 68 GNUNET_PQ_query_param_auto_from_type (nsig), 69 GNUNET_PQ_query_param_end 70 }; 71 bool found; 72 struct GNUNET_PQ_ResultSpec rs[] = { 73 GNUNET_PQ_result_spec_bool ("out_found", 74 &found), 75 GNUNET_PQ_result_spec_end 76 }; 77 enum GNUNET_DB_QueryStatus qs; 78 79 check_connection (pg); 80 PREPARE (pg, 81 "insert_unclaim_signature", 82 "SELECT" 83 " out_found" 84 " FROM merchant_do_insert_unclaim_signature" 85 "($1, $2, $3, $4, $5);"); 86 qs = GNUNET_PQ_eval_prepared_singleton_select ( 87 pg->conn, 88 "insert_unclaim_signature", 89 params, 90 rs); 91 GNUNET_free (nonce_str); 92 GNUNET_free (notify_str); 93 if (qs <= 0) 94 return qs; 95 return found 96 ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 97 : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 98 }