From e650214142bb9dadd54fe76d6235e115aa4bd4e5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 1 Nov 2024 04:06:22 +0100 Subject: working through DB --- .../exchange_do_check_deposit_idempotent.sql | 9 ++++----- src/exchangedb/exchange_do_deposit.sql | 7 ++++++- src/exchangedb/perf_reserves_in_insert.c | 19 +++++++++++-------- src/exchangedb/pg_do_check_deposit_idempotent.c | 7 ++++--- src/exchangedb/pg_do_deposit.c | 10 +++++++--- src/exchangedb/pg_find_aggregation_transient.c | 9 +++++---- src/exchangedb/pg_get_drain_profit.c | 4 ++-- src/exchangedb/pg_get_wire_hash_for_contract.c | 6 +++--- src/exchangedb/pg_have_deposit2.c | 4 ++-- src/exchangedb/pg_insert_aml_decision.c | 6 +++--- src/exchangedb/pg_insert_drain_profit.c | 5 +++-- src/exchangedb/pg_profit_drains_get_pending.c | 7 ++++--- src/exchangedb/pg_reserves_in_insert.c | 4 +--- .../pg_select_aggregation_amounts_for_kyc_check.c | 12 ++++++++---- src/include/taler_exchangedb_plugin.h | 2 +- 15 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/exchangedb/exchange_do_check_deposit_idempotent.sql b/src/exchangedb/exchange_do_check_deposit_idempotent.sql index 1e7414dc0..04d6b9ee6 100644 --- a/src/exchangedb/exchange_do_check_deposit_idempotent.sql +++ b/src/exchangedb/exchange_do_check_deposit_idempotent.sql @@ -13,7 +13,9 @@ -- You should have received a copy of the GNU General Public License along with -- TALER; see the file COPYING. If not, see -- -CREATE OR REPLACE FUNCTION exchange_do_check_deposit_idempotent( + +DROP FUNCTION IF EXISTS exchange_do_check_deposit_idempotent; +CREATE FUNCTION exchange_do_check_deposit_idempotent( -- For batch_deposits IN in_shard INT8, IN in_merchant_pub BYTEA, @@ -27,8 +29,6 @@ CREATE OR REPLACE FUNCTION exchange_do_check_deposit_idempotent( IN in_wire_target_h_payto BYTEA, IN in_policy_details_serial_id INT8, -- can be NULL IN in_policy_blocked BOOLEAN, - -- For wire_targets - IN in_receiver_wire_account TEXT, -- For coin_deposits IN ina_coin_pub BYTEA[], IN ina_coin_sig BYTEA[], @@ -57,8 +57,7 @@ out_exchange_timestamp = in_exchange_timestamp; SELECT wire_target_serial_id INTO wtsi FROM wire_targets - WHERE wire_target_h_payto=in_wire_target_h_payto - AND payto_uri=in_receiver_wire_account; + WHERE wire_target_h_payto=in_wire_target_h_payto; IF NOT FOUND THEN diff --git a/src/exchangedb/exchange_do_deposit.sql b/src/exchangedb/exchange_do_deposit.sql index c89e9e470..ef1d94919 100644 --- a/src/exchangedb/exchange_do_deposit.sql +++ b/src/exchangedb/exchange_do_deposit.sql @@ -13,7 +13,9 @@ -- You should have received a copy of the GNU General Public License along with -- TALER; see the file COPYING. If not, see -- -CREATE OR REPLACE FUNCTION exchange_do_deposit( + +DROP FUNCTION IF EXISTS exchange_do_deposit; +CREATE FUNCTION exchange_do_deposit( -- For batch_deposits IN in_shard INT8, IN in_merchant_pub BYTEA, @@ -25,6 +27,7 @@ CREATE OR REPLACE FUNCTION exchange_do_deposit( IN in_wallet_data_hash BYTEA, -- can be NULL IN in_wire_salt BYTEA, IN in_wire_target_h_payto BYTEA, + IN in_h_normalized_payto BYTEA, IN in_policy_details_serial_id INT8, -- can be NULL IN in_policy_blocked BOOLEAN, -- For wire_targets @@ -57,9 +60,11 @@ BEGIN -- First, get or create the 'wtsi' INSERT INTO wire_targets (wire_target_h_payto + ,h_normalized_payto ,payto_uri) VALUES (in_wire_target_h_payto + ,in_h_normalized_payto ,in_receiver_wire_account) ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto) RETURNING diff --git a/src/exchangedb/perf_reserves_in_insert.c b/src/exchangedb/perf_reserves_in_insert.c index 09c4a43c5..f05c2800f 100644 --- a/src/exchangedb/perf_reserves_in_insert.c +++ b/src/exchangedb/perf_reserves_in_insert.c @@ -33,24 +33,25 @@ static int result; * Report line of error if @a cond is true, and jump to label "drop". */ #define FAILIF(cond) \ - do { \ - if (! (cond)) {break;} \ - GNUNET_break (0); \ - goto drop; \ - } while (0) + do { \ + if (! (cond)) {break;} \ + GNUNET_break (0); \ + goto drop; \ + } while (0) /** * Initializes @a ptr with random data. */ #define RND_BLK(ptr) \ - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr)) + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ + ptr)) /** * Initializes @a ptr with zeros. */ #define ZR_BLK(ptr) \ - memset (ptr, 0, sizeof (*ptr)) + memset (ptr, 0, sizeof (*ptr)) /** * How many rounds do we average over? @@ -123,7 +124,9 @@ run (void *cls) now = GNUNET_TIME_absolute_get (); ts = GNUNET_TIME_timestamp_get (); { - const char *sndr = "payto://x-taler-bank/localhost:8080/1"; + struct TALER_FullPayto sndr = { + .full_payto = (char *) "payto://x-taler-bank/localhost:8080/1" + }; struct TALER_ReservePublicKeyP reserve_pubs[lcm]; struct TALER_EXCHANGEDB_ReserveInInfo reserves[lcm]; enum GNUNET_DB_QueryStatus results[lcm]; diff --git a/src/exchangedb/pg_do_check_deposit_idempotent.c b/src/exchangedb/pg_do_check_deposit_idempotent.c index 8a15200e0..21e56660b 100644 --- a/src/exchangedb/pg_do_check_deposit_idempotent.c +++ b/src/exchangedb/pg_do_check_deposit_idempotent.c @@ -39,6 +39,7 @@ TEH_PG_do_check_deposit_idempotent ( const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)]; const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)]; struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)]; + struct TALER_NormalizedPaytoHashP h_normalized_payto; struct GNUNET_PQ_QueryParam params[] = { /* data for batch_deposits */ GNUNET_PQ_query_param_uint64 (&deposit_shard), @@ -57,8 +58,6 @@ TEH_PG_do_check_deposit_idempotent ( ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id), GNUNET_PQ_query_param_bool (bd->policy_blocked), - /* to create entry in wire_targets */ - GNUNET_PQ_query_param_string (bd->receiver_wire_account), /* arrays for coin_deposits */ GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis, coin_pubs, @@ -83,6 +82,8 @@ TEH_PG_do_check_deposit_idempotent ( }; enum GNUNET_DB_QueryStatus qs; + TALER_full_payto_normalize_and_hash (bd->receiver_wire_account, + &h_normalized_payto); for (unsigned int i = 0; i < bd->num_cdis; i++) { const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi @@ -102,7 +103,7 @@ TEH_PG_do_check_deposit_idempotent ( " out_exchange_timestamp AS exchange_timestamp" ",out_is_idempotent AS is_idempotent" " FROM exchange_do_check_deposit_idempotent" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);"); + " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "call_check_deposit_idempotent", params, diff --git a/src/exchangedb/pg_do_deposit.c b/src/exchangedb/pg_do_deposit.c index 0ba45b628..ed689696a 100644 --- a/src/exchangedb/pg_do_deposit.c +++ b/src/exchangedb/pg_do_deposit.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 @@ -41,6 +41,7 @@ TEH_PG_do_deposit ( const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)]; const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)]; struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)]; + struct TALER_NormalizedPaytoHashP h_normalized_payto; struct GNUNET_PQ_QueryParam params[] = { /* data for batch_deposits */ GNUNET_PQ_query_param_uint64 (&deposit_shard), @@ -55,12 +56,13 @@ TEH_PG_do_deposit ( : GNUNET_PQ_query_param_auto_from_type (&bd->wallet_data_hash), GNUNET_PQ_query_param_auto_from_type (&bd->wire_salt), GNUNET_PQ_query_param_auto_from_type (&bd->wire_target_h_payto), + GNUNET_PQ_query_param_auto_from_type (&h_normalized_payto), (0 == bd->policy_details_serial_id) ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id), GNUNET_PQ_query_param_bool (bd->policy_blocked), /* to create entry in wire_targets */ - GNUNET_PQ_query_param_string (bd->receiver_wire_account), + GNUNET_PQ_query_param_string (bd->receiver_wire_account.full_payto), /* arrays for coin_deposits */ GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis, coin_pubs, @@ -89,6 +91,8 @@ TEH_PG_do_deposit ( }; enum GNUNET_DB_QueryStatus qs; + TALER_full_payto_normalize_and_hash (bd->receiver_wire_account, + &h_normalized_payto); for (unsigned int i = 0; i < bd->num_cdis; i++) { const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi @@ -109,7 +113,7 @@ TEH_PG_do_deposit ( ",out_insufficient_balance_coin_index AS insufficient_balance_coin_index" ",out_conflict AS conflicted" " FROM exchange_do_deposit" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);"); + " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "call_deposit", params, diff --git a/src/exchangedb/pg_find_aggregation_transient.c b/src/exchangedb/pg_find_aggregation_transient.c index 4177926c6..9aa495df7 100644 --- a/src/exchangedb/pg_find_aggregation_transient.c +++ b/src/exchangedb/pg_find_aggregation_transient.c @@ -72,7 +72,7 @@ get_transients_cb (void *cls, for (unsigned int i = 0; iconn, "find_transient_aggregations", diff --git a/src/exchangedb/pg_get_drain_profit.c b/src/exchangedb/pg_get_drain_profit.c index 75fccefcd..bbfdf9a01 100644 --- a/src/exchangedb/pg_get_drain_profit.c +++ b/src/exchangedb/pg_get_drain_profit.c @@ -32,7 +32,7 @@ TEH_PG_get_drain_profit ( const struct TALER_WireTransferIdentifierRawP *wtid, uint64_t *serial, char **account_section, - char **payto_uri, + struct TALER_FullPayto *payto_uri, struct GNUNET_TIME_Timestamp *request_timestamp, struct TALER_Amount *amount, struct TALER_MasterSignatureP *master_sig) @@ -48,7 +48,7 @@ TEH_PG_get_drain_profit ( GNUNET_PQ_result_spec_string ("account_section", account_section), GNUNET_PQ_result_spec_string ("payto_uri", - payto_uri), + &payto_uri->full_payto), GNUNET_PQ_result_spec_timestamp ("trigger_date", request_timestamp), TALER_PQ_RESULT_SPEC_AMOUNT ("amount", diff --git a/src/exchangedb/pg_get_wire_hash_for_contract.c b/src/exchangedb/pg_get_wire_hash_for_contract.c index afd659b18..d19baf23a 100644 --- a/src/exchangedb/pg_get_wire_hash_for_contract.c +++ b/src/exchangedb/pg_get_wire_hash_for_contract.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2023 Taler Systems SA + Copyright (C) 2023, 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 @@ -41,13 +41,13 @@ TEH_PG_get_wire_hash_for_contract ( GNUNET_PQ_query_param_auto_from_type (h_contract_terms), GNUNET_PQ_query_param_end }; - char *payto_uri; + struct TALER_FullPayto payto_uri; struct TALER_WireSaltP wire_salt; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("wire_salt", &wire_salt), GNUNET_PQ_result_spec_string ("payto_uri", - &payto_uri), + &payto_uri.full_payto), GNUNET_PQ_result_spec_end }; diff --git a/src/exchangedb/pg_have_deposit2.c b/src/exchangedb/pg_have_deposit2.c index e00ad7490..42ec24e81 100644 --- a/src/exchangedb/pg_have_deposit2.c +++ b/src/exchangedb/pg_have_deposit2.c @@ -61,7 +61,7 @@ TEH_PG_have_deposit2 ( GNUNET_PQ_result_spec_auto_from_type ("wire_salt", &deposit2.wire_salt), GNUNET_PQ_result_spec_string ("receiver_wire_account", - &deposit2.receiver_wire_account), + &deposit2.receiver_wire_account.full_payto), GNUNET_PQ_result_spec_end }; enum GNUNET_DB_QueryStatus qs; @@ -101,7 +101,7 @@ TEH_PG_have_deposit2 ( TALER_merchant_wire_signature_hash (deposit2.receiver_wire_account, &deposit2.wire_salt, &h_wire2); - GNUNET_free (deposit2.receiver_wire_account); + GNUNET_free (deposit2.receiver_wire_account.full_payto); /* Now we check that the other information in @a deposit also matches, and if not report inconsistencies. */ if ( (GNUNET_TIME_timestamp_cmp (refund_deadline, diff --git a/src/exchangedb/pg_insert_aml_decision.c b/src/exchangedb/pg_insert_aml_decision.c index 4d5368f06..d86bbbb2b 100644 --- a/src/exchangedb/pg_insert_aml_decision.c +++ b/src/exchangedb/pg_insert_aml_decision.c @@ -57,11 +57,11 @@ TEH_PG_insert_aml_decision ( char *notify_s = GNUNET_PQ_get_event_notify_channel (&rep.header); struct GNUNET_PQ_QueryParam params[] = { - 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), GNUNET_PQ_query_param_auto_from_type (h_payto), - NULL == payto_uri + NULL == payto_uri.full_payto ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_auto_from_type (&h_full_payto), GNUNET_PQ_query_param_timestamp (&decision_time), diff --git a/src/exchangedb/pg_insert_drain_profit.c b/src/exchangedb/pg_insert_drain_profit.c index a0de02e9b..0df872d73 100644 --- a/src/exchangedb/pg_insert_drain_profit.c +++ b/src/exchangedb/pg_insert_drain_profit.c @@ -25,12 +25,13 @@ #include "pg_insert_drain_profit.h" #include "pg_helper.h" + enum GNUNET_DB_QueryStatus TEH_PG_insert_drain_profit ( void *cls, const struct TALER_WireTransferIdentifierRawP *wtid, const char *account_section, - const char *payto_uri, + const struct TALER_FullPayto payto_uri, struct GNUNET_TIME_Timestamp request_timestamp, const struct TALER_Amount *amount, const struct TALER_MasterSignatureP *master_sig) @@ -39,7 +40,7 @@ TEH_PG_insert_drain_profit ( struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (wtid), GNUNET_PQ_query_param_string (account_section), - GNUNET_PQ_query_param_string (payto_uri), + GNUNET_PQ_query_param_string (payto_uri.full_payto), GNUNET_PQ_query_param_timestamp (&request_timestamp), TALER_PQ_query_param_amount (pg->conn, amount), diff --git a/src/exchangedb/pg_profit_drains_get_pending.c b/src/exchangedb/pg_profit_drains_get_pending.c index c844a3f38..be5843269 100644 --- a/src/exchangedb/pg_profit_drains_get_pending.c +++ b/src/exchangedb/pg_profit_drains_get_pending.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 @@ -25,13 +25,14 @@ #include "pg_profit_drains_get_pending.h" #include "pg_helper.h" + enum GNUNET_DB_QueryStatus TEH_PG_profit_drains_get_pending ( void *cls, uint64_t *serial, struct TALER_WireTransferIdentifierRawP *wtid, char **account_section, - char **payto_uri, + struct TALER_FullPayto *payto_uri, struct GNUNET_TIME_Timestamp *request_timestamp, struct TALER_Amount *amount, struct TALER_MasterSignatureP *master_sig) @@ -48,7 +49,7 @@ TEH_PG_profit_drains_get_pending ( GNUNET_PQ_result_spec_string ("account_section", account_section), GNUNET_PQ_result_spec_string ("payto_uri", - payto_uri), + &payto_uri->full_payto), GNUNET_PQ_result_spec_timestamp ("trigger_date", request_timestamp), TALER_PQ_RESULT_SPEC_AMOUNT ("amount", diff --git a/src/exchangedb/pg_reserves_in_insert.c b/src/exchangedb/pg_reserves_in_insert.c index abc7032b3..c372f7719 100644 --- a/src/exchangedb/pg_reserves_in_insert.c +++ b/src/exchangedb/pg_reserves_in_insert.c @@ -30,8 +30,6 @@ #include "pg_commit.h" #include "pg_preflight.h" #include "pg_rollback.h" -#include "pg_reserves_get.h" -#include "pg_reserves_update.h" #include "pg_event_notify.h" @@ -326,7 +324,7 @@ TEH_PG_reserves_in_insert ( TALER_PQ_query_param_amount (pg->conn, &balances[i]), GNUNET_PQ_query_param_string (exchange_account_names[i]), - GNUNET_PQ_query_param_auto_from_type (&h_paytos[i]), + GNUNET_PQ_query_param_auto_from_type (&h_full_paytos[i]), GNUNET_PQ_query_param_string (notify_s[i]), GNUNET_PQ_query_param_end }; diff --git a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c index 0ad9b5cfa..455c458eb 100644 --- a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c +++ b/src/exchangedb/pg_select_aggregation_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_aggregation_amounts_for_kyc_check ( void *cls, - const struct TALER_FullPaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) @@ -138,8 +138,12 @@ TEH_PG_select_aggregation_amounts_for_kyc_check ( " amount" ",execution_date AS date" " FROM wire_out" - " WHERE wire_target_h_payto=$1" - " AND execution_date >= $2" + " WHERE wire_target_h_payto IN" + " (SELECT wire_target_h_payto" + " FROM wire_targets" + " WHERE h_normalized_payto=$1" + " )" + " AND execution_date >= $2" " ORDER BY execution_date DESC"); qs = GNUNET_PQ_eval_prepared_multi_select ( diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 881cf88e0..2cf845d79 100644 --- 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 struct TALER_FullPayto sender_account_details; + struct TALER_FullPayto sender_account_details; const char *exchange_account_name; uint64_t wire_reference; }; -- cgit v1.2.3