donau

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

commit 41f7458bfcbc73e859a060b525898f8381910cc3
parent d07e6e7352be9fda67d2846ee57b195eb0abb1ef
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Sun, 14 Jan 2024 21:49:11 +0100

resolve merge

Diffstat:
Msrc/donau/Makefile.am | 2++
Msrc/donau/donau-httpd_get-charities.c | 18++++++++++++++----
Msrc/donau/donau-httpd_get-charity.c | 13++++++++++++-
Asrc/donau/donau-httpd_get-history-entry.c | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donau/donau-httpd_get-history.c | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donau/donau-httpd_history.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/Makefile.am | 1+
Msrc/donaudb/pg_get_charities.c | 26++++++++++++++++++++++++--
Asrc/donaudb/pg_get_history.c | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_get_history.h | 39+++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/pg_helper.h | 10+++++-----
Msrc/donaudb/pg_lookup_charity.c | 18+++++++++++++++---
Msrc/donaudb/plugin_donaudb_postgres.c | 39+++++++++++++++++++++------------------
Msrc/include/donaudb_plugin.h | 171++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
14 files changed, 717 insertions(+), 38 deletions(-)

diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am @@ -44,6 +44,8 @@ donau_httpd_SOURCES = \ donau-httpd_config.c donau-httpd_config.h \ donau-httpd_get-charities.c donau_httpd_charity.h \ donau-httpd_get-charity.c donau-httpd_post-charity.c \ + donau-httpd_get-history-entry.c donau-httpd_history.h \ + donau-httpd_get-history.c \ donau-httpd_terms.c donau-httpd_terms.h # Testcases diff --git a/src/donau/donau-httpd_get-charities.c b/src/donau/donau-httpd_get-charities.c @@ -22,7 +22,6 @@ #include <gnunet/gnunet_util_lib.h> #include <jansson.h> #include <microhttpd.h> -#include <pthread.h> #include <taler/taler_json_lib.h> #include <taler/taler_mhd_lib.h> #include <taler/taler_signatures.h> @@ -45,8 +44,12 @@ static void charities_cb ( void *cls, + struct DONAU_CharityPublicKeyP charity_pub, + const char *charity_name, const char *charity_url, - const char *charity_name) + struct TALER_Amount max_per_year, + struct TALER_Amount receipts_to_date, + uint64_t current_year) { json_t *charities = cls; @@ -55,11 +58,18 @@ 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_string ("name", - charity_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)))); } diff --git a/src/donau/donau-httpd_get-charity.c b/src/donau/donau-httpd_get-charity.c @@ -99,13 +99,24 @@ DH_handler_charity_get ( result = TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_OK, + GNUNET_JSON_pack_data_auto ("charity_pub", + meta.charity_pub), GNUNET_JSON_pack_data_auto ("url", &meta.charity_url), GNUNET_JSON_pack_data_auto ("name", - &meta.charity_name)); + &meta.charity_name), + TALER_JSON_pack_amount ("max_per_year", + meta.max_per_year), + TALER_JSON_pack_amount ("receipts_to_date", + meta.receipts_to_date), + GNUNET_JSON_pack_uint64 ("current_year", + meta.current_year)); + GNUNET_free (meta.charity_pub); GNUNET_free (meta.charity_url); GNUNET_free (meta.charity_name); + GNUNET_free (meta.max_per_year); + GNUNET_free (meta.receipts_to_date); return result; } } diff --git a/src/donau/donau-httpd_get-history-entry.c b/src/donau/donau-httpd_get-history-entry.c @@ -0,0 +1,115 @@ +/* + 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 Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file donau-httpd_history-get.c + * @brief Return summary information about AML decision + * @author Johannes Casaburi + */ +#include "taler/platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler/taler_json_lib.h" +#include "taler/taler_mhd_lib.h" +#include "taler/taler_signatures.h" +#include "donaudb_plugin.h" +#include "donau-httpd_history.h" +// #include "donau-httpd.h" +// #include "donau-httpd_metrics.h" + + +/** + * Maximum number of records we return per request. + */ +#define MAX_RECORDS 1024 + +MHD_RESULT +DH_handler_history_entry_get ( + struct DH_RequestContext *rc, + const char *const args[]) +{ + unsigned long long charity_id; + char dummy; + + if ( (NULL == args[0]) || + (1 != sscanf (args[0], + "%llu%c", + &charity_id, + &dummy)) ) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "charity_id"); + } + + if (NULL != args[1]) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_ENDPOINT_UNKNOWN, + args[1]); + } + + { + const struct TALER_Amount *final_amount; + const uint64_t donation_year; + enum GNUNET_DB_QueryStatus qs; + MHD_RESULT result; + + qs = DH_plugin->lookup_history_entry (DH_plugin->cls, + charity_id, + &final_amount, + donation_year); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + return TALER_MHD_reply_static ( + rc->connection, + MHD_HTTP_NO_CONTENT, + NULL, + NULL, + 0); + break; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } + + result = TALER_MHD_REPLY_JSON_PACK ( + rc->connection, + MHD_HTTP_OK, + TALER_JSON_pack_amount ("final_amount", + final_amount), + GNUNET_JSON_pack_uint64 ("donation_year", + donation_year)); + + GNUNET_free (final_amount); + return result; + } +} + + +/* end of donau-httpd_aml-decision_get.c */ diff --git a/src/donau/donau-httpd_get-history.c b/src/donau/donau-httpd_get-history.c @@ -0,0 +1,120 @@ +/* + 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 Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file donau-httpd_get-history.c + * @brief Return history + * @author Johannes Casaburi + */ +#include "taler/platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include "taler/taler_json_lib.h" +#include "taler/taler_mhd_lib.h" +#include "taler/taler_signatures.h" +#include "donau-httpd.h" +#include "donaudb_plugin.h" +#include "donau-httpd_history.h" +// #include "taler-exchange-httpd_metrics.h" + + +/** + * Maximum number of history we return per request. + */ +#define MAX_RECORDS 1024 + +/** + * Return history information. + * + * @param cls closure + */ +static void +history_cb ( + void *cls, + uint64_t charity_id, + struct TALER_Amount final_amount, + uint64_t donation_year) +{ + json_t *history = cls; + + GNUNET_assert ( + 0 == + json_array_append ( + history, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_int64 ("charity_id", + charity_id), + TALER_JSON_pack_amount ("final_amount", + &final_amount), + GNUNET_JSON_pack_int64 ("donation_year", + donation_year)))); +} + + +MHD_RESULT +DH_handler_history_get ( + struct DH_RequestContext *rc, + const char *const args[]) +{ + + if (NULL != args[1]) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_ENDPOINT_UNKNOWN, + args[1]); + } + + { + json_t *history; + enum GNUNET_DB_QueryStatus qs; + + history = json_array (); + GNUNET_assert (NULL != history); + qs = DH_plugin->get_history (DH_plugin->cls, + &history_cb, + history); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + json_decref (history); + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + return TALER_MHD_reply_static ( + rc->connection, + MHD_HTTP_NO_CONTENT, + NULL, + NULL, + 0); + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } + return TALER_MHD_REPLY_JSON_PACK ( + rc->connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("history", + history)); + } +} + + +/* end of donau-httpd_get-history.c */ diff --git a/src/donau/donau-httpd_history.h b/src/donau/donau-httpd_history.h @@ -0,0 +1,51 @@ +/* + 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 Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file donau-httpd_history.h + * @brief Handle /history requests + * @author Johannes Casaburi + */ +#ifndef DONAU_HTTPD_HISTORY_H +#define DONAU_HTTPD_HISTORY_H + +#include <microhttpd.h> +#include "donau-httpd.h" + +/** + * Handle a GET "/history" request. + * + * @param rc request context + * @param args GET arguments (should be one) + * @return MHD result code + */ +MHD_RESULT +DH_handler_history_get ( + struct DH_RequestContext *rc, + const char *const args[]); + +/** + * Handle a GET "/history/$charity_id" request. + * + * @param rc request context + * @param args GET arguments (should be one) + * @return MHD result code + */ +MHD_RESULT +DH_handler_history_entry_get ( + struct DH_RequestContext *rc, + const char *const args[]); + +#endif diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -83,6 +83,7 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \ 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_history.h pg_get_history.c \ 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_charities.c b/src/donaudb/pg_get_charities.c @@ -65,14 +65,28 @@ get_charities_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { + struct DONAU_CharityPublicKeyP charity_pub; 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_string ("charity_name", &charity_name), GNUNET_PQ_result_spec_string ("charity_url", &charity_url), + TALER_PQ_result_spec_amount ("max_per_year", + "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + &max_per_year), + TALER_PQ_result_spec_amount ("receipts_to_date", + "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + &receipts_to_date), + GNUNET_PQ_result_spec_uint64 ("current_year", + &current_year), GNUNET_PQ_result_spec_end }; @@ -86,8 +100,12 @@ get_charities_cb (void *cls, return; } ctx->cb (ctx->cb_cls, + charity_pub, charity_name, - charity_url); + charity_url, + max_per_year, + receipts_to_date, + current_year); GNUNET_PQ_cleanup_result (rs); } } @@ -112,8 +130,12 @@ DH_PG_get_charities (void *cls, PREPARE (pg, "get_charities", "SELECT" - " charity_name" + " charity_pub" + ",charity_name" ",charity_url" + ",max_per_year" + ",receipts_to_date" + ",current_year" " FROM charities"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, "get_charities", diff --git a/src/donaudb/pg_get_history.c b/src/donaudb/pg_get_history.c @@ -0,0 +1,132 @@ +/* + 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 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_history.c + * @brief Implementation of the lookup_donation_unit_key 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_history.h" +#include "pg_helper.h" + + +/** + * Closure for #get_history_cb(). + */ +struct GetHistoryContext +{ + /** + * Function to call per result. + */ + DONAUDB_GetHistoryCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Flag set to #GNUNET_OK as long as everything is fine. + */ + enum GNUNET_GenericReturnValue status; + +}; + + +/** + * Invoke the callback for each result. + * + * @param cls a `struct MissingWireContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +get_history_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct GetHistoryContext *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t charity_id; + struct TALER_Amount final_amount; + uint64_t donation_year; + + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("charity_id", + &charity_id), + TALER_PQ_result_spec_amount ("final_amount", + "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + &final_amount), + GNUNET_PQ_result_spec_uint64 ("donation_year", + &donation_year), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->status = GNUNET_SYSERR; + return; + } + ctx->cb (ctx->cb_cls, + charity_id, + final_amount, + donation_year); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +DH_PG_get_history (void *cls, + DONAUDB_GetHistoryCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + struct GetHistoryContext ctx = { + .cb = cb, + .cb_cls = cb_cls, + .status = GNUNET_OK + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "get_history", + "SELECT" + " charity_id" + ",final_amount" + ",donation_year" + " FROM history"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "get_history", + params, + &get_history_cb, + &ctx); + if (GNUNET_OK != ctx.status) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/donaudb/pg_get_history.h b/src/donaudb/pg_get_history.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 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_history.h + * @brief implementation of the get_history function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_GET_HISTORY_H +#define PG_GET_HISTORY_H + +#include "donaudb_plugin.h" + +/** + * Obtain information about the enabled wire accounts of the exchange. + * + * @param cls closure + * @param cb function to call on each account + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DH_PG_get_history (void *cls, + DONAUDB_GetHistoryCallback cb, + void *cb_cls); + +#endif diff --git a/src/donaudb/pg_helper.h b/src/donaudb/pg_helper.h @@ -55,16 +55,16 @@ struct PostgresClosure struct GNUNET_PQ_Context *conn; /** + * Name of the current transaction, for debugging. + */ + const char *transaction_name; + + /** * Counts how often we have established a fresh @e conn * to the database. Used to re-prepare statements. */ unsigned long long prep_gen; - /** - * Name of the current transaction, for debugging. - */ - const char *transaction_name; - }; diff --git a/src/donaudb/pg_lookup_charity.c b/src/donaudb/pg_lookup_charity.c @@ -37,18 +37,30 @@ DH_PG_lookup_charity ( GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("charity_url", - &meta->charity_url), + GNUNET_PQ_result_spec_auto_from_type ("charity_pub", + &meta->charity_pub), GNUNET_PQ_result_spec_string ("charity_name", &meta->charity_name), + GNUNET_PQ_result_spec_string ("charity_url", + &meta->charity_url), + TALER_PQ_RESULT_SPEC_AMOUNT ("max_per_year", + meta->max_per_year), + TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date", + meta->receipts_to_date), + GNUNET_PQ_result_spec_uint64 ("current_year", + &meta->current_year), GNUNET_PQ_result_spec_end }; PREPARE (pg, "lookup_charity", "SELECT " - " charity_name" + " charity_pub" + " ,charity_name" " ,charity_url" + " ,max_per_year" + " ,receipts_to_date" + " ,current_year" " FROM charities" " WHERE charity_id=$1;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -52,6 +52,7 @@ #include "pg_add_donation_unit_key.h" #include "pg_lookup_donation_unit.h" #include "pg_insert_history_entry.h" +#include "pg_get_history.h" #include "pg_insert_issued_receipt.h" #include "pg_insert_submitted_receipt.h" #include "pg_insert_signing_key.h" @@ -274,27 +275,29 @@ libtaler_plugin_donaudb_postgres_init (void *cls) = &DH_PG_event_listen_cancel; plugin->event_notify = &DH_PG_event_notify; - // plugin->get_policy_details - // = &DH_PG_get_policy_details; - // plugin->persist_policy_details - // = &DH_PG_persist_policy_details; + //plugin->get_policy_details + // = &DH_PG_get_policy_details; + //plugin->persist_policy_details + // = &DH_PG_persist_policy_details; // plugin->gc // = &DH_PG_gc; - // plugin->add_donation_unit_key - // = &DH_PG_add_donation_unit_key; - // plugin->lookup_donation_unit - // = &DH_PG_lookup_donation_unit; - // plugin->insert_history_entry - // = &DH_PG_insert_history_entry; - // plugin->insert_issued_receipt - // = &DH_PG_insert_issued_receipt; - // plugin->insert_submitted_receipt - // = &DH_PG_insert_submitted_receipt; - // plugin->insert_signing_key - // = &DH_PG_insert_signing_key; - // plugin->lookup_signing_key - // = &DH_PG_lookup_signing_key; + plugin->add_donation_unit_key + = &DH_PG_add_donation_unit_key; + plugin->lookup_donation_unit + = &DH_PG_lookup_donation_unit; + plugin->insert_history_entry + = &DH_PG_insert_history_entry; + plugin->get_history + = &DH_PG_get_history; + plugin->insert_issued_receipt + = &DH_PG_insert_issued_receipt; + plugin->insert_submitted_receipt + = &DH_PG_insert_submitted_receipt; + plugin->insert_signing_key + = &DH_PG_insert_signing_key; + plugin->lookup_signing_key + = &DH_PG_lookup_signing_key; plugin->lookup_charity = &DH_PG_lookup_charity; plugin->insert_charity diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -104,6 +104,11 @@ struct DONAUDB_CharityMetaData */ struct TALER_Amount *receipts_to_date; + /** + * Current year + */ + uint64_t current_year; + }; @@ -177,8 +182,26 @@ typedef void typedef void (*DONAUDB_GetCharitiesCallback)( void *cls, + const struct DONAU_CharityPublicKeyP charity_pub, const char *charity_name, - const char *charity_url); + const char *charity_url, + struct TALER_Amount max_per_year, + struct TALER_Amount receipts_to_date, + uint64_t current_year); + +/** + * Return history. + * + * @param cls closure + * @param charity_url + * @param charity_name + */ +typedef void +(*DONAUDB_GetHistoryCallback)( + void *cls, + uint64_t charity_id, + struct TALER_Amount final_amount, + uint64_t donation_year); /** * @brief The plugin API, returned from the plugin's "init" function. @@ -355,8 +378,7 @@ struct DONAUDB_Plugin * * @param cls closure * @param charity_id - * @param charity_url - * @param charity_name + * @param meta * @return database transaction status */ enum GNUNET_DB_QueryStatus @@ -365,7 +387,7 @@ struct DONAUDB_Plugin uint64_t charity_id, struct DONAUDB_CharityMetaData *meta); -/** + /** * Get charities. * * @param cls closure @@ -410,7 +432,146 @@ struct DONAUDB_Plugin void *cls, DONAUDB_GetDonationUnitsCallback cb, void *cb_cls); -}; + /** + * Get history. + * + * @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_history)( + void *cls, + DONAUDB_GetHistoryCallback cb, + void *cb_cls); + + /** + * Lookup history entry. + * + * @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 + (*lookup_history_entry)( + void *cls, + const uint64_t charity_id, + const struct TALER_Amount *final_amount, + const uint64_t donation_year); + + /** + * Get donation_unit_key. + * + * @param cls closure + * @param donation_unit_pub + * @param meta + * @return database transaction status + */ + enum GNUNET_DB_QueryStatus + (*add_donation_unit_key)( + void *cls, + const struct DONAU_DonationUnitPublicKey *donation_unit_pub, + struct DONAUDB_DonationUnitKeyMetaData *meta); + + /** + * Lookup information about current donation unit key. + * + * @param cls closure + * @param h_donation_unit_pub hash of the donation_unit public key + * @param[out] meta set to various meta data about the key + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*lookup_donation_unit)( + void *cls, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct DONAUDB_DonationUnitKeyMetaData *meta); + + /** + * Insert history entry of a charity + * + * @param cls closure + * @param charity_id charity id + * @param final_amount final donation amount at the end of the donation year + * @param donation_year year of the donations + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*insert_history_entry) ( + void *cls, + const uint64_t charity_id, + const struct TALER_Amount *final_amount, + const uint64_t donation_year); + + /** + * Insert issued blinded donation receipt to the charity. + * + * @param cls closure + * @param charity_sig signature from the charity + * @param charity_id identifier of the charity + * @param h_receipt hash of the donation receipt + * @param amount donation amount + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*insert_issued_receipt) ( + void *cls, + const struct DONAU_CharitySignatureP *charity_sig, + const uint64_t charity_id, + const struct DONAU_DonationReceiptHashP *h_receipt, + const struct TALER_Amount *amount); + + /** + * Insert submitted donation receipt from the donor. + * + * @param cls closure + * @param h_tax_number salted hash of the donors tax number + * @param nonce nonce that is part of the unique donation identifier + * @param donation_unit_pub donation unit public key + * @param donau_sig donau signature in case the sign keys changed + * @param donation_year year of the donation + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*insert_submitted_receipt) ( + void *cls, + const struct DONAU_HashDonorTaxId *h_tax_number, + const union GNUNET_CRYPTO_BlindSessionNonce *nonce, + const struct DONAU_DonationUnitPublicKey *donation_unit_pub, + const struct TALER_DonauSignatureP *donau_sig, + const uint64_t donation_year); + + /** + * Add signing key. + * + * @param cls closure + * @param donau_pub the donau online signing public key + * @param meta meta data about @a donau_pub + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*insert_signing_key) ( + void *cls, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + + /** + * Lookup signing key meta data. + * + * @param cls closure + * @param donau_pub the donau signing public key + * @param[out] meta meta data about @a donau_pub + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*lookup_signing_key) ( + void *cls, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + +}; #endif