diff options
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/Makefile.am | 2 | ||||
-rw-r--r-- | src/backenddb/pg_insert_account.c | 68 | ||||
-rw-r--r-- | src/backenddb/pg_insert_account.h | 43 | ||||
-rw-r--r-- | src/backenddb/pg_update_account.c | 64 | ||||
-rw-r--r-- | src/backenddb/pg_update_account.h | 44 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 49 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 3 |
7 files changed, 230 insertions, 43 deletions
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index 189b7a32..020b3f7b 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -54,6 +54,8 @@ libtalermerchantdb_la_LDFLAGS = \ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_update_wirewatch_progress.h pg_update_wirewatch_progress.c \ pg_select_wirewatch_accounts.h pg_select_wirewatch_accounts.c \ + pg_insert_account.h pg_insert_account.c \ + pg_update_account.h pg_update_account.c \ pg_lookup_instances.h pg_lookup_instances.c \ pg_lookup_transfers.h pg_lookup_transfers.c \ plugin_merchantdb_postgres.c pg_helper.h diff --git a/src/backenddb/pg_insert_account.c b/src/backenddb/pg_insert_account.c new file mode 100644 index 00000000..3b57b0ba --- /dev/null +++ b/src/backenddb/pg_insert_account.c @@ -0,0 +1,68 @@ +/* + This file is part of TALER + Copyright (C) 2022, 2023 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_account.c + * @brief Implementation of the insert_account function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_insert_account.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TMH_PG_insert_account ( + void *cls, + const char *id, + const struct TALER_MERCHANTDB_AccountDetails *account_details) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (id), + GNUNET_PQ_query_param_auto_from_type (&account_details->h_wire), + GNUNET_PQ_query_param_auto_from_type (&account_details->salt), + GNUNET_PQ_query_param_string (account_details->payto_uri), + NULL ==account_details->credit_facade_url + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (account_details->credit_facade_url), + NULL == account_details->credit_facade_credentials + ? GNUNET_PQ_query_param_null () + : TALER_PQ_query_param_json (account_details->credit_facade_credentials), + GNUNET_PQ_query_param_bool (account_details->active), + GNUNET_PQ_query_param_end + }; + + check_connection (pg); + PREPARE (pg, + "insert_account", + "INSERT INTO merchant_accounts" + "(merchant_serial" + ",h_wire" + ",salt" + ",payto_uri" + ",credit_facade_url" + ",credit_facade_credentials" + ",active)" + " SELECT merchant_serial, $2, $3, $4, $5, $6, $7" + " FROM merchant_instances" + " WHERE merchant_id=$1"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_account", + params); +} diff --git a/src/backenddb/pg_insert_account.h b/src/backenddb/pg_insert_account.h new file mode 100644 index 00000000..463bc527 --- /dev/null +++ b/src/backenddb/pg_insert_account.h @@ -0,0 +1,43 @@ +/* + 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_account.h + * @brief implementation of the insert_account function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_INSERT_ACCOUNT_H +#define PG_INSERT_ACCOUNT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + +/** + * Insert information about an instance's account into our database. + * + * @param cls closure + * @param id identifier of the instance + * @param account_details details about the account + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TMH_PG_insert_account ( + void *cls, + const char *id, + const struct TALER_MERCHANTDB_AccountDetails *account_details); + + +#endif diff --git a/src/backenddb/pg_update_account.c b/src/backenddb/pg_update_account.c new file mode 100644 index 00000000..0a95a94c --- /dev/null +++ b/src/backenddb/pg_update_account.c @@ -0,0 +1,64 @@ +/* + This file is part of TALER + Copyright (C) 2023 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_update_account.c + * @brief Implementation of the update_account function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_update_account.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TMH_PG_update_account ( + void *cls, + const char *id, + const struct TALER_MERCHANTDB_AccountDetails *account_details) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (id), + GNUNET_PQ_query_param_auto_from_type (&account_details->h_wire), + NULL ==account_details->credit_facade_url + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (account_details->credit_facade_url), + NULL == account_details->credit_facade_credentials + ? GNUNET_PQ_query_param_null () + : TALER_PQ_query_param_json (account_details->credit_facade_credentials), + GNUNET_PQ_query_param_bool (account_details->active), + GNUNET_PQ_query_param_end + }; + + check_connection (pg); + PREPARE (pg, + "update_account", + "UPDATE merchant_accounts SET" + " credit_facade_url=$3" + ",credit_facade_credentials=$4" + ",active=$5" + " 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, + "update_account", + params); +} diff --git a/src/backenddb/pg_update_account.h b/src/backenddb/pg_update_account.h new file mode 100644 index 00000000..52b476d9 --- /dev/null +++ b/src/backenddb/pg_update_account.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2023 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_update_account.h + * @brief implementation of the update_account function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_UPDATE_ACCOUNT_H +#define PG_UPDATE_ACCOUNT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + + +/** + * Update information about an instance's account in our database. + * + * @param cls closure + * @param id identifier of the instance + * @param account_details details about the account + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TMH_PG_update_account ( + void *cls, + const char *id, + const struct TALER_MERCHANTDB_AccountDetails *account_details); + + +#endif diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 19bd022a..e70d8639 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -30,6 +30,8 @@ #include <taler/taler_mhd_lib.h> #include "taler_merchantdb_plugin.h" #include "pg_helper.h" +#include "pg_insert_account.h" +#include "pg_update_account.h" #include "pg_lookup_instances.h" #include "pg_lookup_transfers.h" #include "pg_update_wirewatch_progress.h" @@ -410,37 +412,6 @@ postgres_insert_instance ( /** - * Insert information about an instance's account into our database. - * - * @param cls closure - * @param id identifier of the instance - * @param account_details details about the account - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_account ( - void *cls, - const char *id, - const struct TALER_MERCHANTDB_AccountDetails *account_details) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (id), - GNUNET_PQ_query_param_auto_from_type (&account_details->h_wire), - GNUNET_PQ_query_param_auto_from_type (&account_details->salt), - GNUNET_PQ_query_param_string (account_details->payto_uri), - GNUNET_PQ_query_param_bool (account_details->active), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_account", - params); -} - - -/** * Closure for kyc_status_cb(). */ struct KycStatusContext @@ -7342,17 +7313,6 @@ postgres_connect (void *cls) " JOIN merchant_kyc" " USING (account_serial)" " WHERE merchant_instances.merchant_id=$1"), - /* for postgres_insert_account() */ - GNUNET_PQ_make_prepare ("insert_account", - "INSERT INTO merchant_accounts" - "(merchant_serial" - ",h_wire" - ",salt" - ",payto_uri" - ",active)" - " SELECT merchant_serial, $2, $3, $4, $5" - " FROM merchant_instances" - " WHERE merchant_id=$1"), /* for postgres_delete_instance_private_key() */ GNUNET_PQ_make_prepare ("delete_key", "DELETE FROM merchant_keys" @@ -9732,7 +9692,10 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->commit = &postgres_commit; plugin->lookup_instance_auth = &postgres_lookup_instance_auth; plugin->insert_instance = &postgres_insert_instance; - plugin->insert_account = &postgres_insert_account; + plugin->insert_account + = &TMH_PG_insert_account; + plugin->update_account + = &TMH_PG_update_account; plugin->account_kyc_set_status = &postgres_account_kyc_set_status; plugin->account_kyc_get_status diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index 3d7d6b8c..708d8c01 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -153,6 +153,9 @@ free_instance_data (struct InstanceData *instance) static void make_account (struct TALER_MERCHANTDB_AccountDetails *account) { + memset (account, + 0, + sizeof (*account)); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &account->h_wire.hash); GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |