merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 0c16f9e8b34fef082d33ffff6fcdc9fcc6b27ed7
parent f5f0a46262229d2c2cc0385d466c53d8be8a53a2
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 20 Jul 2021 12:58:50 +0200

-fix FTBFS and #6920

Diffstat:
Msrc/backend/taler-merchant-httpd.c | 2+-
Msrc/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c | 18------------------
Msrc/backenddb/plugin_merchantdb_postgres.c | 59+++++++++++++++++++++++++++++++++--------------------------
3 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -1689,7 +1689,7 @@ url_handler (void *cls, TMH_compute_auth (TMH_default_auth, &hc->instance->auth.auth_salt, &hc->instance->auth.auth_hash); - GNUNET_free (TMH_default_auth) + GNUNET_free (TMH_default_auth); } } if (NULL != hc->instance) diff --git a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c @@ -142,14 +142,6 @@ authorize_tip (const struct TMH_RequestHandler *rh, } -/** - * Handle a "/reserves/$ID/tip-authorize" request. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] hc context with further information about the request - * @return MHD result code - */ MHD_RESULT TMH_private_post_reserves_ID_authorize_tip (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, @@ -176,16 +168,6 @@ TMH_private_post_reserves_ID_authorize_tip (const struct TMH_RequestHandler *rh, } -/** - * Handle a POST "/tips" request. - * Here the client does not specify the reserve public key, so we - * are free to pick "any" available reserve. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] hc context with further information about the request - * @return MHD result code - */ MHD_RESULT TMH_private_post_tips (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -5303,6 +5303,11 @@ struct LookupReserveForTipContext * Error status. */ enum TALER_ErrorCode ec; + + /** + * Did we find a good reserve? + */ + bool ok; }; @@ -5368,13 +5373,27 @@ lookup_reserve_for_tip_cb (void *cls, if (0 > TALER_amount_cmp (&remaining, &lac->required_amount)) - continue; /* insufficient balance */ + { + /* insufficient balance */ + if (lac->ok) + continue; /* got another reserve */ + lac->ec = TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_INSUFFICIENT_FUNDS; + continue; + } if ( (lac->expiration.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) && ( (expiration.abs_value_us > lac->expiration.abs_value_us) && (GNUNET_TIME_absolute_get_remaining (lac->expiration).rel_value_us > MIN_EXPIRATION.rel_value_us) ) ) + { + /* reserve expired */ + if (lac->ok) + continue; /* got another reserve */ + lac->ec = TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_RESERVE_EXPIRED; continue; + } + lac->ok = true; + lac->ec = TALER_EC_NONE; lac->expiration = expiration; lac->reserve_pub = reserve_pub; } @@ -5445,11 +5464,8 @@ RETRY: } if (NULL == reserve_pubp) { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), - TALER_PQ_query_param_amount (amount), - GNUNET_PQ_query_param_absolute_time (&now), GNUNET_PQ_query_param_end }; @@ -5458,29 +5474,25 @@ RETRY: params, &lookup_reserve_for_tip_cb, &lac); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + switch (qs) { + case GNUNET_DB_STATUS_SOFT_ERROR: postgres_rollback (pg); goto RETRY; - } - if (GNUNET_DB_STATUS_HARD_ERROR == qs) - { + case GNUNET_DB_STATUS_HARD_ERROR: GNUNET_break (0); postgres_rollback (pg); - return - TALER_EC_GENERIC_DB_FETCH_FAILED; - } - if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == - lac.expiration.abs_value_us) - { + return TALER_EC_GENERIC_DB_FETCH_FAILED; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: postgres_rollback (pg); return TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_RESERVE_NOT_FOUND; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + default: + break; } - if (0 == GNUNET_TIME_absolute_get_remaining (lac.expiration).rel_value_us) - { - postgres_rollback (pg); - return TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_RESERVE_EXPIRED; - } + if (TALER_EC_NONE != lac.ec) + return lac.ec; + GNUNET_assert (lac.ok); reserve_pubp = &lac.reserve_pub; } @@ -8412,16 +8424,11 @@ postgres_connect (void *cls) ",tips_committed_frac" " FROM merchant_tip_reserves" " WHERE" - " exchange_initial_balance_val - tips_committed_val > $2" - " OR" - " (exchange_initial_balance_val - tips_committed_val = $2" - " AND exchange_initial_balance_frac - tips_committed_frac >= $3)" - " AND expiration > $4" - " AND merchant_serial =" + " merchant_serial =" " (SELECT merchant_serial" " FROM merchant_instances" " WHERE merchant_id=$1)", - 4), + 1), /* For postgres_authorize_tip() */ GNUNET_PQ_make_prepare ("lookup_reserve_status",