donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 31dc90f8f7bf2d9af0088587af8577ce52309707
parent dffa7bd9e4d1938ffc2e2c3fb5a4714aad5fb648
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 26 Sep 2025 18:59:46 +0200

work related to #10454

Diffstat:
Msrc/donau/donau-httpd_charity_insert.c | 34+++++++++++++++++++++-------------
Msrc/donaudb/pg_insert_charity.c | 13+++++++------
Msrc/donaudb/pg_insert_charity.h | 7++++---
Msrc/include/donaudb_plugin.h | 27+++++++++++++++++----------
4 files changed, 49 insertions(+), 32 deletions(-)

diff --git a/src/donau/donau-httpd_charity_insert.c b/src/donau/donau-httpd_charity_insert.c @@ -76,23 +76,31 @@ insert_charity (void *cls, icc->charity_url, &icc->max_per_year, &icc->receipts_to_date, - &icc->current_year, + icc->current_year, &icc->charity_id); - if (qs <= 0) + switch (qs) { - if (GNUNET_DB_STATUS_SOFT_ERROR != qs) - { - GNUNET_break (0); - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "insert_charity"); - return GNUNET_DB_STATUS_HARD_ERROR; - } + case GNUNET_DB_STATUS_SOFT_ERROR: + return qs; + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert_charity"); + return GNUNET_DB_STATUS_HARD_ERROR; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_break (0); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_CONFLICT, + TALER_EC_DONAU_CHARITY_PUB_EXISTS, + NULL); + return GNUNET_DB_STATUS_HARD_ERROR; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: return qs; } - - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; + GNUNET_assert (0); + return GNUNET_DB_STATUS_HARD_ERROR; } diff --git a/src/donaudb/pg_insert_charity.c b/src/donaudb/pg_insert_charity.c @@ -33,9 +33,9 @@ DH_PG_insert_charity ( const struct DONAU_CharityPublicKeyP *charity_pub, const char *charity_name, const char *charity_url, - struct TALER_Amount *max_per_year, - struct TALER_Amount *receipts_to_date, - uint64_t *current_year, + const struct TALER_Amount *max_per_year, + const struct TALER_Amount *receipts_to_date, + uint64_t current_year, uint64_t *charity_id) { struct PostgresClosure *pg = cls; @@ -47,7 +47,7 @@ DH_PG_insert_charity ( max_per_year), TALER_PQ_query_param_amount (pg->conn, receipts_to_date), - GNUNET_PQ_query_param_uint64 (current_year), + GNUNET_PQ_query_param_uint64 (&current_year), GNUNET_PQ_query_param_end }; @@ -67,8 +67,9 @@ DH_PG_insert_charity ( ",receipts_to_date" ",current_year" ") VALUES " - "($1, $2, $3, $4, $5, $6) " - "RETURNING charity_id;"); + "($1, $2, $3, $4, $5, $6)" + " ON CONFLICT DO NOTHING" + " RETURNING charity_id;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "insert_charity", params, diff --git a/src/donaudb/pg_insert_charity.h b/src/donaudb/pg_insert_charity.h @@ -35,6 +35,7 @@ * @param max_per_year yearly donation limit * @param receipts_to_date current amount of donations in the current year * @param current_year current year + * @param[out] charity_id set to unique ID assigned to this charity * @return transaction status code */ enum GNUNET_DB_QueryStatus @@ -43,9 +44,9 @@ DH_PG_insert_charity ( const struct DONAU_CharityPublicKeyP *charity_pub, const char *charity_name, const char *charity_url, - struct TALER_Amount *max_per_year, - struct TALER_Amount *receipts_to_date, - uint64_t *current_year, + const struct TALER_Amount *max_per_year, + const struct TALER_Amount *receipts_to_date, + uint64_t current_year, uint64_t *charity_id); #endif diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -399,12 +399,18 @@ struct DONAUDB_Plugin DONAUDB_GetCharitiesCallback cb, void *cb_cls); + /** * Insert Charity * * @param cls closure + * @param charity_pub charity public key * @param charity_name * @param charity_url + * @param max_per_year yearly donation limit + * @param receipts_to_date current amount of donations in the current year + * @param current_year current year + * @param[out] charity_id set to unique ID assigned to this charity * @return database transaction status */ enum GNUNET_DB_QueryStatus @@ -413,19 +419,20 @@ struct DONAUDB_Plugin const struct DONAU_CharityPublicKeyP *charity_pub, const char *charity_name, const char *charity_url, - struct TALER_Amount *max_per_year, - struct TALER_Amount *receipts_to_date, - uint64_t *current_year, + const struct TALER_Amount *max_per_year, + const struct TALER_Amount *receipts_to_date, + uint64_t current_year, uint64_t *charity_id); + /** - * Iterate donation units. - * - * @param cls closure - * @param cb callback to invoke on each match - * @param cb_cls closure for @a cb - * @return database transaction status - */ + * Iterate donation units. + * + * @param cls closure + * @param cb callback to invoke on each match + * @param cb_cls closure for @a cb + * @return database transaction status + */ enum GNUNET_DB_QueryStatus (*iterate_donation_units)( void *cls,