commit 042f91464f787fb1a51198acc6f560226c3cc977
parent 5ef79bebc5adef77c94e5d0e77bfd57a71048cc2
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 7 May 2024 19:04:05 +0200
fix kyc-wallet handler
Diffstat:
4 files changed, 40 insertions(+), 119 deletions(-)
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
@@ -139,6 +139,7 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_extensions.c taler-exchange-httpd_extensions.h \
taler-exchange-httpd_keys.c taler-exchange-httpd_keys.h \
taler-exchange-httpd_kyc-proof.c taler-exchange-httpd_kyc-proof.h \
+ taler-exchange-httpd_kyc-wallet.c taler-exchange-httpd_kyc-wallet.h \
taler-exchange-httpd_kyc-webhook.c taler-exchange-httpd_kyc-webhook.h \
taler-exchange-httpd_link.c taler-exchange-httpd_link.h \
taler-exchange-httpd_management.h \
@@ -168,6 +169,7 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_refreshes_reveal.c taler-exchange-httpd_refreshes_reveal.h \
taler-exchange-httpd_refund.c taler-exchange-httpd_refund.h \
taler-exchange-httpd_reserves_attest.c taler-exchange-httpd_reserves_attest.h \
+ taler-exchange-httpd_reserves_close.c taler-exchange-httpd_reserves_close.h \
taler-exchange-httpd_reserves_get.c taler-exchange-httpd_reserves_get.h \
taler-exchange-httpd_reserves_get_attest.c taler-exchange-httpd_reserves_get_attest.h \
taler-exchange-httpd_reserves_history.c taler-exchange-httpd_reserves_history.h \
@@ -179,9 +181,7 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_transfers_get.c taler-exchange-httpd_transfers_get.h \
taler-exchange-httpd_withdraw.c taler-exchange-httpd_withdraw.h
-# taler-exchange-httpd_reserves_close.c taler-exchange-httpd_reserves_close.h \
# taler-exchange-httpd_kyc-check.c taler-exchange-httpd_kyc-check.h \
-# taler-exchange-httpd_kyc-wallet.c taler-exchange-httpd_kyc-wallet.h \
# taler-exchange-httpd_deposits_get.c taler-exchange-httpd_deposits_get.h \
# taler-exchange-httpd_aml-decision.c taler-exchange-httpd_aml-decision.h \
# taler-exchange-httpd_aml-decision-get.c \
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
@@ -433,18 +433,20 @@ trigger_wire_transfer (const struct AggregationUnit *au_active)
}
/* Commit the WTID data to 'wire_out' */
if (qs >= 0)
- qs = db_plugin->store_wire_transfer_out (db_plugin->cls,
- au_active->execution_time,
- &au_active->wtid,
- &au_active->h_payto,
- au_active->wa->section_name,
- &au_active->final_amount);
+ qs = db_plugin->store_wire_transfer_out (
+ db_plugin->cls,
+ au_active->execution_time,
+ &au_active->wtid,
+ &au_active->h_payto,
+ au_active->wa->section_name,
+ &au_active->final_amount);
if ( (qs >= 0) &&
au_active->have_transient)
- qs = db_plugin->delete_aggregation_transient (db_plugin->cls,
- &au_active->h_payto,
- &au_active->wtid);
+ qs = db_plugin->delete_aggregation_transient (
+ db_plugin->cls,
+ &au_active->h_payto,
+ &au_active->wtid);
return qs;
}
@@ -551,7 +553,7 @@ legitimization_satisfied (struct AggregationUnit *au_active)
qs = db_plugin->trigger_kyc_rule_for_account (
db_plugin->cls,
&au_active->h_payto,
- NULL,
+ NULL, /* FIXME: get account pub? Or is NULL fine? */
jrule,
TALER_KYCLOGIC_rule2priority (requirement),
&au_active->requirement_row);
diff --git a/src/exchange/taler-exchange-httpd_kyc-wallet.c b/src/exchange/taler-exchange-httpd_kyc-wallet.c
@@ -29,6 +29,7 @@
#include "taler_kyclogic_lib.h"
#include "taler-exchange-httpd_kyc-wallet.h"
#include "taler-exchange-httpd_responses.h"
+#include "taler-exchange-httpd_withdraw.h"
/**
@@ -56,11 +57,6 @@ struct KycRequestContext
*/
struct TALER_Amount balance;
- /**
- * Name of the required check.
- */
- char *required;
-
};
@@ -112,59 +108,19 @@ wallet_kyc_check (void *cls,
MHD_RESULT *mhd_ret)
{
struct KycRequestContext *krc = cls;
- enum GNUNET_DB_QueryStatus qs;
+ union TALER_AccountPublicKeyP account_pub = {
+ .reserve_pub = krc->reserve_pub
+ };
- qs = TALER_KYCLOGIC_kyc_test_required (
+ return TEH_legitimization_check (
+ &krc->kyc,
+ connection,
+ mhd_ret,
TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE,
&krc->h_payto,
- TEH_plugin->select_satisfied_kyc_processes,
- TEH_plugin->cls,
+ &account_pub,
&balance_iterator,
- krc,
- &krc->required);
- if (qs < 0)
- {
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
- GNUNET_break (0);
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "kyc_test_required");
- return qs;
- }
- if (NULL == krc->required)
- {
- krc->kyc.ok = true;
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "KYC check required at %s is `%s'\n",
- TALER_amount2s (&krc->balance),
- krc->required);
- krc->kyc.ok = false;
- qs = TEH_plugin->insert_kyc_requirement_for_account (TEH_plugin->cls,
- krc->required,
- &krc->h_payto,
- &krc->reserve_pub,
- &krc->kyc.requirement_row);
- if (qs < 0)
- {
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
- GNUNET_break (0);
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "insert_kyc_requirement_for_account");
- return qs;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "KYC requirement inserted for wallet %s (%llu, %d)\n",
- TALER_B2S (&krc->h_payto),
- (unsigned long long) krc->kyc.requirement_row,
- qs);
- return qs;
+ krc);
}
@@ -232,7 +188,7 @@ TEH_handler_kyc_wallet (
&krc);
if (GNUNET_SYSERR == ret)
return res;
- if (NULL == krc.required)
+ if (krc.kyc.ok)
{
/* KYC not required or already satisfied */
return TALER_MHD_reply_static (
@@ -242,7 +198,6 @@ TEH_handler_kyc_wallet (
NULL,
0);
}
- GNUNET_free (krc.required);
return TEH_RESPONSE_reply_kyc_required (rc->connection,
&krc.h_payto,
&krc.kyc);
diff --git a/src/exchange/taler-exchange-httpd_reserves_close.c b/src/exchange/taler-exchange-httpd_reserves_close.c
@@ -29,6 +29,7 @@
#include "taler_dbevents.h"
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_reserves_close.h"
+#include "taler-exchange-httpd_withdraw.h"
#include "taler-exchange-httpd_responses.h"
@@ -37,7 +38,7 @@
* checking the request timestamp?
*/
#define TIMESTAMP_TOLERANCE \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
/**
@@ -228,64 +229,27 @@ reserve_close_transaction (void *cls,
/* KYC check may be needed: we're not returning
the money to the account that funded the reserve
in the first place. */
- char *kyc_needed;
+ union TALER_AccountPublicKeyP account_pub = {
+ /* FIXME: not the correct account pub, should extract
+ from inbound wire transfer! Or pass NULL here? */
+ .reserve_pub = *rcc->reserve_pub
+ };
TALER_payto_hash (rcc->payto_uri,
&rcc->kyc_payto);
rcc->qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_KYCLOGIC_kyc_test_required (
+ qs = TEH_legitimization_check (
+ &rcc->kyc,
+ connection,
+ mhd_ret,
TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE,
&rcc->kyc_payto,
- TEH_plugin->select_satisfied_kyc_processes,
- TEH_plugin->cls,
+ &account_pub,
&amount_it,
- rcc,
- &kyc_needed);
- if (qs < 0)
- {
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "iterate_reserve_close_info");
- return qs;
- }
- if (rcc->qs < 0)
- {
- if (GNUNET_DB_STATUS_SOFT_ERROR == rcc->qs)
- return rcc->qs;
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "iterate_reserve_close_info");
+ rcc);
+ if ( (qs < 0) ||
+ (! rcc->kyc.ok) )
return qs;
- }
- if (NULL != kyc_needed)
- {
- rcc->kyc.ok = false;
- qs = TEH_plugin->insert_kyc_requirement_for_account (
- TEH_plugin->cls,
- kyc_needed,
- &rcc->kyc_payto,
- rcc->reserve_pub,
- &rcc->kyc.requirement_row);
- GNUNET_free (kyc_needed);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- {
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "insert_kyc_requirement_for_account");
- }
- return qs;
- }
}
rcc->kyc.ok = true;