summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-05-08 21:42:23 -0600
committerIván Ávalos <avalos@disroot.org>2023-05-08 21:42:23 -0600
commit7b9000278b12e07350e3d4fb502693d5af08e1bc (patch)
tree7f1200d0b715a6a7e043d008852b30f6121ada40 /src
parent2bdf34b5563725c6ba6b643a021ddeb7649360a8 (diff)
downloadmerchant-7b9000278b12e07350e3d4fb502693d5af08e1bc.tar.gz
merchant-7b9000278b12e07350e3d4fb502693d5af08e1bc.tar.bz2
merchant-7b9000278b12e07350e3d4fb502693d5af08e1bc.zip
Factor out inactivate_account (shit job)
Diffstat (limited to 'src')
-rw-r--r--src/backenddb/Makefile.am1
-rw-r--r--src/backenddb/pg_inactivate_account.c55
-rw-r--r--src/backenddb/pg_inactivate_account.h42
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c42
4 files changed, 101 insertions, 39 deletions
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index 36cfef51..76eb90f2 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -73,6 +73,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
pg_purge_instance.h pg_purge_instance.c \
pg_update_instance.h pg_update_instance.c \
pg_update_instance_auth.h pg_update_instance_auth.c \
+ pg_inactivate_account.h pg_inactivate_account.c \
plugin_merchantdb_postgres.c pg_helper.h
libtaler_plugin_merchantdb_postgres_la_LIBADD = \
$(LTLIBINTL)
diff --git a/src/backenddb/pg_inactivate_account.c b/src/backenddb/pg_inactivate_account.c
new file mode 100644
index 00000000..67c39462
--- /dev/null
+++ b/src/backenddb/pg_inactivate_account.c
@@ -0,0 +1,55 @@
+/*
+ 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_inactivate_account.c
+ * @brief Implementation of the inactivate_account 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_inactivate_account.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_inactivate_account (void *cls,
+ const char *merchant_id,
+ const struct TALER_MerchantWireHashP *h_wire)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (merchant_id),
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+ /* the merchant instance is implied from the random salt
+ that is part of the h_wire calculation */
+ PREPARE (pg,
+ "inactivate_account",
+ "UPDATE merchant_accounts SET"
+ " active=FALSE"
+ " WHERE h_wire=$2"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "inactivate_account",
+ params);
+}
diff --git a/src/backenddb/pg_inactivate_account.h b/src/backenddb/pg_inactivate_account.h
new file mode 100644
index 00000000..5146faca
--- /dev/null
+++ b/src/backenddb/pg_inactivate_account.h
@@ -0,0 +1,42 @@
+/*
+ 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_inactivate_account.h
+ * @brief implementation of the inactivate_account function for Postgres
+ * @author Iván Ávalos
+ */
+#ifndef PG_INACTIVATE_ACCOUNT_H
+#define PG_INACTIVATE_ACCOUNT_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Set an instance's account in our database to "inactive".
+ *
+ * @param cls closure
+ * @param merchant_id merchant backend instance ID
+ * @param h_wire hash of the wire account to set to inactive
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_inactivate_account (void *cls,
+ const char *merchant_id,
+ const struct TALER_MerchantWireHashP *h_wire);
+
+
+#endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 463a8328..b5f8debc 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -51,6 +51,7 @@
#include "pg_purge_instance.h"
#include "pg_update_instance.h"
#include "pg_update_instance_auth.h"
+#include "pg_inactivate_account.h"
#include "pg_set_transfer_status_to_confirmed.h"
@@ -329,33 +330,6 @@ postgres_commit (void *cls)
/**
- * Set an instance's account in our database to "inactive".
- *
- * @param cls closure
- * @param merchant_id merchant backend instance ID
- * @param h_wire hash of the wire account to set to inactive
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_inactivate_account (void *cls,
- const char *merchant_id,
- const struct TALER_MerchantWireHashP *h_wire)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (merchant_id),
- GNUNET_PQ_query_param_auto_from_type (h_wire),
- GNUNET_PQ_query_param_end
- };
-
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "inactivate_account",
- params);
-}
-
-
-/**
* Set an instance's account in our database to "active".
*
* @param cls closure
@@ -6592,17 +6566,6 @@ postgres_connect (void *cls)
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("end_transaction",
"COMMIT"),
- /* for postgres_inactivate_account(); the merchant
- instance is implied from the random salt that
- is part of the h_wire calculation */
- GNUNET_PQ_make_prepare ("inactivate_account",
- "UPDATE merchant_accounts SET"
- " active=FALSE"
- " WHERE h_wire=$2"
- " AND merchant_serial="
- " (SELECT merchant_serial"
- " FROM merchant_instances"
- " WHERE merchant_id=$1)"),
/* for postgres_activate_account() */
GNUNET_PQ_make_prepare ("activate_account",
"UPDATE merchant_accounts SET"
@@ -8928,7 +8891,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->update_instance_auth
= &TMH_PG_update_instance_auth;
plugin->activate_account = &postgres_activate_account;
- plugin->inactivate_account = &postgres_inactivate_account;
+ plugin->inactivate_account
+ = &TMH_PG_inactivate_account;
plugin->update_transfer_status
= &TMH_PG_update_transfer_status;
plugin->lookup_products = &postgres_lookup_products;