Line data Source code
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 0 : get_notify_str (const char *order_id,
37 : const struct TALER_MerchantPublicKeyP *merchant_pub)
38 : {
39 0 : struct TMH_OrderPayEventP pay_eh = {
40 0 : .header.size = htons (sizeof (pay_eh)),
41 0 : .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_STATUS_CHANGED),
42 : .merchant_pub = *merchant_pub
43 : };
44 :
45 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
46 : "Notifying clients about status change of order %s\n",
47 : order_id);
48 0 : GNUNET_CRYPTO_hash (order_id,
49 : strlen (order_id),
50 : &pay_eh.h_order_id);
51 0 : return GNUNET_PQ_get_event_notify_channel (&pay_eh.header);
52 : }
53 :
54 :
55 : enum GNUNET_DB_QueryStatus
56 0 : 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;
67 : bool found;
68 0 : struct GNUNET_PQ_ResultSpec rs[] = {
69 0 : GNUNET_PQ_result_spec_bool ("out_found",
70 : &found),
71 : GNUNET_PQ_result_spec_end
72 : };
73 : enum GNUNET_DB_QueryStatus qs;
74 :
75 0 : GNUNET_assert (NULL != pg->current_merchant_id);
76 0 : GNUNET_assert (0 == strcmp (instance_id,
77 : pg->current_merchant_id));
78 0 : end = GNUNET_STRINGS_data_to_string (nonce,
79 : sizeof (*nonce),
80 : nonce_str,
81 : sizeof (nonce_str));
82 0 : GNUNET_assert (NULL != end);
83 0 : *end = '\0';
84 0 : notify_str = get_notify_str (order_id,
85 0 : &pg->current_merchant_pub);
86 0 : TMH_PQ_prepare_anon (pg,
87 : "SELECT"
88 : " out_found"
89 : " FROM merchant_do_insert_unclaim_signature"
90 : "($1, $2, $3, $4, $5);");
91 : {
92 0 : struct GNUNET_PQ_QueryParam params[] = {
93 0 : GNUNET_PQ_query_param_string (order_id),
94 0 : GNUNET_PQ_query_param_string (nonce_str),
95 0 : GNUNET_PQ_query_param_string (notify_str),
96 0 : GNUNET_PQ_query_param_auto_from_type (h_contract),
97 0 : GNUNET_PQ_query_param_auto_from_type (nsig),
98 : GNUNET_PQ_query_param_end
99 : };
100 :
101 0 : qs = GNUNET_PQ_eval_prepared_singleton_select (
102 : pg->conn,
103 : "",
104 : params,
105 : rs);
106 : }
107 0 : GNUNET_free (notify_str);
108 0 : if (qs <= 0)
109 0 : return qs;
110 : /* FIXME: not a precise set of possible errors... (see stored proc!) */
111 : return found
112 : ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
113 0 : : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
114 : }
|