address DB failure error handling in KYC check

This commit is contained in:
Christian Grothoff 2023-01-27 14:19:14 +01:00
parent c239ba6f18
commit 42bd2dadcf
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 43 additions and 16 deletions

@ -1 +1 @@
Subproject commit 3e659ed54023230dd45dbec5664f176e1763d260 Subproject commit 7884adf99ec4d5ccf52b1a5a251b99fb6ab9c2f6

View File

@ -297,6 +297,7 @@ kyc_check (void *cls,
enum GNUNET_GenericReturnValue ret; enum GNUNET_GenericReturnValue ret;
struct TALER_PaytoHashP h_payto; struct TALER_PaytoHashP h_payto;
char *requirements; char *requirements;
bool satisfied;
qs = TEH_plugin->lookup_kyc_requirement_by_row ( qs = TEH_plugin->lookup_kyc_requirement_by_row (
TEH_plugin->cls, TEH_plugin->cls,
@ -330,12 +331,26 @@ kyc_check (void *cls,
GNUNET_free (requirements); GNUNET_free (requirements);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
if (TALER_KYCLOGIC_check_satisfied ( qs = TALER_KYCLOGIC_check_satisfied (
requirements, requirements,
&h_payto, &h_payto,
&kyp->kyc_details, &kyp->kyc_details,
TEH_plugin->select_satisfied_kyc_processes, TEH_plugin->select_satisfied_kyc_processes,
TEH_plugin->cls)) TEH_plugin->cls,
&satisfied);
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");
GNUNET_free (requirements);
return GNUNET_DB_STATUS_HARD_ERROR;
}
if (satisfied)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"KYC requirements `%s' already satisfied\n", "KYC requirements `%s' already satisfied\n",

View File

@ -214,7 +214,7 @@ typedef enum GNUNET_DB_QueryStatus
* amounts involved in this type of operation * amounts involved in this type of operation
* at the given account * at the given account
* @param ai_cls closure for @a ai * @param ai_cls closure for @a ai
* @param[out] set to NULL if no check is needed, * @param[out] required set to NULL if no check is needed,
* otherwise space-separated list of required checks * otherwise space-separated list of required checks
* @return transaction status * @return transaction status
*/ */
@ -238,14 +238,16 @@ TALER_KYCLOGIC_kyc_test_required (enum TALER_KYCLOGIC_KycTriggerEvent event,
* KYC information was collected * KYC information was collected
* @param ki iterator over satisfied providers * @param ki iterator over satisfied providers
* @param ki_cls closure for @a ki * @param ki_cls closure for @a ki
* @return true if the KYC check was satisfied * @param[out] satisfied set to true if the KYC check was satisfied
* @return transaction status (from @a ki)
*/ */
bool enum GNUNET_DB_QueryStatus
TALER_KYCLOGIC_check_satisfied (const char *requirements, TALER_KYCLOGIC_check_satisfied (const char *requirements,
const struct TALER_PaytoHashP *h_payto, const struct TALER_PaytoHashP *h_payto,
json_t **kyc_details, json_t **kyc_details,
TALER_KYCLOGIC_KycSatisfiedIterator ki, TALER_KYCLOGIC_KycSatisfiedIterator ki,
void *ki_cls); void *ki_cls,
bool *satisfied);
/** /**

View File

@ -1166,18 +1166,22 @@ TALER_KYCLOGIC_kyc_get_details (
} }
bool enum GNUNET_DB_QueryStatus
TALER_KYCLOGIC_check_satisfied (const char *requirements, TALER_KYCLOGIC_check_satisfied (const char *requirements,
const struct TALER_PaytoHashP *h_payto, const struct TALER_PaytoHashP *h_payto,
json_t **kyc_details, json_t **kyc_details,
TALER_KYCLOGIC_KycSatisfiedIterator ki, TALER_KYCLOGIC_KycSatisfiedIterator ki,
void *ki_cls) void *ki_cls,
bool *satisfied)
{ {
struct TALER_KYCLOGIC_KycCheck *needed[num_kyc_checks]; struct TALER_KYCLOGIC_KycCheck *needed[num_kyc_checks];
unsigned int needed_cnt = 0; unsigned int needed_cnt = 0;
if (NULL == requirements) if (NULL == requirements)
return true; {
*satisfied = true;
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
}
{ {
char *req = GNUNET_strdup (requirements); char *req = GNUNET_strdup (requirements);
@ -1204,7 +1208,12 @@ TALER_KYCLOGIC_check_satisfied (const char *requirements,
h_payto, h_payto,
&remove_satisfied, &remove_satisfied,
&rc); &rc);
GNUNET_break (qs >= 0); // FIXME: handle DB failure more nicely? if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
*satisfied = false;
return qs;
}
if (0 != needed_cnt) if (0 != needed_cnt)
{ {
json_decref (rc.kyc_details); json_decref (rc.kyc_details);
@ -1215,7 +1224,8 @@ TALER_KYCLOGIC_check_satisfied (const char *requirements,
*kyc_details = rc.kyc_details; *kyc_details = rc.kyc_details;
} }
} }
return (0 == needed_cnt); *satisfied = (0 == needed_cnt);
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }