insert_unclaim_signature.c (3413B)
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 ( 51 struct TALER_MERCHANTDB_PostgresContext *pg, 52 const char *instance_id, 53 const struct TALER_MerchantPublicKeyP *merchant_pub, 54 const char *order_id, 55 const struct GNUNET_CRYPTO_EddsaPublicKey *nonce, 56 const struct GNUNET_HashCode *h_contract, 57 const struct GNUNET_CRYPTO_EddsaSignature *nsig) 58 { 59 char *nonce_str = GNUNET_STRINGS_data_to_string_alloc (nonce, 60 sizeof (*nonce)); 61 char *notify_str = get_notify_str (order_id, 62 merchant_pub); 63 struct GNUNET_PQ_QueryParam params[] = { 64 GNUNET_PQ_query_param_string (instance_id), 65 GNUNET_PQ_query_param_string (order_id), 66 GNUNET_PQ_query_param_string (nonce_str), 67 GNUNET_PQ_query_param_string (notify_str), 68 GNUNET_PQ_query_param_auto_from_type (h_contract), 69 GNUNET_PQ_query_param_auto_from_type (nsig), 70 GNUNET_PQ_query_param_end 71 }; 72 bool found; 73 struct GNUNET_PQ_ResultSpec rs[] = { 74 GNUNET_PQ_result_spec_bool ("out_found", 75 &found), 76 GNUNET_PQ_result_spec_end 77 }; 78 enum GNUNET_DB_QueryStatus qs; 79 80 check_connection (pg); 81 PREPARE (pg, 82 "insert_unclaim_signature", 83 "SELECT" 84 " out_found" 85 " FROM merchant_do_insert_unclaim_signature" 86 "($1, $2, $3, $4, $5, $6);"); 87 qs = GNUNET_PQ_eval_prepared_singleton_select ( 88 pg->conn, 89 "insert_unclaim_signature", 90 params, 91 rs); 92 GNUNET_free (nonce_str); 93 GNUNET_free (notify_str); 94 if (qs <= 0) 95 return qs; 96 return found 97 ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 98 : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 99 }