commit ebf7eab2d541bd350e203838cd5d1f454572f80b parent 82a0b6522441712c514d836a7e71d37116b0c2f9 Author: Christian Grothoff <christian@grothoff.org> Date: Thu, 31 Oct 2024 11:40:42 +0100 work on DB routines Diffstat:
60 files changed, 253 insertions(+), 283 deletions(-)
diff --git a/src/exchangedb/0002-account_merges.sql b/src/exchangedb/0002-account_merges.sql @@ -54,6 +54,12 @@ BEGIN ,partition_suffix ); PERFORM comment_partitioned_column( + 'hash over the normalized (!) payto:// URI that identifies the receiving wallet' + ,'wallet_h_payto' + ,table_name + ,partition_suffix + ); + PERFORM comment_partitioned_column( 'signature by the reserve private key affirming the merge, of type TALER_SIGNATURE_WALLET_ACCOUNT_MERGE' ,'reserve_sig' ,table_name diff --git a/src/exchangedb/0002-kyc_alerts.sql b/src/exchangedb/0002-kyc_alerts.sql @@ -22,6 +22,6 @@ CREATE TABLE kyc_alerts COMMENT ON TABLE kyc_alerts IS 'alerts about completed KYC events reliably notifying other components (even if they are not running)'; COMMENT ON COLUMN kyc_alerts.h_payto - IS 'hash of the payto://-URI for which the KYC status changed'; + IS 'hash of the normalized payto://-URI for which the KYC status changed'; COMMENT ON COLUMN kyc_alerts.trigger_type IS 'identifies the receiver of the alert, as the same h_payto may require multiple components to be notified'; diff --git a/src/exchangedb/0002-legitimization_processes.sql b/src/exchangedb/0002-legitimization_processes.sql @@ -49,7 +49,7 @@ BEGIN ,shard_suffix ); PERFORM comment_partitioned_column( - 'foreign key linking the entry to the wire_targets table, NOT a primary key (multiple legitimizations are possible per wire target)' + 'hash over the normalized payto URI; foreign key linking the entry to the wire_targets table, NOT a primary key (multiple legitimizations are possible per wire target)' ,'h_payto' ,'legitimization_processes' ,shard_suffix diff --git a/src/exchangedb/0005-kycauths_in.sql b/src/exchangedb/0005-kycauths_in.sql @@ -43,8 +43,11 @@ BEGIN ,table_name ,partition_suffix ); + -- FIXME: check that the *full* payto URI is indeed the best choice here, + -- given that this is mostly used for KYC, we may prefer the normalized + -- payto URI instead! Not sure, to be checked! PERFORM comment_partitioned_column( - 'Identifies the debited bank account and KYC status' + 'Identifies the debited bank account and KYC status by the hash over the full payto URI' ,'wire_source_h_payto' ,table_name ,partition_suffix diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am @@ -195,7 +195,6 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \ pg_lookup_pending_legitimization.h pg_lookup_pending_legitimization.c \ pg_lookup_completed_legitimization.h pg_lookup_completed_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 \ pg_find_aggregation_transient.h pg_find_aggregation_transient.c \ diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql b/src/exchangedb/exchange_do_insert_aml_decision.sql @@ -17,7 +17,8 @@ DROP FUNCTION IF EXISTS exchange_do_insert_aml_decision; CREATE FUNCTION exchange_do_insert_aml_decision( IN in_payto_uri TEXT, -- can be NULL! - IN in_h_payto BYTEA, + IN in_h_normalized_payto BYTEA, + IN in_h_full_payto BYTEA, -- can be NULL! IN in_decision_time INT8, IN in_expiration_time INT8, IN in_properties TEXT, -- can be NULL @@ -62,7 +63,7 @@ out_invalid_officer=FALSE; SELECT decision_time INTO out_last_date FROM legitimization_outcomes - WHERE h_payto=in_h_payto + WHERE h_payto=in_h_normalized_payto AND is_active ORDER BY decision_time DESC; @@ -75,7 +76,7 @@ THEN END IF; UPDATE legitimization_outcomes SET is_active=FALSE - WHERE h_payto=in_h_payto + WHERE h_payto=in_h_normalized_payto AND is_active; ELSE out_last_date = 0; @@ -84,7 +85,7 @@ END IF; SELECT access_token INTO my_access_token FROM wire_targets - WHERE wire_target_h_payto=in_h_payto; + WHERE h_normalized_payto=in_h_normalized_payto; IF NOT FOUND THEN @@ -97,9 +98,11 @@ THEN INSERT INTO wire_targets (wire_target_h_payto + ,h_normalized_payto ,payto_uri) VALUES - (in_h_payto + (in_h_full_payto + ,in_h_normalized_payto ,in_payto_uri) RETURNING access_token INTO my_access_token; @@ -146,7 +149,7 @@ END IF; UPDATE legitimization_outcomes SET is_active=FALSE - WHERE h_payto=in_h_payto + WHERE h_payto=in_h_normalized_payto -- this clause is a minor optimization to avoid -- updating outcomes that have long expired. AND expiration_time >= in_decision_time; @@ -161,7 +164,7 @@ INSERT INTO legitimization_outcomes ,jnew_rules ) VALUES - (in_h_payto + (in_h_normalized_payto ,in_decision_time ,in_expiration_time ,in_properties @@ -182,7 +185,7 @@ INSERT INTO aml_history ,decider_pub ,decider_sig ) VALUES - (in_h_payto + (in_h_normalized_payto ,my_outcome_serial_id ,in_justification ,in_decider_pub @@ -194,7 +197,7 @@ INSERT INTO kyc_alerts (h_payto ,trigger_type) VALUES - (in_h_payto,1) + (in_h_normalized_payto,1) ON CONFLICT DO NOTHING; EXECUTE FORMAT ( @@ -205,5 +208,5 @@ EXECUTE FORMAT ( END $$; -COMMENT ON FUNCTION exchange_do_insert_aml_decision(TEXT, BYTEA, INT8, INT8, TEXT, TEXT, BOOLEAN, TEXT, TEXT, TEXT, BYTEA, BYTEA, TEXT) +COMMENT ON FUNCTION exchange_do_insert_aml_decision(TEXT, BYTEA, BYTEA, INT8, INT8, TEXT, TEXT, BOOLEAN, TEXT, TEXT, TEXT, BYTEA, BYTEA, TEXT) IS 'Checks whether the AML officer is eligible to make AML decisions and if so inserts the decision into the table'; diff --git a/src/exchangedb/exchange_do_kycauth_in_insert.sql b/src/exchangedb/exchange_do_kycauth_in_insert.sql @@ -21,6 +21,7 @@ CREATE PROCEDURE exchange_do_kycauth_in_insert( IN in_wire_reference INT8, IN in_credit taler_amount, IN in_wire_source_h_payto BYTEA, + IN in_h_normalized_payto BYTEA, IN in_payto_uri TEXT, IN in_exchange_account_name TEXT, IN in_execution_date INT8, @@ -60,10 +61,12 @@ BEGIN THEN INSERT INTO wire_targets (wire_target_h_payto + ,h_normalized_payto ,payto_uri ,target_pub ) VALUES ( in_wire_source_h_payto + ,in_h_normalized_payto ,in_payto_uri ,in_account_pub); END IF; diff --git a/src/exchangedb/exchange_do_reserves_in_insert.sql b/src/exchangedb/exchange_do_reserves_in_insert.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2014--2023 Taler Systems SA +-- Copyright (C) 2014--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 @@ -15,7 +15,8 @@ -- -CREATE OR REPLACE FUNCTION exchange_do_array_reserves_insert( +DROP FUNCTION IF EXISTS exchange_do_array_reserves_insert; +CREATE FUNCTION exchange_do_array_reserves_insert( IN in_gc_date INT8, IN in_reserve_expiration INT8, IN ina_reserve_pub BYTEA[], @@ -24,6 +25,7 @@ CREATE OR REPLACE FUNCTION exchange_do_array_reserves_insert( IN ina_exchange_account_name TEXT[], IN ina_execution_date INT8[], IN ina_wire_source_h_payto BYTEA[], + IN ina_h_normalized_payto BYTEA[], IN ina_payto_uri TEXT[], IN ina_notify TEXT[]) RETURNS SETOF exchange_do_array_reserve_insert_return_type @@ -40,6 +42,7 @@ DECLARE ini_exchange_account_name TEXT; ini_execution_date INT8; ini_wire_source_h_payto BYTEA; + ini_h_normalized_payto BYTEA; ini_payto_uri TEXT; ini_notify TEXT; BEGIN @@ -52,6 +55,7 @@ BEGIN ini_exchange_account_name = ina_exchange_account_name[i]; ini_execution_date = ina_execution_date[i]; ini_wire_source_h_payto = ina_wire_source_h_payto[i]; + ini_h_normalized_payto = ina_h_normalized_payto[i]; ini_payto_uri = ina_payto_uri[i]; ini_notify = ina_notify[i]; @@ -59,9 +63,11 @@ BEGIN INSERT INTO wire_targets (wire_target_h_payto + ,h_normalized_payto ,payto_uri ) VALUES ( ini_wire_source_h_payto + ini_h_normalized_payto ,ini_payto_uri ) ON CONFLICT DO NOTHING; diff --git a/src/exchangedb/exchange_do_trigger_kyc_rule_for_account.sql b/src/exchangedb/exchange_do_trigger_kyc_rule_for_account.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2014--2022 Taler Systems SA +-- Copyright (C) 2014--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 @@ -17,10 +17,11 @@ DROP FUNCTION IF EXISTS exchange_do_trigger_kyc_rule_for_account; CREATE FUNCTION exchange_do_trigger_kyc_rule_for_account( - IN in_h_payto BYTEA, + IN in_h_normalized_payto BYTEA, IN in_account_pub BYTEA, -- can be NULL, if given, should be SET IN in_merchant_pub BYTEA, -- can be NULL IN in_payto_uri TEXT, -- can be NULL + IN in_h_full_payto BYTEA, IN in_now INT8, IN in_jmeasures TEXT, IN in_display_priority INT4, @@ -36,7 +37,7 @@ DECLARE my_reserve_pub BYTEA; BEGIN -- Note: in_payto_uri is allowed to be NULL *if* --- in_h_payto is already in wire_targets +-- in_h_normalized_payto is already in wire_targets SELECT @@ -45,7 +46,7 @@ SELECT INTO my_rec FROM wire_targets - WHERE wire_target_h_payto=in_h_payto; + WHERE h_normalized_payto=in_h_normalized_payto; IF FOUND THEN @@ -59,10 +60,12 @@ ELSE INSERT INTO wire_targets (payto_uri ,wire_target_h_payto + ,h_normalized_payto ,target_pub) VALUES (in_payto_uri - ,in_h_payto + ,in_h_full_payto + ,in_h_normalized_payto ,in_account_pub) RETURNING access_token @@ -72,20 +75,19 @@ END IF; IF out_bad_kyc_auth THEN - -- Check most recent reserve_in wire transfer, we also - -- allow that reserve public key for authentication! - SELECT reserve_pub - INTO my_reserve_pub - FROM reserves_in - WHERE wire_source_h_payto=in_h_payto - ORDER BY execution_date DESC - LIMIT 1; + -- Check reserve_in wire transfers, we also + -- allow those reserve public keys for authentication! + PERFORM FROM reserves_in + WHERE wire_source_h_payto IN ( + SELECT wire_target_h_payto + FROM wire_targets + WHERE h_normalized_payto=in_h_normalized_payto + ) + AND reserve_pub = in_merchant_pub + ORDER BY execution_date DESC; IF FOUND THEN - IF in_merchant_pub = my_reserve_pub - THEN - out_bad_kyc_auth = FALSE; - END IF; + out_bad_kyc_auth = FALSE; END IF; END IF; -- First check if a perfectly equivalent legi measure diff --git a/src/exchangedb/pg_aggregate.c b/src/exchangedb/pg_aggregate.c @@ -31,7 +31,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_aggregate ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct TALER_WireTransferIdentifierRawP *wtid, struct TALER_Amount *total) diff --git a/src/exchangedb/pg_create_aggregation_transient.c b/src/exchangedb/pg_create_aggregation_transient.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_create_aggregation_transient ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, const char *exchange_account_section, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct TALER_WireTransferIdentifierRawP *wtid, diff --git a/src/exchangedb/pg_delete_aggregation_transient.c b/src/exchangedb/pg_delete_aggregation_transient.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_delete_aggregation_transient ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, const struct TALER_WireTransferIdentifierRawP *wtid) { struct PostgresClosure *pg = cls; diff --git a/src/exchangedb/pg_do_purse_merge.c b/src/exchangedb/pg_do_purse_merge.c @@ -40,7 +40,7 @@ TEH_PG_do_purse_merge ( bool *in_conflict) { struct PostgresClosure *pg = cls; - struct TALER_PaytoHashP h_payto; + struct TALER_NormalizedPaytoHashP h_payto; struct GNUNET_TIME_Timestamp expiration = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time); struct GNUNET_PQ_QueryParam params[] = { @@ -67,13 +67,13 @@ TEH_PG_do_purse_merge ( }; { - char *payto_uri; + struct TALER_NormalizedPayto payto_uri; payto_uri = TALER_reserve_make_payto (pg->exchange_url, reserve_pub); - TALER_payto_hash (payto_uri, - &h_payto); - GNUNET_free (payto_uri); + TALER_normalized_payto_hash (payto_uri, + &h_payto); + GNUNET_free (payto_uri.normalized_payto); } PREPARE (pg, "call_purse_merge", diff --git a/src/exchangedb/pg_do_reserve_purse.c b/src/exchangedb/pg_do_reserve_purse.c @@ -24,6 +24,8 @@ #include "taler_pq_lib.h" #include "pg_do_reserve_purse.h" #include "pg_helper.h" + + /** * Function called insert request to merge a purse into a reserve by the * respective purse merge key. The purse must not have been merged into a @@ -56,7 +58,7 @@ TEH_PG_do_reserve_purse ( { struct PostgresClosure *pg = cls; struct TALER_Amount zero_fee; - struct TALER_PaytoHashP h_payto; + struct TALER_NormalizedPaytoHashP h_payto; struct GNUNET_TIME_Timestamp reserve_expiration = GNUNET_TIME_absolute_to_timestamp ( GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), @@ -93,18 +95,17 @@ TEH_PG_do_reserve_purse ( }; { - char *payto_uri; + struct TALER_NormalizedPayto payto_uri; payto_uri = TALER_reserve_make_payto (pg->exchange_url, reserve_pub); - TALER_payto_hash (payto_uri, - &h_payto); - GNUNET_free (payto_uri); + TALER_normalized_payto_hash (payto_uri, + &h_payto); + GNUNET_free (payto_uri.normalized_payto); } GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (pg->currency, &zero_fee)); - /* Used in #postgres_do_reserve_purse() */ PREPARE (pg, "call_reserve_purse", "SELECT" diff --git a/src/exchangedb/pg_drain_kyc_alert.c b/src/exchangedb/pg_drain_kyc_alert.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_drain_kyc_alert (void *cls, uint32_t trigger_type, - struct TALER_PaytoHashP *h_payto) + struct TALER_NormalizedPaytoHashP *h_payto) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { diff --git a/src/exchangedb/pg_find_aggregation_transient.c b/src/exchangedb/pg_find_aggregation_transient.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -112,7 +112,7 @@ get_transients_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_find_aggregation_transient ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, TALER_EXCHANGEDB_TransientAggregationCallback cb, void *cb_cls) { diff --git a/src/exchangedb/pg_get_kyc_rules.c b/src/exchangedb/pg_get_kyc_rules.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_get_kyc_rules ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, bool *no_account_pub, union TALER_AccountPublicKeyP *account_pub, bool *no_reserve_pub, @@ -80,7 +80,7 @@ TEH_PG_get_kyc_rules ( " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)" " LEFT JOIN legitimization_outcomes lo" " ON (lo.h_payto = wt.wire_target_h_payto)" - " WHERE wt.wire_target_h_payto=$1" + " WHERE wt.h_normalized_payto=$1" " AND COALESCE(lo.expiration_time >= $2, TRUE)" " AND COALESCE(lo.is_active, TRUE)" " ORDER BY ri.execution_date DESC" diff --git a/src/exchangedb/pg_get_pending_kyc_requirement_process.c b/src/exchangedb/pg_get_pending_kyc_requirement_process.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_get_pending_kyc_requirement_process ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, const char *provider_name, char **redirect_url) { diff --git a/src/exchangedb/pg_insert_aml_decision.c b/src/exchangedb/pg_insert_aml_decision.c @@ -30,8 +30,8 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_aml_decision ( void *cls, - const char *payto_uri, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPayto payto_uri, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Timestamp decision_time, struct GNUNET_TIME_Timestamp expiration_time, const json_t *properties, @@ -53,6 +53,7 @@ TEH_PG_insert_aml_decision ( .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED), .h_payto = *h_payto }; + struct TALER_FullPaytoHashP h_full_payto; char *notify_s = GNUNET_PQ_get_event_notify_channel (&rep.header); struct GNUNET_PQ_QueryParam params[] = { @@ -60,6 +61,9 @@ TEH_PG_insert_aml_decision ( ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_string (payto_uri), GNUNET_PQ_query_param_auto_from_type (h_payto), + NULL == payto_uri + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_auto_from_type (&h_full_payto), GNUNET_PQ_query_param_timestamp (&decision_time), GNUNET_PQ_query_param_timestamp (&expiration_time), NULL != properties @@ -92,6 +96,8 @@ TEH_PG_insert_aml_decision ( }; enum GNUNET_DB_QueryStatus qs; + TALER_full_payto_hash (payto_uri, + &h_full_payto); PREPARE (pg, "do_insert_aml_decision", "SELECT" @@ -100,7 +106,7 @@ TEH_PG_insert_aml_decision ( ",out_last_date" ",out_legitimization_measure_serial_id" " FROM exchange_do_insert_aml_decision" - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "do_insert_aml_decision", params, diff --git a/src/exchangedb/pg_insert_kyc_attributes.c b/src/exchangedb/pg_insert_kyc_attributes.c @@ -37,7 +37,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_kyc_attributes ( void *cls, uint64_t process_row, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, uint32_t birthday, struct GNUNET_TIME_Timestamp collection_time, const char *provider_name, diff --git a/src/exchangedb/pg_insert_kyc_failure.c b/src/exchangedb/pg_insert_kyc_failure.c @@ -31,7 +31,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_kyc_failure ( void *cls, uint64_t process_row, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, const char *provider_name, const char *provider_account_id, const char *provider_legitimization_id, diff --git a/src/exchangedb/pg_insert_kyc_requirement_process.c b/src/exchangedb/pg_insert_kyc_requirement_process.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_kyc_requirement_process ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, uint32_t measure_index, uint64_t legitimization_measure_serial_id, const char *provider_name, diff --git a/src/exchangedb/pg_insert_programmatic_legitimization_outcome.c b/src/exchangedb/pg_insert_programmatic_legitimization_outcome.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_programmatic_legitimization_outcome ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Timestamp decision_time, struct GNUNET_TIME_Absolute expiration_time, const json_t *account_properties, diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c @@ -168,10 +168,12 @@ static enum GNUNET_DB_QueryStatus irbt_cb_table_wire_targets (struct PostgresClosure *pg, const struct TALER_EXCHANGEDB_TableData *td) { - struct TALER_PaytoHashP payto_hash; + struct TALER_NormalizedPaytoHashP normalized_payto_hash; + struct TALER_FullPaytoHashP full_payto_hash; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), - GNUNET_PQ_query_param_auto_from_type (&payto_hash), + GNUNET_PQ_query_param_auto_from_type (&full_payto_hash), + GNUNET_PQ_query_param_auto_from_type (&normalized_payto_hash), GNUNET_PQ_query_param_string ( td->details.wire_targets.payto_uri), GNUNET_PQ_query_param_auto_from_type ( @@ -183,19 +185,23 @@ irbt_cb_table_wire_targets (struct PostgresClosure *pg, GNUNET_PQ_query_param_end }; - TALER_payto_hash ( - td->details.wire_targets.payto_uri, - &payto_hash); + TALER_full_payto_hash ( + td->details.wire_targets.full_payto_uri, + &full_payto_hash); + TALER_full_payto_normalize_and_hash ( + td->details.wire_targets.full_payto_uri, + &h_normalized_payto); PREPARE (pg, "insert_into_table_wire_targets", "INSERT INTO wire_targets" "(wire_target_serial_id" ",wire_target_h_payto" + ",h_normalized_payto" ",payto_uri" ",access_token" ",target_pub" ") VALUES " - "($1, $2, $3, $4, $5);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wire_targets", params); diff --git a/src/exchangedb/pg_insert_reserve_closed.c b/src/exchangedb/pg_insert_reserve_closed.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -32,7 +32,7 @@ TEH_PG_insert_reserve_closed ( void *cls, const struct TALER_ReservePublicKeyP *reserve_pub, struct GNUNET_TIME_Timestamp execution_date, - const char *receiver_account, + const struct TALER_FullPayto receiver_account, const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_Amount *amount_with_fee, const struct TALER_Amount *closing_fee, @@ -41,10 +41,10 @@ TEH_PG_insert_reserve_closed ( struct PostgresClosure *pg = cls; struct TALER_EXCHANGEDB_Reserve reserve; enum GNUNET_DB_QueryStatus qs; - struct TALER_PaytoHashP h_payto; + struct TALER_FullPaytoHashP h_payto; - TALER_payto_hash (receiver_account, - &h_payto); + TALER_full_payto_hash (receiver_account, + &h_payto); { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (reserve_pub), diff --git a/src/exchangedb/pg_iterate_kyc_reference.c b/src/exchangedb/pg_iterate_kyc_reference.c @@ -98,7 +98,7 @@ iterate_kyc_reference_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_iterate_kyc_reference ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, TALER_EXCHANGEDB_LegitimizationProcessCallback lpc, void *lpc_cls) { diff --git a/src/exchangedb/pg_iterate_reserve_close_info.c b/src/exchangedb/pg_iterate_reserve_close_info.c @@ -93,7 +93,7 @@ iterate_reserve_close_info_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_iterate_reserve_close_info ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) diff --git a/src/exchangedb/pg_kyc_provider_account_lookup.c b/src/exchangedb/pg_kyc_provider_account_lookup.c @@ -31,7 +31,7 @@ TEH_PG_kyc_provider_account_lookup ( void *cls, const char *provider_name, const char *provider_legitimization_id, - struct TALER_PaytoHashP *h_payto, + struct TALER_NormalizedPaytoHashP *h_payto, uint64_t *process_row) { struct PostgresClosure *pg = cls; diff --git a/src/exchangedb/pg_kycauth_in_insert.c b/src/exchangedb/pg_kycauth_in_insert.c @@ -32,21 +32,23 @@ TEH_PG_kycauth_in_insert ( const union TALER_AccountPublicKeyP *account_pub, const struct TALER_Amount *credit_amount, struct GNUNET_TIME_Timestamp execution_date, - const char *debit_account_uri, + const struct TALER_FullPayto debit_account_uri, const char *section_name, uint64_t serial_id) { struct PostgresClosure *pg = cls; - struct TALER_PaytoHashP h_payto; - - TALER_payto_hash (debit_account_uri, - &h_payto); + struct TALER_NormalizedPaytoHashP h_normalized_payto; + struct TALER_FullPaytoHashP h_full_payto; + TALER_full_payto_hash (debit_account_uri, + &h_full_payto); + TALER_full_payto_normalize_and_hash (debit_account_uri, + &h_normalized_payto); { struct TALER_KycCompletedEventP rep = { .header.size = htons (sizeof (rep)), .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED), - .h_payto = h_payto + .h_payto = h_normalized_payto }; char *notify_s = GNUNET_PQ_get_event_notify_channel (&rep.header); @@ -55,8 +57,9 @@ TEH_PG_kycauth_in_insert ( GNUNET_PQ_query_param_uint64 (&serial_id), TALER_PQ_query_param_amount (pg->conn, credit_amount), - GNUNET_PQ_query_param_auto_from_type (&h_payto), - GNUNET_PQ_query_param_string (debit_account_uri), + GNUNET_PQ_query_param_auto_from_type (&h_full_payto), + GNUNET_PQ_query_param_auto_from_type (&h_normalized_payto), + GNUNET_PQ_query_param_string (debit_account_uri.full_payto), GNUNET_PQ_query_param_string (section_name), GNUNET_PQ_query_param_timestamp (&execution_date), GNUNET_PQ_query_param_string (notify_s), @@ -68,7 +71,7 @@ TEH_PG_kycauth_in_insert ( "kycauth_in_insert", "CALL" " exchange_do_kycauth_in_insert" - " ($1,$2,$3,$4,$5,$6,$7,$8);"); + " ($1,$2,$3,$4,$5,$6,$7,$8,$9);"); qs = GNUNET_PQ_eval_prepared_non_select ( pg->conn, "kycauth_in_insert", diff --git a/src/exchangedb/pg_lookup_aml_history.c b/src/exchangedb/pg_lookup_aml_history.c @@ -124,7 +124,7 @@ handle_aml_entry (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_lookup_aml_history ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, TALER_EXCHANGEDB_AmlHistoryCallback cb, void *cb_cls) { diff --git a/src/exchangedb/pg_lookup_completed_legitimization.c b/src/exchangedb/pg_lookup_completed_legitimization.c @@ -32,7 +32,7 @@ TEH_PG_lookup_completed_legitimization ( uint64_t legitimization_measure_serial_id, uint32_t measure_index, struct TALER_AccountAccessTokenP *access_token, - struct TALER_PaytoHashP *h_payto, + struct TALER_NormalizedPaytoHashP *h_payto, json_t **jmeasures, bool *is_finished, size_t *encrypted_attributes_len, @@ -73,7 +73,7 @@ TEH_PG_lookup_completed_legitimization ( "lookup_completed_legitimization", "SELECT " " lm.jmeasures" - ",wt.wire_target_h_payto" + ",wt.h_normalized_payto" ",lm.access_token" ",lm.is_finished" ",ka.encrypted_attributes" diff --git a/src/exchangedb/pg_lookup_h_payto_by_access_token.c b/src/exchangedb/pg_lookup_h_payto_by_access_token.c @@ -30,7 +30,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_lookup_h_payto_by_access_token ( void *cls, const struct TALER_AccountAccessTokenP *access_token, - struct TALER_PaytoHashP *h_payto) + struct TALER_NormalizedPaytoHashP *h_payto) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -47,7 +47,7 @@ TEH_PG_lookup_h_payto_by_access_token ( PREPARE (pg, "lookup_h_payto_by_access_token", "SELECT " - " wire_target_h_payto" + " h_normalized_payto" " FROM wire_targets" " WHERE (access_token = $1);"); return GNUNET_PQ_eval_prepared_singleton_select ( diff --git a/src/exchangedb/pg_lookup_kyc_history.c b/src/exchangedb/pg_lookup_kyc_history.c @@ -144,7 +144,7 @@ handle_kyc_entry (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_lookup_kyc_history ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, TALER_EXCHANGEDB_KycHistoryCallback cb, void *cb_cls) { diff --git a/src/exchangedb/pg_lookup_kyc_process_by_account.c b/src/exchangedb/pg_lookup_kyc_process_by_account.c @@ -30,7 +30,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_lookup_kyc_process_by_account ( void *cls, const char *provider_name, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, uint64_t *process_row, struct GNUNET_TIME_Absolute *expiration, char **provider_account_id, diff --git a/src/exchangedb/pg_lookup_kyc_requirement_by_row.c b/src/exchangedb/pg_lookup_kyc_requirement_by_row.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_lookup_kyc_requirement_by_row ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, union TALER_AccountPublicKeyP *account_pub, struct TALER_ReservePublicKeyP *reserve_pub, struct TALER_AccountAccessTokenP *access_token, diff --git a/src/exchangedb/pg_lookup_pending_legitimization.c b/src/exchangedb/pg_lookup_pending_legitimization.c @@ -31,7 +31,7 @@ TEH_PG_lookup_pending_legitimization ( void *cls, uint64_t legitimization_measure_serial_id, struct TALER_AccountAccessTokenP *access_token, - struct TALER_PaytoHashP *h_payto, + struct TALER_NormalizedPaytoHashP *h_payto, json_t **jmeasures, bool *is_finished) { @@ -60,7 +60,7 @@ TEH_PG_lookup_pending_legitimization ( "lookup_pending_legitimization", "SELECT " " lm.jmeasures" - ",wt.wire_target_h_payto" + ",wt.h_normalized_payto" ",lm.access_token" ",lm.is_finished" " FROM legitimization_measures lm" diff --git a/src/exchangedb/pg_lookup_rules_by_access_token.c b/src/exchangedb/pg_lookup_rules_by_access_token.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_lookup_rules_by_access_token ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, json_t **jnew_rules, uint64_t *rowid) { diff --git a/src/exchangedb/pg_lookup_wire_transfer.c b/src/exchangedb/pg_lookup_wire_transfer.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022-2023 Taler Systems SA + Copyright (C) 2022-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 @@ -74,7 +74,7 @@ handle_wt_result (void *cls, uint64_t rowid; struct TALER_PrivateContractHashP h_contract_terms; struct TALER_CoinSpendPublicKeyP coin_pub; - struct TALER_PaytoHashP h_payto; + struct TALER_FullPaytoHashP h_payto; struct TALER_MerchantPublicKeyP merchant_pub; struct GNUNET_TIME_Timestamp exec_time; struct TALER_Amount amount_with_fee; diff --git a/src/exchangedb/pg_reserves_get_origin.c b/src/exchangedb/pg_reserves_get_origin.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -30,8 +30,8 @@ enum GNUNET_DB_QueryStatus TEH_PG_reserves_get_origin ( void *cls, const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_PaytoHashP *h_payto, - char **payto_uri) + struct TALER_FullPaytoHashP *h_payto, + struct TALER_FullPayto *payto_uri) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -44,7 +44,7 @@ TEH_PG_reserves_get_origin ( h_payto), GNUNET_PQ_result_spec_string ( "payto_uri", - payto_uri), + &payto_uri->full_payto), GNUNET_PQ_result_spec_end }; diff --git a/src/exchangedb/pg_reserves_in_insert.c b/src/exchangedb/pg_reserves_in_insert.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022-2023 Taler Systems SA + Copyright (C) 2022-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 @@ -140,7 +140,10 @@ TEH_PG_reserves_in_insert ( struct PostgresClosure *pg = cls; unsigned int dups = 0; - struct TALER_PaytoHashP h_paytos[GNUNET_NZL (reserves_length)]; + struct TALER_FullPaytoHashP h_full_paytos[ + GNUNET_NZL (reserves_length)]; + struct TALER_NormalizedPaytoHashP h_normalized_paytos[ + GNUNET_NZL (reserves_length)]; char *notify_s[GNUNET_NZL (reserves_length)]; struct TALER_ReservePublicKeyP reserve_pubs[GNUNET_NZL (reserves_length)]; struct TALER_Amount balances[GNUNET_NZL (reserves_length)]; @@ -162,13 +165,15 @@ TEH_PG_reserves_in_insert ( { const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i]; - TALER_payto_hash (reserve->sender_account_details, - &h_paytos[i]); + TALER_full_payto_hash (reserve->sender_account_details, + &h_full_paytos[i]); + TALER_full_payto_normalize_and_hash (reserve->sender_account_details, + &h_normalized_paytos[i]); notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub); reserve_pubs[i] = *reserve->reserve_pub; balances[i] = *reserve->balance; execution_times[i] = reserve->execution_time; - sender_account_details[i] = reserve->sender_account_details; + sender_account_details[i] = reserve->sender_account_details.full_payto; exchange_account_names[i] = reserve->exchange_account_name; wire_references[i] = reserve->wire_reference; } @@ -195,7 +200,7 @@ TEH_PG_reserves_in_insert ( " transaction_duplicate" ",ruuid" " FROM exchange_do_array_reserves_insert" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);"); + " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);"); { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_timestamp (&gc), @@ -220,7 +225,11 @@ TEH_PG_reserves_in_insert ( pg->conn), GNUNET_PQ_query_param_array_auto_from_type ( reserves_length, - h_paytos, + h_full_paytos, + pg->conn), + GNUNET_PQ_query_param_array_auto_from_type ( + reserves_length, + h_normalized_paytos, pg->conn), GNUNET_PQ_query_param_array_ptrs_string ( reserves_length, diff --git a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c @@ -113,7 +113,7 @@ get_kyc_amounts_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_aggregation_amounts_for_kyc_check ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) diff --git a/src/exchangedb/pg_select_aggregation_transient.c b/src/exchangedb/pg_select_aggregation_transient.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_select_aggregation_transient ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, const struct TALER_MerchantPublicKeyP *merchant_pub, const char *exchange_account_section, struct TALER_WireTransferIdentifierRawP *wtid, diff --git a/src/exchangedb/pg_select_aml_attributes.c b/src/exchangedb/pg_select_aml_attributes.c @@ -109,7 +109,7 @@ handle_aml_attributes (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_aml_attributes ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, uint64_t offset, int64_t limit, TALER_EXCHANGEDB_AmlAttributeCallback cb, diff --git a/src/exchangedb/pg_select_aml_decisions.c b/src/exchangedb/pg_select_aml_decisions.c @@ -71,7 +71,7 @@ handle_aml_result (void *cls, for (unsigned int i = 0; i<num_results; i++) { - struct TALER_PaytoHashP h_payto; + struct TALER_NormalizedPaytoHashP h_payto; uint64_t rowid; char *justification = NULL; struct GNUNET_TIME_Timestamp decision_time; @@ -135,7 +135,7 @@ handle_aml_result (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_aml_decisions ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, enum TALER_EXCHANGE_YesNoAll investigation_only, enum TALER_EXCHANGE_YesNoAll active_only, uint64_t offset, diff --git a/src/exchangedb/pg_select_batch_deposits_missing_wire.c b/src/exchangedb/pg_select_batch_deposits_missing_wire.c @@ -71,7 +71,7 @@ missing_wire_cb (void *cls, { uint64_t batch_deposit_serial_id; struct GNUNET_TIME_Timestamp deadline; - struct TALER_PaytoHashP wire_target_h_payto; + struct TALER_FullPaytoHashP wire_target_h_payto; struct TALER_Amount total_amount; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id", diff --git a/src/exchangedb/pg_select_deposit_amounts_for_kyc_check.c b/src/exchangedb/pg_select_deposit_amounts_for_kyc_check.c @@ -111,7 +111,7 @@ get_kyc_amounts_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_deposit_amounts_for_kyc_check ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) @@ -138,7 +138,11 @@ TEH_PG_select_deposit_amounts_for_kyc_check ( " FROM batch_deposits bd" " JOIN coin_deposits cd" " USING (batch_deposit_serial_id)" - " WHERE wire_target_h_payto=$1" + " WHERE wire_target_h_payto IN (" + " SELECT wire_target_h_payto" + " FROM wire_targets" + " WHERE h_normalized_payto=$1" + " )" " AND bd.exchange_timestamp >= $2" " ORDER BY bd.exchange_timestamp DESC"); qs = GNUNET_PQ_eval_prepared_multi_select ( diff --git a/src/exchangedb/pg_select_kyc_attributes.c b/src/exchangedb/pg_select_kyc_attributes.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -49,7 +49,7 @@ struct GetAttributesContext /** * Key of our query. */ - const struct TALER_PaytoHashP *h_payto; + const struct TALER_NormalizedPaytoHashP *h_payto; /** * Flag set to #GNUNET_OK as long as everything is fine. @@ -117,7 +117,7 @@ get_attributes_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_kyc_attributes ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, TALER_EXCHANGEDB_AttributeCallback cb, void *cb_cls) { diff --git a/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -112,7 +112,7 @@ get_kyc_amounts_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_merge_amounts_for_kyc_check ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) diff --git a/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -113,7 +113,7 @@ get_kyc_amounts_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_select_withdraw_amounts_for_kyc_check ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) @@ -142,7 +142,11 @@ TEH_PG_select_withdraw_amounts_for_kyc_check ( " ON (rh.reserve_pub = ri.reserve_pub)" " JOIN reserves_out ro" " ON (ro.reserve_out_serial_id = rh.serial_id)" - " WHERE ri.wire_source_h_payto=$1" + " WHERE ri.wire_source_h_payto IN (" + " SELECT wire_target_h_payto" + " FROM wire_targets" + " WHERE h_normalized_payto=$1" + " )" " AND rh.table_name='reserves_out'" " AND ro.execution_date >= $2" " ORDER BY rh.reserve_history_serial_id DESC"); diff --git a/src/exchangedb/pg_store_wire_transfer_out.c b/src/exchangedb/pg_store_wire_transfer_out.c @@ -25,12 +25,13 @@ #include "pg_store_wire_transfer_out.h" #include "pg_helper.h" + enum GNUNET_DB_QueryStatus TEH_PG_store_wire_transfer_out ( void *cls, struct GNUNET_TIME_Timestamp date, const struct TALER_WireTransferIdentifierRawP *wtid, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, const char *exchange_account_section, const struct TALER_Amount *amount) { diff --git a/src/exchangedb/pg_trigger_aml_process.c b/src/exchangedb/pg_trigger_aml_process.c @@ -1,58 +0,0 @@ -/* - 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 exchangedb/pg_trigger_aml_process.c - * @brief Implementation of the trigger_aml_process 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_trigger_aml_process.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_trigger_aml_process ( - void *cls, - const struct TALER_PaytoHashP *h_payto, - const struct TALER_Amount *threshold_crossed) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_payto), - TALER_PQ_query_param_amount (pg->conn, - threshold_crossed), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "trigger_aml_process", - "INSERT INTO aml_status" - "(h_payto" - ",threshold" - ",status)" - " VALUES" - " ($1, $2, 1)" // 1: decision needed - " ON CONFLICT (h_payto) DO" - " UPDATE SET" - " threshold=$2" - " ,status=aml_status.status | 1;"); // do not clear 'frozen' status - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "trigger_aml_process", - params); -} diff --git a/src/exchangedb/pg_trigger_aml_process.h b/src/exchangedb/pg_trigger_aml_process.h @@ -1,45 +0,0 @@ -/* - 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 exchangedb/pg_trigger_aml_process.h - * @brief implementation of the trigger_aml_process function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_TRIGGER_AML_PROCESS_H -#define PG_TRIGGER_AML_PROCESS_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_exchangedb_plugin.h" - - -/** - * Trigger AML process, an account has crossed the threshold. Inserts or - * updates the AML status. - * - * @param cls closure - * @param h_payto account for which the attribute data is stored - * @param threshold_crossed existing threshold that was crossed - * @return database transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_trigger_aml_process ( - void *cls, - const struct TALER_NormalizedPaytoHashP *h_payto, - const struct TALER_Amount *threshold_crossed); - - -#endif diff --git a/src/exchangedb/pg_trigger_kyc_rule_for_account.c b/src/exchangedb/pg_trigger_kyc_rule_for_account.c @@ -29,8 +29,8 @@ enum GNUNET_DB_QueryStatus TEH_PG_trigger_kyc_rule_for_account ( void *cls, - const char *payto_uri, - const struct TALER_PaytoHashP *h_payto, + const struct TLAER_FullPayto payto_uri, + const struct TALER_NormalizedPaytoHashP *h_payto, const union TALER_AccountPublicKeyP *set_account_pub, const struct TALER_MerchantPublicKeyP *check_merchant_pub, const json_t *jmeasures, @@ -48,6 +48,7 @@ TEH_PG_trigger_kyc_rule_for_account ( }; char *notify_str = GNUNET_PQ_get_event_notify_channel (&rep.header); + struct TALER_FullPaytoHashP h_full_payto; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (h_payto), NULL == set_account_pub @@ -56,9 +57,12 @@ TEH_PG_trigger_kyc_rule_for_account ( NULL == check_merchant_pub ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_auto_from_type (check_merchant_pub), - NULL == payto_uri + NULL == payto_uri.full_payto ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (payto_uri), + : GNUNET_PQ_query_param_string (payto_uri.full_payto), + NULL == payto_uri.full_payto + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_auto_from_type (&h_full_payto), GNUNET_PQ_query_param_absolute_time (&now), TALER_PQ_query_param_json (jmeasures), GNUNET_PQ_query_param_uint32 (&display_priority), @@ -84,8 +88,10 @@ TEH_PG_trigger_kyc_rule_for_account ( " ,out_bad_kyc_auth" " AS bad_kyc_auth" " FROM exchange_do_trigger_kyc_rule_for_account" - "($1, $2, $3, $4, $5, $6, $7, $8);"); - + "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + if (NULL != payto_uri.full_payto) + TALER_full_payto_normalize_and_hash (payto_uri, + &h_full_payto); qs = GNUNET_PQ_eval_prepared_singleton_select ( pg->conn, "trigger_kyc_rule_for_account", diff --git a/src/exchangedb/pg_update_aggregation_transient.c b/src/exchangedb/pg_update_aggregation_transient.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_update_aggregation_transient ( void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPaytoHashP *h_payto, const struct TALER_WireTransferIdentifierRawP *wtid, uint64_t kyc_requirement_row, const struct TALER_Amount *total) diff --git a/src/exchangedb/pg_update_kyc_process_by_row.c b/src/exchangedb/pg_update_kyc_process_by_row.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 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 @@ -31,7 +31,7 @@ TEH_PG_update_kyc_process_by_row ( void *cls, uint64_t process_row, const char *provider_name, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, const char *provider_account_id, const char *provider_legitimization_id, const char *redirect_url, diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c @@ -227,7 +227,6 @@ #include "pg_insert_aml_officer.h" #include "pg_test_aml_officer.h" #include "pg_lookup_aml_officer.h" -#include "pg_trigger_aml_process.h" #include "pg_lookup_kyc_requirement_by_row.h" #include "pg_insert_aml_decision.h" #include "pg_batch_ensure_coin_known.h" @@ -818,8 +817,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_lookup_aml_officer; plugin->insert_active_legitimization_measure = &TEH_PG_insert_active_legitimization_measure; - plugin->trigger_aml_process - = &TEH_PG_trigger_aml_process; plugin->insert_aml_decision = &TEH_PG_insert_aml_decision; plugin->lookup_kyc_requirement_by_row diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c @@ -523,8 +523,8 @@ static void cb_wt_never (void *cls, uint64_t serial_id, const struct TALER_MerchantPublicKeyP *merchant_pub, - const char *account_payto_uri, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPayto account_payto_uri, + const struct TALER_FullPaytoHashP *h_payto, struct GNUNET_TIME_Timestamp exec_time, const struct TALER_PrivateContractHashP *h_contract_terms, const struct TALER_DenominationPublicKey *denom_pub, @@ -565,8 +565,8 @@ static void cb_wt_check (void *cls, uint64_t rowid, const struct TALER_MerchantPublicKeyP *merchant_pub, - const char *account_payto_uri, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_FullPayto account_payto_uri, + const struct TALER_FullPaytoHashP *h_payto, struct GNUNET_TIME_Timestamp exec_time, const struct TALER_PrivateContractHashP *h_contract_terms, const struct TALER_DenominationPublicKey *denom_pub, @@ -580,7 +580,7 @@ cb_wt_check (void *cls, GNUNET_assert (cls == &cb_wt_never); GNUNET_assert (0 == GNUNET_memcmp (merchant_pub, &merchant_pub_wt)); - GNUNET_assert (0 == strcmp (account_payto_uri, + GNUNET_assert (0 == strcmp (account_payto_uri.full_payto, "payto://iban/DE67830654080004822650?receiver-name=Test")); GNUNET_assert (GNUNET_TIME_timestamp_cmp (exec_time, ==, @@ -599,7 +599,7 @@ cb_wt_check (void *cls, /** * Here we store the hash of the payto URI. */ -static struct TALER_PaytoHashP global_wire_target_h_payto; +static struct TALER_FullPaytoHashP global_wire_target_h_payto; /** @@ -907,7 +907,7 @@ audit_wire_cb (void *cls, uint64_t rowid, struct GNUNET_TIME_Timestamp date, const struct TALER_WireTransferIdentifierRawP *wtid, - const char *payto_uri, + const struct TALER_FullPayto payto_uri, const struct TALER_Amount *amount) { (void) cls; @@ -937,11 +937,11 @@ static enum GNUNET_GenericReturnValue test_wire_out (const struct TALER_EXCHANGEDB_BatchDeposit *bd) { const struct TALER_EXCHANGEDB_CoinDepositInformation *deposit = &bd->cdis[0]; - struct TALER_PaytoHashP h_payto; + struct TALER_FullPaytoHashP h_payto; GNUNET_assert (0 < bd->num_cdis); - TALER_payto_hash (bd->receiver_wire_account, - &h_payto); + TALER_full_payto_hash (bd->receiver_wire_account, + &h_payto); auditor_row_cnt = 0; memset (&wire_out_wtid, 41, @@ -1126,7 +1126,7 @@ wire_missing_cb ( void *cls, uint64_t batch_deposit_serial_id, const struct TALER_Amount *total_amount, - const struct TALER_PaytoHashP *wire_target_h_payto, + const struct TALER_FullPaytoHashP *wire_target_h_payto, struct GNUNET_TIME_Timestamp deadline) { const struct TALER_EXCHANGEDB_CoinDepositInformation *deposit = cls; @@ -1193,8 +1193,12 @@ run (void *cls) struct TALER_CoinSpendPublicKeyP cpub2; struct TALER_MerchantPublicKeyP mpub2; struct TALER_EXCHANGEDB_Refund refund; - const char *sndr = "payto://x-taler-bank/localhost:8080/1"; - const char *rcvr = "payto://x-taler-bank/localhost:8080/2"; + const struct TALER_FullPayto sndr = { + (char *) "payto://x-taler-bank/localhost:8080/1" + }; + const struct TALER_FullPayto rcvr = { + (char *) "payto://x-taler-bank/localhost:8080/2" + }; const uint32_t num_partitions = 10; unsigned int matched; enum GNUNET_DB_QueryStatus qs; @@ -1518,7 +1522,7 @@ run (void *cls) bool balance_ok; uint32_t bad_balance_idx; bool in_conflict; - struct TALER_PaytoHashP h_payto; + struct TALER_FullPaytoHashP h_payto; RND_BLK (&h_payto); bd.refund_deadline @@ -2142,10 +2146,10 @@ run (void *cls) RND_BLK (&bd.merchant_pub); RND_BLK (&bd.h_contract_terms); RND_BLK (&bd.wire_salt); - bd.receiver_wire_account = - "payto://iban/DE67830654080004822650?receiver-name=Test"; + bd.receiver_wire_account.full_payto = + (char *) "payto://iban/DE67830654080004822650?receiver-name=Test"; TALER_merchant_wire_signature_hash ( - "payto://iban/DE67830654080004822650?receiver-name=Test", + bd.receiver_wire_account, &bd.wire_salt, &h_wire_wt); deposit.amount_with_fee = value; @@ -2176,8 +2180,8 @@ run (void *cls) uint32_t bad_idx; bool ctr_conflict; - TALER_payto_hash (bd.receiver_wire_account, - &bd.wire_target_h_payto); + TALER_full_payto_hash (bd.receiver_wire_account, + &bd.wire_target_h_payto); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->do_deposit (plugin->cls, &bd, @@ -2221,7 +2225,7 @@ run (void *cls) sleep (2); /* give deposit time to be ready */ { struct TALER_MerchantPublicKeyP merchant_pub2; - char *payto_uri2; + struct TALER_FullPayto payto_uri2; FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->get_ready_deposit (plugin->cls, @@ -2231,11 +2235,11 @@ run (void *cls) &payto_uri2)); FAILIF (0 != GNUNET_memcmp (&merchant_pub2, &bd.merchant_pub)); - FAILIF (0 != strcmp (payto_uri2, - bd.receiver_wire_account)); - TALER_payto_hash (payto_uri2, - &global_wire_target_h_payto); - GNUNET_free (payto_uri2); + FAILIF (0 != TALER_full_payto_cmp (payto_uri2, + bd.receiver_wire_account)); + TALER_full_payto_hash (payto_uri2, + &global_wire_target_h_payto); + GNUNET_free (payto_uri2.full_payto); } { diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h @@ -2989,7 +2989,7 @@ struct TALER_EXCHANGEDB_ReserveInInfo const struct TALER_ReservePublicKeyP *reserve_pub; const struct TALER_Amount *balance; struct GNUNET_TIME_Timestamp execution_time; - const char *sender_account_details; + const struct TALER_FullPayto sender_account_details; const char *exchange_account_name; uint64_t wire_reference; }; @@ -3996,7 +3996,7 @@ struct TALER_EXCHANGEDB_Plugin const union TALER_AccountPublicKeyP *account_pub, const struct TALER_Amount *credit_amount, struct GNUNET_TIME_Timestamp execution_date, - const char *debit_account_uri, + const struct TALER_FullPayto debit_account_uri, const char *section_name, uint64_t serial_id); @@ -7416,22 +7416,6 @@ struct TALER_EXCHANGEDB_Plugin /** - * Trigger AML process, an account has crossed the threshold. Inserts or - * updates the AML status. - * - * @param cls closure - * @param h_payto account for which the attribute data is stored - * @param threshold_crossed existing threshold that was crossed - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*trigger_aml_process)( - void *cls, - const struct TALER_NormalizedPaytoHashP *h_payto, - const struct TALER_Amount *threshold_crossed); - - - /** * Lookup AML decisions that have a particular state. * * @param cls closure diff --git a/src/include/taler_util.h b/src/include/taler_util.h @@ -539,6 +539,18 @@ TALER_payto_normalize (const struct TALER_FullPayto input); /** + * Normalize the given full payto URI and hash it. + * + * @param in full payto URI + * @param[out] out hash of the normalized payto URI + */ +void +TALER_full_payto_normalize_and_hash ( + const struct TALER_FullPayto in, + struct TALER_NormalizedPaytoHashP *out); + + +/** * Obtain the account name from a payto URL. * * @param payto an x-taler-bank payto URL diff --git a/src/util/payto.c b/src/util/payto.c @@ -44,6 +44,20 @@ TALER_full_payto_cmp (const struct TALER_FullPayto a, } +void +TALER_full_payto_normalize_and_hash (const struct TALER_FullPayto in, + struct TALER_NormalizedPaytoHashP *out) +{ + struct TALER_NormalizedPayto normalized_payto_uri; + + normalized_payto_uri + = TALER_payto_normalize (in); + TALER_normalized_payto_hash (normalized_payto_uri, + out); + GNUNET_free (normalized_payto_uri.normalized_payto); +} + + /** * Extract the value under @a key from the URI parameters. *