diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-09-10 15:56:03 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-09-10 15:56:03 +0200 |
commit | d31c91783a5d185f749a24965da80c7dbcfc9a8c (patch) | |
tree | edd6f7eeab39d0e180c975c554ab4658983f650f | |
parent | a8f851315ceb958ae7e1ee730f38384b5dab0799 (diff) |
-fix limit calculation
-rw-r--r-- | src/backend/taler-merchant-httpd_exchanges.c | 125 |
1 files changed, 59 insertions, 66 deletions
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c index f4ebaef2..90649a7e 100644 --- a/src/backend/taler-merchant-httpd_exchanges.c +++ b/src/backend/taler-merchant-httpd_exchanges.c @@ -670,7 +670,7 @@ TMH_exchange_check_debit ( bool account_ok = false; bool have_kyc = false; struct TALER_Amount kyc_limit; - bool unlimited = false; + bool unlimited = true; if (NULL == keys) return GNUNET_SYSERR; @@ -680,10 +680,6 @@ TMH_exchange_check_debit ( GNUNET_break (0); return GNUNET_SYSERR; } - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero ( - max_amount->currency, - &kyc_limit)); /* For all accounts of the exchange */ for (unsigned int i = 0; i<keys->accounts_len; i++) { @@ -704,76 +700,73 @@ TMH_exchange_check_debit ( account_ok = true; /* Check legitimization limits we have with this account at this exchange, if we have any, apply them */ + } + { + bool kyc_ok = false; + json_t *jlimits = NULL; + enum GNUNET_DB_QueryStatus qs; + + qs = TMH_db->get_kyc_limits (TMH_db->cls, + wm->payto_uri, + instance_id, + exchange->url, + &kyc_ok, + &jlimits); + GNUNET_break (qs >= 0); + if ( (qs > 0) && + (NULL != jlimits) ) { - bool kyc_ok = false; - json_t *jlimits = NULL; - enum GNUNET_DB_QueryStatus qs; - - qs = TMH_db->get_kyc_limits (TMH_db->cls, - wm->payto_uri, - instance_id, - exchange->url, - &kyc_ok, - &jlimits); - GNUNET_break (qs >= 0); - if (qs <= 0) - { - unlimited = true; - continue; - } - if (NULL == jlimits) - { - unlimited = true; - } - else - { - json_t *jlimit; - size_t idx; - bool found = false; + json_t *jlimit; + size_t idx; - json_array_foreach (jlimits, idx, jlimit) + json_array_foreach (jlimits, idx, jlimit) + { + enum TALER_KYCLOGIC_KycTriggerEvent ot; + struct TALER_Amount threshold; + bool soft_limit = false; + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_kycte ("operation_type", + &ot), + TALER_JSON_spec_amount_any ("threshold", + &threshold), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("soft_limit", + &soft_limit), + NULL), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (jlimit, + spec, + NULL, NULL)) + { + GNUNET_break (0); + continue; + } + if (soft_limit) + continue; + if ( (TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT != ot) && + (TALER_KYCLOGIC_KYC_TRIGGER_TRANSACTION != ot) ) + continue; + if (unlimited) { - enum TALER_KYCLOGIC_KycTriggerEvent ot; - struct TALER_Amount threshold; - bool soft_limit = false; - struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_kycte ("operation_type", - &ot), - TALER_JSON_spec_amount_any ("threshold", - &threshold), - GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_bool ("soft_limit", - &soft_limit), - NULL), - GNUNET_JSON_spec_end () - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (jlimit, - spec, - NULL, NULL)) - { - GNUNET_break (0); - continue; - } - if (soft_limit) - continue; - if ( (TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT != ot) && - (TALER_KYCLOGIC_KYC_TRIGGER_TRANSACTION != ot) ) - continue; - found = true; - TALER_amount_max (&kyc_limit, + unlimited = false; + kyc_limit = threshold; + } + else + { + TALER_amount_min (&kyc_limit, &kyc_limit, &threshold); } - json_decref (jlimit); - if (! found) - unlimited = true; } - if (kyc_ok) - have_kyc = true; + json_decref (jlimits); } + if (kyc_ok) + have_kyc = true; } + if (! unlimited) TALER_amount_min (max_amount, max_amount, |