pg_insert_unclaim_signature.c (3394B)
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 backenddb/pg_insert_unclaim_signature.c 18 * @brief Implementation of the insert_unclaim_signature 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_unclaim_signature.h" 26 #include "pg_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 TMH_PG_insert_unclaim_signature ( 51 void *cls, 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 struct PostgresClosure *pg = cls; 60 char *nonce_str = GNUNET_STRINGS_data_to_string_alloc (nonce, 61 sizeof (*nonce)); 62 char *notify_str = get_notify_str (order_id, 63 merchant_pub); 64 struct GNUNET_PQ_QueryParam params[] = { 65 GNUNET_PQ_query_param_string (instance_id), 66 GNUNET_PQ_query_param_string (order_id), 67 GNUNET_PQ_query_param_string (nonce_str), 68 GNUNET_PQ_query_param_string (notify_str), 69 GNUNET_PQ_query_param_auto_from_type (h_contract), 70 GNUNET_PQ_query_param_auto_from_type (nsig), 71 GNUNET_PQ_query_param_end 72 }; 73 bool found; 74 struct GNUNET_PQ_ResultSpec rs[] = { 75 GNUNET_PQ_result_spec_bool ("out_found", 76 &found), 77 GNUNET_PQ_result_spec_end 78 }; 79 enum GNUNET_DB_QueryStatus qs; 80 81 check_connection (pg); 82 PREPARE (pg, 83 "insert_unclaim_signature", 84 "SELECT" 85 " out_found" 86 " FROM merchant_do_insert_unclaim_signature" 87 "($1, $2, $3, $4, $5);"); 88 qs = GNUNET_PQ_eval_prepared_singleton_select ( 89 pg->conn, 90 "insert_unclaim_signature", 91 params, 92 rs); 93 GNUNET_free (nonce_str); 94 GNUNET_free (notify_str); 95 if (qs <= 0) 96 return qs; 97 return found 98 ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 99 : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 100 }