donau

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

commit 27b5cdbf3906061465c5cea6664cbd107f0174dd
parent 7b23d713d3bb4a16c7b158dbb9ef10d8348e1752
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date:   Tue, 22 Jul 2025 16:58:28 +0200

adding new select from db to get the value by donation_unit_hash

Diffstat:
Msrc/donaudb/Makefile.am | 1+
Asrc/donaudb/pg_lookup_donation_unit_amount.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_lookup_donation_unit_amount.h | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/plugin_donaudb_postgres.c | 19+++++++++++--------
Msrc/include/donaudb_plugin.h | 67++++++++++++++++++++++++++++++++++++++++---------------------------
5 files changed, 156 insertions(+), 35 deletions(-)

diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -91,6 +91,7 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \ pg_insert_history_entry.h pg_insert_history_entry.c \ pg_lookup_charity.h pg_lookup_charity.c \ pg_lookup_issued_receipts.h pg_lookup_issued_receipts.c \ + pg_lookup_donation_unit_amount.h pg_lookup_donation_unit_amount.c \ pg_insert_issued_receipt.h pg_insert_issued_receipt.c \ pg_insert_submitted_receipts.h pg_insert_submitted_receipts.c diff --git a/src/donaudb/pg_lookup_donation_unit_amount.c b/src/donaudb/pg_lookup_donation_unit_amount.c @@ -0,0 +1,60 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + 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 donaudb/pg_lookup_donation_unit_amount.c + * @brief Implmentation of getting the donation unit amount + * from the donation_units table. + * @author Bohdan Potuzhnyi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_template.h" +#include "pg_helper.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DH_PG_lookup_donation_unit_amount ( + void *cls, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct TALER_Amount *value) +{ + struct PostgresClosure *pg = cls; + + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_donation_unit_pub), + GNUNET_PQ_query_param_end + }; + + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_RESULT_SPEC_AMOUNT ("value", + value), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "lookup_donation_unit", + "SELECT value" + " FROM donation_units" + " WHERE h_donation_unit_pub=$1;"); + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_donation_unit", + params, + rs); +} diff --git a/src/donaudb/pg_lookup_donation_unit_amount.h b/src/donaudb/pg_lookup_donation_unit_amount.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + 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 donaudb/pg_lookup_donation_unit_amount.h + * @brief Getting the donation unit amount + * @author Bohdan Potuzhnyi + */ +#ifndef PG_LOOKUP_DONATION_UNIT_H +#define PG_LOOKUP_DONATION_UNIT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "donaudb_plugin.h" +/** + * Look up the face value of one donation-unit entry. + * + * @param cls plugin’s `struct PostgresClosure *` + * @param h_donation_unit_pub hash of the donation-unit public key (PRIMARY KEY) + * @param[out] value amount stored in the table + * @return same semantics as every other DH_PG_* lookup: + * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT (==1) on success, + * 0 if not found, negative on hard error. + */ +enum GNUNET_DB_QueryStatus +DH_PG_lookup_donation_unit_amount ( + void *cls, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct TALER_Amount *value); + +#endif /* PG_LOOKUP_DONATION_UNIT_H */ +\ No newline at end of file diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -50,6 +50,7 @@ #include "pg_iterate_active_signing_keys.h" #include "pg_lookup_signing_key.h" #include "pg_lookup_charity.h" +#include "pg_lookup_donation_unit_amount.h" #include "pg_lookup_issued_receipts.h" #include "pg_get_charities.h" #include "pg_insert_charity.h" @@ -70,14 +71,14 @@ * @param conn SQL connection that was used */ #define BREAK_DB_ERR(result,conn) do { \ - GNUNET_break (0); \ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ - "Database failure: %s/%s/%s/%s/%s", \ - PQresultErrorField (result, PG_DIAG_MESSAGE_PRIMARY), \ - PQresultErrorField (result, PG_DIAG_MESSAGE_DETAIL), \ - PQresultErrorMessage (result), \ - PQresStatus (PQresultStatus (result)), \ - PQerrorMessage (conn)); \ + GNUNET_break (0); \ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ + "Database failure: %s/%s/%s/%s/%s", \ + PQresultErrorField (result, PG_DIAG_MESSAGE_PRIMARY), \ + PQresultErrorField (result, PG_DIAG_MESSAGE_DETAIL), \ + PQresultErrorMessage (result), \ + PQresStatus (PQresultStatus (result)), \ + PQerrorMessage (conn)); \ } while (0) @@ -227,6 +228,8 @@ libtaler_plugin_donaudb_postgres_init (void *cls) = &DH_PG_insert_donation_unit; plugin->iterate_donation_units = &DH_PG_iterate_donation_units; + plugin->lookup_donation_unit_amount + = &DH_PG_lookup_donation_unit_amount; plugin->insert_history_entry = &DH_PG_insert_history_entry; plugin->get_history diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -215,7 +215,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 +228,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 +240,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 +253,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 +265,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 +276,7 @@ struct DONAUDB_Plugin * @return transaction status */ enum GNUNET_DB_QueryStatus - (*commit)(void *cls); + (*commit)(void *cls); /** @@ -290,7 +290,7 @@ struct DONAUDB_Plugin * #GNUNET_SYSERR on hard errors */ enum GNUNET_GenericReturnValue - (*preflight)(void *cls); + (*preflight)(void *cls); /** @@ -311,7 +311,7 @@ struct DONAUDB_Plugin * #GNUNET_SYSERR on DB errors */ enum GNUNET_GenericReturnValue - (*gc)(void *cls); + (*gc)(void *cls); /** @@ -366,7 +366,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 +381,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 +394,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 +408,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 +427,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 +441,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 +455,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 +469,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 +486,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 +505,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 +526,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,13 +541,26 @@ 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, struct TALER_Amount *total_donations); /** + * Lookup amount of the donation unit hash. + * + * @param cls closure + * @param h_donation_unit_pub the hash over the donation unit public key + * @param value the amount of the donation unit + */ + enum GNUNET_DB_QueryStatus + (*lookup_donation_unit_amount)( + void *cls, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct TALER_Amount *value); + + /** * Lookup issued receipts from the charity. * * @param cls closure @@ -556,7 +569,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); @@ -570,7 +583,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); @@ -584,7 +597,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); @@ -598,7 +611,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);