donau

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

commit 4388d7c28f1fd261f92ea529e801332a6463b935
parent 21768edf813779f29730f8aa657fd3e26a3c4b59
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Tue, 19 Mar 2024 16:03:00 +0100

[donaudb] add lookup issued receipts pg request

Diffstat:
Msrc/donau/donau-httpd_post-batch-issue.c | 4+---
Msrc/donaudb/Makefile.am | 3++-
Msrc/donaudb/pg_lookup_charity.h | 4++--
Asrc/donaudb/pg_lookup_issued_receipts.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_lookup_issued_receipts.h | 39+++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/plugin_donaudb_postgres.c | 5++++-
Msrc/include/donau_crypto_lib.h | 8++++++++
Msrc/include/donaudb_plugin.h | 21+++++++++++++++++++++
8 files changed, 138 insertions(+), 7 deletions(-)

diff --git a/src/donau/donau-httpd_post-batch-issue.c b/src/donau/donau-httpd_post-batch-issue.c @@ -28,7 +28,7 @@ #include <taler/taler_mhd_lib.h> #include <taler/taler_signatures.h> #include "donaudb_plugin.h" -#include "donau-httpd_charity.h" +#include "donau-httpd_post-batch-issue.h" #include "donau-httpd_db.h" #include "donau-httpd_metrics.h" @@ -204,10 +204,8 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, } // Get charity pub - struct DONAUDB_CharityMetaData meta; enum GNUNET_DB_QueryStatus qs; - //MHD_RESULT result; qs = DH_plugin->lookup_charity (DH_plugin->cls, (uint64_t) charity_id, diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -87,8 +87,9 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \ pg_get_charities.h pg_get_charities.c \ pg_insert_charity.h pg_insert_charity.c \ pg_do_charity_delete.h pg_do_charity_delete.c \ - pg_lookup_charity.h pg_lookup_charity.c \ 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_insert_issued_receipt.h pg_insert_issued_receipt.c \ pg_insert_submitted_receipt.h pg_insert_submitted_receipt.c diff --git a/src/donaudb/pg_lookup_charity.h b/src/donaudb/pg_lookup_charity.h @@ -18,8 +18,8 @@ * @brief implementation of the lookup_charity function for Postgres * @author Johannes Casaburi */ -#ifndef PG_GET_DONATION_UNIT_INFO_H -#define PG_GET_DONATION_UNIT_INFO_H +#ifndef PG_GET_CHARITY_INFO_H +#define PG_GET_CHARITY_INFO_H #include <taler/taler_util.h> #include <taler/taler_json_lib.h> diff --git a/src/donaudb/pg_lookup_issued_receipts.c b/src/donaudb/pg_lookup_issued_receipts.c @@ -0,0 +1,61 @@ +/* + This file is part of TALER + Copyright (C) 2024 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_issued_receipts.c + * @brief Implementation of the lookup_issued_receipts function for Postgres + * @author Lukas Matyja + */ +#include <taler/platform.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_lookup_issued_receipts.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +DH_PG_lookup_issued_receipts ( + void *cls, + struct DONAU_BudiKeyPairsHashP bkp_hash, + struct DONAUDB_IssuedReceiptsMetaData *meta) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (&bkp_hash), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("charity_sig", + &meta->charity_sig), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", + &meta->amount), + GNUNET_PQ_result_spec_uint64 ("charity_id", + &meta->charity_id), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "lookup_issued_receipts", + "SELECT " + " charity_sig" + " ,amount" + " ,charity_id" + " FROM receipts_issued" + " WHERE receipt_hash=$1;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_issued_receipts", + params, + rs); +} diff --git a/src/donaudb/pg_lookup_issued_receipts.h b/src/donaudb/pg_lookup_issued_receipts.h @@ -0,0 +1,39 @@ +/* + This file is part of TALER + Copyright (C) 2024 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_issued_receipts.h + * @brief implementation of the lookup_issued_receipts function for Postgres + * @author Lukas Matyja + */ +#ifndef PG_GET_ISSUED_RECEIPTS_H +#define PG_GET_ISSUED_RECEIPTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "donaudb_plugin.h" +/** + * Fetch information about an issued receipts request. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param[out] info information with value and other info about the issued receipts + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DH_PG_lookup_issued_receipts ( + void *cls, + struct DONAU_BudiKeyPairsHashP bkp_hash, + struct DONAUDB_IssuedReceiptsMetaData *meta); +#endif diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -59,6 +59,7 @@ #include "pg_iterate_active_signing_keys.h" #include "pg_lookup_signing_key.h" #include "pg_lookup_charity.h" +#include "pg_lookup_issued_receipts.h" #include "pg_get_charities.h" #include "pg_insert_charity.h" #include "pg_do_charity_delete.h" @@ -248,8 +249,10 @@ libtaler_plugin_donaudb_postgres_init (void *cls) = &DH_PG_get_history; plugin->insert_issued_receipt = &DH_PG_insert_issued_receipt; + plugin->lookup_issued_receipts + = &DH_PG_lookup_issued_receipts; plugin->insert_submitted_receipt - = &DH_PG_insert_submitted_receipt; + = &DH_PG_insert_submitted_receipts; plugin->insert_signing_key = &DH_PG_insert_signing_key; plugin->lookup_signing_key diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h @@ -264,6 +264,14 @@ struct DONAU_BlindedUniqueDonationIdentifierKeyPair }; +/** + * Hash of a budikeypair array + */ +struct DONAU_BudiKeyPairsHashP +{ + struct GNUNET_HashCode hash; +}; + /* ********************* charity eddsa signing ************************** */ diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -89,6 +89,27 @@ struct DONAUDB_CharityMetaData }; +/** + * Meta data about issued receipts of a request. + */ +struct DONAUDB_IssuedReceiptsMetaData +{ + /** + * Charity id + */ + uint64_t charity_id; + + /** + * total issued amount of the receipts + */ + struct TALER_Amount amount; + + /** + * Charity signature + */ + struct DONAU_CharitySignatureP charity_sig; + +}; /** * @brief All information about a donation unit key.