diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-09-10 13:15:01 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-09-10 13:15:01 +0200 |
commit | 044c308a71b692977b02556cf9633fb5bb2f094a (patch) | |
tree | 2a0150095426e6cce01f7b58502beca10a215dea | |
parent | ef9998604e14d03ca42b787976ecfe20bd25c5ce (diff) |
clean up order, no semantic change
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 422 | ||||
-rw-r--r-- | src/backend/taler-merchant-kyccheck.c | 1 |
2 files changed, 211 insertions, 212 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index 8fcbf7c4..8a02625b 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2023 Taler Systems SA + (C) 2014-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -1136,216 +1136,6 @@ salt_forgettable (struct OrderContext *oc) /** - * Update MAX STEFAN fees based on @a keys. - * - * @param[in,out] oc order context to update - * @param keys keys to derive STEFAN fees from - */ -static void -update_stefan (struct OrderContext *oc, - const struct TALER_EXCHANGE_Keys *keys) -{ - struct TALER_Amount net; - - if (GNUNET_SYSERR != - TALER_EXCHANGE_keys_stefan_b2n (keys, - &oc->parse_order.brutto, - &net)) - { - struct TALER_Amount fee; - - TALER_EXCHANGE_keys_stefan_round (keys, - &net); - if (-1 == TALER_amount_cmp (&oc->parse_order.brutto, - &net)) - { - /* brutto < netto! */ - /* => after rounding, there is no real difference */ - net = oc->parse_order.brutto; - } - GNUNET_assert (0 <= - TALER_amount_subtract (&fee, - &oc->parse_order.brutto, - &net)); - if ( (GNUNET_OK != - TALER_amount_is_valid (&oc->set_exchanges.max_stefan_fee)) || - (-1 == TALER_amount_cmp (&oc->set_exchanges.max_stefan_fee, - &fee)) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Updated STEFAN-based fee to %s\n", - TALER_amount2s (&fee)); - oc->set_exchanges.max_stefan_fee = fee; - } - } -} - - -/** - * Compute the set of exchanges that would be acceptable - * for this order. - * - * @param cls our `struct OrderContext` - * @param url base URL of an exchange (not used) - * @param exchange internal handle for the exchange - */ -static void -get_acceptable (void *cls, - const char *url, - const struct TMH_Exchange *exchange) -{ - struct OrderContext *oc = cls; - unsigned int priority = 42; /* make compiler happy */ - json_t *j_exchange; - enum GNUNET_GenericReturnValue res; - - res = TMH_exchange_check_debit (exchange, - oc->add_payment_details.wm); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Exchange %s evaluated at %d\n", - url, - res); - switch (res) - { - case GNUNET_OK: - priority = 1024; /* high */ - oc->set_exchanges.exchange_good = true; - break; - case GNUNET_NO: - if (oc->set_exchanges.forced_reload) - priority = 0; /* fresh negative response */ - else - priority = 512; /* stale negative response */ - break; - case GNUNET_SYSERR: - if (oc->set_exchanges.forced_reload) - priority = 256; /* fresh, no accounts yet */ - else - priority = 768; /* stale, no accounts yet */ - break; - } - j_exchange = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("url", - url), - GNUNET_JSON_pack_uint64 ("priority", - priority), - GNUNET_JSON_pack_data_auto ("master_pub", - TMH_EXCHANGES_get_master_pub (exchange))); - GNUNET_assert (NULL != j_exchange); - GNUNET_assert (0 == - json_array_append_new (oc->set_exchanges.exchanges, - j_exchange)); -} - - -/** - * Exchange `/keys` processing is done, resume handling - * the order. - * - * @param[in,out] oc context to resume - */ -static void -resume_with_keys (struct OrderContext *oc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Resuming order processing after /keys downloads (now have %u accounts)\n", - (unsigned int) json_array_size (oc->set_exchanges.exchanges)); - GNUNET_assert (GNUNET_YES == oc->suspended); - GNUNET_CONTAINER_DLL_remove (oc_head, - oc_tail, - oc); - oc->suspended = GNUNET_NO; - MHD_resume_connection (oc->connection); - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ -} - - -/** - * Function called with the result of a #TMH_EXCHANGES_keys4exchange() - * operation. - * - * @param cls closure with our `struct RekeyExchange *` - * @param keys the keys of the exchange - * @param exchange representation of the exchange - */ -static void -keys_cb ( - void *cls, - struct TALER_EXCHANGE_Keys *keys, - struct TMH_Exchange *exchange) -{ - struct RekeyExchange *rx = cls; - struct OrderContext *oc = rx->oc; - const struct TALER_MERCHANTDB_InstanceSettings *settings = - &oc->hc->instance->settings; - - rx->fo = NULL; - GNUNET_CONTAINER_DLL_remove (oc->set_exchanges.pending_reload_head, - oc->set_exchanges.pending_reload_tail, - rx); - if (NULL == keys) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to download %skeys\n", - rx->url); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Got response for %skeys\n", - rx->url); - if ( (settings->use_stefan) && - (GNUNET_OK != - TALER_amount_is_valid (&oc->parse_order.max_fee)) ) - update_stefan (oc, - keys); - get_acceptable (oc, - rx->url, - exchange); - } - GNUNET_free (rx->url); - GNUNET_free (rx); - if (NULL != oc->set_exchanges.pending_reload_head) - return; - resume_with_keys (oc); -} - - -/** - * Force re-downloading of /keys from @a exchange, - * we currently have no acceptable exchange, so we - * should try to get one. - * - * @param cls closure with our `struct OrderContext` - * @param url base URL of the exchange - * @param exchange internal handle for the exchange - */ -static void -get_exchange_keys (void *cls, - const char *url, - const struct TMH_Exchange *exchange) -{ - struct OrderContext *oc = cls; - struct RekeyExchange *rx; - - rx = GNUNET_new (struct RekeyExchange); - rx->oc = oc; - rx->url = GNUNET_strdup (url); - GNUNET_CONTAINER_DLL_insert (oc->set_exchanges.pending_reload_head, - oc->set_exchanges.pending_reload_tail, - rx); - if (oc->set_exchanges.forced_reload) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Forcing download of %skeys\n", - url); - rx->fo = TMH_EXCHANGES_keys4exchange (url, - oc->set_exchanges.forced_reload, - &keys_cb, - rx); -} - - -/** * Get rounded time interval. @a start is calculated by rounding * @a ts down to the nearest multiple of @a precision. @a end is * the next higher multiple of @a precision. @@ -2036,6 +1826,216 @@ set_max_fee (struct OrderContext *oc) /** + * Exchange `/keys` processing is done, resume handling + * the order. + * + * @param[in,out] oc context to resume + */ +static void +resume_with_keys (struct OrderContext *oc) +{ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Resuming order processing after /keys downloads (now have %u accounts)\n", + (unsigned int) json_array_size (oc->set_exchanges.exchanges)); + GNUNET_assert (GNUNET_YES == oc->suspended); + GNUNET_CONTAINER_DLL_remove (oc_head, + oc_tail, + oc); + oc->suspended = GNUNET_NO; + MHD_resume_connection (oc->connection); + TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ +} + + +/** + * Update MAX STEFAN fees based on @a keys. + * + * @param[in,out] oc order context to update + * @param keys keys to derive STEFAN fees from + */ +static void +update_stefan (struct OrderContext *oc, + const struct TALER_EXCHANGE_Keys *keys) +{ + struct TALER_Amount net; + + if (GNUNET_SYSERR != + TALER_EXCHANGE_keys_stefan_b2n (keys, + &oc->parse_order.brutto, + &net)) + { + struct TALER_Amount fee; + + TALER_EXCHANGE_keys_stefan_round (keys, + &net); + if (-1 == TALER_amount_cmp (&oc->parse_order.brutto, + &net)) + { + /* brutto < netto! */ + /* => after rounding, there is no real difference */ + net = oc->parse_order.brutto; + } + GNUNET_assert (0 <= + TALER_amount_subtract (&fee, + &oc->parse_order.brutto, + &net)); + if ( (GNUNET_OK != + TALER_amount_is_valid (&oc->set_exchanges.max_stefan_fee)) || + (-1 == TALER_amount_cmp (&oc->set_exchanges.max_stefan_fee, + &fee)) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Updated STEFAN-based fee to %s\n", + TALER_amount2s (&fee)); + oc->set_exchanges.max_stefan_fee = fee; + } + } +} + + +/** + * Compute the set of exchanges that would be acceptable + * for this order. + * + * @param cls our `struct OrderContext` + * @param url base URL of an exchange (not used) + * @param exchange internal handle for the exchange + */ +static void +get_acceptable (void *cls, + const char *url, + const struct TMH_Exchange *exchange) +{ + struct OrderContext *oc = cls; + unsigned int priority = 42; /* make compiler happy */ + json_t *j_exchange; + enum GNUNET_GenericReturnValue res; + + res = TMH_exchange_check_debit (exchange, + oc->add_payment_details.wm); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Exchange %s evaluated at %d\n", + url, + res); + switch (res) + { + case GNUNET_OK: + priority = 1024; /* high */ + oc->set_exchanges.exchange_good = true; + break; + case GNUNET_NO: + if (oc->set_exchanges.forced_reload) + priority = 0; /* fresh negative response */ + else + priority = 512; /* stale negative response */ + break; + case GNUNET_SYSERR: + if (oc->set_exchanges.forced_reload) + priority = 256; /* fresh, no accounts yet */ + else + priority = 768; /* stale, no accounts yet */ + break; + } + j_exchange = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("url", + url), + GNUNET_JSON_pack_uint64 ("priority", + priority), + GNUNET_JSON_pack_data_auto ("master_pub", + TMH_EXCHANGES_get_master_pub (exchange))); + GNUNET_assert (NULL != j_exchange); + GNUNET_assert (0 == + json_array_append_new (oc->set_exchanges.exchanges, + j_exchange)); +} + + +/** + * Function called with the result of a #TMH_EXCHANGES_keys4exchange() + * operation. + * + * @param cls closure with our `struct RekeyExchange *` + * @param keys the keys of the exchange + * @param exchange representation of the exchange + */ +static void +keys_cb ( + void *cls, + struct TALER_EXCHANGE_Keys *keys, + struct TMH_Exchange *exchange) +{ + struct RekeyExchange *rx = cls; + struct OrderContext *oc = rx->oc; + const struct TALER_MERCHANTDB_InstanceSettings *settings = + &oc->hc->instance->settings; + + rx->fo = NULL; + GNUNET_CONTAINER_DLL_remove (oc->set_exchanges.pending_reload_head, + oc->set_exchanges.pending_reload_tail, + rx); + if (NULL == keys) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to download %skeys\n", + rx->url); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Got response for %skeys\n", + rx->url); + if ( (settings->use_stefan) && + (GNUNET_OK != + TALER_amount_is_valid (&oc->parse_order.max_fee)) ) + update_stefan (oc, + keys); + get_acceptable (oc, + rx->url, + exchange); + } + GNUNET_free (rx->url); + GNUNET_free (rx); + if (NULL != oc->set_exchanges.pending_reload_head) + return; + resume_with_keys (oc); +} + + +/** + * Force re-downloading of /keys from @a exchange, + * we currently have no acceptable exchange, so we + * should try to get one. + * + * @param cls closure with our `struct OrderContext` + * @param url base URL of the exchange + * @param exchange internal handle for the exchange + */ +static void +get_exchange_keys (void *cls, + const char *url, + const struct TMH_Exchange *exchange) +{ + struct OrderContext *oc = cls; + struct RekeyExchange *rx; + + rx = GNUNET_new (struct RekeyExchange); + rx->oc = oc; + rx->url = GNUNET_strdup (url); + GNUNET_CONTAINER_DLL_insert (oc->set_exchanges.pending_reload_head, + oc->set_exchanges.pending_reload_tail, + rx); + if (oc->set_exchanges.forced_reload) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Forcing download of %skeys\n", + url); + rx->fo = TMH_EXCHANGES_keys4exchange (url, + oc->set_exchanges.forced_reload, + &keys_cb, + rx); +} + + +/** * Set list of acceptable exchanges in @a oc. Upon success, continue * processing with set_max_fee(). * diff --git a/src/backend/taler-merchant-kyccheck.c b/src/backend/taler-merchant-kyccheck.c index e1152d14..7d6b7558 100644 --- a/src/backend/taler-merchant-kyccheck.c +++ b/src/backend/taler-merchant-kyccheck.c @@ -688,7 +688,6 @@ is_eligible (const struct TALER_EXCHANGE_Keys *keys, /* FIXME: move into convenience function in libtalerexchange? See also taler-merchant-httpd_private-get-instances-ID-kyc.c, taler-merchant-httpd_exchanges (!)*/ const struct TALER_EXCHANGE_WireAccount *account = &keys->accounts[i]; - bool account_restricted = false; /* KYC auth transfers are never supported with conversion */ if (NULL != account->conversion_url) |