diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-03-24 16:34:57 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-03-24 16:34:57 +0100 |
commit | fc798355cb23a63eba9192155adbb5f39bda7810 (patch) | |
tree | c56c5ccf1d8b7775b3acc13e6692103b4de58657 | |
parent | 365d933c98eb9cb2474fe70dfe389da0f5ee70d4 (diff) |
clean up tipping transactiton mess a bit (wip)
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 8 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_refund.c | 69 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_tip-authorize.c | 25 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_tip-pickup.c | 12 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_tip-query.c | 37 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 260 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 150 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 34 | ||||
-rw-r--r-- | src/lib/test_merchant_api_new.c | 2 |
9 files changed, 303 insertions, 294 deletions
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index cb8ef8bf..96dbdc02 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -1781,8 +1781,8 @@ begin_transaction (struct PayContext *pc) db->rollback (db->cls); if (GNUNET_DB_STATUS_SOFT_ERROR == qs) { - begin_transaction (pc); - return; + begin_transaction (pc); + return; } /* Always report on hard error as well to enable diagnostics */ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); @@ -1816,8 +1816,8 @@ begin_transaction (struct PayContext *pc) db->rollback (db->cls); if (GNUNET_DB_STATUS_SOFT_ERROR == qs) { - begin_transaction (pc); - return; + begin_transaction (pc); + return; } /* Always report on hard error as well to enable diagnostics */ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); diff --git a/src/backend/taler-merchant-httpd_refund.c b/src/backend/taler-merchant-httpd_refund.c index 75f6ed91..fbf72f16 100644 --- a/src/backend/taler-merchant-httpd_refund.c +++ b/src/backend/taler-merchant-httpd_refund.c @@ -130,6 +130,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + enum GNUNET_DB_QueryStatus qsx; if (NULL == *connection_cls) { @@ -178,17 +179,17 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, GNUNET_JSON_parse_free (spec); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_REFUND_INSTANCE_UNKNOWN, - "Unknown instance given"); + "Unknown instance given"); } db->preflight (db->cls); /* Convert order id to h_contract_terms */ qs = db->find_contract_terms (db->cls, - &contract_terms, + &contract_terms, &last_session_id, - order_id, - &mi->pubkey); + order_id, + &mi->pubkey); if (0 > qs) { /* single, read-only SQL statements should never cause @@ -226,12 +227,46 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, } for (unsigned int i=0;i<MAX_RETRIES;i++) { + if (GNUNET_OK != + db->start (db->cls, + "increase refund")) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } qs = db->increase_refund_for_contract (db->cls, - &h_contract_terms, - &mi->pubkey, - &refund, - reason); - if (GNUNET_DB_STATUS_SOFT_ERROR != qs) + &h_contract_terms, + &mi->pubkey, + &refund, + reason); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "increase refund returned %d\n", + qs); + if (GNUNET_DB_STATUS_HARD_ERROR == qs) + { + GNUNET_break (0); + db->rollback (db->cls); + break; + } + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + { + db->rollback (db->cls); + continue; + } + /* Got one or more deposits */ + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) + { + db->rollback (db->cls); + break; + } + qsx = db->commit (db->cls); + if (GNUNET_DB_STATUS_HARD_ERROR == qsx) + { + GNUNET_break (0); + qs = qsx; + break; + } + if (GNUNET_DB_STATUS_SOFT_ERROR != qsx) break; } if (0 > qs) @@ -265,7 +300,6 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, * Just a "200 OK" should be fine here, as the frontend has all * the information needed to generate the right response. */ - confirmation.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND_OK); confirmation.purpose.size = htonl (sizeof (struct TALER_MerchantRefundConfirmationPS)); GNUNET_CRYPTO_hash (order_id, @@ -465,10 +499,10 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, /* Convert order id to h_contract_terms */ contract_terms = NULL; qs = db->find_contract_terms (db->cls, - &contract_terms, + &contract_terms, &last_session_id, - order_id, - &mi->pubkey); + order_id, + &mi->pubkey); if (0 > qs) { /* single, read-only SQL statements should never cause @@ -554,13 +588,14 @@ TM_get_refund_json (const struct MerchantInstance *mi, prd.h_contract_terms = h_contract_terms; prd.merchant = mi; prd.ec = TALER_EC_NONE; + db->preflight (db->cls); for (unsigned int i=0;i<MAX_RETRIES;i++) { qs = db->get_refunds_from_contract_terms_hash (db->cls, - &mi->pubkey, - h_contract_terms, - &process_refunds_cb, - &prd); + &mi->pubkey, + h_contract_terms, + &process_refunds_cb, + &prd); if (GNUNET_DB_STATUS_SOFT_ERROR != qs) break; } diff --git a/src/backend/taler-merchant-httpd_tip-authorize.c b/src/backend/taler-merchant-httpd_tip-authorize.c index 58ee405c..9301df92 100644 --- a/src/backend/taler-merchant-httpd_tip-authorize.c +++ b/src/backend/taler-merchant-httpd_tip-authorize.c @@ -202,11 +202,11 @@ handle_status (void *cls, GNUNET_CRYPTO_hash (history[i].details.in_details.wire_reference, history[i].details.in_details.wire_reference_size, &uuid); - qs = db->enable_tip_reserve (db->cls, - &tac->reserve_priv, - &uuid, - &history[i].amount, - expiration); + qs = db->enable_tip_reserve_TR (db->cls, + &tac->reserve_priv, + &uuid, + &history[i].amount, + expiration); if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -377,14 +377,13 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, "exchange for tipping not configured for the instance"); } tac->reserve_priv = mi->tip_reserve; - db->preflight (db->cls); - ec = db->authorize_tip (db->cls, - tac->justification, - &tac->amount, - &mi->tip_reserve, - mi->tip_exchange, - &expiration, - &tip_id); + ec = db->authorize_tip_TR (db->cls, + tac->justification, + &tac->amount, + &mi->tip_reserve, + mi->tip_exchange, + &expiration, + &tip_id); /* If we have insufficient funds according to OUR database, check with exchange to see if the reserve has been topped up in the meantime (or if tips were not withdrawn yet). */ diff --git a/src/backend/taler-merchant-httpd_tip-pickup.c b/src/backend/taler-merchant-httpd_tip-pickup.c index 7b3403d2..3c810cb0 100644 --- a/src/backend/taler-merchant-httpd_tip-pickup.c +++ b/src/backend/taler-merchant-httpd_tip-pickup.c @@ -181,7 +181,7 @@ pickup_cleanup (struct TM_HandlerContext *hc) */ static int run_pickup (struct MHD_Connection *connection, - struct PickupContext *pc) + struct PickupContext *pc) { struct TALER_ReservePrivateKeyP reserve_priv; struct TALER_ReservePublicKeyP reserve_pub; @@ -195,11 +195,11 @@ run_pickup (struct MHD_Connection *connection, pc->ec, pc->error_hint); } - ec = db->pickup_tip (db->cls, - &pc->total, - &pc->tip_id, - &pc->pickup_id, - &reserve_priv); + ec = db->pickup_tip_TR (db->cls, + &pc->total, + &pc->tip_id, + &pc->pickup_id, + &reserve_priv); if (TALER_EC_NONE != ec) { unsigned int response_code; diff --git a/src/backend/taler-merchant-httpd_tip-query.c b/src/backend/taler-merchant-httpd_tip-query.c index e4ade936..9664eaa5 100644 --- a/src/backend/taler-merchant-httpd_tip-query.c +++ b/src/backend/taler-merchant-httpd_tip-query.c @@ -199,7 +199,7 @@ handle_status (void *cls, { GNUNET_break_op (0); resume_with_response (tqc, - MHD_HTTP_SERVICE_UNAVAILABLE, + MHD_HTTP_SERVICE_UNAVAILABLE, TMH_RESPONSE_make_error (TALER_EC_TIP_QUERY_RESERVE_STATUS_FAILED_EXCHANGE_DOWN, "Unable to obtain reserve status from exchange")); return; @@ -209,7 +209,7 @@ handle_status (void *cls, { GNUNET_break_op (0); resume_with_response (tqc, - MHD_HTTP_SERVICE_UNAVAILABLE, + MHD_HTTP_SERVICE_UNAVAILABLE, TMH_RESPONSE_make_error (TALER_EC_TIP_QUERY_RESERVE_HISTORY_FAILED_EMPTY, "Exchange returned empty reserve history")); return; @@ -219,7 +219,7 @@ handle_status (void *cls, { GNUNET_break_op (0); resume_with_response (tqc, - MHD_HTTP_SERVICE_UNAVAILABLE, + MHD_HTTP_SERVICE_UNAVAILABLE, TMH_RESPONSE_make_error (TALER_EC_TIP_QUERY_RESERVE_HISTORY_INVALID_NO_DEPOSIT, "Exchange returned invalid reserve history")); return; @@ -231,18 +231,18 @@ handle_status (void *cls, { GNUNET_break_op (0); resume_with_response (tqc, - MHD_HTTP_SERVICE_UNAVAILABLE, + MHD_HTTP_SERVICE_UNAVAILABLE, TMH_RESPONSE_make_error (TALER_EC_TIP_QUERY_RESERVE_HISTORY_INVALID_CURRENCY, "Exchange returned invalid reserve history")); return; } if (0 != strcasecmp (TMH_currency, - history[0].amount.currency)) + history[0].amount.currency)) { GNUNET_break_op (0); resume_with_response (tqc, - MHD_HTTP_SERVICE_UNAVAILABLE, + MHD_HTTP_SERVICE_UNAVAILABLE, TMH_RESPONSE_make_error (TALER_EC_TIP_QUERY_RESERVE_CURRENCY_MISSMATCH, "Exchange currency unexpected")); return; @@ -271,11 +271,11 @@ handle_status (void *cls, GNUNET_CRYPTO_hash (history[i].details.in_details.wire_reference, history[i].details.in_details.wire_reference_size, &uuid); - qs = db->enable_tip_reserve (db->cls, - &tqc->reserve_priv, - &uuid, - &history[i].amount, - deposit_expiration); + qs = db->enable_tip_reserve_TR (db->cls, + &tqc->reserve_priv, + &uuid, + &history[i].amount, + deposit_expiration); if (GNUNET_OK != TALER_amount_add (&tqc->amount_deposited, &tqc->amount_deposited, @@ -425,10 +425,10 @@ exchange_cont (void *cls, */ int MH_handler_tip_query (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size) + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size) { struct TipQueryContext *tqc; int res; @@ -471,7 +471,7 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, "instance"); if (NULL == tqc->instance) return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, + TALER_EC_PARAMETER_MISSING, "instance"); mi = TMH_lookup_instance (tqc->instance); @@ -495,11 +495,11 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, } tqc->reserve_priv = mi->tip_reserve; - db->preflight (db->cls); { int qs; for (unsigned int i=0;i<MAX_RETRIES;i++) { + db->preflight (db->cls); qs = db->get_authorized_tip_amount (db->cls, &tqc->reserve_priv, &tqc->amount_authorized); @@ -517,12 +517,11 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { /* we'll set amount_authorized to zero later once - we know the currency */ + we know the currency */ tqc->none_authorized = GNUNET_YES; } } - MHD_suspend_connection (connection); tqc->suspended = GNUNET_YES; diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index beeeb4eb..3aa471fb 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2018 INRIA + (C) 2014--2019 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -421,20 +421,19 @@ postgres_initialize (void *cls) 3), GNUNET_PQ_make_prepare ("find_refunds_from_contract_terms_hash", "SELECT" - " coin_pub" - ",rtransaction_id" - ",refund_amount_val" - ",refund_amount_frac" - ",refund_amount_curr" - ",refund_fee_val" - ",refund_fee_frac" - ",refund_fee_curr" - ",reason" - " FROM merchant_refunds" + " coin_pub" + ",rtransaction_id" + ",refund_amount_val" + ",refund_amount_frac" + ",refund_amount_curr" + ",refund_fee_val" + ",refund_fee_frac" + ",refund_fee_curr" + ",reason" + " FROM merchant_refunds" " WHERE merchant_pub=$1" " AND h_contract_terms=$2", 2), - GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range_asc", "SELECT" " contract_terms" @@ -449,7 +448,6 @@ postgres_initialize (void *cls) " ORDER BY row_id ASC, timestamp ASC" " LIMIT $4", 4), - GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range", "SELECT" " contract_terms" @@ -464,7 +462,6 @@ postgres_initialize (void *cls) " ORDER BY row_id DESC, timestamp DESC" " LIMIT $4", 4), - GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range_past_asc", "SELECT" " contract_terms" @@ -496,7 +493,7 @@ postgres_initialize (void *cls) GNUNET_PQ_make_prepare ("find_deposits", "SELECT" " coin_pub" - ",exchange_url" + ",exchange_url" ",amount_with_fee_val" ",amount_with_fee_frac" ",amount_with_fee_curr" @@ -528,7 +525,7 @@ postgres_initialize (void *cls) ",wire_fee_val" ",wire_fee_frac" ",wire_fee_curr" - ",exchange_url" + ",exchange_url" ",exchange_proof" " FROM merchant_deposits" " WHERE h_contract_terms=$1" @@ -618,7 +615,7 @@ postgres_initialize (void *cls) "INSERT INTO merchant_tips" "(reserve_priv" ",tip_id" - ",exchange_url" + ",exchange_url" ",justification" ",timestamp" ",amount_val" @@ -701,7 +698,6 @@ postgres_initialize (void *cls) GNUNET_break (0); return GNUNET_SYSERR; } - if (GNUNET_OK != GNUNET_PQ_prepare_statements (pg->conn, ps)) @@ -733,6 +729,42 @@ check_connection (struct PostgresClosure *pg) /** + * Do a pre-flight check that we are not in an uncommitted transaction. + * If we are, try to commit the previous transaction and output a warning. + * Does not return anything, as we will continue regardless of the outcome. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + */ +static void +postgres_preflight (void *cls) +{ + struct PostgresClosure *pg = cls; + PGresult *result; + ExecStatusType status; + + if (NULL == pg->transaction_name) + return; /* all good */ + result = PQexec (pg->conn, + "COMMIT"); + status = PQresultStatus (result); + if (PGRES_COMMAND_OK == status) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BUG: Preflight check committed transaction `%s'!\n", + pg->transaction_name); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BUG: Preflight check failed to commit transaction `%s'!\n", + pg->transaction_name); + } + pg->transaction_name = NULL; + PQclear (result); +} + + +/** * Start a transaction. * * @param cls the `struct PostgresClosure` with the plugin-specific state @@ -749,6 +781,7 @@ postgres_start (void *cls, ExecStatusType ex; check_connection (pg); + postgres_preflight (pg); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting merchant DB transaction\n"); result = PQexec (pg->conn, @@ -793,42 +826,6 @@ postgres_rollback (void *cls) /** - * Do a pre-flight check that we are not in an uncommitted transaction. - * If we are, try to commit the previous transaction and output a warning. - * Does not return anything, as we will continue regardless of the outcome. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - */ -static void -postgres_preflight (void *cls) -{ - struct PostgresClosure *pg = cls; - PGresult *result; - ExecStatusType status; - - if (NULL == pg->transaction_name) - return; /* all good */ - result = PQexec (pg->conn, - "COMMIT"); - status = PQresultStatus (result); - if (PGRES_COMMAND_OK == status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "BUG: Preflight check committed transaction `%s'!\n", - pg->transaction_name); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "BUG: Preflight check failed to commit transaction `%s'!\n", - pg->transaction_name); - } - pg->transaction_name = NULL; - PQclear (result); -} - - -/** * Commit the current transaction of a database connection. * * @param cls the `struct PostgresClosure` with the plugin-specific state @@ -846,8 +843,8 @@ postgres_commit (void *cls) "Committing merchant DB transaction\n"); pg->transaction_name = NULL; return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "end_transaction", - params); + "end_transaction", + params); } @@ -913,6 +910,8 @@ postgres_find_paid_contract_terms_from_hash (void *cls, GNUNET_PQ_result_spec_end }; + /* no preflight check here, runs in its own transaction from + caller (in /pay case) */ check_connection (pg); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "find_paid_contract_terms_from_hash", @@ -1727,7 +1726,7 @@ find_payments_cb (void *cls, static enum GNUNET_DB_QueryStatus postgres_find_payments (void *cls, const struct GNUNET_HashCode *h_contract_terms, - const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_MerchantPublicKeyP *merchant_pub, TALER_MERCHANTDB_CoinDepositCallback cb, void *cb_cls) { @@ -1744,6 +1743,8 @@ postgres_find_payments (void *cls, }; enum GNUNET_DB_QueryStatus qs; + /* no preflight check here, run in its own transaction by the + caller! */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finding payment for h_contract_terms '%s'\n", GNUNET_h2s (h_contract_terms)); @@ -2263,6 +2264,7 @@ postgres_get_refunds_from_contract_terms_hash (void *cls, }; enum GNUNET_DB_QueryStatus qs; + /* no preflight check here, run in transaction by caller! */ TALER_LOG_DEBUG ("Looking for refund %s + %s\n", GNUNET_h2s (h_contract_terms), TALER_B2S (merchant_pub)); @@ -2358,6 +2360,7 @@ postgres_store_wire_fee_by_exchange (void *cls, GNUNET_PQ_query_param_end }; + /* no preflight check here, run in its own transaction by the caller */ check_connection (pg); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Storing wire fee for %s starting at %s of %s\n", @@ -2540,8 +2543,8 @@ struct InsertRefundContext */ static void process_deposits_for_refund_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct InsertRefundContext *ctx = cls; struct TALER_Amount current_refund; @@ -2556,7 +2559,6 @@ process_deposits_for_refund_cb (void *cls, /* Pass 1: Collect amount of existing refunds into current_refund. * Also store existing refunded amount for each deposit in deposit_refund. */ - for (unsigned int i=0; i<num_results; i++) { struct TALER_CoinSpendPublicKeyP coin_pub; @@ -2616,8 +2618,8 @@ process_deposits_for_refund_cb (void *cls, deposit_refund_fee[i] = refund_fee; if (GNUNET_SYSERR == TALER_amount_add (¤t_refund, - ¤t_refund, - &ictx.refunded_amount)) + ¤t_refund, + &ictx.refunded_amount)) { GNUNET_break (0); ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; @@ -2642,7 +2644,6 @@ process_deposits_for_refund_cb (void *cls, } /* Phase 2: Try to increase current refund until it matches desired refund */ - for (unsigned int i=0;i<num_results; i++) { const struct TALER_Amount *increment; @@ -2651,9 +2652,9 @@ process_deposits_for_refund_cb (void *cls, /* How much of the coin is left after the existing refunds? */ if (GNUNET_SYSERR == - TALER_amount_subtract (&left, - &deposit_amount_with_fee[i], - &deposit_refund[i])) + TALER_amount_subtract (&left, + &deposit_amount_with_fee[i], + &deposit_refund[i])) { GNUNET_break (0); ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; @@ -2661,20 +2662,20 @@ process_deposits_for_refund_cb (void *cls, } if ( (0 == left.value) && - (0 == left.fraction) ) + (0 == left.fraction) ) { /* coin was fully refunded, move to next coin */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Coin %s fully refunded, moving to next coin\n", - TALER_B2S (&deposit_coin_pubs[i])); + "Coin %s fully refunded, moving to next coin\n", + TALER_B2S (&deposit_coin_pubs[i])); continue; } /* How much of the refund is left? */ if (GNUNET_SYSERR == - TALER_amount_subtract (&remaining_refund, - ctx->refund, - ¤t_refund)) + TALER_amount_subtract (&remaining_refund, + ctx->refund, + ¤t_refund)) { GNUNET_break (0); ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; @@ -2683,7 +2684,7 @@ process_deposits_for_refund_cb (void *cls, /* By how much will we increase the refund for this coin? */ if (0 >= TALER_amount_cmp (&remaining_refund, - &left)) + &left)) { /* remaining_refund <= left */ increment = &remaining_refund; @@ -2694,9 +2695,9 @@ process_deposits_for_refund_cb (void *cls, } if (GNUNET_SYSERR == - TALER_amount_add (¤t_refund, - ¤t_refund, - increment)) + TALER_amount_add (¤t_refund, + ¤t_refund, + increment)) { GNUNET_break (0); ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; @@ -2705,28 +2706,28 @@ process_deposits_for_refund_cb (void *cls, /* actually run the refund */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Coin %s deposit amount is %s\n", - TALER_B2S (&deposit_coin_pubs[i]), - TALER_amount2s (&deposit_amount_with_fee[i])); + "Coin %s deposit amount is %s\n", + TALER_B2S (&deposit_coin_pubs[i]), + TALER_amount2s (&deposit_amount_with_fee[i])); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Coin %s refund will be incremented by %s\n", - TALER_B2S (&deposit_coin_pubs[i]), - TALER_amount2s (increment)); + "Coin %s refund will be incremented by %s\n", + TALER_B2S (&deposit_coin_pubs[i]), + TALER_amount2s (increment)); { enum GNUNET_DB_QueryStatus qs; if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - (qs = insert_refund (ctx->pg, - ctx->merchant_pub, - ctx->h_contract_terms, - &deposit_coin_pubs[i], - ctx->reason, - increment, - &deposit_refund_fee[i]))) + (qs = insert_refund (ctx->pg, + ctx->merchant_pub, + ctx->h_contract_terms, + &deposit_coin_pubs[i], + ctx->reason, + increment, + &deposit_refund_fee[i]))) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - ctx->qs = qs; - return; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + ctx->qs = qs; + return; } } /* stop immediately if we are done */ @@ -2742,8 +2743,8 @@ process_deposits_for_refund_cb (void *cls, * rely upon the frontend being correct. */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "The refund of %s is bigger than the order's value\n", - TALER_amount2s (ctx->refund)); + "The refund of %s is bigger than the order's value\n", + TALER_amount2s (ctx->refund)); ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; } @@ -2784,13 +2785,6 @@ postgres_increase_refund_for_contract (void *cls, "Asked to refund %s on contract %s\n", TALER_amount2s (refund), GNUNET_h2s (h_contract_terms)); - if (GNUNET_OK != - postgres_start (cls, - "increase refund")) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } ctx.pg = pg; ctx.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; ctx.refund = refund; @@ -2798,10 +2792,10 @@ postgres_increase_refund_for_contract (void *cls, ctx.h_contract_terms = h_contract_terms; ctx.merchant_pub = merchant_pub; qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "find_deposits", - params, - &process_deposits_for_refund_cb, - &ctx); + "find_deposits", + params, + &process_deposits_for_refund_cb, + &ctx); switch (qs) { case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: @@ -2809,28 +2803,12 @@ postgres_increase_refund_for_contract (void *cls, "Unknown contract: %s (merchant_pub: %s), no refund possible\n", GNUNET_h2s (h_contract_terms), TALER_B2S (merchant_pub)); - postgres_rollback (cls); return qs; case GNUNET_DB_STATUS_SOFT_ERROR: case GNUNET_DB_STATUS_HARD_ERROR: - postgres_rollback (cls); return qs; default: /* Got one or more deposits */ - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ctx.qs) - { - postgres_rollback (cls); - return ctx.qs; - } - qs = postgres_commit (cls); - if (0 > qs) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to commit transaction increasing refund\n"); - return qs; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Committed refund transaction\n"); return ctx.qs; } } @@ -2899,11 +2877,11 @@ postgres_find_proof_by_wtid (void *cls, * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a credit_uuid already known */ static enum GNUNET_DB_QueryStatus -postgres_enable_tip_reserve (void *cls, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const struct GNUNET_HashCode *credit_uuid, - const struct TALER_Amount *credit, - struct GNUNET_TIME_Absolute expiration) +postgres_enable_tip_reserve_TR (void *cls, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const struct GNUNET_HashCode *credit_uuid, + const struct TALER_Amount *credit, + struct GNUNET_TIME_Absolute expiration) { struct PostgresClosure *pg = cls; struct GNUNET_TIME_Absolute old_expiration; @@ -3092,13 +3070,13 @@ postgres_enable_tip_reserve (void *cls, * #TALER_EC_NONE upon success */ static enum TALER_ErrorCode -postgres_authorize_tip (void *cls, - const char *justification, - const struct TALER_Amount *amount, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const char *exchange_url, - struct GNUNET_TIME_Absolute *expiration, - struct GNUNET_HashCode *tip_id) +postgres_authorize_tip_TR (void *cls, + const char *justification, + const struct TALER_Amount *amount, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const char *exchange_url, + struct GNUNET_TIME_Absolute *expiration, + struct GNUNET_HashCode *tip_id) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -3295,11 +3273,11 @@ postgres_lookup_tip_by_id (void *cls, * #TALER_EC_NONE upon success (@a reserve_priv was set) */ static enum TALER_ErrorCode -postgres_pickup_tip (void *cls, - const struct TALER_Amount *amount, - const struct GNUNET_HashCode *tip_id, - const struct GNUNET_HashCode *pickup_id, - struct TALER_ReservePrivateKeyP *reserve_priv) +postgres_pickup_tip_TR (void *cls, + const struct TALER_Amount *amount, + const struct GNUNET_HashCode *tip_id, + const struct GNUNET_HashCode *pickup_id, + struct TALER_ReservePrivateKeyP *reserve_priv) { struct PostgresClosure *pg = cls; struct TALER_Amount left_amount; @@ -3536,10 +3514,10 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->lookup_wire_fee = &postgres_lookup_wire_fee; plugin->increase_refund_for_contract = &postgres_increase_refund_for_contract; plugin->mark_proposal_paid = &postgres_mark_proposal_paid; - plugin->enable_tip_reserve = &postgres_enable_tip_reserve; - plugin->authorize_tip = &postgres_authorize_tip; + plugin->enable_tip_reserve_TR = &postgres_enable_tip_reserve_TR; + plugin->authorize_tip_TR = &postgres_authorize_tip_TR; plugin->lookup_tip_by_id = &postgres_lookup_tip_by_id; - plugin->pickup_tip = &postgres_pickup_tip; + plugin->pickup_tip_TR = &postgres_pickup_tip_TR; plugin->start = postgres_start; plugin->commit = postgres_commit; plugin->preflight = postgres_preflight; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index aa3db96a..fbea98c7 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -507,13 +507,13 @@ test_tipping () RND_BLK (&tip_reserve_priv); if (TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS != - plugin->authorize_tip (plugin->cls, - "testing tips reserve unknown", - &amount, - &tip_reserve_priv, - "http://localhost:8081/", - &tip_expiration, - &tip_id)) + plugin->authorize_tip_TR (plugin->cls, + "testing tips reserve unknown", + &amount, + &tip_reserve_priv, + "http://localhost:8081/", + &tip_expiration, + &tip_id)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -527,22 +527,22 @@ test_tipping () reserve_expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->enable_tip_reserve (plugin->cls, - &tip_reserve_priv, - &tip_credit_uuid, - &total, - reserve_expiration)) + plugin->enable_tip_reserve_TR (plugin->cls, + &tip_reserve_priv, + &tip_credit_uuid, + &total, + reserve_expiration)) { GNUNET_break (0); return GNUNET_SYSERR; } /* check idempotency */ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - plugin->enable_tip_reserve (plugin->cls, - &tip_reserve_priv, - &tip_credit_uuid, - &total, - reserve_expiration)) + plugin->enable_tip_reserve_TR (plugin->cls, + &tip_reserve_priv, + &tip_credit_uuid, + &total, + reserve_expiration)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -550,13 +550,13 @@ test_tipping () /* Make sure it has expired, so at this point the value is back at ZERO! */ sleep (3); if (TALER_EC_TIP_AUTHORIZE_RESERVE_EXPIRED != - plugin->authorize_tip (plugin->cls, - "testing tips too late", - &amount, - &tip_reserve_priv, - "http://localhost:8081/", - &tip_expiration, - &tip_id)) + plugin->authorize_tip_TR (plugin->cls, + "testing tips too late", + &amount, + &tip_reserve_priv, + "http://localhost:8081/", + &tip_expiration, + &tip_id)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -567,11 +567,11 @@ test_tipping () reserve_expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->enable_tip_reserve (plugin->cls, - &tip_reserve_priv, - &tip_credit_uuid, - &total, - reserve_expiration)) + plugin->enable_tip_reserve_TR (plugin->cls, + &tip_reserve_priv, + &tip_credit_uuid, + &total, + reserve_expiration)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -581,11 +581,11 @@ test_tipping () RND_BLK (&tip_credit_uuid); reserve_expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->enable_tip_reserve (plugin->cls, - &tip_reserve_priv, - &tip_credit_uuid, - &total, - reserve_expiration)) + plugin->enable_tip_reserve_TR (plugin->cls, + &tip_reserve_priv, + &tip_credit_uuid, + &total, + reserve_expiration)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -596,13 +596,13 @@ test_tipping () TALER_string_to_amount (CURRENCY ":4", &amount)); if (TALER_EC_NONE != - plugin->authorize_tip (plugin->cls, - "testing tips", - &amount, - &tip_reserve_priv, - "http://localhost:8081/", - &tip_expiration, - &tip_id)) + plugin->authorize_tip_TR (plugin->cls, + "testing tips", + &amount, + &tip_reserve_priv, + "http://localhost:8081/", + &tip_expiration, + &tip_id)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -630,13 +630,13 @@ test_tipping () } GNUNET_free (url); if (TALER_EC_NONE != - plugin->authorize_tip (plugin->cls, - "testing tips more", - &amount, - &tip_reserve_priv, - "http://localhost:8081/", - &tip_expiration, - &tip_id)) + plugin->authorize_tip_TR (plugin->cls, + "testing tips more", + &amount, + &tip_reserve_priv, + "http://localhost:8081/", + &tip_expiration, + &tip_id)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -653,11 +653,11 @@ test_tipping () &inc)); RND_BLK (&pickup_id); if (TALER_EC_NONE != - plugin->pickup_tip (plugin->cls, - &inc, - &tip_id, - &pickup_id, - &pres)) + plugin->pickup_tip_TR (plugin->cls, + &inc, + &tip_id, + &pickup_id, + &pres)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -671,11 +671,11 @@ test_tipping () } RND_BLK (&pickup_id); if (TALER_EC_NONE != - plugin->pickup_tip (plugin->cls, - &inc, - &tip_id, - &pickup_id, - &pres)) + plugin->pickup_tip_TR (plugin->cls, + &inc, + &tip_id, + &pickup_id, + &pres)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -691,11 +691,11 @@ test_tipping () /* Third attempt should fail, as we've picked up 4/4 in amount */ RND_BLK (&pickup_id); if (TALER_EC_TIP_PICKUP_NO_FUNDS != - plugin->pickup_tip (plugin->cls, - &inc, - &tip_id, - &pickup_id, - &pres)) + plugin->pickup_tip_TR (plugin->cls, + &inc, + &tip_id, + &pickup_id, + &pres)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -703,13 +703,13 @@ test_tipping () /* We authorized 8 out of 10, so going for another 4 should fail with insufficient funds */ if (TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS != - plugin->authorize_tip (plugin->cls, - "testing tips insufficient funds", - &amount, - &tip_reserve_priv, - "http://localhost:8081/", - &tip_expiration, - &tip_id)) + plugin->authorize_tip_TR (plugin->cls, + "testing tips insufficient funds", + &amount, + &tip_reserve_priv, + "http://localhost:8081/", + &tip_expiration, + &tip_id)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -719,11 +719,11 @@ test_tipping () RND_BLK (&tip_id); RND_BLK (&pickup_id); if (TALER_EC_TIP_PICKUP_TIP_ID_UNKNOWN != - plugin->pickup_tip (plugin->cls, - &inc, - &tip_id, - &pickup_id, - &pres)) + plugin->pickup_tip_TR (plugin->cls, + &inc, + &tip_id, + &pickup_id, + &pres)) { GNUNET_break (0); return GNUNET_SYSERR; diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index f8a95019..228523b6 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -650,11 +650,11 @@ struct TALER_MERCHANTDB_Plugin * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a credit_uuid already known */ enum GNUNET_DB_QueryStatus - (*enable_tip_reserve)(void *cls, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const struct GNUNET_HashCode *credit_uuid, - const struct TALER_Amount *credit, - struct GNUNET_TIME_Absolute expiration); + (*enable_tip_reserve_TR)(void *cls, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const struct GNUNET_HashCode *credit_uuid, + const struct TALER_Amount *credit, + struct GNUNET_TIME_Absolute expiration); /** @@ -678,13 +678,13 @@ struct TALER_MERCHANTDB_Plugin * #TALER_EC_NONE upon success */ enum TALER_ErrorCode - (*authorize_tip)(void *cls, - const char *justification, - const struct TALER_Amount *amount, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const char *exchange_url, - struct GNUNET_TIME_Absolute *expiration, - struct GNUNET_HashCode *tip_id); + (*authorize_tip_TR)(void *cls, + const char *justification, + const struct TALER_Amount *amount, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const char *exchange_url, + struct GNUNET_TIME_Absolute *expiration, + struct GNUNET_HashCode *tip_id); /** * Get the total amount of authorized tips for a tipping reserve. @@ -739,11 +739,11 @@ struct TALER_MERCHANTDB_Plugin * #TALER_EC_NONE upon success (@a reserve_priv was set) */ enum TALER_ErrorCode - (*pickup_tip)(void *cls, - const struct TALER_Amount *amount, - const struct GNUNET_HashCode *tip_id, - const struct GNUNET_HashCode *pickup_id, - struct TALER_ReservePrivateKeyP *reserve_priv); + (*pickup_tip_TR)(void *cls, + const struct TALER_Amount *amount, + const struct GNUNET_HashCode *tip_id, + const struct GNUNET_HashCode *pickup_id, + struct TALER_ReservePrivateKeyP *reserve_priv); /** diff --git a/src/lib/test_merchant_api_new.c b/src/lib/test_merchant_api_new.c index ca7859e4..94aafac6 100644 --- a/src/lib/test_merchant_api_new.c +++ b/src/lib/test_merchant_api_new.c @@ -441,7 +441,6 @@ run (void *cls, }; struct TALER_TESTING_Command refund[] = { - TALER_TESTING_cmd_refund_increase ("refund-increase-1", merchant_url, @@ -458,7 +457,6 @@ run (void *cls, "deposit-simple", "1", MHD_HTTP_OK), - /* Trying to pick up refund from non existent proposal. */ TALER_TESTING_cmd_refund_lookup ("refund-lookup-non-existent", merchant_url, |