more work on API atomization

This commit is contained in:
Christian Grothoff 2023-07-03 17:22:33 +02:00
parent f969bd3c5b
commit 75ea35722b
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 49 additions and 50 deletions

View File

@ -4030,7 +4030,9 @@ typedef void
* Run interaction with exchange to check KYC status * Run interaction with exchange to check KYC status
* of a merchant. * of a merchant.
* *
* @param eh exchange handle to use * @param ctx CURL context
* @param url exchange base URL
* @param keys keys of the exchange
* @param requirement_row number identifying the KYC requirement * @param requirement_row number identifying the KYC requirement
* @param h_payto hash of the payto:// URI at @a payment_target * @param h_payto hash of the payto:// URI at @a payment_target
* @param ut type of the entity performing the KYC check * @param ut type of the entity performing the KYC check
@ -4040,13 +4042,16 @@ typedef void
* @return NULL on error * @return NULL on error
*/ */
struct TALER_EXCHANGE_KycCheckHandle * struct TALER_EXCHANGE_KycCheckHandle *
TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *eh, TALER_EXCHANGE_kyc_check (
uint64_t requirement_row, struct GNUNET_CURL_Context *ctx,
const struct TALER_PaytoHashP *h_payto, const char *url,
enum TALER_KYCLOGIC_KycUserType ut, struct TALER_EXCHANGE_Keys *keys,
struct GNUNET_TIME_Relative timeout, uint64_t requirement_row,
TALER_EXCHANGE_KycStatusCallback cb, const struct TALER_PaytoHashP *h_payto,
void *cb_cls); enum TALER_KYCLOGIC_KycUserType ut,
struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_KycStatusCallback cb,
void *cb_cls);
/** /**

View File

@ -36,16 +36,16 @@
struct TALER_EXCHANGE_KycCheckHandle struct TALER_EXCHANGE_KycCheckHandle
{ {
/**
* The connection to exchange this request handle will use
*/
struct TALER_EXCHANGE_Handle *exchange;
/** /**
* The url for this request. * The url for this request.
*/ */
char *url; char *url;
/**
* Keys of the exchange.
*/
struct TALER_EXCHANGE_Keys *keys;
/** /**
* Handle for the request. * Handle for the request.
*/ */
@ -111,7 +111,6 @@ handle_kyc_check_finished (void *cls,
&status), &status),
GNUNET_JSON_spec_end () GNUNET_JSON_spec_end ()
}; };
const struct TALER_EXCHANGE_Keys *key_state;
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_JSON_parse (j, GNUNET_JSON_parse (j,
@ -126,9 +125,8 @@ handle_kyc_check_finished (void *cls,
ks.details.ok.kyc_details = kyc_details; ks.details.ok.kyc_details = kyc_details;
ks.details.ok.aml_status ks.details.ok.aml_status
= (enum TALER_AmlDecisionState) status; = (enum TALER_AmlDecisionState) status;
key_state = TALER_EXCHANGE_get_keys (kch->exchange);
if (GNUNET_OK != if (GNUNET_OK !=
TALER_EXCHANGE_test_signing_key (key_state, TALER_EXCHANGE_test_signing_key (kch->keys,
&ks.details.ok.exchange_pub)) &ks.details.ok.exchange_pub))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
@ -249,25 +247,21 @@ handle_kyc_check_finished (void *cls,
struct TALER_EXCHANGE_KycCheckHandle * struct TALER_EXCHANGE_KycCheckHandle *
TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_kyc_check (
uint64_t requirement_row, struct GNUNET_CURL_Context *ctx,
const struct TALER_PaytoHashP *h_payto, const char *url,
enum TALER_KYCLOGIC_KycUserType ut, struct TALER_EXCHANGE_Keys *keys,
struct GNUNET_TIME_Relative timeout, uint64_t requirement_row,
TALER_EXCHANGE_KycStatusCallback cb, const struct TALER_PaytoHashP *h_payto,
void *cb_cls) enum TALER_KYCLOGIC_KycUserType ut,
struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_KycStatusCallback cb,
void *cb_cls)
{ {
struct TALER_EXCHANGE_KycCheckHandle *kch; struct TALER_EXCHANGE_KycCheckHandle *kch;
CURL *eh; CURL *eh;
struct GNUNET_CURL_Context *ctx;
char *arg_str; char *arg_str;
if (GNUNET_YES !=
TEAH_handle_is_ready (exchange))
{
GNUNET_break (0);
return NULL;
}
{ {
char payto_str[sizeof (*h_payto) * 2]; char payto_str[sizeof (*h_payto) * 2];
char *end; char *end;
@ -282,19 +276,19 @@ TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
timeout_ms = timeout.rel_value_us timeout_ms = timeout.rel_value_us
/ GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
GNUNET_asprintf (&arg_str, GNUNET_asprintf (&arg_str,
"/kyc-check/%llu/%s/%s?timeout_ms=%llu", "kyc-check/%llu/%s/%s?timeout_ms=%llu",
(unsigned long long) requirement_row, (unsigned long long) requirement_row,
payto_str, payto_str,
TALER_KYCLOGIC_kyc_user_type2s (ut), TALER_KYCLOGIC_kyc_user_type2s (ut),
timeout_ms); timeout_ms);
} }
kch = GNUNET_new (struct TALER_EXCHANGE_KycCheckHandle); kch = GNUNET_new (struct TALER_EXCHANGE_KycCheckHandle);
kch->exchange = exchange;
kch->h_payto = *h_payto; kch->h_payto = *h_payto;
kch->cb = cb; kch->cb = cb;
kch->cb_cls = cb_cls; kch->cb_cls = cb_cls;
kch->url = TEAH_path_to_url (exchange, kch->url = TALER_url_join (url,
arg_str); arg_str,
NULL);
GNUNET_free (arg_str); GNUNET_free (arg_str);
if (NULL == kch->url) if (NULL == kch->url)
{ {
@ -309,7 +303,7 @@ TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_free (kch); GNUNET_free (kch);
return NULL; return NULL;
} }
ctx = TEAH_handle_to_context (exchange); kch->keys = TALER_EXCHANGE_keys_incref (keys);
kch->job = GNUNET_CURL_job_add_with_ct_json (ctx, kch->job = GNUNET_CURL_job_add_with_ct_json (ctx,
eh, eh,
&handle_kyc_check_finished, &handle_kyc_check_finished,
@ -326,6 +320,7 @@ TALER_EXCHANGE_kyc_check_cancel (struct TALER_EXCHANGE_KycCheckHandle *kch)
GNUNET_CURL_job_cancel (kch->job); GNUNET_CURL_job_cancel (kch->job);
kch->job = NULL; kch->job = NULL;
} }
TALER_EXCHANGE_keys_decref (kch->keys);
GNUNET_free (kch->url); GNUNET_free (kch->url);
GNUNET_free (kch); GNUNET_free (kch);
} }

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2021 Taler Systems SA Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as it under the terms of the GNU General Public License as
@ -114,16 +114,12 @@ check_kyc_run (void *cls,
const struct TALER_TESTING_Command *res_cmd; const struct TALER_TESTING_Command *res_cmd;
const uint64_t *requirement_row; const uint64_t *requirement_row;
const struct TALER_PaytoHashP *h_payto; const struct TALER_PaytoHashP *h_payto;
struct TALER_EXCHANGE_Handle *exchange
= TALER_TESTING_get_exchange (is);
(void) cmd; (void) cmd;
if (NULL == exchange)
return;
kcg->is = is; kcg->is = is;
res_cmd = TALER_TESTING_interpreter_lookup_command (kcg->is, res_cmd = TALER_TESTING_interpreter_lookup_command (
kcg-> kcg->is,
payment_target_reference); kcg->payment_target_reference);
if (NULL == res_cmd) if (NULL == res_cmd)
{ {
GNUNET_break (0); GNUNET_break (0);
@ -152,13 +148,16 @@ check_kyc_run (void *cls,
TALER_TESTING_interpreter_fail (kcg->is); TALER_TESTING_interpreter_fail (kcg->is);
return; return;
} }
kcg->kwh = TALER_EXCHANGE_kyc_check (exchange, kcg->kwh = TALER_EXCHANGE_kyc_check (
*requirement_row, TALER_TESTING_interpreter_get_context (is),
h_payto, TALER_TESTING_get_exchange_url (is),
TALER_KYCLOGIC_KYC_UT_INDIVIDUAL, TALER_TESTING_get_keys (is),
GNUNET_TIME_UNIT_SECONDS, *requirement_row,
&check_kyc_cb, h_payto,
kcg); TALER_KYCLOGIC_KYC_UT_INDIVIDUAL,
GNUNET_TIME_UNIT_SECONDS,
&check_kyc_cb,
kcg);
GNUNET_assert (NULL != kcg->kwh); GNUNET_assert (NULL != kcg->kwh);
} }