From 8d4ec086b4dd1b91e27e33dc05609ca98f5b92a9 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 8 May 2023 21:30:43 -0600 Subject: Factor out purge_instance and update_instance (shit job) --- src/backenddb/plugin_merchantdb_postgres.c | 99 ++---------------------------- 1 file changed, 6 insertions(+), 93 deletions(-) (limited to 'src/backenddb/plugin_merchantdb_postgres.c') diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 80f03871..61e35837 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -48,6 +48,8 @@ #include "pg_account_kyc_set_status.h" #include "pg_account_kyc_get_status.h" #include "pg_delete_instance_private_key.h" +#include "pg_purge_instance.h" +#include "pg_update_instance.h" #include "pg_set_transfer_status_to_confirmed.h" @@ -325,75 +327,6 @@ postgres_commit (void *cls) } -/** - * Purge an instance and all associated information from our database. - * Highly likely to cause undesired data loss. Use with caution. - * - * @param cls closure - * @param merchant_id identifier of the instance - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_purge_instance (void *cls, - const char *merchant_id) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (merchant_id), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "purge_instance", - params); -} - - -/** - * Update information about an instance into our database. - * - * @param cls closure - * @param is details about the instance - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_update_instance (void *cls, - const struct TALER_MERCHANTDB_InstanceSettings *is) -{ - struct PostgresClosure *pg = cls; - uint32_t ut32 = (uint32_t) is->ut; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (is->id), - GNUNET_PQ_query_param_string (is->name), - 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_uint32 (&ut32), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_instance", - params); -} - - /** * Update information about an instance's authentication settings * into our database. @@ -6688,28 +6621,6 @@ postgres_connect (void *cls) struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("end_transaction", "COMMIT"), - /* for postgres_purge_instance() */ - GNUNET_PQ_make_prepare ("purge_instance", - "DELETE FROM merchant_instances" - " WHERE merchant_instances.merchant_id = $1"), - /* for postgres_update_instance() */ - GNUNET_PQ_make_prepare ("update_instance", - "UPDATE merchant_instances SET" - " merchant_name=$2" - ",address=$3" - ",jurisdiction=$4" - ",default_max_deposit_fee_val=$5" - ",default_max_deposit_fee_frac=$6" - ",default_max_wire_fee_val=$7" - ",default_max_wire_fee_frac=$8" - ",default_wire_fee_amortization=$9" - ",default_wire_transfer_delay=$10" - ",default_pay_delay=$11" - ",website=$12" - ",email=$13" - ",logo=$14" - ",user_type=$15" - " WHERE merchant_id=$1"), /* for postgres_update_instance_auth() */ GNUNET_PQ_make_prepare ("update_instance_auth", "UPDATE merchant_instances SET" @@ -9045,8 +8956,10 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_account_kyc_get_status; plugin->delete_instance_private_key = &TMH_PG_delete_instance_private_key; - plugin->purge_instance = &postgres_purge_instance; - plugin->update_instance = &postgres_update_instance; + plugin->purge_instance + = &TMH_PG_purge_instance; + plugin->update_instance + = &TMH_PG_update_instance; plugin->update_instance_auth = &postgres_update_instance_auth; plugin->activate_account = &postgres_activate_account; plugin->inactivate_account = &postgres_inactivate_account; -- cgit v1.2.3