commit 6608bb77485125db00f214427715c8c5385336a3
parent b0902b5efd07d766767f7645a37ad11b93a810db
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Sun, 3 Aug 2025 11:57:36 +0200
fix charities manipulation API
Diffstat:
5 files changed, 54 insertions(+), 69 deletions(-)
diff --git a/src/donau/donau-httpd_charities_get.c b/src/donau/donau-httpd_charities_get.c
@@ -43,12 +43,10 @@
static enum GNUNET_GenericReturnValue
charities_cb (
void *cls,
- const struct DONAU_CharityPublicKeyP charity_pub,
+ uint64_t charity_id,
const char *charity_name,
- const char *charity_url,
struct TALER_Amount max_per_year,
- struct TALER_Amount receipts_to_date,
- uint64_t current_year)
+ struct TALER_Amount receipts_to_date)
{
json_t *charities = cls;
@@ -57,18 +55,14 @@ charities_cb (
json_array_append (
charities,
GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("charity_pub",
- &charity_pub),
- GNUNET_JSON_pack_string ("url",
- charity_url),
+ GNUNET_JSON_pack_uint64 ("charity_id",
+ charity_id),
GNUNET_JSON_pack_string ("name",
charity_name),
TALER_JSON_pack_amount ("max_per_year",
&max_per_year),
TALER_JSON_pack_amount ("receipts_to_date",
- &receipts_to_date),
- GNUNET_JSON_pack_int64 ("current_year",
- current_year))));
+ &receipts_to_date))));
return GNUNET_OK;
}
diff --git a/src/donaudb/pg_get_charities.c b/src/donaudb/pg_get_charities.c
@@ -71,20 +71,16 @@ get_charities_cb (void *cls,
for (unsigned int i = 0; i < num_results; i++)
{
- struct DONAU_CharityPublicKeyP charity_pub;
+ uint64_t charity_id;
char *charity_name;
- char *charity_url;
struct TALER_Amount max_per_year;
struct TALER_Amount receipts_to_date;
uint64_t current_year;
-
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("charity_pub",
- &charity_pub),
+ GNUNET_PQ_result_spec_uint64 ("charity_id",
+ &charity_id),
GNUNET_PQ_result_spec_string ("charity_name",
&charity_name),
- GNUNET_PQ_result_spec_string ("charity_url",
- &charity_url),
TALER_PQ_RESULT_SPEC_AMOUNT ("max_per_year",
&max_per_year),
TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date",
@@ -103,16 +99,18 @@ get_charities_cb (void *cls,
ctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
return;
}
-
+ if (current_year !=
+ GNUNET_TIME_get_current_year ())
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (max_per_year.currency,
+ &receipts_to_date));
ctx->qs = i + 1;
if (GNUNET_OK !=
ctx->cb (ctx->cb_cls,
- charity_pub,
+ charity_id,
charity_name,
- charity_url,
max_per_year,
- receipts_to_date,
- current_year))
+ receipts_to_date))
break;
}
}
@@ -137,9 +135,8 @@ DH_PG_get_charities (void *cls,
PREPARE (pg,
"get_charities",
"SELECT"
- " charity_pub"
+ " charity_id"
",charity_name"
- ",charity_url"
",max_per_year"
",receipts_to_date"
",current_year"
diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c
@@ -76,20 +76,16 @@ static struct DONAUDB_Plugin *plugin;
static enum GNUNET_GenericReturnValue
charities_cb (
void *cls,
- const struct DONAU_CharityPublicKeyP charity_pub,
+ uint64_t charity_id,
const char *charity_name,
- const char *charity_url,
struct TALER_Amount max_per_year,
- struct TALER_Amount receipts_to_date,
- uint64_t current_year)
+ struct TALER_Amount receipts_to_date)
{
(void) cls;
- (void) charity_pub;
+ (void) charity_id;
(void) charity_name;
- (void) charity_url;
(void) max_per_year;
(void) receipts_to_date;
- (void) current_year;
return GNUNET_OK;
}
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
@@ -162,6 +162,7 @@ typedef enum GNUNET_GenericReturnValue
uint64_t validity_year,
struct TALER_Amount *value);
+
/**
* Return charities.
*
@@ -170,12 +171,10 @@ typedef enum GNUNET_GenericReturnValue
typedef enum GNUNET_GenericReturnValue
(*DONAUDB_GetCharitiesCallback)(
void *cls,
- const struct DONAU_CharityPublicKeyP charity_pub,
+ uint64_t charity_id,
const char *charity_name,
- const char *charity_url,
struct TALER_Amount max_per_year,
- struct TALER_Amount receipts_to_date,
- uint64_t current_year);
+ struct TALER_Amount receipts_to_date);
/**
* Return history.
@@ -215,7 +214,7 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*drop_tables)(void *cls);
+ (*drop_tables)(void *cls);
/**
* Create the necessary tables if they are not present
@@ -228,7 +227,7 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*create_tables)(void *cls);
+ (*create_tables)(void *cls);
/**
@@ -240,8 +239,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start)(void *cls,
- const char *name);
+ (*start)(void *cls,
+ const char *name);
/**
@@ -253,8 +252,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start_read_committed)(void *cls,
- const char *name);
+ (*start_read_committed)(void *cls,
+ const char *name);
/**
* Start a READ ONLY serializable transaction.
@@ -265,8 +264,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start_read_only)(void *cls,
- const char *name);
+ (*start_read_only)(void *cls,
+ const char *name);
/**
@@ -276,7 +275,7 @@ struct DONAUDB_Plugin
* @return transaction status
*/
enum GNUNET_DB_QueryStatus
- (*commit)(void *cls);
+ (*commit)(void *cls);
/**
@@ -290,7 +289,7 @@ struct DONAUDB_Plugin
* #GNUNET_SYSERR on hard errors
*/
enum GNUNET_GenericReturnValue
- (*preflight)(void *cls);
+ (*preflight)(void *cls);
/**
@@ -311,7 +310,7 @@ struct DONAUDB_Plugin
* #GNUNET_SYSERR on DB errors
*/
enum GNUNET_GenericReturnValue
- (*gc)(void *cls);
+ (*gc)(void *cls);
/**
@@ -366,7 +365,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*lookup_charity)(
+ (*lookup_charity)(
void *cls,
uint64_t charity_id,
struct DONAUDB_CharityMetaData *meta);
@@ -381,7 +380,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*do_charity_delete)(
+ (*do_charity_delete)(
void *cls,
uint64_t charity_id);
@@ -394,7 +393,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_charities)(
+ (*get_charities)(
void *cls,
DONAUDB_GetCharitiesCallback cb,
void *cb_cls);
@@ -408,7 +407,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*insert_charity)(
+ (*insert_charity)(
void *cls,
const struct DONAU_CharityPublicKeyP *charity_pub,
const char *charity_name,
@@ -427,7 +426,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_donation_units)(
+ (*iterate_donation_units)(
void *cls,
DONAUDB_IterateDonationUnitsCallback cb,
void *cb_cls);
@@ -441,7 +440,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_history)(
+ (*get_history)(
void *cls,
DONAUDB_GetHistoryCallback cb,
void *cb_cls);
@@ -455,7 +454,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*lookup_history_entry)(
+ (*lookup_history_entry)(
void *cls,
const unsigned long long charity_id,
const struct TALER_Amount *final_amount,
@@ -469,7 +468,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*insert_donation_unit)(
+ (*insert_donation_unit)(
void *cls,
const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
@@ -486,7 +485,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_history_entry)(
+ (*insert_history_entry)(
void *cls,
const uint64_t charity_id,
const struct TALER_Amount *final_amount,
@@ -505,7 +504,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_issued_receipt)(
+ (*insert_issued_receipt)(
void *cls,
const size_t num_blinded_sig,
const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig],
@@ -526,7 +525,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_submitted_receipts)(
+ (*insert_submitted_receipts)(
void *cls,
struct DONAU_HashDonorTaxId *h_donor_tax_id,
size_t num_dr,
@@ -541,7 +540,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_submitted_receipts)(
+ (*iterate_submitted_receipts)(
void *cls,
const uint64_t donation_year,
const struct DONAU_HashDonorTaxId *h_donor_tax_id,
@@ -555,7 +554,7 @@ struct DONAUDB_Plugin
* @param value the amount of the donation unit
*/
enum GNUNET_DB_QueryStatus
- (*lookup_donation_unit_amount)(
+ (*lookup_donation_unit_amount)(
void *cls,
const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
struct TALER_Amount *value);
@@ -569,7 +568,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_issued_receipts)(
+ (*lookup_issued_receipts)(
void *cls,
struct DONAU_DonationReceiptHashP *h_receitps,
struct DONAUDB_IssuedReceiptsMetaData *meta);
@@ -583,7 +582,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_signing_key)(
+ (*insert_signing_key)(
void *cls,
const struct DONAU_DonauPublicKeyP *donau_pub,
struct DONAUDB_SignkeyMetaData *meta);
@@ -597,7 +596,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_signing_key)(
+ (*lookup_signing_key)(
void *cls,
const struct DONAU_DonauPublicKeyP *donau_pub,
struct DONAUDB_SignkeyMetaData *meta);
@@ -611,7 +610,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_active_signing_keys)(
+ (*iterate_active_signing_keys)(
void *cls,
DONAUDB_IterateActiveSigningKeysCallback cb,
void *cb_cls);
diff --git a/src/lib/donau_api_charities_get.c b/src/lib/donau_api_charities_get.c
@@ -94,20 +94,19 @@ handle_charities_get_ok (const json_t *resp_obj,
charity_obj)
{
struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 ("charity_id",
+ &charities[index].charity_id),
GNUNET_JSON_spec_string ("name",
&charities[index].name),
TALER_JSON_spec_amount_any ("max_per_year",
&charities[index].max_per_year),
TALER_JSON_spec_amount_any ("receipts_to_date",
- &charities[index].
- receipts_to_date),
- GNUNET_JSON_spec_uint64 ("charity_id",
- &charities[index].charity_id),
+ &charities[index].receipts_to_date),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
- GNUNET_JSON_parse (resp_obj,
+ GNUNET_JSON_parse (charity_obj,
spec,
NULL,
NULL))