aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-07-31 23:39:55 +0200
committerChristian Grothoff <christian@grothoff.org>2024-07-31 23:39:55 +0200
commitc10874a858745b4205feabb38ed8f5e8bd11acc1 (patch)
tree1aa235f8e543ec5e2055bd6ac8b521b44b3840c2 /src/backend
parent854bad7d7c220c9ea9f4d61eb8fd46548a160da2 (diff)
fix account_kyc_set_status
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-depositcheck.c63
-rw-r--r--src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c218
2 files changed, 186 insertions, 95 deletions
diff --git a/src/backend/taler-merchant-depositcheck.c b/src/backend/taler-merchant-depositcheck.c
index cd0242f0..ff90c505 100644
--- a/src/backend/taler-merchant-depositcheck.c
+++ b/src/backend/taler-merchant-depositcheck.c
@@ -407,8 +407,9 @@ run_at (struct GNUNET_TIME_Absolute deadline)
* @param dr HTTP response data
*/
static void
-deposit_get_cb (void *cls,
- const struct TALER_EXCHANGE_GetDepositResponse *dr)
+deposit_get_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_GetDepositResponse *dr)
{
struct ExchangeInteraction *w = cls;
struct GNUNET_TIME_Absolute future_retry;
@@ -425,9 +426,10 @@ deposit_get_cb (void *cls,
"Exchange returned wire transfer over %s for deposited coin %s\n",
TALER_amount2s (&dr->details.ok.coin_contribution),
TALER_B2S (&w->coin_pub));
- qs = db_plugin->insert_deposit_to_transfer (db_plugin->cls,
- w->deposit_serial,
- &dr->details.ok);
+ qs = db_plugin->insert_deposit_to_transfer (
+ db_plugin->cls,
+ w->deposit_serial,
+ &dr->details.ok);
if (qs < 0)
{
GNUNET_break (0);
@@ -468,6 +470,12 @@ deposit_get_cb (void *cls,
exchange_url,
dr->details.accepted.requirement_row,
now,
+ MHD_HTTP_ACCEPTED,
+ TALER_EC_NONE,
+ NULL,
+ 0,
+ NULL,
+ false,
dr->details.accepted.kyc_ok);
if (qs < 0)
{
@@ -598,7 +606,8 @@ pending_deposits_cb (
const struct TALER_Amount *deposit_fee,
const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
- struct ExchangeInteraction *w = GNUNET_new (struct ExchangeInteraction);
+ struct ExchangeInteraction *w
+ = GNUNET_new (struct ExchangeInteraction);
(void) cls;
if (GNUNET_TIME_absolute_is_future (wire_deadline))
@@ -624,7 +633,8 @@ pending_deposits_cb (
w);
w_count++;
GNUNET_assert (NULL != keys);
- if (GNUNET_TIME_absolute_is_past (keys->key_data_expiration.abs_time))
+ if (GNUNET_TIME_absolute_is_past (
+ keys->key_data_expiration.abs_time))
{
/* Parent should re-start us, then we will re-fetch /keys */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -693,7 +703,8 @@ select_work (void *cls)
GNUNET_break (0);
return;
}
- if (GNUNET_TIME_absolute_is_past (keys->key_data_expiration.abs_time))
+ if (GNUNET_TIME_absolute_is_past (
+ keys->key_data_expiration.abs_time))
{
/* Parent should re-start us, then we will re-fetch /keys */
GNUNET_SCHEDULER_shutdown ();
@@ -706,12 +717,13 @@ select_work (void *cls)
db_plugin->preflight (db_plugin->cls);
if (retry)
limit = 1;
- qs = db_plugin->lookup_pending_deposits (db_plugin->cls,
- exchange_url,
- limit,
- retry,
- &pending_deposits_cb,
- NULL);
+ qs = db_plugin->lookup_pending_deposits (
+ db_plugin->cls,
+ exchange_url,
+ limit,
+ retry,
+ &pending_deposits_cb,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Looking up pending deposits query status was %d\n",
(int) qs);
@@ -792,17 +804,18 @@ start_worker (const char *base_url)
"Launching worker for exchange `%s' using `%s`\n",
base_url,
cfg_filename);
- return GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL,
- NULL,
- NULL,
- "taler-merchant-depositcheck",
- "taler-merchant-depositcheck",
- "-c", cfg_filename,
- "-e", base_url,
- "-L", "INFO",
- test_mode ? "-t" : NULL,
- NULL);
+ return GNUNET_OS_start_process (
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL,
+ NULL,
+ NULL,
+ "taler-merchant-depositcheck",
+ "taler-merchant-depositcheck",
+ "-c", cfg_filename,
+ "-e", base_url,
+ "-L", "INFO",
+ test_mode ? "-t" : NULL,
+ NULL);
}
diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c
index 3cf4b161..9c215872 100644
--- a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c
+++ b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c
@@ -475,6 +475,78 @@ ekr_finished (struct ExchangeKycRequest *ekr)
/**
+ * Store KYC response from the exchange in the
+ * local database.
+ *
+ * @param ekr request context
+ * @param ks HTTP response details
+ * @param aks account KYC status details
+ * @return true if the operation was successful
+ */
+static bool
+store_kyc_status (
+ const struct ExchangeKycRequest *ekr,
+ const struct TALER_EXCHANGE_KycStatus *ks,
+ const struct TALER_EXCHANGE_AccountKycStatus *aks)
+{
+ unsigned int dl_cnt = 0;
+
+ for (unsigned int i = 0; i<aks->limits_length; i++)
+ {
+ const struct TALER_EXCHANGE_AccountLimit *limit
+ = &aks->limits[i];
+
+ if (TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT ==
+ limit->operation_type)
+ dl_cnt++;
+ }
+
+ {
+ struct TALER_MERCHANTDB_DepositLimits dls[GNUNET_NZL (dl_cnt)];
+ enum GNUNET_DB_QueryStatus qs;
+ unsigned int off = 0;
+
+ for (unsigned int i = 0; i<aks->limits_length; i++)
+ {
+ const struct TALER_EXCHANGE_AccountLimit *limit
+ = &aks->limits[i];
+ struct TALER_MERCHANTDB_DepositLimits *dl
+ = &dls[off];
+
+ if (TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT !=
+ limit->operation_type)
+ continue;
+ dl->timeframe = limit->timeframe;
+ dl->threshold = limit->threshold;
+ dl->soft_limit = limit->soft_limit;
+ off++;
+ }
+ qs = TMH_db->account_kyc_set_status (
+ TMH_db->cls,
+ ekr->kc->mi->settings.id,
+ &ekr->h_wire,
+ ekr->exchange_url,
+ ekr->exchange_kyc_serial,
+ GNUNET_TIME_timestamp_get (),
+ ks->hr.http_status,
+ ks->hr.ec,
+ &aks->access_token,
+ dl_cnt,
+ dls,
+ aks->aml_review,
+ false);
+ if (qs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to store KYC status in database!\n");
+ return false;
+ }
+ }
+ return true;
+}
+
+
+/**
* Function called with the result of a KYC check.
*
* @param cls a `struct ExchangeKycRequest *`
@@ -493,44 +565,35 @@ exchange_check_cb (
{
case MHD_HTTP_OK:
{
- enum GNUNET_DB_QueryStatus qs;
const struct TALER_EXCHANGE_AccountKycStatus *aks;
aks = &ks->details.ok;
- // FIXME: also store aks->access_token, limits,
- // aml_review, etc.!
- qs = TMH_db->account_kyc_set_status (
- TMH_db->cls,
- kc->mi->settings.id,
- &ekr->h_wire,
- ekr->exchange_url,
- ekr->exchange_kyc_serial,
- GNUNET_TIME_timestamp_get (),
- true);
- if (qs < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to store KYC status in database!\n");
- }
+ GNUNET_break (store_kyc_status (ekr,
+ ks,
+ aks));
}
break;
case MHD_HTTP_ACCEPTED:
{
- struct GNUNET_TIME_Timestamp now;
- enum GNUNET_DB_QueryStatus qs;
- const struct TALER_EXCHANGE_AccountKycStatus *aks;
+ const struct TALER_EXCHANGE_AccountKycStatus *aks
+ = &ks->details.accepted;
char *kyc_url;
- char *ats;
-
- aks = &ks->details.accepted;
- ats = GNUNET_STRINGS_data_to_string_alloc (
- &aks->access_token,
- sizeof (aks->access_token));
- GNUNET_asprintf (&kyc_url,
- "%s/kyc-spa/%s",
- ekr->exchange_url,
- ats);
- GNUNET_free (ats);
+
+ GNUNET_break (store_kyc_status (ekr,
+ ks,
+ aks));
+ {
+ char *ats;
+
+ ats = GNUNET_STRINGS_data_to_string_alloc (
+ &aks->access_token,
+ sizeof (aks->access_token));
+ GNUNET_asprintf (&kyc_url,
+ "%s/kyc-spa/%s",
+ ekr->exchange_url,
+ ats);
+ GNUNET_free (ats);
+ }
GNUNET_assert (
0 ==
json_array_append_new (
@@ -545,37 +608,25 @@ exchange_check_cb (
GNUNET_JSON_pack_string ("payto_uri",
ekr->payto_uri))));
GNUNET_free (kyc_url);
- now = GNUNET_TIME_timestamp_get ();
- // FIXME: also store aks->access_token, limits,
- // aml_review, etc.!
- qs = TMH_db->account_kyc_set_status (
- TMH_db->cls,
- kc->mi->settings.id,
- &ekr->h_wire,
- ekr->exchange_url,
- ekr->exchange_kyc_serial,
- now,
- false);
- if (qs < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to store KYC status in database!\n");
- }
break;
}
case MHD_HTTP_NO_CONTENT:
{
- struct GNUNET_TIME_Timestamp now;
enum GNUNET_DB_QueryStatus qs;
- now = GNUNET_TIME_timestamp_get ();
qs = TMH_db->account_kyc_set_status (
TMH_db->cls,
kc->mi->settings.id,
&ekr->h_wire,
ekr->exchange_url,
ekr->exchange_kyc_serial,
- now,
+ GNUNET_TIME_timestamp_get (),
+ MHD_HTTP_NO_CONTENT,
+ TALER_EC_NONE,
+ NULL,
+ 0,
+ NULL,
+ false,
true);
if (qs < 0)
{
@@ -587,9 +638,8 @@ exchange_check_cb (
case MHD_HTTP_FORBIDDEN:
case MHD_HTTP_NOT_FOUND:
case MHD_HTTP_CONFLICT:
- case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS: // FIXME: real?
{
- struct GNUNET_TIME_Timestamp now;
enum GNUNET_DB_QueryStatus qs;
GNUNET_assert (
@@ -605,15 +655,19 @@ exchange_check_cb (
ks->hr.http_status),
GNUNET_JSON_pack_string ("payto_uri",
ekr->payto_uri))));
- now = GNUNET_TIME_timestamp_get ();
- // FIXME: also store HTTP status code + EC in DB!
qs = TMH_db->account_kyc_set_status (
TMH_db->cls,
kc->mi->settings.id,
&ekr->h_wire,
ekr->exchange_url,
ekr->exchange_kyc_serial,
- now,
+ GNUNET_TIME_timestamp_get (),
+ ks->hr.http_status,
+ ks->hr.ec,
+ NULL,
+ 0,
+ NULL,
+ false,
true);
if (qs < 0)
{
@@ -623,22 +677,46 @@ exchange_check_cb (
}
break;
default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Exchange responded with HTTP status %u (%d) to /kyc-check request!\n",
- ks->hr.http_status,
- ks->hr.ec);
- kc->response_code = MHD_HTTP_BAD_GATEWAY;
- GNUNET_assert (
- 0 ==
- json_array_append_new (
- kc->timeout_kycs,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("exchange_url",
- ekr->exchange_url),
- GNUNET_JSON_pack_uint64 ("exchange_code",
- ks->hr.ec),
- GNUNET_JSON_pack_uint64 ("exchange_http_status",
- ks->hr.http_status))));
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Exchange responded with HTTP status %u (%d) to /kyc-check request!\n",
+ ks->hr.http_status,
+ ks->hr.ec);
+ kc->response_code = MHD_HTTP_BAD_GATEWAY;
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ kc->timeout_kycs,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("exchange_url",
+ ekr->exchange_url),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ ks->hr.ec),
+ GNUNET_JSON_pack_uint64 ("exchange_http_status",
+ ks->hr.http_status))));
+ qs = TMH_db->account_kyc_set_status (
+ TMH_db->cls,
+ kc->mi->settings.id,
+ &ekr->h_wire,
+ ekr->exchange_url,
+ ekr->exchange_kyc_serial,
+ GNUNET_TIME_timestamp_get (),
+ ks->hr.http_status,
+ ks->hr.ec,
+ NULL,
+ 0,
+ NULL,
+ false,
+ true);
+ if (qs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to store KYC status in database!\n");
+ }
+ break;
+ }
}
ekr_finished (ekr);
}