donau

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

commit cba61048b6ce3614fb48c2d7b1870a1170827bed
parent 317e3d9ab6465fc637a0e7e75f9b755fbf59bf90
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Fri, 12 Jan 2024 15:45:22 +0100

[db] added get donation units

Diffstat:
Msrc/donaudb/Makefile.am | 1+
Asrc/donaudb/pg_get_donation_units.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_get_donation_units.h | 39+++++++++++++++++++++++++++++++++++++++
Msrc/include/donaudb_plugin.h | 26+++++++++++++++++++++++++-
4 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -83,6 +83,7 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \ pg_lookup_signing_key.h pg_lookup_signing_key.c \ pg_add_donation_unit_key.c pg_add_donation_unit_key.h \ pg_lookup_donation_unit.c pg_lookup_donation_unit.h \ + pg_get_donation_units.c pg_get_donation_units.h \ pg_get_charities.h pg_get_charities.c \ pg_insert_charity.h pg_insert_charity.c \ pg_lookup_charity.h pg_lookup_charity.c \ diff --git a/src/donaudb/pg_get_donation_units.c b/src/donaudb/pg_get_donation_units.c @@ -0,0 +1,55 @@ +/* + This file is part of TALER + Copyright (C) 2023 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 CHARITYABILITY 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_get_donation_units.c + * @brief Implementation of the get_donation_units function for Postgres + * @author Johannes Casaburi + */ +#include "taler/platform.h" +#include "taler/taler_error_codes.h" +#include "taler/taler_dbevents.h" +#include "taler/taler_pq_lib.h" +#include "pg_get_donation_units.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +DH_PG_get_donation_units ( + void *cls, + struct DONAUDB_DonationUnitKeyMetaData *meta) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("validity_year", + &meta->validity_year), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", + &meta->value), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "get_donation_units", + "SELECT" + " validity_year" + ",amount" + " FROM donation_units"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "get_donation_units", + params, + rs); +} diff --git a/src/donaudb/pg_get_donation_units.h b/src/donaudb/pg_get_donation_units.h @@ -0,0 +1,39 @@ +/* + This file is part of TALER + Copyright (C) 2023 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 CHARITYABILITY 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_get_donation_units.h + * @brief implementation of the get_donation_units function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_LOOKUP_DONATION_UNIT_KEY_H +#define PG_LOOKUP_DONATION_UNIT_KEY_H + +#include <taler/taler_util.h> +#include "taler/taler_json_lib.h" +#include "donaudb_plugin.h" +/** + * Lookup information about current donation unit key. + * + * @param cls closure + * @param[out] meta set to various meta data about the key + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DH_PG_get_donation_units ( + void *cls, + struct DONAUDB_DonationUnitKeyMetaData *meta); + +#endif diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -135,11 +135,22 @@ struct DONAUDB_DonationUnitKey * @param info donation unit key information */ typedef void -(*DONAUDB_DonationUnitsCallback)( +(*DONAUDB_DonationUnitCallback)( void *cls, const struct DONAU_DonationUnitPublicKey *donation_unit_pub, struct DONAUDB_DonationUnitKeyMetaData *info); +/** + * Signature of a function called with information about the donau's + * donation unit keys. + * + * @param cls closure with a `struct DH_KeyStateHandle *` + * @param info donation unit key information + */ +typedef void +(*DONAUDB_GetDonationUnitsCallback)( + void *cls, + struct DONAUDB_DonationUnitKeyMetaData *info); /** * Signature of a function called with information about the donau's @@ -386,6 +397,19 @@ struct DONAUDB_Plugin struct TALER_Amount *receipts_to_date, uint64_t current_year); + /** + * Get keys. + * + * @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 + (*get_keys)( + void *cls, + DONAUDB_GetDonationUnitsCallback cb, + void *cb_cls); };