Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2022, 2025 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_instance.c
18 : * @brief Implementation of the insert_instance function for Postgres
19 : * @author Christian Grothoff
20 : * @author Iván Ávalos
21 : */
22 : #include "platform.h"
23 : #include <taler/taler_error_codes.h>
24 : #include <taler/taler_dbevents.h>
25 : #include <taler/taler_pq_lib.h>
26 : #include "pg_insert_instance.h"
27 : #include "pg_helper.h"
28 :
29 : enum GNUNET_DB_QueryStatus
30 31 : TMH_PG_insert_instance (
31 : void *cls,
32 : const struct TALER_MerchantPublicKeyP *merchant_pub,
33 : const struct TALER_MerchantPrivateKeyP *merchant_priv,
34 : const struct TALER_MERCHANTDB_InstanceSettings *is,
35 : const struct TALER_MERCHANTDB_InstanceAuthSettings *ias,
36 : bool validation_needed)
37 : {
38 31 : struct PostgresClosure *pg = cls;
39 31 : struct GNUNET_PQ_QueryParam params[] = {
40 31 : GNUNET_PQ_query_param_auto_from_type (merchant_pub),
41 31 : GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash),
42 31 : GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt),
43 31 : GNUNET_PQ_query_param_string (is->id),
44 31 : GNUNET_PQ_query_param_string (is->name),
45 31 : TALER_PQ_query_param_json (is->address),
46 31 : TALER_PQ_query_param_json (is->jurisdiction),
47 31 : GNUNET_PQ_query_param_bool (is->use_stefan),
48 31 : GNUNET_PQ_query_param_relative_time (
49 : &is->default_wire_transfer_delay),
50 31 : GNUNET_PQ_query_param_relative_time (&is->default_pay_delay),
51 31 : GNUNET_PQ_query_param_relative_time (&is->default_refund_delay),
52 31 : (NULL == is->website)
53 31 : ? GNUNET_PQ_query_param_null ()
54 31 : : GNUNET_PQ_query_param_string (is->website),
55 31 : (NULL == is->email)
56 31 : ? GNUNET_PQ_query_param_null ()
57 31 : : GNUNET_PQ_query_param_string (is->email),
58 31 : (NULL == is->logo)
59 31 : ? GNUNET_PQ_query_param_null ()
60 31 : : GNUNET_PQ_query_param_string (is->logo),
61 31 : (NULL == is->phone)
62 31 : ? GNUNET_PQ_query_param_null ()
63 31 : : GNUNET_PQ_query_param_string (is->phone),
64 31 : GNUNET_PQ_query_param_bool (is->phone_validated),
65 31 : GNUNET_PQ_query_param_bool (is->email_validated),
66 31 : GNUNET_PQ_query_param_bool (validation_needed),
67 31 : GNUNET_PQ_query_param_string (
68 : GNUNET_TIME_round_interval2s (
69 31 : is->default_wire_transfer_rounding_interval)),
70 : GNUNET_PQ_query_param_end
71 : };
72 31 : struct GNUNET_PQ_QueryParam params_priv[] = {
73 31 : GNUNET_PQ_query_param_auto_from_type (merchant_priv),
74 31 : GNUNET_PQ_query_param_string (is->id),
75 : GNUNET_PQ_query_param_end
76 : };
77 : enum GNUNET_DB_QueryStatus qs;
78 :
79 31 : check_connection (pg);
80 31 : PREPARE (pg,
81 : "insert_instance",
82 : "INSERT INTO merchant_instances"
83 : "(merchant_pub"
84 : ",auth_hash"
85 : ",auth_salt"
86 : ",merchant_id"
87 : ",merchant_name"
88 : ",address"
89 : ",jurisdiction"
90 : ",use_stefan"
91 : ",default_wire_transfer_delay"
92 : ",default_pay_delay"
93 : ",default_refund_delay"
94 : ",website"
95 : ",email"
96 : ",logo"
97 : ",phone_number"
98 : ",phone_validated"
99 : ",email_validated"
100 : ",validation_needed"
101 : ",default_wire_transfer_rounding_interval)"
102 : "VALUES"
103 : "($1,$2,$3,$4,$5,$6::TEXT::JSONB,$7::TEXT::JSONB,$8,$9,$10,$11,"
104 : "$12,$13,$14,$15,$16,$17,$18,$19::time_rounder_interval)");
105 31 : PREPARE (pg,
106 : "insert_keys",
107 : "INSERT INTO merchant_keys"
108 : "(merchant_priv"
109 : ",merchant_serial)"
110 : " SELECT $1, merchant_serial"
111 : " FROM merchant_instances"
112 : " WHERE merchant_id=$2");
113 31 : qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
114 : "insert_instance",
115 : params);
116 31 : if (qs <= 0)
117 0 : return qs;
118 31 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
119 : "insert_keys",
120 : params_priv);
121 : }
|