insert_unclaim_signature.c (3878B)
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_dbevents.h> 23 #include <taler/taler_pq_lib.h> 24 #include "merchant-database/insert_unclaim_signature.h" 25 #include "helper.h" 26 27 /** 28 * Compute the notification code for the given 29 * @a order_id and @a merchant_pub. 30 * 31 * @param order_id order to notify for 32 * @param merchant_pub merchant to notify for 33 * @return notification code, to be freed by caller 34 */ 35 static char * 36 get_notify_str (const char *order_id, 37 const struct TALER_MerchantPublicKeyP *merchant_pub) 38 { 39 struct TMH_OrderPayEventP pay_eh = { 40 .header.size = htons (sizeof (pay_eh)), 41 .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_STATUS_CHANGED), 42 .merchant_pub = *merchant_pub 43 }; 44 45 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 46 "Notifying clients about status change of order %s\n", 47 order_id); 48 GNUNET_CRYPTO_hash (order_id, 49 strlen (order_id), 50 &pay_eh.h_order_id); 51 return GNUNET_PQ_get_event_notify_channel (&pay_eh.header); 52 } 53 54 55 enum GNUNET_DB_QueryStatus 56 TALER_MERCHANTDB_insert_unclaim_signature ( 57 struct TALER_MERCHANTDB_PostgresContext *pg, 58 const char *instance_id, 59 const char *order_id, 60 const struct GNUNET_CRYPTO_EddsaPublicKey *nonce, 61 const struct GNUNET_HashCode *h_contract, 62 const struct GNUNET_CRYPTO_EddsaSignature *nsig) 63 { 64 char nonce_str[sizeof (*nonce) * 2]; 65 char *end; 66 char *notify_str = get_notify_str (order_id, 67 &pg->current_merchant_pub); 68 struct GNUNET_PQ_QueryParam params[] = { 69 GNUNET_PQ_query_param_string (order_id), 70 GNUNET_PQ_query_param_string (nonce_str), 71 GNUNET_PQ_query_param_string (notify_str), 72 GNUNET_PQ_query_param_auto_from_type (h_contract), 73 GNUNET_PQ_query_param_auto_from_type (nsig), 74 GNUNET_PQ_query_param_end 75 }; 76 bool found; 77 struct GNUNET_PQ_ResultSpec rs[] = { 78 GNUNET_PQ_result_spec_bool ("out_found", 79 &found), 80 GNUNET_PQ_result_spec_end 81 }; 82 enum GNUNET_DB_QueryStatus qs; 83 84 GNUNET_assert (NULL != pg->current_merchant_id); 85 GNUNET_assert (0 == strcmp (instance_id, 86 pg->current_merchant_id)); 87 check_connection (pg); 88 end = GNUNET_STRINGS_data_to_string (nonce, 89 sizeof (*nonce), 90 nonce_str, 91 sizeof (nonce_str)); 92 GNUNET_assert (NULL != end); 93 *end = '\0'; 94 TMH_PQ_prepare_anon (pg, 95 "SELECT" 96 " out_found" 97 " FROM merchant_do_insert_unclaim_signature" 98 "($1, $2, $3, $4, $5);"); 99 qs = GNUNET_PQ_eval_prepared_singleton_select ( 100 pg->conn, 101 "", 102 params, 103 rs); 104 GNUNET_free (notify_str); 105 if (qs <= 0) 106 return qs; 107 /* FIXME: not a precise set of possible errors... (see stored proc!) */ 108 return found 109 ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 110 : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 111 }