aboutsummaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-09-10 15:47:31 +0200
committerChristian Grothoff <christian@grothoff.org>2024-09-10 15:47:31 +0200
commita8f851315ceb958ae7e1ee730f38384b5dab0799 (patch)
tree2a21a8f3067a78865b37861e5f6a8ddadcdf886e /src/backenddb
parent044c308a71b692977b02556cf9633fb5bb2f094a (diff)
add logic to enforce hard limit on order creation
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/Makefile.am1
-rw-r--r--src/backenddb/pg_get_kyc_limits.c75
-rw-r--r--src/backenddb/pg_get_kyc_limits.h48
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c3
4 files changed, 127 insertions, 0 deletions
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index 792bfb53..af79c4f6 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -104,6 +104,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
pg_insert_instance.h pg_insert_instance.c \
pg_account_kyc_set_status.h pg_account_kyc_set_status.c \
pg_get_kyc_status.h pg_get_kyc_status.c \
+ pg_get_kyc_limits.h pg_get_kyc_limits.c \
pg_account_kyc_get_status.h pg_account_kyc_get_status.c \
pg_delete_instance_private_key.h pg_delete_instance_private_key.c \
pg_purge_instance.h pg_purge_instance.c \
diff --git a/src/backenddb/pg_get_kyc_limits.c b/src/backenddb/pg_get_kyc_limits.c
new file mode 100644
index 00000000..d6249e56
--- /dev/null
+++ b/src/backenddb/pg_get_kyc_limits.c
@@ -0,0 +1,75 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 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_get_kyc_limits.c
+ * @brief Implementation of the get_kyc_limits 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_get_kyc_limits.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_get_kyc_limits (
+ void *cls,
+ const char *merchant_account_uri,
+ const char *instance_id,
+ const char *exchange_url,
+ bool *kyc_ok,
+ json_t **jlimits)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (merchant_account_uri),
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_string (exchange_url),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("kyc_ok",
+ kyc_ok),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("jaccount_limits",
+ jlimits),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ PREPARE (pg,
+ "get_kyc_limits",
+ "SELECT"
+ " mk.kyc_ok"
+ ",mk.jaccount_limits"
+ " FROM merchant_kyc mk"
+ " WHERE mk.exchange_url=$3"
+ " AND mk.account_serial="
+ " (SELECT account_serial"
+ " FROM merchant_accounts"
+ " WHERE payto_uri=$1"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$2));");
+ *jlimits = NULL;
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_kyc_limits",
+ params,
+ rs);
+}
diff --git a/src/backenddb/pg_get_kyc_limits.h b/src/backenddb/pg_get_kyc_limits.h
new file mode 100644
index 00000000..b630003e
--- /dev/null
+++ b/src/backenddb/pg_get_kyc_limits.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 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_get_kyc_limits.h
+ * @brief implementation of the get_kyc_limits function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_KYC_LIMITS_H
+#define PG_GET_KYC_LIMITS_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Check an account's KYC limits at an exchange.
+ *
+ * @param cls closure
+ * @param merchant_payto_uri merchant backend instance ID
+ * @param instance_id the instance for which to check
+ * @param exchange_url base URL of the exchange
+ * @param[out] kyc_ok true if no urgent KYC work must be done for this account
+ * @param[out] jlimits set to JSON array with AccountLimits, NULL if unknown (and likely defaults apply or KYC auth is urgently needed, see @a auth_ok)
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_get_kyc_limits (
+ void *cls,
+ const char *merchant_account_uri,
+ const char *instance_id,
+ const char *exchange_url,
+ bool *kyc_ok,
+ json_t **jlimits);
+
+#endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 690f066e..86dec660 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -33,6 +33,7 @@
#include "pg_helper.h"
#include "pg_insert_otp.h"
#include "pg_get_kyc_status.h"
+#include "pg_get_kyc_limits.h"
#include "pg_delete_otp.h"
#include "pg_update_otp.h"
#include "pg_select_otp.h"
@@ -584,6 +585,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
= &TMH_PG_select_category_by_name;
plugin->get_kyc_status
= &TMH_PG_get_kyc_status;
+ plugin->get_kyc_limits
+ = &TMH_PG_get_kyc_limits;
plugin->select_category
= &TMH_PG_select_category;
plugin->update_category