diff options
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/Makefile.am | 1 | ||||
-rw-r--r-- | src/backenddb/pg_insert_instance.c | 111 | ||||
-rw-r--r-- | src/backenddb/pg_insert_instance.h | 45 | ||||
-rw-r--r-- | src/backenddb/pg_lookup_instance_auth.c | 7 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 99 |
5 files changed, 160 insertions, 103 deletions
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index 10c362d8..6e66751f 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -66,6 +66,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_insert_exchange_account.h pg_insert_exchange_account.c \ pg_lookup_reserves.h pg_lookup_reserves.c \ pg_lookup_instance_auth.h pg_lookup_instance_auth.c \ + pg_insert_instance.h pg_insert_instance.c \ plugin_merchantdb_postgres.c pg_helper.h libtaler_plugin_merchantdb_postgres_la_LIBADD = \ $(LTLIBINTL) diff --git a/src/backenddb/pg_insert_instance.c b/src/backenddb/pg_insert_instance.c new file mode 100644 index 00000000..3777f743 --- /dev/null +++ b/src/backenddb/pg_insert_instance.c @@ -0,0 +1,111 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_insert_instance.c + * @brief Implementation of the insert_instance function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_insert_instance.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TMH_PG_insert_instance ( + void *cls, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_InstanceSettings *is, + const struct TALER_MERCHANTDB_InstanceAuthSettings *ias) +{ + struct PostgresClosure *pg = cls; + uint32_t ut32 = (uint32_t) is->ut; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (merchant_pub), + GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash), + GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt), + GNUNET_PQ_query_param_string (is->id), + GNUNET_PQ_query_param_string (is->name), + GNUNET_PQ_query_param_uint32 (&ut32), + TALER_PQ_query_param_json (is->address), + TALER_PQ_query_param_json (is->jurisdiction), + TALER_PQ_query_param_amount (&is->default_max_deposit_fee), + TALER_PQ_query_param_amount (&is->default_max_wire_fee), + GNUNET_PQ_query_param_uint32 (&is->default_wire_fee_amortization), + GNUNET_PQ_query_param_relative_time ( + &is->default_wire_transfer_delay), + GNUNET_PQ_query_param_relative_time (&is->default_pay_delay), + (NULL == is->website) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (is->website), + (NULL == is->email) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (is->email), + (NULL == is->logo) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (is->logo), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_QueryParam params_priv[] = { + GNUNET_PQ_query_param_auto_from_type (merchant_priv), + GNUNET_PQ_query_param_string (is->id), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + check_connection (pg); + PREPARE (pg, + "insert_instance", + "INSERT INTO merchant_instances" + "(merchant_pub" + ",auth_hash" + ",auth_salt" + ",merchant_id" + ",merchant_name" + ",user_type" + ",address" + ",jurisdiction" + ",default_max_deposit_fee_val" + ",default_max_deposit_fee_frac" + ",default_max_wire_fee_val" + ",default_max_wire_fee_frac" + ",default_wire_fee_amortization" + ",default_wire_transfer_delay" + ",default_pay_delay" + ",website" + ",email" + ",logo)" + "VALUES" + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)"); + qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_instance", + params); + if (qs <= 0) + return qs; + PREPARE (pg, + "insert_keys", + "INSERT INTO merchant_keys" + "(merchant_priv" + ",merchant_serial)" + " SELECT $1, merchant_serial" + " FROM merchant_instances" + " WHERE merchant_id=$2"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_keys", + params_priv); +} diff --git a/src/backenddb/pg_insert_instance.h b/src/backenddb/pg_insert_instance.h new file mode 100644 index 00000000..5b347363 --- /dev/null +++ b/src/backenddb/pg_insert_instance.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_insert_instance.h + * @brief implementation of the insert_instance function for Postgres + * @author Iván Ávalos + */ +#ifndef PG_INSERT_INSTANCE_H +#define PG_INSERT_INSTANCE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + +/** + * Insert information about an instance into our database. + * + * @param cls closure + * @param merchant_pub public key of the instance + * @param merchant_priv private key of the instance + * @param is details about the instance + * @param ias authentication settings for the instance + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TMH_PG_insert_instance (void *cls, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_InstanceSettings *is, + const struct TALER_MERCHANTDB_InstanceAuthSettings *ias); + +#endif diff --git a/src/backenddb/pg_lookup_instance_auth.c b/src/backenddb/pg_lookup_instance_auth.c index a78ba361..1360cce9 100644 --- a/src/backenddb/pg_lookup_instance_auth.c +++ b/src/backenddb/pg_lookup_instance_auth.c @@ -25,13 +25,6 @@ #include "pg_lookup_instance_auth.h" #include "pg_helper.h" -/** - * Lookup authentication data of an instance. - * - * @param cls closure - * @param instance_id instance to query - * @param[out] ias where to store the auth data - */ enum GNUNET_DB_QueryStatus TMH_PG_lookup_instance_auth ( void *cls, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index a28fd716..9605c29e 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -44,6 +44,7 @@ #include "pg_lookup_reserves.h" #include "pg_lookup_instance_auth.h" #include "pg_update_transfer_status.h" +#include "pg_insert_instance.h" #include "pg_set_transfer_status_to_confirmed.h" @@ -320,70 +321,6 @@ postgres_commit (void *cls) params); } -/** - * Insert information about an instance into our database. - * - * @param cls closure - * @param merchant_pub public key of the instance - * @param merchant_priv private key of the instance - * @param is details about the instance - * @param ias authentication settings for the instance - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_instance ( - void *cls, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const struct TALER_MerchantPrivateKeyP *merchant_priv, - const struct TALER_MERCHANTDB_InstanceSettings *is, - const struct TALER_MERCHANTDB_InstanceAuthSettings *ias) -{ - struct PostgresClosure *pg = cls; - uint32_t ut32 = (uint32_t) is->ut; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash), - GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt), - GNUNET_PQ_query_param_string (is->id), - GNUNET_PQ_query_param_string (is->name), - GNUNET_PQ_query_param_uint32 (&ut32), - TALER_PQ_query_param_json (is->address), - TALER_PQ_query_param_json (is->jurisdiction), - TALER_PQ_query_param_amount (&is->default_max_deposit_fee), - TALER_PQ_query_param_amount (&is->default_max_wire_fee), - GNUNET_PQ_query_param_uint32 (&is->default_wire_fee_amortization), - GNUNET_PQ_query_param_relative_time ( - &is->default_wire_transfer_delay), - GNUNET_PQ_query_param_relative_time (&is->default_pay_delay), - (NULL == is->website) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (is->website), - (NULL == is->email) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (is->email), - (NULL == is->logo) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (is->logo), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params_priv[] = { - GNUNET_PQ_query_param_auto_from_type (merchant_priv), - GNUNET_PQ_query_param_string (is->id), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_instance", - params); - if (qs <= 0) - return qs; - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_keys", - params_priv); -} - /** * Closure for kyc_status_cb(). @@ -6994,37 +6931,6 @@ postgres_connect (void *cls) struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("end_transaction", "COMMIT"), - /* for postgres_insert_instance() */ - GNUNET_PQ_make_prepare ("insert_instance", - "INSERT INTO merchant_instances" - "(merchant_pub" - ",auth_hash" - ",auth_salt" - ",merchant_id" - ",merchant_name" - ",user_type" - ",address" - ",jurisdiction" - ",default_max_deposit_fee_val" - ",default_max_deposit_fee_frac" - ",default_max_wire_fee_val" - ",default_max_wire_fee_frac" - ",default_wire_fee_amortization" - ",default_wire_transfer_delay" - ",default_pay_delay" - ",website" - ",email" - ",logo)" - "VALUES" - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)"), - /* for postgres_insert_instance() */ - GNUNET_PQ_make_prepare ("insert_keys", - "INSERT INTO merchant_keys" - "(merchant_priv" - ",merchant_serial)" - " SELECT $1, merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$2"), /* for postgres_account_kyc_set_status */ GNUNET_PQ_make_prepare ("upsert_account_kyc", "INSERT INTO merchant_kyc" @@ -9417,7 +9323,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->commit = &postgres_commit; plugin->lookup_instance_auth = &TMH_PG_lookup_instance_auth; - plugin->insert_instance = &postgres_insert_instance; + plugin->insert_instance + = &TMH_PG_insert_instance; plugin->insert_account = &TMH_PG_insert_account; plugin->update_account |