aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/0005-reserves_in.sql45
-rw-r--r--src/exchangedb/Makefile.am1
-rw-r--r--src/exchangedb/exchange_do_insert_kyc_attributes.sql13
-rw-r--r--src/exchangedb/pg_insert_kyc_attributes.c17
-rw-r--r--src/exchangedb/pg_insert_kyc_attributes.h14
-rw-r--r--src/exchangedb/pg_lookup_active_legitimization.c66
-rw-r--r--src/exchangedb/pg_lookup_active_legitimization.h49
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c3
8 files changed, 198 insertions, 10 deletions
diff --git a/src/exchangedb/0005-reserves_in.sql b/src/exchangedb/0005-reserves_in.sql
new file mode 100644
index 000000000..157e52308
--- /dev/null
+++ b/src/exchangedb/0005-reserves_in.sql
@@ -0,0 +1,45 @@
+--
+-- 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/>
+--
+
+CREATE FUNCTION foreign_table_reserves_in5()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserves_in';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wire_target_h_payto_foreign'
+ ' FOREIGN KEY (wire_source_h_payto)'
+ ' REFERENCES wire_targets (wire_target_h_payto)'
+ ' ON DELETE RESTRICT'
+ );
+END
+$$;
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves_in5'
+ ,'exchange-0005'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index ae80a5123..e7619657e 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -171,6 +171,7 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \
pg_test_aml_officer.h pg_test_aml_officer.c \
pg_lookup_aml_officer.h pg_lookup_aml_officer.c \
pg_lookup_pending_legitimization.h pg_lookup_pending_legitimization.c \
+ pg_lookup_active_legitimization.h pg_lookup_active_legitimization.c \
pg_trigger_aml_process.h pg_trigger_aml_process.c \
pg_insert_aml_decision.h pg_insert_aml_decision.c \
pg_select_aggregation_transient.h pg_select_aggregation_transient.c \
diff --git a/src/exchangedb/exchange_do_insert_kyc_attributes.sql b/src/exchangedb/exchange_do_insert_kyc_attributes.sql
index 54ab51bbe..8ae2ff0c3 100644
--- a/src/exchangedb/exchange_do_insert_kyc_attributes.sql
+++ b/src/exchangedb/exchange_do_insert_kyc_attributes.sql
@@ -14,7 +14,9 @@
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
-CREATE OR REPLACE FUNCTION exchange_do_insert_kyc_attributes(
+DELETE FUNCTION exchange_do_insert_kyc_attributes
+ IF EXISTS;
+CREATE FUNCTION exchange_do_insert_kyc_attributes(
IN in_process_row INT8,
IN in_h_payto BYTEA,
IN in_birthday INT4,
@@ -24,6 +26,9 @@ CREATE OR REPLACE FUNCTION exchange_do_insert_kyc_attributes(
IN in_collection_time_ts INT8,
IN in_expiration_time INT8,
IN in_expiration_time_ts INT8,
+ IN in_account_properties TEXT, -- FIXME: use!
+ IN in_new_rules TEXT, -- FIXME: use!
+ IN ina_events TEXT[], -- FIXME: use!
IN in_enc_attributes BYTEA,
IN in_require_aml BOOLEAN,
IN in_kyc_completed_notify_s TEXT,
@@ -41,12 +46,14 @@ INSERT INTO exchange.kyc_attributes
,expiration_time
,encrypted_attributes
,legitimization_serial
+ ,trigger_outcome_serial
) VALUES
(in_h_payto
,in_collection_time_ts
,in_expiration_time_ts
,in_enc_attributes
- ,in_process_row);
+ ,in_process_row
+ ,FIXME);
UPDATE legitimization_processes
SET provider_user_id=in_provider_account_id
@@ -102,5 +109,5 @@ INSERT INTO kyc_alerts
END $$;
-COMMENT ON FUNCTION exchange_do_insert_kyc_attributes(INT8, BYTEA, INT4, TEXT, TEXT, TEXT, INT8, INT8, INT8, BYTEA, BOOL, TEXT)
+COMMENT ON FUNCTION exchange_do_insert_kyc_attributes(INT8, BYTEA, INT4, TEXT, TEXT, TEXT, INT8, INT8, INT8, TEXT, TEXT, TEXT[], BYTEA, BOOL, TEXT)
IS 'Inserts new KYC attributes and updates the status of the legitimization process and the AML status for the account';
diff --git a/src/exchangedb/pg_insert_kyc_attributes.c b/src/exchangedb/pg_insert_kyc_attributes.c
index a72e4e67b..37e833863 100644
--- a/src/exchangedb/pg_insert_kyc_attributes.c
+++ b/src/exchangedb/pg_insert_kyc_attributes.c
@@ -37,9 +37,13 @@ TEH_PG_insert_kyc_attributes (
const char *provider_account_id,
const char *provider_legitimization_id,
struct GNUNET_TIME_Absolute expiration_time,
+ const json_t *account_properties,
+ const json_t *new_rules,
+ bool to_investigate,
+ unsigned int num_events,
+ const char **events,
size_t enc_attributes_size,
- const void *enc_attributes,
- bool require_aml)
+ const void *enc_attributes)
{
struct PostgresClosure *pg = cls;
struct GNUNET_TIME_Timestamp expiration
@@ -72,9 +76,14 @@ TEH_PG_insert_kyc_attributes (
GNUNET_PQ_query_param_timestamp (&collection_time),
GNUNET_PQ_query_param_absolute_time (&expiration_time),
GNUNET_PQ_query_param_timestamp (&expiration),
+ TALER_PQ_query_param_json (account_properties),
+ TALER_PQ_query_param_json (new_rules),
+ GNUNET_PQ_query_param_array_string (pg,
+ num_events,
+ events),
GNUNET_PQ_query_param_fixed_size (enc_attributes,
enc_attributes_size),
- GNUNET_PQ_query_param_bool (require_aml),
+ GNUNET_PQ_query_param_bool (to_investigate),
GNUNET_PQ_query_param_string (kyc_completed_notify_s),
GNUNET_PQ_query_param_end
};
@@ -94,7 +103,7 @@ TEH_PG_insert_kyc_attributes (
"SELECT "
" out_ok"
" FROM exchange_do_insert_kyc_attributes "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"insert_kyc_attributes",
params,
diff --git a/src/exchangedb/pg_insert_kyc_attributes.h b/src/exchangedb/pg_insert_kyc_attributes.h
index 09ebbf04a..e33f3a152 100644
--- a/src/exchangedb/pg_insert_kyc_attributes.h
+++ b/src/exchangedb/pg_insert_kyc_attributes.h
@@ -39,9 +39,13 @@
* @param provider_account_id provider account ID
* @param provider_legitimization_id provider legitimization ID
* @param expiration_time when does the data expire
+ * @param account_properties new account properties
+ * @param new_rules new KYC rules to apply to the account
+ * @param to_investigate true to flag account for investigation
+ * @param num_events length of the @a events array
+ * @param events array of KYC events to trigger
* @param enc_attributes_size number of bytes in @a enc_attributes
* @param enc_attributes encrypted attribute data
- * @param require_aml true to trigger AML
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
@@ -55,9 +59,13 @@ TEH_PG_insert_kyc_attributes (
const char *provider_account_id,
const char *provider_legitimization_id,
struct GNUNET_TIME_Absolute expiration_time,
+ const json_t *account_properties,
+ const json_t *new_rules,
+ bool to_investigate,
+ unsigned int num_events,
+ const char **events,
size_t enc_attributes_size,
- const void *enc_attributes,
- bool require_aml);
+ const void *enc_attributes);
#endif
diff --git a/src/exchangedb/pg_lookup_active_legitimization.c b/src/exchangedb/pg_lookup_active_legitimization.c
new file mode 100644
index 000000000..38c95fd4d
--- /dev/null
+++ b/src/exchangedb/pg_lookup_active_legitimization.c
@@ -0,0 +1,66 @@
+/*
+ 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 exchangedb/pg_lookup_pending_legitimization.c
+ * @brief Implementation of the lookup_pending_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_active_legitimization.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_active_legitimization (
+ void *cls,
+ uint64_t legitimization_process_serial_id,
+ uint32_t *measure_index,
+ json_t **jmeasures)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&legitimization_process_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_json (
+ "jmeasures",
+ jmeasures),
+ GNUNET_PQ_result_spec_uint32 (
+ "measure_index",
+ measure_index),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "lookup_active_legitimization",
+ "SELECT "
+ " lm.jmeasures"
+ ",lp.measure_index"
+ " FROM legitimization_processes lp"
+ " JOIN legitimization_measures lm"
+ " USING (legitimization_measure_serial_id)"
+ " WHERE lp.legitimization_process_serial_id=$1"
+ " AND NOT lm.is_finished;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "lookup_active_legitimization",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_active_legitimization.h b/src/exchangedb/pg_lookup_active_legitimization.h
new file mode 100644
index 000000000..f7bce41cb
--- /dev/null
+++ b/src/exchangedb/pg_lookup_active_legitimization.h
@@ -0,0 +1,49 @@
+/*
+ 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 exchangedb/pg_lookup_active_legitimization.h
+ * @brief implementation of the lookup_active_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_ACTIVE_LEGITIMIZATION_H
+#define PG_LOOKUP_ACTIVE_LEGITIMIZATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup measure data for an active legitimization process.
+ *
+ * @param cls closure
+ * @param legitimization_process_serial_id
+ * row in legitimization_processes table to access
+ * @param[out] measure_index set to the measure the
+ * process is trying to satisfy
+ * @param[out] jmeasures set to the legitimization
+ * measures that were put on the account
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_active_legitimization (
+ void *cls,
+ uint64_t legitimization_process_serial_id,
+ uint32_t *measure_index,
+ json_t **jmeasures);
+
+
+#endif
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index c9ea6a752..3587ed2e0 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -54,6 +54,7 @@
#include "pg_lookup_kyc_status_by_token.h"
#include "pg_lookup_serial_by_table.h"
#include "pg_lookup_pending_legitimization.h"
+#include "pg_lookup_active_legitimization.h"
#include "pg_select_account_merges_above_serial_id.h"
#include "pg_select_all_purse_decisions_above_serial_id.h"
#include "pg_select_purse.h"
@@ -749,6 +750,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &TEH_PG_lookup_denomination_key;
plugin->lookup_pending_legitimization
= &TEH_PG_lookup_pending_legitimization;
+ plugin->lookup_active_legitimization
+ = &TEH_PG_lookup_active_legitimization;
plugin->insert_auditor_denom_sig
= &TEH_PG_insert_auditor_denom_sig;
plugin->select_auditor_denom_sig