diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-11-24 09:51:53 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-11-24 09:51:53 +0100 |
commit | 6fa958a3cec156bc0eb89ddfae8b150d7400d2be (patch) | |
tree | 7b1f970e24cd24aee0c584757ccf300ebc541c8c | |
parent | f0e6846a4f5f398faa8a7bbbcfad5096fdd4352b (diff) |
address misc. FIXMEs
m--------- | contrib/wallet-core | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders.c | 46 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-instances.c | 46 | ||||
-rw-r--r-- | src/lib/merchant_api_post_order_pay.c | 10 |
4 files changed, 77 insertions, 25 deletions
diff --git a/contrib/wallet-core b/contrib/wallet-core -Subproject 5bc771e151df3145e61c017b3bc816c58ad9496 +Subproject 2347be694c713959528ad59f3f157d866d7ad42 diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c index 0e0511cc..b55a5552 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders.c +++ b/src/backend/taler-merchant-httpd_private-get-orders.c @@ -225,6 +225,23 @@ cleanup (void *ctx) /** + * Closure for #process_refunds_cb(). + */ +struct ProcessRefundsClosure +{ + /** + * Place where we accumulate the refunds. + */ + struct TALER_Amount total_refund_amount; + + /** + * Set to an error code if something goes wrong. + */ + enum TALER_ErrorCode ec; +}; + + +/** * Function called with information about a refund. * It is responsible for summing up the refund amount. * @@ -249,21 +266,20 @@ process_refunds_cb (void *cls, const struct TALER_Amount *refund_amount, bool pending) { - struct TALER_Amount *total_refund_amount = cls; + struct ProcessRefundsClosure *prc = cls; if (GNUNET_OK != - TALER_amount_cmp_currency (total_refund_amount, + TALER_amount_cmp_currency (&prc->total_refund_amount, refund_amount)) { /* Database error, refunds in mixed currency in DB. Not OK! */ - /* FIXME: we may want to return DB error to the client instead of just - ignoring the refund. */ + prc->ec = TALER_EC_GENERIC_DB_INVARIANT_FAILURE; GNUNET_break (0); return; } GNUNET_assert (0 <= - TALER_amount_add (total_refund_amount, - total_refund_amount, + TALER_amount_add (&prc->total_refund_amount, + &prc->total_refund_amount, refund_amount)); } @@ -395,16 +411,18 @@ add_order (void *cls, if (GNUNET_TIME_absolute_is_future (rd.abs_time) && paid) { - struct TALER_Amount refund_amount; + struct ProcessRefundsClosure prc = { + .ec = TALER_EC_NONE + }; GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (order_amount.currency, - &refund_amount)); + &prc.total_refund_amount)); qs = TMH_db->lookup_refunds_detailed (TMH_db->cls, po->instance_id, &h_contract_terms, &process_refunds_cb, - &refund_amount); + &prc); if (0 > qs) { GNUNET_break (0); @@ -413,7 +431,15 @@ add_order (void *cls, GNUNET_free (order_id); return; } - if (0 > TALER_amount_cmp (&refund_amount, + if (TALER_EC_NONE != prc.ec) + { + GNUNET_break (0); + po->result = prc.ec; + json_decref (contract_terms); + GNUNET_free (order_id); + return; + } + if (0 > TALER_amount_cmp (&prc.total_refund_amount, &order_amount)) refundable = true; } diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c b/src/backend/taler-merchant-httpd_private-post-instances.c index bc87ab41..396008c8 100644 --- a/src/backend/taler-merchant-httpd_private-post-instances.c +++ b/src/backend/taler-merchant-httpd_private-post-instances.c @@ -304,21 +304,41 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, &mi->merchant_priv, &mi->settings, &mi->auth); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) + switch (qs) { - MHD_RESULT ret; + case GNUNET_DB_STATUS_HARD_ERROR: + { + MHD_RESULT ret; - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - GNUNET_break (0); // FIXME: distinguish better by qs - ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS, - is.id); - mi->rc = 1; - TMH_instance_decref (mi); - return ret; + TMH_db->rollback (TMH_db->cls); + GNUNET_break (0); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + is.id); + mi->rc = 1; + TMH_instance_decref (mi); + return ret; + } + case GNUNET_DB_STATUS_SOFT_ERROR: + goto retry; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + { + MHD_RESULT ret; + + TMH_db->rollback (TMH_db->cls); + GNUNET_break (0); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_CONFLICT, + TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS, + is.id); + mi->rc = 1; + TMH_instance_decref (mi); + return ret; + } + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + /* handled below */ + break; } qs = TMH_db->commit (TMH_db->cls); if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c index 5a5c1631..57c85565 100644 --- a/src/lib/merchant_api_post_order_pay.c +++ b/src/lib/merchant_api_post_order_pay.c @@ -476,6 +476,8 @@ TALER_MERCHANT_order_pay ( TALER_MERCHANT_OrderPayCallback pay_cb, void *pay_cb_cls) { + struct GNUNET_HashCode wallet_data_hash; + if (GNUNET_YES != TALER_amount_cmp_currency (amount, max_fee)) @@ -483,7 +485,9 @@ TALER_MERCHANT_order_pay ( GNUNET_break (0); return NULL; } - + if (NULL != wallet_data) + TALER_json_hash (wallet_data, + &wallet_data_hash); { struct TALER_MERCHANT_PaidCoin pc[num_coins]; @@ -510,7 +514,9 @@ TALER_MERCHANT_order_pay ( &fee, h_wire, h_contract_terms, - NULL /* FIXME: compute using wallet_data */, + (NULL != wallet_data) + ? &wallet_data_hash + : NULL, coin->h_age_commitment, NULL /* h_extensions! */, &h_denom_pub, |