From f5b99b5282e50bfaf744941d22bb5766cec76cb9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 14 Aug 2022 19:03:30 +0200 Subject: [PATCH] -work on new KYC logic: remove old DB code --- src/exchangedb/plugin_exchangedb_postgres.c | 50 --------------------- src/exchangedb/procedures.sql | 42 ----------------- src/include/taler_exchangedb_plugin.h | 20 --------- 3 files changed, 112 deletions(-) diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 25d30d005..cf995e365 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -890,16 +890,6 @@ prepare_statements (struct PostgresClosure *pg) " FROM exchange_do_batch_withdraw_insert" " ($1,$2,$3,$4,$5,$6,$7,$8,$9);", 9), - /* Used in #postgres_do_withdraw_limit_check() to check - if the withdrawals remain below the limit under which - KYC is not required. */ - GNUNET_PQ_make_prepare ( - "call_withdraw_limit_check", - "SELECT " - " below_limit" - " FROM exchange_do_withdraw_limit_check" - " ($1,$2,$3,$4);", - 4), /* Used in #postgres_do_deposit() to execute a deposit, checking the coin's balance in the process as needed. */ GNUNET_PQ_make_prepare ( @@ -6299,45 +6289,6 @@ postgres_do_batch_withdraw_insert ( } -/** - * Check that reserve remains below threshold for KYC - * checks after withdraw operation. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param ruuid reserve to check - * @param withdraw_start starting point to accumulate from - * @param upper_limit maximum amount allowed - * @param[out] below_limit set to true if the limit was not exceeded - * @return query execution status - */ -static enum GNUNET_DB_QueryStatus -postgres_do_withdraw_limit_check ( - void *cls, - uint64_t ruuid, - struct GNUNET_TIME_Absolute withdraw_start, - const struct TALER_Amount *upper_limit, - bool *below_limit) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&ruuid), - GNUNET_PQ_query_param_absolute_time (&withdraw_start), - TALER_PQ_query_param_amount (upper_limit), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("below_limit", - below_limit), - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_withdraw_limit_check", - params, - rs); -} - - /** * Compute the shard number of a given @a merchant_pub. * @@ -17219,7 +17170,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->do_withdraw = &postgres_do_withdraw; plugin->do_batch_withdraw = &postgres_do_batch_withdraw; plugin->do_batch_withdraw_insert = &postgres_do_batch_withdraw_insert; - plugin->do_withdraw_limit_check = &postgres_do_withdraw_limit_check; plugin->do_deposit = &postgres_do_deposit; plugin->do_melt = &postgres_do_melt; plugin->do_refund = &postgres_do_refund; diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql index 447a5ce3b..28a074b45 100644 --- a/src/exchangedb/procedures.sql +++ b/src/exchangedb/procedures.sql @@ -409,48 +409,6 @@ COMMENT ON FUNCTION exchange_do_batch_withdraw_insert(BYTEA, INT8, INT4, BYTEA, -CREATE OR REPLACE FUNCTION exchange_do_withdraw_limit_check( - IN ruuid INT8, - IN start_time INT8, - IN upper_limit_val INT8, - IN upper_limit_frac INT4, - OUT below_limit BOOLEAN) -LANGUAGE plpgsql -AS $$ -DECLARE - total_val INT8; -DECLARE - total_frac INT8; -- INT4 could overflow during accumulation! -BEGIN --- NOTE: Read-only, but crosses shards. --- Shards: reserves by reserve_pub --- reserves_out by reserve_uuid -- crosses shards!! - - -SELECT - SUM(amount_with_fee_val) -- overflow here is not plausible - ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits - INTO - total_val - ,total_frac - FROM exchange.reserves_out - WHERE reserve_uuid=ruuid - AND execution_date > start_time; - --- normalize result -total_val = total_val + total_frac / 100000000; -total_frac = total_frac % 100000000; - --- compare to threshold -below_limit = (total_val < upper_limit_val) OR - ( (total_val = upper_limit_val) AND - (total_frac <= upper_limit_frac) ); -END $$; - -COMMENT ON FUNCTION exchange_do_withdraw_limit_check(INT8, INT8, INT8, INT4) - IS 'Check whether the withdrawals from the given reserve since the given time are below the given threshold'; - - -- NOTE: experiment, currently dead, see postgres_Start_deferred_wire_out; -- now done inline. FIXME: Remove code here once inline version is confirmed working nicely! CREATE OR REPLACE PROCEDURE defer_wire_out() diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index cb3f7e5cd..ef25fb46b 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -3226,26 +3226,6 @@ struct TALER_EXCHANGEDB_Plugin bool *nonce_reuse); - /** - * Check that reserve remains below threshold for KYC - * checks after withdraw operation. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param ruuid identifies the reserve to check - * @param withdraw_start starting point to accumulate from - * @param upper_limit maximum amount allowed - * @param[out] below_limit set to true if the limit was not exceeded - * @return query execution status - */ - enum GNUNET_DB_QueryStatus - (*do_withdraw_limit_check)( - void *cls, - uint64_t ruuid, - struct GNUNET_TIME_Absolute withdraw_start, - const struct TALER_Amount *upper_limit, - bool *below_limit); - - /** * Perform deposit operation, checking for sufficient balance * of the coin and possibly persisting the deposit details.