From 881381503f7f51b294c2740e9fcf7f28ef43f973 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 3 Jan 2024 23:41:35 +0100 Subject: simplify logic: only look in orders table if contracts table failed --- .../taler-merchant-httpd_private-get-orders-ID.c | 68 +++++++++------------- 1 file changed, 29 insertions(+), 39 deletions(-) (limited to 'src/backend') diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index cd26d378..602a970f 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -763,16 +763,15 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc) "contract terms")); return; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) { - gorc->order_only = true; + gorc->phase++; + return; } - /* FIXME: what is the point of doing the lookup_order - below if order_only is false (qs == 1 above)? - Seems we could just return here, or not? */ + /* No contract, only order, fetch from orders table */ + gorc->order_only = true; { struct TALER_MerchantPostDataHashP unused; - json_t *ct = NULL; /* We need the order for two cases: Either when the contract doesn't exist yet, * or when the order is claimed but unpaid, and we need the claim token. */ @@ -781,39 +780,30 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc) hc->infix, &gorc->claim_token, &unused, - &ct); - if (0 > qs) - { - /* single, read-only SQL statements should never cause - serialization problems */ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs); - /* Always report on hard error as well to enable diagnostics */ - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - phase_end (gorc, - TALER_MHD_reply_with_error (gorc->sc.con, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, - "order")); - return; - } - if (gorc->order_only && - (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) ) - { - phase_end (gorc, - TALER_MHD_reply_with_error (gorc->sc.con, - MHD_HTTP_NOT_FOUND, - TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN, - hc->infix)); - return; - } - if (gorc->order_only) - { - gorc->contract_terms = ct; - } - else if (NULL != ct) - { - json_decref (ct); - } + &gorc->contract_terms); + } + if (0 > qs) + { + /* single, read-only SQL statements should never cause + serialization problems */ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs); + /* Always report on hard error as well to enable diagnostics */ + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + phase_end (gorc, + TALER_MHD_reply_with_error (gorc->sc.con, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "order")); + return; + } + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + { + phase_end (gorc, + TALER_MHD_reply_with_error (gorc->sc.con, + MHD_HTTP_NOT_FOUND, + TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN, + hc->infix)); + return; } gorc->phase++; } -- cgit v1.2.3