[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-exchange] branch master updated: implement insert_sanction_list_h
From: |
gnunet |
Subject: |
[taler-exchange] branch master updated: implement insert_sanction_list_hit |
Date: |
Sun, 05 Jan 2025 22:54:32 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository exchange.
The following commit(s) were added to refs/heads/master by this push:
new a6a25936f implement insert_sanction_list_hit
a6a25936f is described below
commit a6a25936f3df04f5690426b3c7ed5363bd7a558a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jan 5 22:54:24 2025 +0100
implement insert_sanction_list_hit
---
.../exchange_do_insert_sanction_list_hit.sql | 77 ++++++++++++++++++++++
src/exchangedb/pg_insert_sanction_list_hit.c | 54 ++++++++++++++-
src/exchangedb/pg_insert_sanction_list_hit.h | 2 +
src/exchangedb/procedures.sql.in | 1 +
src/include/taler_exchangedb_plugin.h | 2 +
src/include/taler_kyclogic_lib.h | 2 +
src/kyclogic/kyclogic_sanctions.c | 9 ++-
7 files changed, 142 insertions(+), 5 deletions(-)
diff --git a/src/exchangedb/exchange_do_insert_sanction_list_hit.sql
b/src/exchangedb/exchange_do_insert_sanction_list_hit.sql
new file mode 100644
index 000000000..265c25973
--- /dev/null
+++ b/src/exchangedb/exchange_do_insert_sanction_list_hit.sql
@@ -0,0 +1,77 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2025 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/>
+--
+
+DROP FUNCTION IF EXISTS exchange_do_insert_sanction_list_hit;
+CREATE FUNCTION exchange_do_insert_sanction_list_hit(
+ IN in_h_normalized_payto BYTEA,
+ IN in_decision_time INT8,
+ IN in_expiration_time INT8,
+ IN in_properties TEXT, -- can be NULL
+ IN in_new_rules TEXT, -- can be NULL
+ IN in_to_investigate BOOLEAN,
+ IN in_notify_s TEXT,
+ IN ina_events TEXT[],
+ OUT out_outcome_serial_id INT8)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_i INT4;
+ ini_event TEXT;
+BEGIN
+
+INSERT INTO legitimization_outcomes
+ (h_payto
+ ,decision_time
+ ,expiration_time
+ ,jproperties
+ ,to_investigate
+ ,jnew_rules
+ )
+ VALUES
+ (in_h_normalized_payto
+ ,in_decision_time
+ ,in_expiration_time
+ ,in_properties
+ ,in_to_investigate
+ ,in_new_rules
+ )
+ RETURNING
+ outcome_serial_id
+ INTO
+ out_outcome_serial_id;
+
+-- Trigger events
+FOR i IN 1..COALESCE(array_length(ina_events,1),0)
+LOOP
+ ini_event = ina_events[i];
+ INSERT INTO kyc_events
+ (event_timestamp
+ ,event_type)
+ VALUES
+ (in_decision_time
+ ,ini_event);
+END LOOP;
+
+EXECUTE FORMAT (
+ 'NOTIFY %s'
+ ,in_notify_s);
+
+
+END $$;
+
+
+COMMENT ON FUNCTION exchange_do_insert_sanction_list_hit(BYTEA, INT8, INT8,
TEXT, TEXT, BOOLEAN, TEXT, TEXT[])
+ IS 'Insert result from sanction list check into the table';
diff --git a/src/exchangedb/pg_insert_sanction_list_hit.c
b/src/exchangedb/pg_insert_sanction_list_hit.c
index fa8380f9c..639b1f3bf 100644
--- a/src/exchangedb/pg_insert_sanction_list_hit.c
+++ b/src/exchangedb/pg_insert_sanction_list_hit.c
@@ -33,9 +33,59 @@ TEH_PG_insert_sanction_list_hit (
bool to_investigate,
const json_t *new_rules,
const json_t *account_properties,
+ struct GNUNET_TIME_Timestamp expiration_time,
unsigned int num_events,
const char **events)
{
- GNUNET_break (0); // FIXME-#9053: not implemented
- return -2;
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp now
+ = GNUNET_TIME_timestamp_get ();
+ struct TALER_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ char *notify_s
+ = GNUNET_PQ_get_event_notify_channel (&rep.header);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_timestamp (&expiration_time),
+ NULL != account_properties
+ ? TALER_PQ_query_param_json (account_properties)
+ : GNUNET_PQ_query_param_null (),
+ NULL != new_rules
+ ? TALER_PQ_query_param_json (new_rules)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_bool (to_investigate),
+ GNUNET_PQ_query_param_string (notify_s),
+ GNUNET_PQ_query_param_array_ptrs_string (num_events,
+ events,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ uint64_t outcome_serial_id;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("outcome_serial_id",
+ &outcome_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "do_insert_sanction_list_hit",
+ "SELECT"
+ " out_outcome_serial_id"
+ " FROM exchange_insert_sanction_list_hit"
+ "($1,$2,$3,$4,$5,$6,$7,$8);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "do_insert_sanction_list_hit",
+ params,
+ rs);
+ (void) outcome_serial_id;
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ GNUNET_free (notify_s);
+ GNUNET_PQ_event_do_poll (pg->conn);
+ return qs;
}
diff --git a/src/exchangedb/pg_insert_sanction_list_hit.h
b/src/exchangedb/pg_insert_sanction_list_hit.h
index 3dc425a74..5149034fd 100644
--- a/src/exchangedb/pg_insert_sanction_list_hit.h
+++ b/src/exchangedb/pg_insert_sanction_list_hit.h
@@ -36,6 +36,7 @@
* @param new_rules new KYC rules to apply to the account, NULL to preserve
* existing rules
* @param account_properties new account properties
+ * @param expiration_time when does the sanction list entry expire?
* @param num_events length of the @a events array
* @param events array of KYC events to trigger
* @return database transaction status
@@ -47,6 +48,7 @@ TEH_PG_insert_sanction_list_hit (
bool to_investigate,
const json_t *new_rules,
const json_t *account_properties,
+ struct GNUNET_TIME_Timestamp expiration_time,
unsigned int num_events,
const char **events);
diff --git a/src/exchangedb/procedures.sql.in b/src/exchangedb/procedures.sql.in
index 16c1f2b2b..f2936b5a7 100644
--- a/src/exchangedb/procedures.sql.in
+++ b/src/exchangedb/procedures.sql.in
@@ -59,5 +59,6 @@ SET search_path TO exchange;
#include "exchange_do_persist_kyc_attributes.sql"
#include "exchange_do_insert_aml_program_failure.sql"
#include "exchange_do_set_aml_lock.sql"
+#include "exchange_do_insert_sanction_list_hit.sql"
COMMIT;
diff --git a/src/include/taler_exchangedb_plugin.h
b/src/include/taler_exchangedb_plugin.h
index 70c827a96..db6801732 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -7390,6 +7390,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param new_rules new KYC rules to apply to the account, NULL to preserve
* existing rules
* @param account_properties new account properties
+ * @param expiration_time when does the sanction list entry expire?
* @param num_events length of the @a events array
* @param events array of KYC events to trigger
* @return database transaction status
@@ -7401,6 +7402,7 @@ struct TALER_EXCHANGEDB_Plugin
bool to_investigate,
const json_t *new_rules,
const json_t *account_properties,
+ struct GNUNET_TIME_Timestamp expiration_time,
unsigned int num_events,
const char **events);
diff --git a/src/include/taler_kyclogic_lib.h b/src/include/taler_kyclogic_lib.h
index 360c57a84..35016e970 100644
--- a/src/include/taler_kyclogic_lib.h
+++ b/src/include/taler_kyclogic_lib.h
@@ -1143,6 +1143,7 @@ struct TALER_KYCLOGIC_SanctionRater;
* @param cls closure
* @param ec error code, #TALER_EC_NONE on success
* @param best_match identifies the sanction list entry with the best match
+ * @param expiration_time when does the sanction list entry expire
* @param rating likelihood of the match, from 0 (none) to 1 (perfect)
* @param confidence confidence in the evaluation, from 0 (none) to 1 (perfect)
*/
@@ -1151,6 +1152,7 @@ typedef void
void *cls,
enum TALER_ErrorCode ec,
const char *best_match,
+ struct GNUNET_TIME_Timestamp expiration_time,
double rating,
double confidence);
diff --git a/src/kyclogic/kyclogic_sanctions.c
b/src/kyclogic/kyclogic_sanctions.c
index 018ddfe72..86406fe3f 100644
--- a/src/kyclogic/kyclogic_sanctions.c
+++ b/src/kyclogic/kyclogic_sanctions.c
@@ -199,21 +199,23 @@ process_buffer (struct TALER_KYCLOGIC_SanctionRater *sr)
char *nl;
double rating;
double confidence;
+ unsigned long long expire;
char best_match[1024];
size_t line_len;
+
nl = memchr (buf,
'\n',
buf_len);
GNUNET_assert (NULL != nl);
*nl = '\0';
line_len = nl - buf;
- if (3 !=
+ if (4 !=
sscanf (buf,
- "%lf %lf %1023s",
-
+ "%lf %lf %llu %1023s",
&rating,
&confidence,
+ &expire,
best_match))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -231,6 +233,7 @@ process_buffer (struct TALER_KYCLOGIC_SanctionRater *sr)
ee->cb (ee->cb_cls,
TALER_EC_NONE,
best_match,
+ GNUNET_TIME_timestamp_from_s (expire),
rating,
confidence);
free (ee->write_buf);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-exchange] branch master updated: implement insert_sanction_list_hit,
gnunet <=