merchant

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

commit ed56de150c2ea1b983a9a2f400bfd388dee9fbeb
parent fda894cbf1a0ef9bcd71365a31991dbd537b4563
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date:   Fri,  1 Aug 2025 14:52:18 +0200

code cleanup

Diffstat:
Msrc/backend/taler-merchant-httpd_post-orders-ID-pay.c | 28++++++++++++++++++++++++++--
Msrc/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c | 5+----
Msrc/backend/taler-merchant-httpd_private-get-donau-instances.c | 3---
Msrc/backend/taler-merchant-httpd_private-post-donau-instance.c | 8++++----
Msrc/backenddb/pg_delete_donau_instance.h | 1+
Msrc/backenddb/pg_insert_order_blinded_sigs.c | 12++++++------
Msrc/backenddb/pg_insert_order_blinded_sigs.h | 11++++++-----
Msrc/backenddb/pg_insert_order_budis.c | 2--
Msrc/backenddb/pg_insert_order_budis.h | 1-
Msrc/backenddb/pg_lookup_donau_keys.h | 2++
Msrc/backenddb/pg_lookup_order_charity.h | 1+
Msrc/backenddb/pg_select_donau_instances.c | 1-
Msrc/backenddb/pg_select_donau_instances.h | 11++++++-----
Msrc/backenddb/pg_select_order_blinded_sigs.h | 1+
Msrc/backenddb/pg_upsert_donau_keys.h | 1+
Msrc/backenddb/plugin_merchantdb_postgres.c | 6+++---
Msrc/include/taler_merchant_donau.h | 6------
Msrc/include/taler_merchant_pay_service.h | 11+++++------
Msrc/include/taler_merchantdb_plugin.h | 35++++++++++++++++++++---------------
19 files changed, 83 insertions(+), 63 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -2163,7 +2163,8 @@ merchant_parse_json_bkp (struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, if (GNUNET_OK != GNUNET_JSON_parse (bkp_key_obj, spec, - NULL, NULL)) + NULL, + NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -4633,7 +4634,30 @@ pay_context_cleanup (void *cls) pc_tail, pc); GNUNET_free (pc->check_contract.pos_key); - // TODO: add donau cleanup here +#ifdef HAVE_DONAU_DONAU_SERVICE_H + if (NULL != pc->donau_receipt.donau_sigs_json) + { + json_decref (pc->donau_receipt.donau_sigs_json); + pc->donau_receipt.donau_sigs_json = NULL; + } + if (NULL != pc->donau_receipt.sigs) + { + GNUNET_free (pc->donau_receipt.sigs); + pc->donau_receipt.sigs = NULL; + pc->donau_receipt.num_sigs = 0; + } + if (NULL != pc->parse_wallet_data.bkps) + { + GNUNET_free (pc->parse_wallet_data.bkps); + pc->parse_wallet_data.bkps = NULL; + pc->parse_wallet_data.num_bkps = 0; + } + if (NULL != pc->parse_wallet_data.donau_keys) + { + DONAU_keys_decref (pc->parse_wallet_data.donau_keys); + pc->parse_wallet_data.donau_keys = NULL; + } +#endif GNUNET_free (pc); } diff --git a/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c b/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c @@ -44,7 +44,6 @@ TMH_private_delete_donau_instance_ID (const struct TMH_RequestHandler *rh, uint64_t charity_id; char dummy; - (void) rh; GNUNET_assert (NULL != mi); if (1 != sscanf (hc->infix, @@ -61,7 +60,6 @@ TMH_private_delete_donau_instance_ID (const struct TMH_RequestHandler *rh, qs = TMH_db->delete_donau_instance (TMH_db->cls, &hc->instance->merchant_pub, charity_id); - switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -74,7 +72,7 @@ TMH_private_delete_donau_instance_ID (const struct TMH_RequestHandler *rh, GNUNET_break (0); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, + TALER_EC_GENERIC_DB_SOFT_FAILURE, "delete_donau_instance (soft)"); case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: @@ -90,7 +88,6 @@ TMH_private_delete_donau_instance_ID (const struct TMH_RequestHandler *rh, NULL, 0); } - GNUNET_assert (0); return MHD_NO; } \ No newline at end of file diff --git a/src/backend/taler-merchant-httpd_private-get-donau-instances.c b/src/backend/taler-merchant-httpd_private-get-donau-instances.c @@ -94,13 +94,11 @@ TMH_private_get_donau_instances (const struct TMH_RequestHandler *rh, json_t *json_donau_instances = json_array (); enum GNUNET_DB_QueryStatus qs; - GNUNET_assert (NULL != json_donau_instances); TMH_db->preflight (TMH_db->cls); qs = TMH_db->select_donau_instances (TMH_db->cls, &hc->instance->merchant_pub, &add_donau_instance, json_donau_instances); - if (0 > qs) { GNUNET_break (0); @@ -111,7 +109,6 @@ TMH_private_get_donau_instances (const struct TMH_RequestHandler *rh, NULL); } - /* Return the JSON array as the response */ return TALER_MHD_REPLY_JSON_PACK (connection, MHD_HTTP_OK, GNUNET_JSON_pack_array_steal ( diff --git a/src/backend/taler-merchant-httpd_private-post-donau-instance.c b/src/backend/taler-merchant-httpd_private-post-donau-instance.c @@ -139,13 +139,13 @@ donau_charity_get_cb (void *cls, switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: TALER_MHD_reply_with_error (pdc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_STORE_FAILED, "insert_donau_instance: Failed to insert Donau instance"); break; case GNUNET_DB_STATUS_SOFT_ERROR: - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: TALER_MHD_reply_with_error (pdc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_SOFT_FAILURE, @@ -163,7 +163,8 @@ donau_charity_get_cb (void *cls, strlen (pdc->donau_url) + 1); TALER_MHD_reply_static (pdc->connection, MHD_HTTP_NO_CONTENT, - NULL, NULL, + NULL, + NULL, 0); break; } @@ -217,8 +218,7 @@ TMH_private_post_donau_instance (const struct TMH_RequestHandler *rh, }; if (GNUNET_OK != TALER_MHD_parse_json_data (connection, hc->request_body, - spec) - ) + spec)) { return MHD_NO; } diff --git a/src/backenddb/pg_delete_donau_instance.h b/src/backenddb/pg_delete_donau_instance.h @@ -30,6 +30,7 @@ * Delete an existing Donau charity instance from the database. * * @param cls closure + * @param merchant_pub merchant_pub_key that we use as reference for the merchant_instance * @param charity_id unique identifier of the charity instance to be deleted * @return transaction status code */ diff --git a/src/backenddb/pg_insert_order_blinded_sigs.c b/src/backenddb/pg_insert_order_blinded_sigs.c @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file backenddb/insert_order_blinded_sigs.c + * @file backenddb/pg_insert_order_blinded_sigs.c * @brief implementation of insert_order_blinded_sigs() for Postgres * @author Bohdan Potuzhnyi */ @@ -26,11 +26,11 @@ enum GNUNET_DB_QueryStatus -TMH_PG_insert_order_blinded_sigs (void *cls, - const char *order_id, - const json_t *blinded_sigs, - const struct - GNUNET_CRYPTO_BlindedSignature *blind_sig) +TMH_PG_insert_order_blinded_sigs ( + void *cls, + const char *order_id, + const json_t *blinded_sigs, + const struct GNUNET_CRYPTO_BlindedSignature *blind_sig) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { diff --git a/src/backenddb/pg_insert_order_blinded_sigs.h b/src/backenddb/pg_insert_order_blinded_sigs.h @@ -32,13 +32,14 @@ * @param cls closure (our `struct PostgresClosure *`) * @param order_id business-level order identifier * @param blinded_sigs JSON with Donau blinded signature(s) + * @param blind_sig blinded signature of the first blinded_sigs * @return GNUNET_DB status code */ enum GNUNET_DB_QueryStatus -TMH_PG_insert_order_blinded_sigs (void *cls, - const char *order_id, - const json_t *blinded_sigs, - const struct - GNUNET_CRYPTO_BlindedSignature *blind_sig); +TMH_PG_insert_order_blinded_sigs ( + void *cls, + const char *order_id, + const json_t *blinded_sigs, + const struct GNUNET_CRYPTO_BlindedSignature *blind_sig); #endif diff --git a/src/backenddb/pg_insert_order_budis.c b/src/backenddb/pg_insert_order_budis.c @@ -13,7 +13,6 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * @file backenddb/pg_insert_order_budis.c * @brief Implementation of the insert_order_budis function for Postgres @@ -51,7 +50,6 @@ TMH_PG_insert_order_budis ( "FROM merchant_orders " "WHERE order_id = $1"); - /* Execute the prepared statement */ return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_order_budis", params); diff --git a/src/backenddb/pg_insert_order_budis.h b/src/backenddb/pg_insert_order_budis.h @@ -13,7 +13,6 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * @file backenddb/pg_insert_order_budis.h * @brief Declaration of the insert_order_budis function for Postgres diff --git a/src/backenddb/pg_lookup_donau_keys.h b/src/backenddb/pg_lookup_donau_keys.h @@ -32,6 +32,8 @@ * * @param cls plugin closure * @param donau_url base URL of the exchange + * @param first_retry if the query fails, this is set to the + * time when the next retry should be attempted * @param[out] keys set to the keys of the exchange * @return transaction status */ diff --git a/src/backenddb/pg_lookup_order_charity.h b/src/backenddb/pg_lookup_order_charity.h @@ -48,6 +48,7 @@ * @param[out] charity_receipts_to_date set to the total amount of receipts * issued to date * @param[out] donau_keys_json set to the JSON object containing the Donau keys + * @param[out] donau_instance_serial set to the serial number of the Donau instance in DB */ enum GNUNET_DB_QueryStatus TMH_PG_lookup_order_charity ( diff --git a/src/backenddb/pg_select_donau_instances.c b/src/backenddb/pg_select_donau_instances.c @@ -118,7 +118,6 @@ select_donau_instance_cb (void *cls, } -/*FIXME: We might want to limit the select by merchant_pub for charity_pub_key*/ enum GNUNET_DB_QueryStatus TMH_PG_select_donau_instances (void *cls, const struct diff --git a/src/backenddb/pg_select_donau_instances.h b/src/backenddb/pg_select_donau_instances.h @@ -32,15 +32,16 @@ * Select multiple Donau instances from the database. * * @param cls the closure for the database context + * @param merchant_pub merchant_pub to select only instance related instances * @param cb callback function to call with each result * @param cb_cls closure for the callback * @return status of the PG */ enum GNUNET_DB_QueryStatus -TMH_PG_select_donau_instances (void *cls, - const struct - TALER_MerchantPublicKeyP *merchant_pub, - TALER_MERCHANTDB_DonauInstanceCallback cb, - void *cb_cls); +TMH_PG_select_donau_instances ( + void *cls, + const struct TALER_MerchantPublicKeyP *merchant_pub, + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls); #endif diff --git a/src/backenddb/pg_select_order_blinded_sigs.h b/src/backenddb/pg_select_order_blinded_sigs.h @@ -34,6 +34,7 @@ * @param cls closure (our `struct PostgresClosure *`) * @param order_id business-level order identifier * @param[out] blinded_sigs where to write the JSON object (refcount +1) + * @param[out] blind_sig_out first signature of the blinded_sigs * @return GNUNET_DB status code */ enum GNUNET_DB_QueryStatus diff --git a/src/backenddb/pg_upsert_donau_keys.h b/src/backenddb/pg_upsert_donau_keys.h @@ -32,6 +32,7 @@ * * @param cls closure * @param keys the DONAU_Keys object + * @param first_retry time when we make retry to update keys * @return GNUNET_DB_QueryStatus transaction status */ enum GNUNET_DB_QueryStatus diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -91,6 +91,7 @@ #include "pg_insert_order_budis.h" #include "pg_unlock_inventory.h" #include "pg_insert_order_lock.h" +#include "pg_select_order_blinded_sigs.h" #include "pg_lookup_contract_terms3.h" #include "pg_lookup_contract_terms2.h" #include "pg_lookup_contract_terms.h" @@ -174,7 +175,6 @@ #include "pg_upsert_donau_keys.h" #include "pg_update_donau_instance.h" #include "pg_insert_order_blinded_sigs.h" -#include "pg_select_order_blinded_sigs.h" #endif /** @@ -493,6 +493,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_unlock_inventory; plugin->insert_order_lock = &TMH_PG_insert_order_lock; + plugin->select_order_blinded_sigs + = &TMH_PG_select_order_blinded_sigs; plugin->lookup_contract_terms = &TMH_PG_lookup_contract_terms; plugin->lookup_contract_terms2 @@ -688,8 +690,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_update_donau_instance; plugin->insert_order_blinded_sigs = &TMH_PG_insert_order_blinded_sigs; - plugin->select_order_blinded_sigs - = &TMH_PG_select_order_blinded_sigs; #endif return plugin; } diff --git a/src/include/taler_merchant_donau.h b/src/include/taler_merchant_donau.h @@ -156,7 +156,6 @@ typedef void * * @param cls Closure to pass additional context or data to the callback function. * @param donau_url The URL of the Donau instance. - * @param charity_max_per_year Maximum allowed donations to the charity for the current year. */ typedef void (*TALER_MERCHANTDB_DonauInstanceFilteredCallback)( @@ -174,11 +173,6 @@ typedef void struct TALER_MERCHANT_DonauInstanceGetHandle; /** - * Handle for a GET /donau operation. - */ -struct TALER_MERCHANT_DonauInstanceGetHandle; - -/** * Individual Donau instance details. */ struct TALER_MERCHANT_DonauInstanceEntry diff --git a/src/include/taler_merchant_pay_service.h b/src/include/taler_merchant_pay_service.h @@ -32,11 +32,6 @@ #include <gnunet/gnunet_time_lib.h> -/** - * seems a bit odd - */ -// #define TALER_MERCHANT_ORDER_PAY_CALLBACK_CLOSURE_TYPE struct PayState - #ifndef TALER_MERCHANT_ORDER_PAY_CALLBACK_CLOSURE_TYPE #define TALER_MERCHANT_ORDER_PAY_CALLBACK_CLOSURE_TYPE void #endif @@ -80,7 +75,11 @@ enum TALER_MERCHANT_OrderPayOptionType */ struct TALER_MERCHANT_OrderPayOption { - enum TALER_MERCHANT_OrderPayOptionType ot; /**< Which field inside the union is valid */ + /** + * Type of the option being supplied. + */ + enum TALER_MERCHANT_OrderPayOptionType ot; + union { const char *merchant_url; diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -2355,13 +2355,16 @@ struct TALER_MERCHANTDB_Plugin /** * Adds BUDIs to the table matching the order * - * FIXME: Add all params + * @param cls + * @param order_id alphanumeric string that uniquely identifies the order + * @param donau_budis JSON object with BUDIs to insert */ enum GNUNET_DB_QueryStatus (*insert_order_budis)(void *cls, const char *order_id, const json_t *donau_budis); + /** * Release an inventory lock by UUID. Releases ALL stocks locked under * the given UUID. @@ -2398,6 +2401,22 @@ struct TALER_MERCHANTDB_Plugin /** + * Select blinded signatures for an order. + * + * @param cls closure + * @param order_id order ID to select blinded signatures for + * @param blinded_sigs set to the JSON array of blinded signatures on success + * @param blind_sig_out set to the first blinded signature of blinded_sigs + */ + enum GNUNET_DB_QueryStatus + (*select_order_blinded_sigs)( + void *cls, + const char *order_id, + json_t **blinded_sigs, + struct GNUNET_CRYPTO_BlindedSignature *blind_sig_out); + + + /** * Retrieve contract terms given its @a order_id * * @param cls closure @@ -4226,20 +4245,6 @@ struct TALER_MERCHANTDB_Plugin void *cb_cls); /** - * Select blinded signatures for an order. - * - * @param cls closure - * @param order_id order ID to select blinded signatures for - * @param blinded_sigs set to the JSON array of blinded signatures on success - */ - enum GNUNET_DB_QueryStatus - (*select_order_blinded_sigs)( - void *cls, - const char *order_id, - json_t **blinded_sigs, - struct GNUNET_CRYPTO_BlindedSignature *blind_sig_out); - - /** * Delete information about a Donau instance. * * @param cls closure