diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-07-13 23:07:50 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-07-13 23:08:23 +0200 |
commit | 86f9c6823ec9d92dfbbbc1220655c91b129020cf (patch) | |
tree | c2a21180a3b8350ab4a98644bd359139df150c8c /src/backend/taler-merchant-httpd_private-post-reserves.c | |
parent | 4e45f3a965d5454b136eaf041d5d523f614343d4 (diff) | |
download | merchant-86f9c6823ec9d92dfbbbc1220655c91b129020cf.tar.gz merchant-86f9c6823ec9d92dfbbbc1220655c91b129020cf.tar.bz2 merchant-86f9c6823ec9d92dfbbbc1220655c91b129020cf.zip |
merging /keys and /wire API in the exchange
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-reserves.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-reserves.c | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c b/src/backend/taler-merchant-httpd_private-post-reserves.c index c6641876..db40b017 100644 --- a/src/backend/taler-merchant-httpd_private-post-reserves.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves.c @@ -89,11 +89,6 @@ struct PostReserveContext struct TMH_EXCHANGES_KeysOperation *fo; /** - * Handle for contacting the exchange for /wire. - */ - struct TMH_EXCHANGES_WireOperation *wo; - - /** * Master public key of the exchange matching * @e exchange_url. */ @@ -127,6 +122,11 @@ struct PostReserveContext * without a response due to shutdown. */ enum GNUNET_GenericReturnValue suspended; + + /** + * True if we already force reloaded /keys. + */ + bool force_reload; }; @@ -168,11 +168,6 @@ TMH_force_rc_resume () TMH_EXCHANGES_keys4exchange_cancel (rc->fo); rc->fo = NULL; } - if (NULL != rc->wo) - { - TMH_EXCHANGES_wire4exchange_cancel (rc->wo); - rc->wo = NULL; - } } } @@ -216,49 +211,17 @@ resume_request (struct PostReserveContext *rc) /** - * Function called once we go the /wire response from the exchange. - * - * @param cls a `struct PostReserveContext *` - * @param wire exchange wire details - */ -static void -wire_cb (void *cls, - const struct TMH_ExchangeWireDetails *wire) -{ - struct PostReserveContext *rc = cls; - - rc->wo = NULL; - rc->accounts = TMH_exchange_accounts_by_method ( - &rc->master_pub, - rc->wire_method); - if (NULL == rc->accounts) - { - rc->ec = TALER_EC_GENERIC_DB_FETCH_FAILED; - rc->http_status = MHD_HTTP_CONFLICT; - resume_request (rc); - return; - } - if (0 == json_array_size (rc->accounts)) - { - rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_UNSUPPORTED_WIRE_METHOD; - rc->http_status = MHD_HTTP_CONFLICT; - resume_request (rc); - return; - } - resume_request (rc); -} - - -/** * Function called with the result of a #TMH_EXCHANGES_keys4exchange() * operation. * * @param cls closure with our `struct PostReserveContext *` * @param keys exchange keys + * @param exchange representation of the exchange */ static void handle_exchange (void *cls, - struct TALER_EXCHANGE_Keys *keys) + struct TALER_EXCHANGE_Keys *keys, + struct TMH_Exchange *exchange) { struct PostReserveContext *rc = cls; @@ -273,6 +236,18 @@ handle_exchange (void *cls, } if (! keys->rewards_allowed) { + if (! rc->force_reload) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Forcing %s/keys reload (rewards not allowed)\n", + rc->exchange_url); + rc->force_reload = true; + rc->fo = TMH_EXCHANGES_keys4exchange (rc->exchange_url, + true, + &handle_exchange, + rc); + return; + } rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_REWARDS_NOT_ALLOWED; rc->http_status = MHD_HTTP_CONFLICT; resume_request (rc); @@ -281,9 +256,33 @@ handle_exchange (void *cls, rc->master_pub = keys->master_pub; rc->reserve_expiration = GNUNET_TIME_relative_to_timestamp (keys->reserve_closing_delay); - rc->wo = TMH_EXCHANGES_wire4exchange (rc->exchange_url, - &wire_cb, - rc); + rc->accounts = TMH_exchange_accounts_by_method ( + &rc->master_pub, + rc->wire_method); + if ( (NULL == rc->accounts) || + (0 == json_array_size (rc->accounts)) ) + { + if (! rc->force_reload) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Forcing %s/keys reload (no accounts)\n", + rc->exchange_url); + rc->force_reload = true; + rc->fo = TMH_EXCHANGES_keys4exchange (rc->exchange_url, + true, + &handle_exchange, + rc); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Wire method `%s' not supported\n", + rc->wire_method); + rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_UNSUPPORTED_WIRE_METHOD; + rc->http_status = MHD_HTTP_CONFLICT; + resume_request (rc); + return; + } + resume_request (rc); } @@ -326,6 +325,7 @@ TMH_private_post_reserves (const struct TMH_RequestHandler *rh, : MHD_NO; } rc->fo = TMH_EXCHANGES_keys4exchange (rc->exchange_url, + false, &handle_exchange, rc); rc->suspended = GNUNET_YES; |