donau

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

commit 1545c60c9a920e88cd31624c067d72e7ca16ac86
parent 725d18fe72bf77420dc2b134ddd5cbae99fa35c4
Author: Christian Grothoff <grothoff@gnu.org>
Date:   Wed,  8 Apr 2026 19:38:43 +0200

get rid of unweildy plugin abstraction for the database

Diffstat:
Mdebian/donau.install | 2+-
Mdebian/libdonau.install | 5++++-
Msrc/donau-tools/donau-dbinit.c | 18+++++++++---------
Msrc/donau/donau-httpd.c | 22+++++++++++-----------
Msrc/donau/donau-httpd.h | 6+++---
Msrc/donau/donau-httpd_db.c | 20++++++++++++--------
Msrc/donau/donau-httpd_delete-charities-CHARITY_ID.c | 5+++--
Msrc/donau/donau-httpd_get-charities.c | 8++++----
Msrc/donau/donau-httpd_get-charity-CHARITY_ID.c | 9++++-----
Msrc/donau/donau-httpd_get-charity-CHARITY_ID.h | 1-
Msrc/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.c | 11+++++------
Msrc/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.h | 1-
Msrc/donau/donau-httpd_get-history.c | 9++++-----
Msrc/donau/donau-httpd_get-keys.c | 52+++++++++++++++++++++++++++-------------------------
Msrc/donau/donau-httpd_get-keys.h | 3+--
Msrc/donau/donau-httpd_patch-charities-CHARITY_ID.c | 24+++++++++++++-----------
Msrc/donau/donau-httpd_post-batch-issue-CHARITY_ID.c | 33++++++++++++++++-----------------
Msrc/donau/donau-httpd_post-batch-submit.c | 18++++++++----------
Msrc/donau/donau-httpd_post-charities.c | 19+++++++++----------
Msrc/donau/donau-httpd_post-csr-issue.c | 2--
Msrc/donau/donau-httpd_post-csr-issue.h | 5++---
Msrc/donaudb/Makefile.am | 90+++++++++++++++++++++++++++++++------------------------------------------------
Asrc/donaudb/commit.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/create_tables.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/do_charity_delete.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/donau_do_insert_charity.sql | 1-
Msrc/donaudb/donau_do_insert_issued_receipts.sql | 15+++++++--------
Dsrc/donaudb/donaudb_plugin.c | 75---------------------------------------------------------------------------
Asrc/donaudb/drop_tables.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/event_listen.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/event_listen_cancel.c | 34++++++++++++++++++++++++++++++++++
Asrc/donaudb/event_notify.c | 39+++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/get_charities.c | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/get_history.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/helper.h | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/insert_charity.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/insert_donation_unit.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/insert_history_entry.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/insert_issued_receipt.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/insert_signing_key.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/insert_submitted_receipts.c | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/iterate_active_signing_keys.c | 137+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/iterate_donation_units.c | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/iterate_submitted_receipts.c | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/lookup_charity.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/lookup_donation_unit_amount.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/lookup_issued_receipts.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/lookup_signing_key.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/pg_commit.c | 58----------------------------------------------------------
Dsrc/donaudb/pg_commit.h | 37-------------------------------------
Dsrc/donaudb/pg_create_tables.c | 82-------------------------------------------------------------------------------
Dsrc/donaudb/pg_create_tables.h | 42------------------------------------------
Dsrc/donaudb/pg_do_charity_delete.c | 51---------------------------------------------------
Dsrc/donaudb/pg_do_charity_delete.h | 41-----------------------------------------
Dsrc/donaudb/pg_drop_tables.c | 58----------------------------------------------------------
Dsrc/donaudb/pg_drop_tables.h | 38--------------------------------------
Dsrc/donaudb/pg_event_listen.c | 53-----------------------------------------------------
Dsrc/donaudb/pg_event_listen.h | 45---------------------------------------------
Dsrc/donaudb/pg_event_listen_cancel.c | 36------------------------------------
Dsrc/donaudb/pg_event_listen_cancel.h | 38--------------------------------------
Dsrc/donaudb/pg_event_notify.c | 41-----------------------------------------
Dsrc/donaudb/pg_event_notify.h | 42------------------------------------------
Dsrc/donaudb/pg_get_charities.c | 160-------------------------------------------------------------------------------
Dsrc/donaudb/pg_get_charities.h | 39---------------------------------------
Dsrc/donaudb/pg_get_history.c | 140-------------------------------------------------------------------------------
Dsrc/donaudb/pg_get_history.h | 39---------------------------------------
Dsrc/donaudb/pg_helper.h | 121-------------------------------------------------------------------------------
Dsrc/donaudb/pg_insert_charity.c | 73-------------------------------------------------------------------------
Dsrc/donaudb/pg_insert_charity.h | 48------------------------------------------------
Dsrc/donaudb/pg_insert_donation_unit.c | 59-----------------------------------------------------------
Dsrc/donaudb/pg_insert_donation_unit.h | 46----------------------------------------------
Dsrc/donaudb/pg_insert_history_entry.c | 54------------------------------------------------------
Dsrc/donaudb/pg_insert_history_entry.h | 43-------------------------------------------
Dsrc/donaudb/pg_insert_issued_receipt.c | 79-------------------------------------------------------------------------------
Dsrc/donaudb/pg_insert_issued_receipt.h | 51---------------------------------------------------
Dsrc/donaudb/pg_insert_signing_key.c | 55-------------------------------------------------------
Dsrc/donaudb/pg_insert_signing_key.h | 42------------------------------------------
Dsrc/donaudb/pg_insert_submitted_receipts.c | 102-------------------------------------------------------------------------------
Dsrc/donaudb/pg_insert_submitted_receipts.h | 48------------------------------------------------
Dsrc/donaudb/pg_iterate_active_signing_keys.c | 134-------------------------------------------------------------------------------
Dsrc/donaudb/pg_iterate_active_signing_keys.h | 39---------------------------------------
Dsrc/donaudb/pg_iterate_donation_units.c | 135-------------------------------------------------------------------------------
Dsrc/donaudb/pg_iterate_donation_units.h | 39---------------------------------------
Dsrc/donaudb/pg_iterate_submitted_receipts.c | 78------------------------------------------------------------------------------
Dsrc/donaudb/pg_iterate_submitted_receipts.h | 42------------------------------------------
Dsrc/donaudb/pg_lookup_charity.c | 70----------------------------------------------------------------------
Dsrc/donaudb/pg_lookup_charity.h | 41-----------------------------------------
Dsrc/donaudb/pg_lookup_donation_unit_amount.c | 61-------------------------------------------------------------
Dsrc/donaudb/pg_lookup_donation_unit_amount.h | 44--------------------------------------------
Dsrc/donaudb/pg_lookup_issued_receipts.c | 78------------------------------------------------------------------------------
Dsrc/donaudb/pg_lookup_issued_receipts.h | 41-----------------------------------------
Dsrc/donaudb/pg_lookup_signing_key.c | 64----------------------------------------------------------------
Dsrc/donaudb/pg_lookup_signing_key.h | 43-------------------------------------------
Dsrc/donaudb/pg_preflight.c | 59-----------------------------------------------------------
Dsrc/donaudb/pg_preflight.h | 56--------------------------------------------------------
Dsrc/donaudb/pg_rollback.c | 50--------------------------------------------------
Dsrc/donaudb/pg_rollback.h | 36------------------------------------
Dsrc/donaudb/pg_start.c | 56--------------------------------------------------------
Dsrc/donaudb/pg_start.h | 40----------------------------------------
Dsrc/donaudb/pg_start_read_committed.c | 56--------------------------------------------------------
Dsrc/donaudb/pg_start_read_committed.h | 39---------------------------------------
Dsrc/donaudb/pg_start_read_only.c | 57---------------------------------------------------------
Dsrc/donaudb/pg_start_read_only.h | 40----------------------------------------
Msrc/donaudb/pg_template.c | 2+-
Msrc/donaudb/pg_template.h | 2+-
Dsrc/donaudb/pg_update_charity.c | 63---------------------------------------------------------------
Dsrc/donaudb/pg_update_charity.h | 47-----------------------------------------------
Msrc/donaudb/plugin_donaudb_postgres.c | 151+++++++++++--------------------------------------------------------------------
Asrc/donaudb/preflight.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/rollback.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/start.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/start_read_committed.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/start_read_only.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/test-donau-db-postgres.conf | 1-
Msrc/donaudb/test_donaudb.c | 96+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Asrc/donaudb/update_charity.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/Makefile.am | 35+++++++++++++++++++++++++++++++++--
Asrc/include/donau-database/commit.h | 36++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/create_tables.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/do_charity_delete.h | 39+++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/drop_tables.h | 36++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/event_listen.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/event_listen_cancel.h | 39+++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/event_notify.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/get_charities.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/get_history.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/insert_charity.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/insert_donation_unit.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/insert_history_entry.h | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/insert_issued_receipt.h | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/insert_signing_key.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/insert_submitted_receipts.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/iterate_active_signing_keys.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/iterate_donation_units.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/iterate_submitted_receipts.h | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/lookup_charity.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/lookup_donation_unit_amount.h | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/lookup_issued_receipts.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/lookup_signing_key.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/preflight.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/rollback.h | 35+++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/start.h | 40++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/start_read_committed.h | 40++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/start_read_only.h | 40++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/update_charity.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/donaudb_lib.h | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Dsrc/include/donaudb_plugin.h | 647-------------------------------------------------------------------------------
147 files changed, 3791 insertions(+), 4469 deletions(-)

diff --git a/debian/donau.install b/debian/donau.install @@ -1,5 +1,5 @@ usr/bin/donau-* -usr/lib/*/donau/libdonau_plugin_*.so +usr/lib/*/libdonaudb* usr/share/donau/config.d/* usr/share/donau/sql/* usr/share/man/man*/donau* diff --git a/debian/libdonau.install b/debian/libdonau.install @@ -1,4 +1,7 @@ -usr/lib/*/libdonau*.so.* +usr/lib/*/libdonau.so.* +usr/lib/*/libdonaujson.so.* +usr/lib/*/libdonauutil.so.* +usr/lib/*/libdonaupq.so.* usr/share/donau/config.d/paths.conf usr/share/donau/config.d/donau.conf diff --git a/src/donau-tools/donau-dbinit.c b/src/donau-tools/donau-dbinit.c @@ -22,6 +22,8 @@ #include "donau_config.h" #include <gnunet/gnunet_util_lib.h> #include "donaudb_lib.h" +#include "donau-database/drop_tables.h" +#include "donau-database/create_tables.h" #include "donau_util.h" @@ -75,16 +77,16 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - struct DONAUDB_Plugin *plugin; + struct DONAUDB_PostgresContext *ctx; (void) cls; (void) args; (void) cfgfile; if (NULL == - (plugin = DONAUDB_plugin_load (cfg))) + (ctx = DONAUDB_connect (cfg))) { fprintf (stderr, - "Failed to initialize database plugin.\n"); + "Failed to initialize database ctx.\n"); global_ret = EXIT_NOTINSTALLED; return; } @@ -92,7 +94,7 @@ run (void *cls, if (reset_db) { if (GNUNET_OK != - plugin->drop_tables (plugin->cls)) + DONAUDB_drop_tables (ctx)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not drop tables as requested. Either database was not yet initialized, or permission denied. Consult the logs. Will still try to create new tables.\n"); @@ -100,18 +102,16 @@ run (void *cls, } if (GNUNET_OK != - plugin->create_tables (plugin->cls)) + DONAUDB_create_tables (ctx)) { fprintf (stderr, "Failed to initialize database.\n"); - DONAUDB_plugin_unload (plugin); - plugin = NULL; + DONAUDB_disconnect (ctx); global_ret = EXIT_NOPERMISSION; return; } - DONAUDB_plugin_unload (plugin); - plugin = NULL; + DONAUDB_disconnect (ctx); } diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c @@ -40,9 +40,9 @@ #include "donau-httpd_post-batch-issue-CHARITY_ID.h" #include "donau-httpd_post-batch-submit.h" #include "donau-httpd_get-history.h" +#include "donau-database/preflight.h" #include "donau-httpd_post-csr-issue.h" #include "donau-httpd_terms.h" -#include "donaudb_plugin.h" #include <gnunet/gnunet_mhd_compat.h> /* LSB-style exit status codes */ @@ -104,9 +104,9 @@ const struct GNUNET_CONFIGURATION_Handle *DH_cfg; static bool have_daemons; /** - * Our DB plugin. (global) + * Our DB context. (global) */ -struct DONAUDB_Plugin *DH_plugin; +struct DONAUDB_PostgresContext *DH_context; /** * Our currency. @@ -241,7 +241,7 @@ handle_mhd_completion_callback (void *cls, TALER_MHD_parse_post_cleanup_callback (rc->opaque_post_parsing_context); /* Sanity-check that we didn't leave any transactions hanging */ GNUNET_break (GNUNET_OK == - DH_plugin->preflight (DH_plugin->cls)); + DONAUDB_preflight (DH_context)); { struct GNUNET_TIME_Relative latency; latency = GNUNET_TIME_absolute_get_duration (rc->start_time); @@ -856,15 +856,15 @@ donau_serve_process_config (void) for (unsigned int i = 0; i<MAX_DB_RETRIES; i++) { - DH_plugin = DONAUDB_plugin_load (DH_cfg); - if (NULL != DH_plugin) + DH_context = DONAUDB_connect (DH_cfg); + if (NULL != DH_context) break; GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect to DB, will try again %u times\n", MAX_DB_RETRIES - i); sleep (1); } - if (NULL == DH_plugin) + if (NULL == DH_context) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem. Giving up.\n"); @@ -925,10 +925,10 @@ do_shutdown (void *cls) TALER_MHD_daemons_halt (); TALER_MHD_daemons_destroy (); DH_keys_finished (); - if (NULL != DH_plugin) + if (NULL != DH_context) { - DONAUDB_plugin_unload (DH_plugin); - DH_plugin = NULL; + DONAUDB_disconnect (DH_context); + DH_context = NULL; } if (NULL != DH_curl_ctx) { @@ -1040,7 +1040,7 @@ run (void *cls, } if (GNUNET_SYSERR == - DH_plugin->preflight (DH_plugin->cls)) + DONAUDB_preflight (DH_context)) { DH_global_ret = EXIT_FAILURE; GNUNET_SCHEDULER_shutdown (); diff --git a/src/donau/donau-httpd.h b/src/donau/donau-httpd.h @@ -27,7 +27,7 @@ #include <taler/taler_json_lib.h> #include <taler/taler_util.h> #include <gnunet/gnunet_mhd_compat.h> -#include "donaudb_plugin.h" +#include "donaudb_lib.h" /** @@ -63,9 +63,9 @@ extern bool DH_suicide; extern int DH_global_ret; /** - * Our DB plugin. + * Our DB context. */ -extern struct DONAUDB_Plugin *DH_plugin; +extern struct DONAUDB_PostgresContext *DH_context; /** * Our currency. diff --git a/src/donau/donau-httpd_db.c b/src/donau/donau-httpd_db.c @@ -25,6 +25,10 @@ #include <taler/taler_json_lib.h> #include <taler/taler_mhd_lib.h> #include "donaudb_lib.h" +#include "donau-database/preflight.h" +#include "donau-database/start.h" +#include "donau-database/rollback.h" +#include "donau-database/commit.h" #include "donau-httpd_db.h" #include "donau-httpd.h" @@ -39,7 +43,7 @@ DH_DB_run_transaction (struct MHD_Connection *connection, if (NULL != mhd_ret) *mhd_ret = -1; /* set to invalid value, to help detect bugs */ if (GNUNET_OK != - DH_plugin->preflight (DH_plugin->cls)) + DONAUDB_preflight (DH_context)) { GNUNET_break (0); if (NULL != mhd_ret) @@ -56,8 +60,8 @@ DH_DB_run_transaction (struct MHD_Connection *connection, enum GNUNET_DB_QueryStatus qs; if (GNUNET_OK != - DH_plugin->start (DH_plugin->cls, - name)) + DONAUDB_start (DH_context, + name)) { GNUNET_break (0); if (NULL != mhd_ret) @@ -72,16 +76,16 @@ DH_DB_run_transaction (struct MHD_Connection *connection, mhd_ret); if (0 > qs) { - DH_plugin->rollback (DH_plugin->cls); + DONAUDB_rollback (DH_context); if (GNUNET_DB_STATUS_HARD_ERROR == qs) return GNUNET_SYSERR; } else { - qs = DH_plugin->commit (DH_plugin->cls); + qs = DONAUDB_commit (DH_context); if (GNUNET_DB_STATUS_HARD_ERROR == qs) { - DH_plugin->rollback (DH_plugin->cls); + DONAUDB_rollback (DH_context); if (NULL != mhd_ret) *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, @@ -90,7 +94,7 @@ DH_DB_run_transaction (struct MHD_Connection *connection, return GNUNET_SYSERR; } if (0 > qs) - DH_plugin->rollback (DH_plugin->cls); + DONAUDB_rollback (DH_context); } /* make sure callback did not violate invariants! */ GNUNET_assert ( (NULL == mhd_ret) || @@ -98,7 +102,7 @@ DH_DB_run_transaction (struct MHD_Connection *connection, if (0 <= qs) return GNUNET_OK; } - DH_plugin->rollback (DH_plugin->cls); + DONAUDB_rollback (DH_context); TALER_LOG_ERROR ("Transaction `%s' commit failed %u times\n", name, MAX_TRANSACTION_COMMIT_RETRIES); diff --git a/src/donau/donau-httpd_delete-charities-CHARITY_ID.c b/src/donau/donau-httpd_delete-charities-CHARITY_ID.c @@ -28,6 +28,7 @@ #include "taler/taler_json_lib.h" #include "taler/taler_mhd_lib.h" #include "donau-httpd_delete-charities-CHARITY_ID.h" +#include "donau-database/do_charity_delete.h" MHD_RESULT @@ -54,8 +55,8 @@ DH_handler_delete_charities ( { enum GNUNET_DB_QueryStatus qs; - qs = DH_plugin->do_charity_delete (DH_plugin->cls, - (uint64_t) charity_id); + qs = DONAUDB_do_charity_delete (DH_context, + (uint64_t) charity_id); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-charities.c b/src/donau/donau-httpd_get-charities.c @@ -26,8 +26,8 @@ #include <taler/taler_mhd_lib.h> #include <taler/taler_signatures.h> #include "donau-httpd.h" -#include "donaudb_plugin.h" #include "donau-httpd_get-charities.h" +#include "donau-database/get_charities.h" /** @@ -84,9 +84,9 @@ DH_handler_get_charities ( charities = json_array (); GNUNET_assert (NULL != charities); - qs = DH_plugin->get_charities (DH_plugin->cls, - &charities_cb, - charities); + qs = DONAUDB_get_charities (DH_context, + &charities_cb, + charities); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-charity-CHARITY_ID.c b/src/donau/donau-httpd_get-charity-CHARITY_ID.c @@ -22,12 +22,11 @@ #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_get-charity-CHARITY_ID.h" +#include "donau-database/lookup_charity.h" /** @@ -63,9 +62,9 @@ DH_handler_get_charity ( enum GNUNET_DB_QueryStatus qs; MHD_RESULT result; - qs = DH_plugin->lookup_charity (DH_plugin->cls, - (uint64_t) charity_id, - &meta); + qs = DONAUDB_lookup_charity (DH_context, + (uint64_t) charity_id, + &meta); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-charity-CHARITY_ID.h b/src/donau/donau-httpd_get-charity-CHARITY_ID.h @@ -23,7 +23,6 @@ #include <microhttpd.h> #include "donau-httpd.h" -#include "donaudb_plugin.h" /** diff --git a/src/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.c b/src/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.c @@ -22,13 +22,12 @@ #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_get-keys.h" #include "donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.h" +#include "donau-database/iterate_submitted_receipts.h" MHD_RESULT @@ -73,10 +72,10 @@ DH_handler_get_donation_statement ( enum GNUNET_DB_QueryStatus qs; MHD_RESULT result; - qs = DH_plugin->iterate_submitted_receipts (DH_plugin->cls, - (uint64_t) donation_year, - &h_donor_tax_id, - &total_donations); + qs = DONAUDB_iterate_submitted_receipts (DH_context, + (uint64_t) donation_year, + &h_donor_tax_id, + &total_donations); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.h b/src/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.h @@ -23,7 +23,6 @@ #include <microhttpd.h> #include "donau-httpd.h" -#include "donaudb_plugin.h" /** diff --git a/src/donau/donau-httpd_get-history.c b/src/donau/donau-httpd_get-history.c @@ -26,9 +26,8 @@ #include "taler/taler_mhd_lib.h" #include "taler/taler_signatures.h" #include "donau-httpd.h" -#include "donaudb_plugin.h" #include "donau-httpd_get-history.h" - +#include "donau-database/get_history.h" /** * Maximum number of history we return per request. @@ -86,9 +85,9 @@ DH_handler_get_history ( history = json_array (); GNUNET_assert (NULL != history); - qs = DH_plugin->get_history (DH_plugin->cls, - &history_cb, - history); + qs = DONAUDB_get_history (DH_context, + &history_cb, + history); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-keys.c b/src/donau/donau-httpd_get-keys.c @@ -28,7 +28,12 @@ #include "donau-httpd.h" #include "donau-httpd_get-keys.h" #include "donau-httpd_get-config.h" -#include "donaudb_plugin.h" +#include "donaudb_lib.h" +#include "donau-database/insert_donation_unit.h" +#include "donau-database/insert_signing_key.h" +#include "donau-database/iterate_donation_units.h" +#include "donau-database/iterate_active_signing_keys.h" +#include "donau-database/preflight.h" #include "donau_util.h" @@ -724,12 +729,11 @@ helper_rsa_cb ( du, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - qs = DH_plugin->insert_donation_unit ( - DH_plugin->cls, - &du->h_donation_unit_pub, - &du->donation_unit_pub, - du->validity_year, - &du->value); + qs = DONAUDB_insert_donation_unit (DH_context, + &du->h_donation_unit_pub, + &du->donation_unit_pub, + du->validity_year, + &du->value); if (qs < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -825,12 +829,11 @@ helper_cs_cb ( du, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - qs = DH_plugin->insert_donation_unit ( - DH_plugin->cls, - &du->h_donation_unit_pub, - &du->donation_unit_pub, - du->validity_year, - &du->value); + qs = DONAUDB_insert_donation_unit (DH_context, + &du->h_donation_unit_pub, + &du->donation_unit_pub, + du->validity_year, + &du->value); if (qs < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -934,10 +937,9 @@ helper_esign_cb ( sk, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - qs = DH_plugin->insert_signing_key ( - DH_plugin->cls, - &donau_pubkey, - &sk->meta); + qs = DONAUDB_insert_signing_key (DH_context, + &donau_pubkey, + &sk->meta); if (qs < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -1105,10 +1107,10 @@ build_key_state () /* NOTE: fetches master-signed signkeys, but ALSO those that were revoked! */ GNUNET_break (GNUNET_OK == - DH_plugin->preflight (DH_plugin->cls)); - qs = DH_plugin->iterate_donation_units (DH_plugin->cls, - &donation_unit_info_cb, - NULL); + DONAUDB_preflight (DH_context)); + qs = DONAUDB_iterate_donation_units (DH_context, + &donation_unit_info_cb, + NULL); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fetched %d donation unit keys from DB\n", (int) qs); @@ -1123,9 +1125,9 @@ build_key_state () /* NOTE: ONLY fetches active signkeys! */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fetching active signing keys from DB\n"); - qs = DH_plugin->iterate_active_signing_keys (DH_plugin->cls, - &iterate_active_signing_keys_cb, - NULL); + qs = DONAUDB_iterate_active_signing_keys (DH_context, + &iterate_active_signing_keys_cb, + NULL); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fetched %d active signing keys from DB\n", (int) qs); @@ -1184,7 +1186,7 @@ DH_keys_get_state () MHD_RESULT DH_handler_get_keys (struct DH_RequestContext *rc, - const char *const args[]) + const char *const args[]) { struct MHD_Connection *connection = rc->connection; struct DH_KeyStateHandle *ksh; diff --git a/src/donau/donau-httpd_get-keys.h b/src/donau/donau-httpd_get-keys.h @@ -22,7 +22,6 @@ #include <taler/taler_json_lib.h> #include <taler/taler_mhd_lib.h> #include "donau_util.h" -#include "donaudb_plugin.h" #include "donau-httpd.h" #ifndef DONAU_HTTPD_GET_KEYS_H @@ -145,7 +144,7 @@ TEH_resume_keys_requests (bool do_shutdown); */ MHD_RESULT DH_handler_get_keys (struct DH_RequestContext *rc, - const char *const args[]); + const char *const args[]); /** diff --git a/src/donau/donau-httpd_patch-charities-CHARITY_ID.c b/src/donau/donau-httpd_patch-charities-CHARITY_ID.c @@ -28,12 +28,14 @@ #include <taler/taler_util.h> #include "donau-httpd_patch-charities-CHARITY_ID.h" #include "donau-httpd_db.h" +#include "donau-database/lookup_charity.h" +#include "donau-database/update_charity.h" MHD_RESULT DH_handler_patch_charities (struct DH_RequestContext *rc, - const json_t *root, - const char *const args[]) + const json_t *root, + const char *const args[]) { struct DONAU_CharityPublicKeyP charity_pub; uint64_t charity_id; @@ -86,9 +88,9 @@ DH_handler_patch_charities (struct DH_RequestContext *rc, struct DONAUDB_CharityMetaData meta; enum GNUNET_DB_QueryStatus qs; - qs = DH_plugin->lookup_charity (DH_plugin->cls, - charity_id, - &meta); + qs = DONAUDB_lookup_charity (DH_context, + charity_id, + &meta); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -119,12 +121,12 @@ DH_handler_patch_charities (struct DH_RequestContext *rc, "max_per_year must NOT be SMALLER than receipts_to_date"); } - qs = DH_plugin->update_charity (DH_plugin->cls, - charity_id, - &charity_pub, - charity_name, - charity_url, - &max_per_year); + qs = DONAUDB_update_charity (DH_context, + charity_id, + &charity_pub, + charity_name, + charity_url, + &max_per_year); GNUNET_free (meta.charity_name); GNUNET_free (meta.charity_url); diff --git a/src/donau/donau-httpd_post-batch-issue-CHARITY_ID.c b/src/donau/donau-httpd_post-batch-issue-CHARITY_ID.c @@ -23,16 +23,16 @@ #include <gnunet/gnunet_json_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_post-batch-issue-CHARITY_ID.h" #include "donau-httpd_db.h" #include "donau_json_lib.h" #include "donau-httpd_get-keys.h" - +#include "donau-database/lookup_charity.h" +#include "donau-database/lookup_issued_receipts.h" +#include "donau-database/insert_issued_receipt.h" /** * Parse a bkp encoded in JSON. @@ -214,9 +214,9 @@ DH_handler_post_batch_issue (struct DH_RequestContext *rc, { enum GNUNET_DB_QueryStatus qs_charity; - qs_charity = DH_plugin->lookup_charity (DH_plugin->cls, - charity_id, - &charity_meta); + qs_charity = DONAUDB_lookup_charity (DH_context, + charity_id, + &charity_meta); switch (qs_charity) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -311,9 +311,9 @@ DH_handler_post_batch_issue (struct DH_RequestContext *rc, start: qs_check_receipts - = DH_plugin->lookup_issued_receipts (DH_plugin->cls, - &h_receipts, - &check_receipts_meta); + = DONAUDB_lookup_issued_receipts (DH_context, + &h_receipts, + &check_receipts_meta); switch (qs_check_receipts) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -413,14 +413,13 @@ start: /* save new receipts to date and save receipts Request (blinded signatures, * charity id, amount, hash over bkps) to make it idempotent*/ - qs_insert_ir = DH_plugin->insert_issued_receipt ( - DH_plugin->cls, - num_bkps, - du_sigs, - (uint64_t) charity_id, - &h_receipts, - &receipts_sum, - &smaller_than_max_per_year); + qs_insert_ir = DONAUDB_insert_issued_receipt (DH_context, + num_bkps, + du_sigs, + (uint64_t) charity_id, + &h_receipts, + &receipts_sum, + &smaller_than_max_per_year); switch (qs_insert_ir) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_post-batch-submit.c b/src/donau/donau-httpd_post-batch-submit.c @@ -23,13 +23,12 @@ #include <gnunet/gnunet_json_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_post-batch-submit.h" #include "donau-httpd_get-keys.h" +#include "donau-database/insert_submitted_receipts.h" /** @@ -96,8 +95,8 @@ free_irc (struct InsertReceiptContext *irc) MHD_RESULT DH_handler_post_batch_submit (struct DH_RequestContext *rc, - const json_t *root, - const char *const args[]) + const json_t *root, + const char *const args[]) { struct InsertReceiptContext irc = {0}; const json_t *donation_receipts; @@ -224,12 +223,11 @@ DH_handler_post_batch_submit (struct DH_RequestContext *rc, { enum GNUNET_DB_QueryStatus qs; - qs = DH_plugin->insert_submitted_receipts ( - DH_plugin->cls, - &irc.h_donor_tax_id, - num_dr, - irc.donation_receipts, - irc.donation_year); + qs = DONAUDB_insert_submitted_receipts (DH_context, + &irc.h_donor_tax_id, + num_dr, + irc.donation_receipts, + irc.donation_year); free_irc (&irc); if (qs < 0) { diff --git a/src/donau/donau-httpd_post-charities.c b/src/donau/donau-httpd_post-charities.c @@ -24,19 +24,18 @@ #include <gnunet/gnunet_json_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_post-charities.h" #include "donau-httpd_db.h" +#include "donau-database/insert_charity.h" MHD_RESULT DH_handler_post_charities (struct DH_RequestContext *rc, - const json_t *root, - const char *const args[]) + const json_t *root, + const char *const args[]) { struct DONAU_CharityPublicKeyP charity_pub; const char *charity_name; @@ -72,12 +71,12 @@ DH_handler_post_charities (struct DH_RequestContext *rc, return MHD_YES; /* failure */ } } - qs = DH_plugin->insert_charity (DH_plugin->cls, - &charity_pub, - charity_name, - charity_url, - &max_per_year, - &charity_id); + qs = DONAUDB_insert_charity (DH_context, + &charity_pub, + charity_name, + charity_url, + &max_per_year, + &charity_id); switch (qs) { case GNUNET_DB_STATUS_SOFT_ERROR: diff --git a/src/donau/donau-httpd_post-csr-issue.c b/src/donau/donau-httpd_post-csr-issue.c @@ -25,11 +25,9 @@ #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_get-keys.h" #include "donau-httpd_post-csr-issue.h" diff --git a/src/donau/donau-httpd_post-csr-issue.h b/src/donau/donau-httpd_post-csr-issue.h @@ -23,7 +23,6 @@ #include <microhttpd.h> #include "donau-httpd.h" -#include "donaudb_plugin.h" /** @@ -36,7 +35,7 @@ */ MHD_RESULT DH_handler_post_csr_issue (struct DH_RequestContext *rc, - const json_t *root, - const char *const args[]); + const json_t *root, + const char *const args[]); #endif diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -1,5 +1,5 @@ # This Makefile.am is in the public domain -AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/pq/ $(POSTGRESQL_CPPFLAGS) +AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/include/donau-database -I$(top_srcdir)/src/pq/ $(POSTGRESQL_CPPFLAGS) if USE_COVERAGE AM_CFLAGS = --coverage -O0 @@ -58,46 +58,40 @@ EXTRA_DIST = \ pg_template.h pg_template.c \ pg_template.sh -plugindir = $(libdir)/donau - -if HAVE_POSTGRESQL -plugin_LTLIBRARIES = \ - libdonau_plugin_donaudb_postgres.la -endif +lib_LTLIBRARIES = \ + libdonaudb.la -libdonau_plugin_donaudb_postgres_la_SOURCES = \ - plugin_donaudb_postgres.c pg_helper.h \ - pg_preflight.h pg_preflight.c \ - pg_commit.h pg_commit.c \ - pg_drop_tables.h pg_drop_tables.c \ - pg_create_tables.h pg_create_tables.c \ - pg_event_listen.h pg_event_listen.c \ - pg_event_listen_cancel.h pg_event_listen_cancel.c \ - pg_event_notify.h pg_event_notify.c \ - pg_start.h pg_start.c \ - pg_rollback.h pg_rollback.c \ - pg_start_read_committed.h pg_start_read_committed.c \ - pg_start_read_only.h pg_start_read_only.c \ - pg_insert_signing_key.c pg_insert_signing_key.h \ - pg_lookup_signing_key.h pg_lookup_signing_key.c \ - pg_iterate_active_signing_keys.c pg_iterate_active_signing_keys.h \ - pg_insert_donation_unit.c pg_insert_donation_unit.h \ - pg_iterate_donation_units.c pg_iterate_donation_units.h \ - pg_iterate_submitted_receipts.c pg_iterate_submitted_receipts.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_update_charity.h pg_update_charity.c \ - pg_do_charity_delete.h pg_do_charity_delete.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_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 - - -libdonau_plugin_donaudb_postgres_la_LIBADD = \ +libdonaudb_la_SOURCES = \ + plugin_donaudb_postgres.c helper.h \ + preflight.c \ + commit.c \ + drop_tables.c \ + create_tables.c \ + event_listen.c \ + event_listen_cancel.c \ + event_notify.c \ + start.c \ + rollback.c \ + start_read_committed.c \ + start_read_only.c \ + insert_signing_key.c \ + lookup_signing_key.c \ + iterate_active_signing_keys.c \ + insert_donation_unit.c \ + iterate_donation_units.c \ + iterate_submitted_receipts.c \ + get_history.c \ + get_charities.c \ + insert_charity.c \ + update_charity.c \ + do_charity_delete.c \ + insert_history_entry.c \ + lookup_charity.c \ + lookup_issued_receipts.c \ + lookup_donation_unit_amount.c \ + insert_issued_receipt.c \ + insert_submitted_receipts.c +libdonaudb_la_LIBADD = \ $(LTLIBINTL) \ $(top_builddir)/src/pq/libdonaupq.la \ $(top_builddir)/src/util/libdonauutil.la \ @@ -107,25 +101,11 @@ libdonau_plugin_donaudb_postgres_la_LIBADD = \ -lgnunetutil \ -lpq \ $(XLIB) -libdonau_plugin_donaudb_postgres_la_LDFLAGS = \ - $(TALER_PLUGIN_LDFLAGS) - - -lib_LTLIBRARIES = \ - libdonaudb.la - -libdonaudb_la_SOURCES = \ - donaudb_plugin.c -libdonaudb_la_LIBADD = \ - $(top_builddir)/src/util/libdonauutil.la \ - -lgnunetutil \ - $(XLIB) libdonaudb_la_LDFLAGS = \ $(POSTGRESQL_LDFLAGS) \ -version-info 1:0:0 \ -no-undefined - AM_TESTS_ENVIRONMENT=export DONAU_PREFIX=$${DONAU_PREFIX:-@libdir@};export PATH=$${DONAU_PREFIX:-@prefix@}/bin:$$PATH; check_PROGRAMS = \ test-donaudb-postgres @@ -148,4 +128,4 @@ test_donaudb_postgres_LDADD = \ $(XLIB) EXTRA_test_donaudb_postgres_DEPENDENCIES = \ - libdonau_plugin_donaudb_postgres.la + libdonaudb.la diff --git a/src/donaudb/commit.c b/src/donaudb/commit.c @@ -0,0 +1,54 @@ +/* + 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 src/donaudb/commit.c + * @brief Implementation of the commit function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include "commit.h" +#include "helper.h" + + +/** + * Commit the current transaction of a database connection. + * + * @param cls the `struct DONAUDB_PostgresContext` with the plugin-specific state + * @return final transaction status + */ +enum GNUNET_DB_QueryStatus +DONAUDB_commit (struct DONAUDB_PostgresContext *ctx) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_break (NULL != ctx->transaction_name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Committing transaction `%s'\n", + ctx->transaction_name); + /* used in #postgres_commit */ + PREPARE (ctx, + "do_commit", + "COMMIT"); + + qs = GNUNET_PQ_eval_prepared_non_select (ctx->conn, + "do_commit", + params); + ctx->transaction_name = NULL; + return qs; +} diff --git a/src/donaudb/create_tables.c b/src/donaudb/create_tables.c @@ -0,0 +1,81 @@ +/* + 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 src/donaudb/create_tables.c + * @brief Implementation of the create_tables function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "create_tables.h" +#include "helper.h" + + +enum GNUNET_GenericReturnValue +DONAUDB_create_tables (struct DONAUDB_PostgresContext *ctx) +{ + struct GNUNET_PQ_Context *conn; + enum GNUNET_GenericReturnValue ret = GNUNET_OK; + + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_PreparedStatement ps[] = { + GNUNET_PQ_make_prepare ("create_tables", + "CALL" + " donau.do_create_tables" + " ();"), + GNUNET_PQ_PREPARED_STATEMENT_END + }; + struct GNUNET_PQ_ExecuteStatement es[] = { + GNUNET_PQ_make_try_execute ("SET search_path TO donau;"), + GNUNET_PQ_EXECUTE_STATEMENT_END + }; + + conn = GNUNET_PQ_connect_with_cfg (ctx->cfg, + "donaudb-postgres", + "donau-", + es, + ps); + if (NULL == conn) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to database\n"); + return GNUNET_SYSERR; + } + if (0 > + GNUNET_PQ_eval_prepared_non_select (conn, + "create_tables", + params)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create tables\n"); + ret = GNUNET_SYSERR; + } + if (GNUNET_OK == ret) + { + ret = GNUNET_PQ_exec_sql (conn, + "procedures"); + if (GNUNET_OK != ret) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to load stored procedures: %d\n", + ret); + } + GNUNET_PQ_disconnect (conn); + return ret; +} diff --git a/src/donaudb/do_charity_delete.c b/src/donaudb/do_charity_delete.c @@ -0,0 +1,49 @@ +/* + 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 src/donaudb/do_charity_delete.c + * @brief Implementation of the do_charity_delete function for Postgres + * @author Johannes Casaburi + */ +#include "donau_config.h" +#include "taler/taler_error_codes.h" +#include "taler/taler_dbevents.h" +#include "taler/taler_pq_lib.h" +#include "do_charity_delete.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_do_charity_delete (struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&charity_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_end + }; + + PREPARE (ctx, + "call_charity_delete", + "DELETE FROM charities " + "WHERE charity_id=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "call_charity_delete", + params, + rs); +} diff --git a/src/donaudb/donau_do_insert_charity.sql b/src/donaudb/donau_do_insert_charity.sql @@ -56,7 +56,6 @@ BEGIN END IF; END IF; END $$; -COMMIT; COMMENT ON FUNCTION do_insert_charity IS 'Insert a charity. Also succeeds if a charity with the same parameters already exists. If a conflicting charity exists, the out_charity_id is set to 0.'; diff --git a/src/donaudb/donau_do_insert_issued_receipts.sql b/src/donaudb/donau_do_insert_issued_receipts.sql @@ -29,11 +29,11 @@ DECLARE max_per_year taler_amount; BEGIN -- Get charity values - SELECT - (chari.receipts_to_date).val - ,(chari.receipts_to_date).frac - ,(chari.max_per_year).val - ,(chari.max_per_year).frac + SELECT + (chari.receipts_to_date).val + ,(chari.receipts_to_date).frac + ,(chari.max_per_year).val + ,(chari.max_per_year).frac INTO old_receipts_to_date.val ,old_receipts_to_date.frac @@ -49,9 +49,9 @@ BEGIN IF ( (max_per_year.val > new_receipts_to_date.val) OR ( (max_per_year.val = new_receipts_to_date.val) AND (max_per_year.frac > new_receipts_to_date.frac) ) ) - THEN + THEN out_smaller_than_max_per_year=TRUE; - UPDATE charities + UPDATE charities SET receipts_to_date=new_receipts_to_date WHERE charity_id=in_charity_id; INSERT INTO receipts_issued (blinded_sig, charity_id, receipt_hash, amount) @@ -60,7 +60,6 @@ BEGIN out_smaller_than_max_per_year=FALSE; END IF; END $$; -COMMIT; COMMENT ON FUNCTION do_insert_issued_receipts IS 'This is a transaction for updating the current amount of receipts of a year of a charity and saves the receipts request what makes it idempotent'; diff --git a/src/donaudb/donaudb_plugin.c b/src/donaudb/donaudb_plugin.c @@ -1,75 +0,0 @@ -/* - 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/donaudb_plugin.c - * @brief Logic to load database plugin - * @author Johannes Casaburi - */ -#include "donau_config.h" -#include "donau_util.h" -#include "donaudb_lib.h" -#include "donaudb_plugin.h" -#include <ltdl.h> - - -struct DONAUDB_Plugin * -DONAUDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - char *plugin_name; - char *lib_name; - struct DONAUDB_Plugin *plugin; - - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - "donau", - "db", - &plugin_name)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "donau", - "db"); - return NULL; - } - GNUNET_asprintf (&lib_name, - "libdonau_plugin_donaudb_%s", - plugin_name); - GNUNET_free (plugin_name); - plugin = GNUNET_PLUGIN_load (DONAU_project_data (), - lib_name, - (void *) cfg); - if (NULL != plugin) - plugin->library_name = lib_name; - else - GNUNET_free (lib_name); - return plugin; -} - - -void -DONAUDB_plugin_unload (struct DONAUDB_Plugin *plugin) -{ - char *lib_name; - - if (NULL == plugin) - return; - lib_name = plugin->library_name; - GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name, - plugin)); - GNUNET_free (lib_name); -} - - -/* end of donaudb_plugin.c */ diff --git a/src/donaudb/drop_tables.c b/src/donaudb/drop_tables.c @@ -0,0 +1,57 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/drop_tables.c + * @brief Implementation of the drop_tables function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "drop_tables.h" +#include "helper.h" + + +/** + * Drop all Taler tables. This should only be used by testcases. + * + * @param cls the `struct DONAUDB_PostgresContext` with the plugin-specific state + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure + */ +enum GNUNET_GenericReturnValue +DONAUDB_drop_tables (struct DONAUDB_PostgresContext *ctx) +{ + struct GNUNET_PQ_Context *conn; + enum GNUNET_GenericReturnValue ret; + + if (NULL != ctx->conn) + { + GNUNET_PQ_disconnect (ctx->conn); + ctx->conn = NULL; + } + conn = GNUNET_PQ_connect_with_cfg (ctx->cfg, + "donaudb-postgres", + NULL, + NULL, + NULL); + if (NULL == conn) + return GNUNET_SYSERR; + ret = GNUNET_PQ_exec_sql (conn, + "drop"); + GNUNET_PQ_disconnect (conn); + return ret; +} diff --git a/src/donaudb/event_listen.c b/src/donaudb/event_listen.c @@ -0,0 +1,51 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/event_listen.c + * @brief Implementation of the event_listen function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "event_listen.h" +#include "helper.h" + +/** + * Register callback to be invoked on events of type @a es. + * + * @param cls database context to use + * @param timeout how long until to generate a timeout event + * @param es specification of the event to listen for + * @param cb function to call when the event happens, possibly + * multiple times (until cancel is invoked) + * @param cb_cls closure for @a cb + * @return handle useful to cancel the listener + */ +struct GNUNET_DB_EventHandler * +DONAUDB_event_listen (struct DONAUDB_PostgresContext *ctx, + struct GNUNET_TIME_Relative timeout, + const struct GNUNET_DB_EventHeaderP *es, + GNUNET_DB_EventCallback cb, + void *cb_cls) +{ + return GNUNET_PQ_event_listen (ctx->conn, + es, + timeout, + cb, + cb_cls); +} diff --git a/src/donaudb/event_listen_cancel.c b/src/donaudb/event_listen_cancel.c @@ -0,0 +1,34 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/event_listen_cancel.c + * @brief Implementation of the event_listen_cancel function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "event_listen_cancel.h" +#include "helper.h" + + +void +DONAUDB_event_listen_cancel (struct DONAUDB_PostgresContext *ctx, + struct GNUNET_DB_EventHandler *eh) +{ + GNUNET_PQ_event_listen_cancel (eh); +} diff --git a/src/donaudb/event_notify.c b/src/donaudb/event_notify.c @@ -0,0 +1,39 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/event_notify.c + * @brief Implementation of the event_notify function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "event_notify.h" +#include "helper.h" + + +void +DONAUDB_event_notify (struct DONAUDB_PostgresContext *ctx, + const struct GNUNET_DB_EventHeaderP *es, + const void *extra, + size_t extra_size) +{ + GNUNET_PQ_event_notify (ctx->conn, + es, + extra, + extra_size); +} diff --git a/src/donaudb/get_charities.c b/src/donaudb/get_charities.c @@ -0,0 +1,159 @@ +/* + 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 src/donaudb/get_charities.c + * @brief Implementation of the lookup_donation_unit_key function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "get_charities.h" +#include "helper.h" + + +/** + * Closure for #get_charities_cb(). + */ +struct GetCharitiesContext +{ + /** + * Function to call per result. + */ + DONAUDB_GetCharitiesCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct DONAUDB_PostgresContext *ctx; + + /** + * Number of results processed. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * Invoke the callback for each result. + * + * @param cls a `struct GetCharitiesContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +get_charities_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct GetCharitiesContext *gctx = cls; + struct DONAUDB_PostgresContext *ctx = gctx->ctx; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t charity_id; + struct DONAU_CharityPublicKeyP charity_pub; + char *charity_name; + struct TALER_Amount max_per_year; + struct TALER_Amount receipts_to_date; + uint32_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), + TALER_PQ_RESULT_SPEC_AMOUNT ("max_per_year", + &max_per_year), + GNUNET_PQ_result_spec_uint32 ("current_year", + &current_year), + TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date", + &receipts_to_date), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_GenericReturnValue ret; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + gctx->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)); + gctx->qs = i + 1; + ret = gctx->cb (gctx->cb_cls, + charity_id, + &charity_pub, + charity_name, + &max_per_year, + current_year, + &receipts_to_date); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != ret) + break; + } +} + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_charities (struct DONAUDB_PostgresContext *ctx, + DONAUDB_GetCharitiesCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct GetCharitiesContext gctx = { + .cb = cb, + .cb_cls = cb_cls, + .ctx = ctx + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "get_charities", + "SELECT" + " charity_id" + ",charity_pub" + ",charity_name" + ",max_per_year" + ",receipts_to_date" + ",current_year" + " FROM charities"); + qs = GNUNET_PQ_eval_prepared_multi_select (ctx->conn, + "get_charities", + params, + &get_charities_cb, + &gctx); + if (qs <= 0) + return qs; + return gctx.qs; +} diff --git a/src/donaudb/get_history.c b/src/donaudb/get_history.c @@ -0,0 +1,139 @@ +/* + 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 src/donaudb/get_history.c + * @brief Implementation of the lookup_donation_unit_key function for Postgres + * @author Johannes Casaburi + */ +#include "donau_config.h" +#include "taler/taler_error_codes.h" +#include "taler/taler_dbevents.h" +#include "taler/taler_pq_lib.h" +#include "get_history.h" +#include "helper.h" + + +/** + * Closure for #get_history_cb(). + */ +struct GetHistoryContext +{ + /** + * Function to call per result. + */ + DONAUDB_GetHistoryCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct DONAUDB_PostgresContext *ctx; + + /** + * Number of results processed. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * Invoke the callback for each result. + * + * @param cls a `struct GetHistoryContext *` + * @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 *gctx = cls; + struct DONAUDB_PostgresContext *ctx = gctx->ctx; + + 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", + &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); + gctx->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + + gctx->qs = i + 1; + if (GNUNET_OK != + gctx->cb (gctx->cb_cls, + charity_id, + final_amount, + donation_year)) + break; + } +} + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_history (struct DONAUDB_PostgresContext *ctx, + DONAUDB_GetHistoryCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct GetHistoryContext gctx = { + .cb = cb, + .cb_cls = cb_cls, + .ctx = ctx + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "get_history", + "SELECT" + " charity_id" + ",final_amount" + ",donation_year" + " FROM history"); + qs = GNUNET_PQ_eval_prepared_multi_select (ctx->conn, + "get_history", + params, + &get_history_cb, + &gctx); + if (qs <= 0) + return qs; + return gctx.qs; +} diff --git a/src/donaudb/helper.h b/src/donaudb/helper.h @@ -0,0 +1,124 @@ +/* + 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 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 helper.h + * @brief shared internal definitions for postgres DB plugin + * @author Johannes Casaburi + */ +#ifndef PG_HELPER_H +#define PG_HELPER_H + +#include "donaudb_lib.h" + + +/** + * Type of the "cls" argument given to each of the functions in + * our API. + */ +struct DONAUDB_PostgresContext +{ + + /** + * Our configuration. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Which currency should we assume all amounts to be in? + */ + char *currency; + + /** + * Our base URL. + */ + char *donau_url; + + /** + * Postgres connection handle. + */ + 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; + +}; + + +/** + * Prepares SQL statement @a sql under @a name for + * connection @a pg once. + * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure. + * + * @param pg a `struct DONAUDB_PostgresContext` + * @param name name to prepare the statement under + * @param sql actual SQL text + */ +#define PREPARE(pg,name,sql) \ + do { \ + static struct { \ + unsigned long long cnt; \ + struct DONAUDB_PostgresContext *pg; \ + } preps[2]; /* 2 ctrs for taler-auditor-sync*/ \ + unsigned int off = 0; \ + \ + while ( (NULL != preps[off].pg) && \ + (ctx != preps[off].pg) && \ + (off < sizeof(preps) / sizeof(*preps)) ) \ + off++; \ + GNUNET_assert (off < \ + sizeof(preps) / sizeof(*preps)); \ + if (preps[off].cnt < ctx->prep_gen) \ + { \ + struct GNUNET_PQ_PreparedStatement ps[] = { \ + GNUNET_PQ_make_prepare (name, sql), \ + GNUNET_PQ_PREPARED_STATEMENT_END \ + }; \ + \ + if (GNUNET_OK != \ + GNUNET_PQ_prepare_statements (pg->conn, \ + ps)) \ + { \ + GNUNET_break (0); \ + return GNUNET_DB_STATUS_HARD_ERROR; \ + } \ + preps[off].pg = ctx; \ + preps[off].cnt = pg->prep_gen; \ + } \ + } while (0) + + +/** + * Wrapper macro to add the currency from the plugin's state + * when fetching amounts from the database. + * + * @param field name of the database field to fetch amount from + * @param[out] amountp pointer to amount to set + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT(field, \ + amountp) \ + TALER_PQ_result_spec_amount ( \ + field,ctx->currency,amountp) + + +#endif diff --git a/src/donaudb/insert_charity.c b/src/donaudb/insert_charity.c @@ -0,0 +1,71 @@ +/* + This file is part of TALER + Copyright (C) 2023--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 src/donaudb/insert_charity.c + * @brief Implementation of the insert_charity function for Postgres + * @author Johannes Casaburi + * @author Lukas Matyja + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "insert_charity.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_charity (struct DONAUDB_PostgresContext *ctx, + const struct DONAU_CharityPublicKeyP *charity_pub, + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year, + uint64_t *charity_id) +{ + uint32_t current_year + = GNUNET_TIME_get_current_year (); + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (charity_pub), + GNUNET_PQ_query_param_string (charity_name), + GNUNET_PQ_query_param_string (charity_url), + TALER_PQ_query_param_amount (ctx->conn, + max_per_year), + GNUNET_PQ_query_param_uint32 (&current_year), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("charity_id", + charity_id), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "insert_charity", + "SELECT out_charity_id AS charity_id" + " FROM do_insert_charity" + " ($1, $2, $3, $4, $5);"); + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "insert_charity", + params, + rs); + if (qs <= 0) + return qs; + if (0 == *charity_id) + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + return qs; +} diff --git a/src/donaudb/insert_donation_unit.c b/src/donaudb/insert_donation_unit.c @@ -0,0 +1,59 @@ +/* + 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 src/donaudb/insert_donation_unit.c + * @brief Implementation of the insert_donation_unit function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "insert_donation_unit.h" +#include "helper.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_donation_unit (struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonationUnitHashP * + h_donation_unit_pub, + const struct DONAU_DonationUnitPublicKey * + donation_unit_pub, + const uint64_t validity_year, + const struct TALER_Amount *value) +{ + struct GNUNET_PQ_QueryParam iparams[] = { + GNUNET_PQ_query_param_auto_from_type (h_donation_unit_pub), + DONAU_PQ_query_param_donation_unit_pub (donation_unit_pub), + GNUNET_PQ_query_param_uint64 (&validity_year), + TALER_PQ_query_param_amount (ctx->conn, + value), + GNUNET_PQ_query_param_end + }; + + PREPARE (ctx, + "donation_unit_insert", + "INSERT INTO donation_units " + "(h_donation_unit_pub" + ",donation_unit_pub" + ",validity_year" + ",value" + ") VALUES ($1, $2, $3, $4);"); + return GNUNET_PQ_eval_prepared_non_select (ctx->conn, + "donation_unit_insert", + iparams); +} diff --git a/src/donaudb/insert_history_entry.c b/src/donaudb/insert_history_entry.c @@ -0,0 +1,53 @@ +/* + 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 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 src/donaudb/insert_history_entry.c + * @brief Implementation of the insert_history_entry function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "insert_history_entry.h" +#include "helper.h" + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_history_entry (struct DONAUDB_PostgresContext *ctx, + const uint64_t charity_id, + const struct TALER_Amount *final_amount, + const uint64_t donation_year) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&charity_id), + TALER_PQ_query_param_amount (ctx->conn, + final_amount), + GNUNET_PQ_query_param_uint64 (&donation_year), + GNUNET_PQ_query_param_end + }; + + PREPARE (ctx, + "insert_history_entry", + "INSERT INTO history " + "(charity_id" + ",final_amount" + ",donation_year" + ") VALUES " + "($1, $2, $3);"); + return GNUNET_PQ_eval_prepared_non_select (ctx->conn, + "insert_history_entry", + params); +} diff --git a/src/donaudb/insert_issued_receipt.c b/src/donaudb/insert_issued_receipt.c @@ -0,0 +1,77 @@ +/* + 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 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 src/donaudb/insert_issued_receipt.c + * @brief Implementation of the insert_issued_receipt function for Postgres + * @author Johannes Casaburi + * @author Lukas Matyja + */ +#include <donau_config.h> +#include <gnunet/gnunet_pq_lib.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "insert_issued_receipt.h" +#include "helper.h" +#include "donau_service.h" +#include "donau_pq_lib.h" + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_issued_receipt ( + struct DONAUDB_PostgresContext *ctx, + const size_t num_blinded_sig, + const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], + const uint64_t charity_id, + const struct DONAU_DonationReceiptHashP *h_receipt, + const struct TALER_Amount *amount_receipts_request, + bool *smaller_than_max_per_year) +{ + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_bool ("smaller_than_max_per_year", + smaller_than_max_per_year), + GNUNET_PQ_result_spec_end + }; + + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&charity_id), + DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, + signatures, + ctx->conn), + GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash), + TALER_PQ_query_param_amount (ctx->conn, + amount_receipts_request), + GNUNET_PQ_query_param_end + }; + + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "insert_issued_receipts_request", + "SELECT " + " out_smaller_than_max_per_year AS smaller_than_max_per_year" + " FROM do_insert_issued_receipts" + "($1,$2,$3,$4);"); + + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "insert_issued_receipts_request", + params, + rs); + GNUNET_PQ_cleanup_query_params_closures (params); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Is the new receipts_to_day smaller than the max_per_year (1 = true): %d\n", + (*smaller_than_max_per_year)); + return qs; +} diff --git a/src/donaudb/insert_signing_key.c b/src/donaudb/insert_signing_key.c @@ -0,0 +1,55 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/insert_signing_key.c + * @brief Implementation of the insert_signing_key function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "insert_signing_key.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_signing_key ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta) +{ + struct GNUNET_PQ_QueryParam iparams[] = { + GNUNET_PQ_query_param_auto_from_type (donau_pub), + GNUNET_PQ_query_param_timestamp (&meta->valid_from), + GNUNET_PQ_query_param_timestamp (&meta->expire_sign), + GNUNET_PQ_query_param_timestamp (&meta->expire_legal), + GNUNET_PQ_query_param_end + }; + + PREPARE (ctx, + "insert_signkey", + "INSERT INTO donau_sign_keys " + "(donau_pub" + ",valid_from" + ",expire_sign" + ",expire_legal" + ") VALUES " + "($1, $2, $3, $4);"); + return GNUNET_PQ_eval_prepared_non_select (ctx->conn, + "insert_signkey", + iparams); +} diff --git a/src/donaudb/insert_submitted_receipts.c b/src/donaudb/insert_submitted_receipts.c @@ -0,0 +1,101 @@ +/* + 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 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 src/donaudb/insert_submitted_receipts.c + * @brief Implementation of the insert_submitted_receipts function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "insert_submitted_receipts.h" +#include "helper.h" +#include "donau_service.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_submitted_receipts (struct DONAUDB_PostgresContext *ctx, + struct DONAU_HashDonorTaxId *h_donor_tax_id, + size_t num_dr, + const struct DONAU_DonationReceipt + donation_receipts[static num_dr], + uint64_t donation_year) +{ + struct GNUNET_HashCode h_donation_unit_pubs[GNUNET_NZL (num_dr)]; + struct DONAU_UniqueDonorIdentifierNonce nonces[GNUNET_NZL (num_dr)]; + struct DONAU_DonationUnitSignature donation_unit_sigs[GNUNET_NZL (num_dr)]; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id), + GNUNET_PQ_query_param_array_auto_from_type (num_dr, + h_donation_unit_pubs, + ctx->conn), + GNUNET_PQ_query_param_array_auto_from_type (num_dr, + nonces, + ctx->conn), + DONAU_PQ_query_param_array_donation_unit_sig (num_dr, + donation_unit_sigs, + ctx->conn), + GNUNET_PQ_query_param_uint64 (&donation_year), + GNUNET_PQ_query_param_end + }; + bool *conflicted = NULL; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_array_bool (ctx->conn, + "conflicted", + &num_dr, + &conflicted), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + for (unsigned int i = 0; i < num_dr; i++) + { + const struct DONAU_DonationReceipt *dr = &donation_receipts[i]; + + h_donation_unit_pubs[i] = dr->h_donation_unit_pub.hash; + nonces[i] = dr->nonce; + donation_unit_sigs[i] = dr->donation_unit_sig; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Do insert submitted receipt\n"); + } + + PREPARE (ctx, + "call_insert_submitted_receipts", + "SELECT " + " out_conflict AS conflicted" + " FROM do_insert_submitted_receipts" + "($1,$2,$3,$4,$5);"); + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "call_insert_submitted_receipts", + params, + rs); + GNUNET_PQ_cleanup_query_params_closures (params); + + for (size_t i = 0; i < num_dr; i++) + { + if (conflicted[i]) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Submitted donation receipt at index %ld already present!\n", + i); + } + } + GNUNET_free (conflicted); + GNUNET_PQ_cleanup_result (rs); + return qs; +} diff --git a/src/donaudb/iterate_active_signing_keys.c b/src/donaudb/iterate_active_signing_keys.c @@ -0,0 +1,137 @@ +/* + 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 src/donaudb/iterate_active_signing_keys.c + * @brief Implementation of the iterate_active_signing_keys function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "iterate_active_signing_keys.h" +#include "helper.h" + +/** + * Closure for #signkeys_cb_helper(). + */ +struct IterateActiveSigningKeysContext +{ + /** + * Function to call per result. + */ + DONAUDB_IterateActiveSigningKeysCallback 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 IterateActiveSigningKeysContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +signkeys_cb_helper (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct IterateActiveSigningKeysContext *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct DONAU_DonauPublicKeyP donau_pub; + struct DONAUDB_SignkeyMetaData meta; + + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("donau_pub", + &donau_pub), + GNUNET_PQ_result_spec_timestamp ("valid_from", + &meta.valid_from), + GNUNET_PQ_result_spec_timestamp ("expire_sign", + &meta.expire_sign), + GNUNET_PQ_result_spec_timestamp ("expire_legal", + &meta.expire_legal), + 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, + &donau_pub, + &meta); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +DONAUDB_iterate_active_signing_keys ( + struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateActiveSigningKeysCallback cb, + void *cb_cls) +{ + struct GNUNET_TIME_Absolute now = {0}; + struct IterateActiveSigningKeysContext ictx = { + .cb = cb, + .cb_cls = cb_cls, + .status = GNUNET_OK + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_absolute_time (&now), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "iterate_active_signing_keys", + "SELECT" + " donau_pub" + ",valid_from" + ",expire_sign" + ",expire_legal" + " FROM donau_sign_keys dsk" + " WHERE" + " expire_sign > $1"); + qs = GNUNET_PQ_eval_prepared_multi_select (ctx->conn, + "iterate_active_signing_keys", + params, + &signkeys_cb_helper, + &ictx); + if (GNUNET_OK != ictx.status) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + return qs; +} diff --git a/src/donaudb/iterate_donation_units.c b/src/donaudb/iterate_donation_units.c @@ -0,0 +1,134 @@ +/* + 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 src/donaudb/iterate_donation_units.c + * @brief Implementation of the iterate_donation_units function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "iterate_donation_units.h" +#include "helper.h" +#include "donau_pq_lib.h" + +/** + * Closure for #get_donation_units_cb(). + */ +struct IterateDonationUnitsContext +{ + /** + * Function to call per result. + */ + DONAUDB_IterateDonationUnitsCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct DONAUDB_PostgresContext *ctx; + +}; + +/** + * Invoke the callback for each result. + * + * @param cls a `struct IterateDonationUnitsContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +iterate_donation_units_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct IterateDonationUnitsContext *ictx = cls; + struct DONAUDB_PostgresContext *ctx = ictx->ctx; + + for (unsigned int i = 0; i < num_results; i++) + { + struct DONAU_DonationUnitHashP h_donation_unit_pub; + struct DONAU_DonationUnitPublicKey donation_unit_pub; + uint64_t validity_year; + struct TALER_Amount value; + enum GNUNET_GenericReturnValue iret; + + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("h_donation_unit_pub", + &h_donation_unit_pub), + DONAU_PQ_result_spec_donation_unit_pub ("donation_unit_pub", + &donation_unit_pub), + GNUNET_PQ_result_spec_uint64 ("validity_year", + &validity_year), + TALER_PQ_RESULT_SPEC_AMOUNT ("value", + &value), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + return; + } + + iret = ictx->cb (ictx->cb_cls, + &h_donation_unit_pub, + &donation_unit_pub, + validity_year, + &value); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != iret) + break; + } +} + + +enum GNUNET_DB_QueryStatus +DONAUDB_iterate_donation_units (struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateDonationUnitsCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct IterateDonationUnitsContext ictx = { + .cb = cb, + .cb_cls = cb_cls, + .ctx = ctx + }; + + PREPARE (ctx, + "iterate_donation_units", + "SELECT" + " h_donation_unit_pub" + ",donation_unit_pub" + ",validity_year" + ",value" + " FROM donation_units"); + return GNUNET_PQ_eval_prepared_multi_select (ctx->conn, + "iterate_donation_units", + params, + &iterate_donation_units_cb, + &ictx); +} diff --git a/src/donaudb/iterate_submitted_receipts.c b/src/donaudb/iterate_submitted_receipts.c @@ -0,0 +1,75 @@ +/* + 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 src/donaudb/iterate_submitted_receipts.c + * @brief Implementation of the iterate_submitted_receipts function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "iterate_submitted_receipts.h" +#include "helper.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_iterate_submitted_receipts ( + struct DONAUDB_PostgresContext *ctx, + const uint64_t donation_year, + const struct DONAU_HashDonorTaxId *h_donor_tax_id, + struct TALER_Amount *total_donations) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&donation_year), + GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id), + GNUNET_PQ_query_param_end + }; + uint64_t valueSum = 0; + uint64_t fractionSum = 0; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("valueSum", + &valueSum), + GNUNET_PQ_result_spec_uint64 ("fractionSum", + &fractionSum), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "lookup_submitted_receipts", + "SELECT " + " CAST(SUM((donation_units.value).val) AS INT8) AS valueSum" + ",CAST(SUM(CAST((donation_units.value).frac AS INT8)) AS INT8) AS fractionSum" + " FROM receipts_submitted ref" + " JOIN donation_units USING (h_donation_unit_pub)" + " WHERE donation_year=$1" + " AND h_tax_number=$2"); + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "lookup_submitted_receipts", + params, + rs); + if (qs < 0) + return qs; + valueSum += fractionSum / TALER_AMOUNT_FRAC_BASE; + fractionSum %= TALER_AMOUNT_FRAC_BASE; + TALER_amount_set_zero (ctx->currency, + total_donations); + total_donations->value = valueSum; + total_donations->fraction = fractionSum; + return qs; +} diff --git a/src/donaudb/lookup_charity.c b/src/donaudb/lookup_charity.c @@ -0,0 +1,70 @@ +/* + 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_donation_unit_key.c + * @brief Implementation of the lookup_donation_unit_key function for Postgres + * @author Johannes Casaburi + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "lookup_charity.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_charity ( + struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id, + struct DONAUDB_CharityMetaData *meta) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&charity_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + 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_uint32 ("current_year", + &meta->current_year), + GNUNET_PQ_result_spec_end + }; + + PREPARE (ctx, + "lookup_charity", + "SELECT " + " 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 (ctx->conn, + "lookup_charity", + params, + rs); +} diff --git a/src/donaudb/lookup_donation_unit_amount.c b/src/donaudb/lookup_donation_unit_amount.c @@ -0,0 +1,56 @@ +/* + 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 src/donaudb/lookup_donation_unit_amount.c + * @brief Implmentation of getting the donation unit amount + * @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 "helper.h" +#include "donau_pq_lib.h" +#include "lookup_donation_unit_amount.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_donation_unit_amount ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct TALER_Amount *value) +{ + 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 (ctx, + "lookup_donation_unit", + "SELECT value" + " FROM donation_units" + " WHERE h_donation_unit_pub=$1;"); + return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "lookup_donation_unit", + params, + rs); +} diff --git a/src/donaudb/lookup_issued_receipts.c b/src/donaudb/lookup_issued_receipts.c @@ -0,0 +1,76 @@ +/* + This file is part of TALER + Copyright (C) 2024, 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 src/donaudb/lookup_issued_receipts.c + * @brief Implementation of the lookup_issued_receipts function for Postgres + * @author Lukas Matyja + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "lookup_issued_receipts.h" +#include "helper.h" +#include "donau_pq_lib.h" + +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_issued_receipts (struct DONAUDB_PostgresContext *ctx, + struct DONAU_DonationReceiptHashP *h_receipts, + struct DONAUDB_IssuedReceiptsMetaData *meta) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_receipts), + GNUNET_PQ_query_param_end + }; + struct DONAU_BlindedDonationUnitSignature *du_sigs; + size_t num_sigs; + struct GNUNET_PQ_ResultSpec rs[] = { + DONAU_PQ_result_spec_array_blinded_donation_unit_sig ( + ctx->conn, + "blinded_sig", + &num_sigs, + &du_sigs), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", + &meta->amount), + GNUNET_PQ_result_spec_uint64 ("charity_id", + &meta->charity_id), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "lookup_issued_receipts", + "SELECT " + " blinded_sig" + " ,amount" + " ,charity_id" + " FROM receipts_issued" + " WHERE receipt_hash=$1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "lookup_issued_receipts", + params, + rs); + if (qs > 0) + { + /* prevent the result cleanup from freeing the signatures */ + meta->num_sig = num_sigs; + meta->blinded_sigs = du_sigs; + num_sigs = 0; + du_sigs = NULL; + } + GNUNET_PQ_cleanup_result (rs); + return qs; +} diff --git a/src/donaudb/lookup_signing_key.c b/src/donaudb/lookup_signing_key.c @@ -0,0 +1,62 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/lookup_signing_key.c + * @brief Implementation of the lookup_signing_key function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "lookup_signing_key.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_signing_key (struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (donau_pub), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_timestamp ("valid_from", + &meta->valid_from), + GNUNET_PQ_result_spec_timestamp ("expire_sign", + &meta->expire_sign), + GNUNET_PQ_result_spec_timestamp ("expire_legal", + &meta->expire_legal), + GNUNET_PQ_result_spec_end + }; + + + PREPARE (ctx, + "lookup_signing_key", + "SELECT" + " valid_from" + ",expire_sign" + ",expire_legal" + " FROM donau_sign_keys" + " WHERE donau_pub=$1"); + + return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "lookup_signing_key", + params, + rs); +} diff --git a/src/donaudb/pg_commit.c b/src/donaudb/pg_commit.c @@ -1,58 +0,0 @@ -/* - 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_commit.c - * @brief Implementation of the commit function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_commit.h" -#include "pg_helper.h" - - -/** - * Commit the current transaction of a database connection. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @return final transaction status - */ -enum GNUNET_DB_QueryStatus -DH_PG_commit (void *cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_break (NULL != pg->transaction_name); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Committing transaction `%s'\n", - pg->transaction_name); - /* used in #postgres_commit */ - PREPARE (pg, - "do_commit", - "COMMIT"); - - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "do_commit", - params); - pg->transaction_name = NULL; - return qs; -} diff --git a/src/donaudb/pg_commit.h b/src/donaudb/pg_commit.h @@ -1,37 +0,0 @@ -/* - 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_commit.h - * @brief implementation of the commit function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_COMMIT_H -#define PG_COMMIT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Commit the current transaction of a database connection. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @return final transaction status - */ -enum GNUNET_DB_QueryStatus -DH_PG_commit (void *cls); - -#endif diff --git a/src/donaudb/pg_create_tables.c b/src/donaudb/pg_create_tables.c @@ -1,82 +0,0 @@ -/* - 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_create_tables.c - * @brief Implementation of the create_tables function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_create_tables.h" -#include "pg_helper.h" - - -enum GNUNET_GenericReturnValue -DH_PG_create_tables (void *cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_Context *conn; - enum GNUNET_GenericReturnValue ret = GNUNET_OK; - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_PreparedStatement ps[] = { - GNUNET_PQ_make_prepare ("create_tables", - "CALL" - " donau.do_create_tables" - " ();"), - GNUNET_PQ_PREPARED_STATEMENT_END - }; - struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_try_execute ("SET search_path TO donau;"), - GNUNET_PQ_EXECUTE_STATEMENT_END - }; - - conn = GNUNET_PQ_connect_with_cfg (pg->cfg, - "donaudb-postgres", - "donau-", - es, - ps); - if (NULL == conn) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to database\n"); - return GNUNET_SYSERR; - } - if (0 > - GNUNET_PQ_eval_prepared_non_select (conn, - "create_tables", - params)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create tables\n"); - ret = GNUNET_SYSERR; - } - if (GNUNET_OK == ret) - { - ret = GNUNET_PQ_exec_sql (conn, - "procedures"); - if (GNUNET_OK != ret) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to load stored procedures: %d\n", - ret); - } - GNUNET_PQ_disconnect (conn); - return ret; -} diff --git a/src/donaudb/pg_create_tables.h b/src/donaudb/pg_create_tables.h @@ -1,42 +0,0 @@ -/* - 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_create_tables.h - * @brief implementation of the create_tables function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_CREATE_TABLES_H -#define PG_CREATE_TABLES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Create the necessary tables if they are not present - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param support_partitions true to enable partitioning support (disables foreign key constraints) - * @param num_partitions number of partitions to create, - * (0 to not actually use partitions, 1 to only - * setup a default partition, >1 for real partitions) - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure - */ -enum GNUNET_GenericReturnValue -DH_PG_create_tables (void *cls); - - -#endif diff --git a/src/donaudb/pg_do_charity_delete.c b/src/donaudb/pg_do_charity_delete.c @@ -1,51 +0,0 @@ -/* - 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 exchangedb/pg_do_charity_delete.c - * @brief Implementation of the do_charity_delete function for Postgres - * @author Johannes Casaburi - */ -#include "donau_config.h" -#include "taler/taler_error_codes.h" -#include "taler/taler_dbevents.h" -#include "taler/taler_pq_lib.h" -#include "pg_do_charity_delete.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_do_charity_delete ( - void *cls, - uint64_t charity_id) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&charity_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "call_charity_delete", - "DELETE FROM charities " - "WHERE charity_id=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_charity_delete", - params, - rs); -} diff --git a/src/donaudb/pg_do_charity_delete.h b/src/donaudb/pg_do_charity_delete.h @@ -1,41 +0,0 @@ -/* - 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 exchangedb/pg_do_charity_delete.h - * @brief implementation of the do_charity_delete function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_DO_PURSE_DELETE_H -#define PG_DO_PURSE_DELETE_H - -#include "taler/taler_util.h" -#include "taler/taler_json_lib.h" -#include "donaudb_plugin.h" - - -/** - * Function called to explicitly delete a charity. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param charity_id charity to delete - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_do_charity_delete ( - void *cls, - uint64_t charity_id); - -#endif diff --git a/src/donaudb/pg_drop_tables.c b/src/donaudb/pg_drop_tables.c @@ -1,58 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_drop_tables.c - * @brief Implementation of the drop_tables function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_drop_tables.h" -#include "pg_helper.h" - - -/** - * Drop all Taler tables. This should only be used by testcases. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure - */ -enum GNUNET_GenericReturnValue -DH_PG_drop_tables (void *cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_Context *conn; - enum GNUNET_GenericReturnValue ret; - - if (NULL != pg->conn) - { - GNUNET_PQ_disconnect (pg->conn); - pg->conn = NULL; - } - conn = GNUNET_PQ_connect_with_cfg (pg->cfg, - "donaudb-postgres", - NULL, - NULL, - NULL); - if (NULL == conn) - return GNUNET_SYSERR; - ret = GNUNET_PQ_exec_sql (conn, - "drop"); - GNUNET_PQ_disconnect (conn); - return ret; -} diff --git a/src/donaudb/pg_drop_tables.h b/src/donaudb/pg_drop_tables.h @@ -1,38 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_drop_tables.h - * @brief implementation of the drop_tables function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_DROP_TABLES_H -#define PG_DROP_TABLES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - - -/** - * Drop all Taler tables. This should only be used by testcases. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure - */ -enum GNUNET_GenericReturnValue -DH_PG_drop_tables (void *cls); - -#endif diff --git a/src/donaudb/pg_event_listen.c b/src/donaudb/pg_event_listen.c @@ -1,53 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_event_listen.c - * @brief Implementation of the event_listen function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_event_listen.h" -#include "pg_helper.h" - -/** - * Register callback to be invoked on events of type @a es. - * - * @param cls database context to use - * @param timeout how long until to generate a timeout event - * @param es specification of the event to listen for - * @param cb function to call when the event happens, possibly - * multiple times (until cancel is invoked) - * @param cb_cls closure for @a cb - * @return handle useful to cancel the listener - */ -struct GNUNET_DB_EventHandler * -DH_PG_event_listen (void *cls, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_DB_EventHeaderP *es, - GNUNET_DB_EventCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - - return GNUNET_PQ_event_listen (pg->conn, - es, - timeout, - cb, - cb_cls); -} diff --git a/src/donaudb/pg_event_listen.h b/src/donaudb/pg_event_listen.h @@ -1,45 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_event_listen.h - * @brief implementation of the event_listen function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_EVENT_LISTEN_H -#define PG_EVENT_LISTEN_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" -/** - * Register callback to be invoked on events of type @a es. - * - * @param cls database context to use - * @param timeout how long until to generate a timeout event - * @param es specification of the event to listen for - * @param cb function to call when the event happens, possibly - * multiple times (until cancel is invoked) - * @param cb_cls closure for @a cb - * @return handle useful to cancel the listener - */ -struct GNUNET_DB_EventHandler * -DH_PG_event_listen (void *cls, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_DB_EventHeaderP *es, - GNUNET_DB_EventCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_event_listen_cancel.c b/src/donaudb/pg_event_listen_cancel.c @@ -1,36 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_event_listen_cancel.c - * @brief Implementation of the event_listen_cancel function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_event_listen_cancel.h" -#include "pg_helper.h" - - -void -DH_PG_event_listen_cancel (void *cls, - struct GNUNET_DB_EventHandler *eh) - -{ - (void) cls; - GNUNET_PQ_event_listen_cancel (eh); -} diff --git a/src/donaudb/pg_event_listen_cancel.h b/src/donaudb/pg_event_listen_cancel.h @@ -1,38 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_event_listen_cancel.h - * @brief implementation of the event_listen_cancel function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_EVENT_LISTEN_CANCEL_H -#define PG_EVENT_LISTEN_CANCEL_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - - -/** - * Stop notifications. - * - * @param cls the plugin's `struct PostgresClosure` - * @param eh handle to unregister. - */ -void -DH_PG_event_listen_cancel (void *cls, - struct GNUNET_DB_EventHandler *eh); -#endif diff --git a/src/donaudb/pg_event_notify.c b/src/donaudb/pg_event_notify.c @@ -1,41 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_event_notify.c - * @brief Implementation of the event_notify function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_event_notify.h" -#include "pg_helper.h" - - -void -DH_PG_event_notify (void *cls, - const struct GNUNET_DB_EventHeaderP *es, - const void *extra, - size_t extra_size) -{ - struct PostgresClosure *pg = cls; - - GNUNET_PQ_event_notify (pg->conn, - es, - extra, - extra_size); -} diff --git a/src/donaudb/pg_event_notify.h b/src/donaudb/pg_event_notify.h @@ -1,42 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_event_notify.h - * @brief implementation of the event_notify function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_EVENT_NOTIFY_H -#define PG_EVENT_NOTIFY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Notify all that listen on @a es of an event. - * - * @param cls database context to use - * @param es specification of the event to generate - * @param extra additional event data provided - * @param extra_size number of bytes in @a extra - */ -void -DH_PG_event_notify (void *cls, - const struct GNUNET_DB_EventHeaderP *es, - const void *extra, - size_t extra_size); - -#endif diff --git a/src/donaudb/pg_get_charities.c b/src/donaudb/pg_get_charities.c @@ -1,160 +0,0 @@ -/* - 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_get_charities.c - * @brief Implementation of the lookup_donation_unit_key function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_get_charities.h" -#include "pg_helper.h" - - -/** - * Closure for #get_charities_cb(). - */ -struct GetCharitiesContext -{ - /** - * Function to call per result. - */ - DONAUDB_GetCharitiesCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Number of results processed. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * 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_charities_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct GetCharitiesContext *ctx = cls; - struct PostgresClosure *pg = ctx->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t charity_id; - struct DONAU_CharityPublicKeyP charity_pub; - char *charity_name; - struct TALER_Amount max_per_year; - struct TALER_Amount receipts_to_date; - uint32_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), - TALER_PQ_RESULT_SPEC_AMOUNT ("max_per_year", - &max_per_year), - GNUNET_PQ_result_spec_uint32 ("current_year", - &current_year), - TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date", - &receipts_to_date), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_GenericReturnValue ret; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - 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; - ret = ctx->cb (ctx->cb_cls, - charity_id, - &charity_pub, - charity_name, - &max_per_year, - current_year, - &receipts_to_date); - GNUNET_PQ_cleanup_result (rs); - if (GNUNET_OK != ret) - break; - } -} - - -enum GNUNET_DB_QueryStatus -DH_PG_get_charities (void *cls, - DONAUDB_GetCharitiesCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - struct GetCharitiesContext ctx = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "get_charities", - "SELECT" - " charity_id" - ",charity_pub" - ",charity_name" - ",max_per_year" - ",receipts_to_date" - ",current_year" - " FROM charities"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "get_charities", - params, - &get_charities_cb, - &ctx); - if (qs <= 0) - return qs; - return ctx.qs; -} diff --git a/src/donaudb/pg_get_charities.h b/src/donaudb/pg_get_charities.h @@ -1,39 +0,0 @@ -/* - 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_get_charities.h - * @brief implementation of the get_charities function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_GET_CHARITIES_H -#define PG_GET_CHARITIES_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_charities (void *cls, - DONAUDB_GetCharitiesCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_get_history.c b/src/donaudb/pg_get_history.c @@ -1,140 +0,0 @@ -/* - 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_get_history.c - * @brief Implementation of the lookup_donation_unit_key function for Postgres - * @author Johannes Casaburi - */ -#include "donau_config.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; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Number of results processed. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * Invoke the callback for each result. - * - * @param cls a `struct GetHistoryContext *` - * @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; - struct PostgresClosure *pg = ctx->pg; - - 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", - &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->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - - ctx->qs = i + 1; - if (GNUNET_OK != - ctx->cb (ctx->cb_cls, - charity_id, - final_amount, - donation_year)) - break; - } -} - - -enum GNUNET_DB_QueryStatus -DH_PG_get_history (void *cls, - DONAUDB_GetHistoryCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - struct GetHistoryContext ctx = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - 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 (qs <= 0) - return qs; - return ctx.qs; -} diff --git a/src/donaudb/pg_get_history.h b/src/donaudb/pg_get_history.h @@ -1,39 +0,0 @@ -/* - 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_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 history of charities. - * - * @param cls closure - * @param cb function to call on each result - * @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 @@ -1,121 +0,0 @@ -/* - 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 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 pg_helper.h - * @brief shared internal definitions for postgres DB plugin - * @author Johannes Casaburi - */ -#ifndef PG_HELPER_H -#define PG_HELPER_H - - -/** - * Type of the "cls" argument given to each of the functions in - * our API. - */ -struct PostgresClosure -{ - - /** - * Our configuration. - */ - const struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * Which currency should we assume all amounts to be in? - */ - char *currency; - - /** - * Our base URL. - */ - char *donau_url; - - /** - * Postgres connection handle. - */ - 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; - -}; - - -/** - * Prepares SQL statement @a sql under @a name for - * connection @a pg once. - * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure. - * - * @param pg a `struct PostgresClosure` - * @param name name to prepare the statement under - * @param sql actual SQL text - */ -#define PREPARE(pg,name,sql) \ - do { \ - static struct { \ - unsigned long long cnt; \ - struct PostgresClosure *pg; \ - } preps[2]; /* 2 ctrs for taler-auditor-sync*/ \ - unsigned int off = 0; \ - \ - while ( (NULL != preps[off].pg) && \ - (pg != preps[off].pg) && \ - (off < sizeof(preps) / sizeof(*preps)) ) \ - off++; \ - GNUNET_assert (off < \ - sizeof(preps) / sizeof(*preps)); \ - if (preps[off].cnt < pg->prep_gen) \ - { \ - struct GNUNET_PQ_PreparedStatement ps[] = { \ - GNUNET_PQ_make_prepare (name, sql), \ - GNUNET_PQ_PREPARED_STATEMENT_END \ - }; \ - \ - if (GNUNET_OK != \ - GNUNET_PQ_prepare_statements (pg->conn, \ - ps)) \ - { \ - GNUNET_break (0); \ - return GNUNET_DB_STATUS_HARD_ERROR; \ - } \ - preps[off].pg = pg; \ - preps[off].cnt = pg->prep_gen; \ - } \ - } while (0) - - -/** - * Wrapper macro to add the currency from the plugin's state - * when fetching amounts from the database. - * - * @param field name of the database field to fetch amount from - * @param[out] amountp pointer to amount to set - */ -#define TALER_PQ_RESULT_SPEC_AMOUNT(field, \ - amountp) TALER_PQ_result_spec_amount ( \ - field,pg->currency,amountp) - - -#endif diff --git a/src/donaudb/pg_insert_charity.c b/src/donaudb/pg_insert_charity.c @@ -1,73 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023--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_insert_charity.c - * @brief Implementation of the insert_charity function for Postgres - * @author Johannes Casaburi - * @author Lukas Matyja - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_charity.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_insert_charity ( - void *cls, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - const struct TALER_Amount *max_per_year, - uint64_t *charity_id) -{ - struct PostgresClosure *pg = cls; - uint32_t current_year - = GNUNET_TIME_get_current_year (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (charity_pub), - GNUNET_PQ_query_param_string (charity_name), - GNUNET_PQ_query_param_string (charity_url), - TALER_PQ_query_param_amount (pg->conn, - max_per_year), - GNUNET_PQ_query_param_uint32 (&current_year), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("charity_id", - charity_id), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "insert_charity", - "SELECT out_charity_id AS charity_id" - " FROM do_insert_charity" - " ($1, $2, $3, $4, $5);"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "insert_charity", - params, - rs); - if (qs <= 0) - return qs; - if (0 == *charity_id) - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - return qs; -} diff --git a/src/donaudb/pg_insert_charity.h b/src/donaudb/pg_insert_charity.h @@ -1,48 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_insert_charity.h - * @brief implementation of the insert_charity function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_INSERT_CHARITY_H -#define PG_INSERT_CHARITY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Add a new charity - * - * @param cls closure - * @param charity_pub charity public key - * @param charity_name charity name - * @param charity_url Web site of the charity - * @param max_per_year yearly donation limit - * @param[out] charity_id set to unique ID assigned to this charity - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_insert_charity ( - void *cls, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - const struct TALER_Amount *max_per_year, - uint64_t *charity_id); - -#endif diff --git a/src/donaudb/pg_insert_donation_unit.c b/src/donaudb/pg_insert_donation_unit.c @@ -1,59 +0,0 @@ -/* - 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_insert_donation_unit.c - * @brief Implementation of the insert_donation_unit function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_donation_unit.h" -#include "pg_helper.h" -#include "donau_pq_lib.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_insert_donation_unit ( - void *cls, - const struct DONAU_DonationUnitHashP *h_donation_unit_pub, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - const uint64_t validity_year, - const struct TALER_Amount *value) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam iparams[] = { - GNUNET_PQ_query_param_auto_from_type (h_donation_unit_pub), - DONAU_PQ_query_param_donation_unit_pub (donation_unit_pub), - GNUNET_PQ_query_param_uint64 (&validity_year), - TALER_PQ_query_param_amount (pg->conn, - value), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "donation_unit_insert", - "INSERT INTO donation_units " - "(h_donation_unit_pub" - ",donation_unit_pub" - ",validity_year" - ",value" - ") VALUES ($1, $2, $3, $4);"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "donation_unit_insert", - iparams); -} diff --git a/src/donaudb/pg_insert_donation_unit.h b/src/donaudb/pg_insert_donation_unit.h @@ -1,46 +0,0 @@ -/* - 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 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_insert_donation_unit.h - * @brief implementation of the insert_donation_unit function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_INSERT_DONATION_UNIT_H -#define PG_INSERT_DONATION_UNIT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Add donation unit key. - * - * @param cls closure - * @param donation_unit_hash hash of the public key - * @param donation_unit_pub the actual donation_unit key - * @param validity_year validity year - * @param value value that the donation unit represents - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_insert_donation_unit ( - void *cls, - const struct DONAU_DonationUnitHashP *h_donation_unit_pub, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - const uint64_t validity_year, - const struct TALER_Amount *value); - -#endif diff --git a/src/donaudb/pg_insert_history_entry.c b/src/donaudb/pg_insert_history_entry.c @@ -1,54 +0,0 @@ -/* - 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 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_insert_history_entry.c - * @brief Implementation of the insert_history_entry function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_history_entry.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -DH_PG_insert_history_entry (void *cls, - const uint64_t charity_id, - const struct TALER_Amount *final_amount, - const uint64_t donation_year) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&charity_id), - TALER_PQ_query_param_amount (pg->conn, - final_amount), - GNUNET_PQ_query_param_uint64 (&donation_year), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "insert_history_entry", - "INSERT INTO history " - "(charity_id" - ",final_amount" - ",donation_year" - ") VALUES " - "($1, $2, $3);"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_history_entry", - params); -} diff --git a/src/donaudb/pg_insert_history_entry.h b/src/donaudb/pg_insert_history_entry.h @@ -1,43 +0,0 @@ -/* - 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 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_insert_history_entry.h - * @brief implementation of the insert_history_entry function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_INSERT_HISTORY_ENTRY_H -#define PG_INSERT_HISTORY_ENTRY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * 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 -DH_PG_insert_history_entry (void *cls, - const uint64_t charity_id, - const struct TALER_Amount *final_amount, - const uint64_t donation_year); - -#endif diff --git a/src/donaudb/pg_insert_issued_receipt.c b/src/donaudb/pg_insert_issued_receipt.c @@ -1,79 +0,0 @@ -/* - 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 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_insert_issued_receipt.c - * @brief Implementation of the insert_issued_receipt function for Postgres - * @author Johannes Casaburi - * @author Lukas Matyja - */ -#include <donau_config.h> -#include <gnunet/gnunet_pq_lib.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_issued_receipt.h" -#include "pg_helper.h" -#include "donau_service.h" -#include "donau_pq_lib.h" - -enum GNUNET_DB_QueryStatus -DH_PG_insert_issued_receipt ( - void *cls, - const size_t num_blinded_sig, - const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], - const uint64_t charity_id, - const struct DONAU_DonationReceiptHashP *h_receipt, - const struct TALER_Amount *amount_receipts_request, - bool *smaller_than_max_per_year) -{ - struct PostgresClosure *pc = cls; - - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("smaller_than_max_per_year", - smaller_than_max_per_year), - GNUNET_PQ_result_spec_end - }; - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&charity_id), - DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, - signatures, - pc->conn), - GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash), - TALER_PQ_query_param_amount (pc->conn, - amount_receipts_request), - GNUNET_PQ_query_param_end - }; - - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pc, - "insert_issued_receipts_request", - "SELECT " - " out_smaller_than_max_per_year AS smaller_than_max_per_year" - " FROM do_insert_issued_receipts" - "($1,$2,$3,$4);"); - - qs = GNUNET_PQ_eval_prepared_singleton_select (pc->conn, - "insert_issued_receipts_request", - params, - rs); - GNUNET_PQ_cleanup_query_params_closures (params); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Is the new receipts_to_day smaller than the max_per_year (1 = true): %d\n", - (*smaller_than_max_per_year)); - return qs; -} diff --git a/src/donaudb/pg_insert_issued_receipt.h b/src/donaudb/pg_insert_issued_receipt.h @@ -1,51 +0,0 @@ -/* - 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 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_insert_issued_receipt.h - * @brief implementation of the insert_issued_receipt function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_INSERT_ISSUED_RECEIPT_H -#define PG_INSERT_ISSUED_RECEIPT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Insert issued blinded donation receipt to the charity. - * - * @param cls closure - * @param num_blinded_sig - * @param signatures blinded signatures - * @param charity_id identifier of the charity - * @param h_receipt hash of the donation receipt - * @param amount_receipts_request donation amount - * @param smaller_than_max_per_year new receipts to day smaller than the max? - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_insert_issued_receipt ( - void *cls, - const size_t num_blinded_sig, - const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], - const uint64_t charity_id, - const struct DONAU_DonationReceiptHashP *h_receipt, - const struct TALER_Amount *amount_receipts_request, - bool *smaller_than_max_per_year - ); - -#endif diff --git a/src/donaudb/pg_insert_signing_key.c b/src/donaudb/pg_insert_signing_key.c @@ -1,55 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_insert_signing_key.c - * @brief Implementation of the insert_signing_key function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_signing_key.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -DH_PG_insert_signing_key ( - void *cls, - const struct DONAU_DonauPublicKeyP *donau_pub, - struct DONAUDB_SignkeyMetaData *meta) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam iparams[] = { - GNUNET_PQ_query_param_auto_from_type (donau_pub), - GNUNET_PQ_query_param_timestamp (&meta->valid_from), - GNUNET_PQ_query_param_timestamp (&meta->expire_sign), - GNUNET_PQ_query_param_timestamp (&meta->expire_legal), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "insert_signkey", - "INSERT INTO donau_sign_keys " - "(donau_pub" - ",valid_from" - ",expire_sign" - ",expire_legal" - ") VALUES " - "($1, $2, $3, $4);"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_signkey", - iparams); -} diff --git a/src/donaudb/pg_insert_signing_key.h b/src/donaudb/pg_insert_signing_key.h @@ -1,42 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_insert_signing_key.h - * @brief implementation of the insert_signing_key function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_INSERT_SIGNING_KEY_H -#define PG_INSERT_SIGNING_KEY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * 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 -DH_PG_insert_signing_key ( - void *cls, - const struct DONAU_DonauPublicKeyP *donau_pub, - struct DONAUDB_SignkeyMetaData *meta); - -#endif diff --git a/src/donaudb/pg_insert_submitted_receipts.c b/src/donaudb/pg_insert_submitted_receipts.c @@ -1,102 +0,0 @@ -/* - 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 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_insert_submitted_receipts.c - * @brief Implementation of the insert_submitted_receipts function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_submitted_receipts.h" -#include "pg_helper.h" -#include "donau_service.h" -#include "donau_pq_lib.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_insert_submitted_receipts ( - void *cls, - struct DONAU_HashDonorTaxId *h_donor_tax_id, - size_t num_dr, - const struct DONAU_DonationReceipt donation_receipts[static num_dr], - uint64_t donation_year) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_HashCode h_donation_unit_pubs[GNUNET_NZL (num_dr)]; - struct DONAU_UniqueDonorIdentifierNonce nonces[GNUNET_NZL (num_dr)]; - struct DONAU_DonationUnitSignature donation_unit_sigs[GNUNET_NZL (num_dr)]; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id), - GNUNET_PQ_query_param_array_auto_from_type (num_dr, - h_donation_unit_pubs, - pg->conn), - GNUNET_PQ_query_param_array_auto_from_type (num_dr, - nonces, - pg->conn), - DONAU_PQ_query_param_array_donation_unit_sig (num_dr, - donation_unit_sigs, - pg->conn), - GNUNET_PQ_query_param_uint64 (&donation_year), - GNUNET_PQ_query_param_end - }; - bool *conflicted = NULL; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_array_bool (pg->conn, - "conflicted", - &num_dr, - &conflicted), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - for (unsigned int i = 0; i < num_dr; i++) - { - const struct DONAU_DonationReceipt *dr = &donation_receipts[i]; - - h_donation_unit_pubs[i] = dr->h_donation_unit_pub.hash; - nonces[i] = dr->nonce; - donation_unit_sigs[i] = dr->donation_unit_sig; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Do insert submitted receipt\n"); - } - - PREPARE (pg, - "call_insert_submitted_receipts", - "SELECT " - " out_conflict AS conflicted" - " FROM do_insert_submitted_receipts" - "($1,$2,$3,$4,$5);"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_insert_submitted_receipts", - params, - rs); - GNUNET_PQ_cleanup_query_params_closures (params); - - for (size_t i = 0; i < num_dr; i++) - { - if (conflicted[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Submitted donation receipt at index %ld already present!\n", - i); - } - } - GNUNET_free (conflicted); - GNUNET_PQ_cleanup_result (rs); - return qs; -} diff --git a/src/donaudb/pg_insert_submitted_receipts.h b/src/donaudb/pg_insert_submitted_receipts.h @@ -1,48 +0,0 @@ -/* - 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 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_insert_submitted_receipts.h - * @brief implementation of the insert_submitted_receipts function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_INSERT_SUBMITTED_RECEIPT_H -#define PG_INSERT_SUBMITTED_RECEIPT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" -#include "donau_service.h" - -/** - * Insert submitted donation receipt from the donor. - * - * @param cls closure - * @param h_donor_tax_id salted hash of the donors tax number - * @param num_dr number of donation receipts - * @param donation_receipts array of donation receipts - * @param donation_year year of the donation - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_insert_submitted_receipts ( - void *cls, - struct DONAU_HashDonorTaxId *h_donor_tax_id, - size_t num_dr, - const struct DONAU_DonationReceipt donation_receipts[static num_dr], - uint64_t donation_year - ); - -#endif diff --git a/src/donaudb/pg_iterate_active_signing_keys.c b/src/donaudb/pg_iterate_active_signing_keys.c @@ -1,134 +0,0 @@ -/* - 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_iterate_active_signing_keys.c - * @brief Implementation of the iterate_active_signing_keys function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_iterate_active_signing_keys.h" -#include "pg_helper.h" - -/** - * Closure for #signkeys_cb_helper(). - */ -struct IterateActiveSigningKeysContext -{ - /** - * Function to call per result. - */ - DONAUDB_IterateActiveSigningKeysCallback 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 -signkeys_cb_helper (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct IterateActiveSigningKeysContext *ctx = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct DONAU_DonauPublicKeyP donau_pub; - struct DONAUDB_SignkeyMetaData meta; - - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("donau_pub", - &donau_pub), - GNUNET_PQ_result_spec_timestamp ("valid_from", - &meta.valid_from), - GNUNET_PQ_result_spec_timestamp ("expire_sign", - &meta.expire_sign), - GNUNET_PQ_result_spec_timestamp ("expire_legal", - &meta.expire_legal), - 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, - &donau_pub, - &meta); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -DH_PG_iterate_active_signing_keys (void *cls, - DONAUDB_IterateActiveSigningKeysCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_TIME_Absolute now = {0}; - struct IterateActiveSigningKeysContext ctx = { - .cb = cb, - .cb_cls = cb_cls, - .status = GNUNET_OK - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "iterate_active_signing_keys", - "SELECT" - " donau_pub" - ",valid_from" - ",expire_sign" - ",expire_legal" - " FROM donau_sign_keys dsk" - " WHERE" - " expire_sign > $1"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "iterate_active_signing_keys", - params, - &signkeys_cb_helper, - &ctx); - if (GNUNET_OK != ctx.status) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/donaudb/pg_iterate_active_signing_keys.h b/src/donaudb/pg_iterate_active_signing_keys.h @@ -1,39 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_iterate_active_signing_keys.h - * @brief implementation of the iterate_active_signing_keys function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_ITERATE_ACTIVE_SIGNING_KEYS_H -#define PG_ITERATE_ACTIVE_SIGNING_KEYS_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_iterate_active_signing_keys (void *cls, - DONAUDB_IterateActiveSigningKeysCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_iterate_donation_units.c b/src/donaudb/pg_iterate_donation_units.c @@ -1,135 +0,0 @@ -/* - 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_iterate_donation_units.c - * @brief Implementation of the iterate_donation_units function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_iterate_donation_units.h" -#include "pg_helper.h" -#include "donau_pq_lib.h" - -/** - * Closure for #get_donation_units_cb(). - */ -struct IterateDonationUnitsContext -{ - /** - * Function to call per result. - */ - DONAUDB_IterateDonationUnitsCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - -}; - -/** - * 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 -iterate_donation_units_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct IterateDonationUnitsContext *ctx = cls; - struct PostgresClosure *pg = ctx->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct DONAU_DonationUnitHashP h_donation_unit_pub; - struct DONAU_DonationUnitPublicKey donation_unit_pub; - uint64_t validity_year; - struct TALER_Amount value; - enum GNUNET_GenericReturnValue iret; - - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_donation_unit_pub", - &h_donation_unit_pub), - DONAU_PQ_result_spec_donation_unit_pub ("donation_unit_pub", - &donation_unit_pub), - GNUNET_PQ_result_spec_uint64 ("validity_year", - &validity_year), - TALER_PQ_RESULT_SPEC_AMOUNT ("value", - &value), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - return; - } - - iret = ctx->cb (ctx->cb_cls, - &h_donation_unit_pub, - &donation_unit_pub, - validity_year, - &value); - GNUNET_PQ_cleanup_result (rs); - if (GNUNET_OK != iret) - break; - } -} - - -enum GNUNET_DB_QueryStatus -DH_PG_iterate_donation_units (void *cls, - DONAUDB_IterateDonationUnitsCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - struct IterateDonationUnitsContext ctx = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - - PREPARE (pg, - "iterate_donation_units", - "SELECT" - " h_donation_unit_pub" - ",donation_unit_pub" - ",validity_year" - ",value" - " FROM donation_units"); - return GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "iterate_donation_units", - params, - &iterate_donation_units_cb, - &ctx); -} diff --git a/src/donaudb/pg_iterate_donation_units.h b/src/donaudb/pg_iterate_donation_units.h @@ -1,39 +0,0 @@ -/* - 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 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_iterate_donation_units.h - * @brief implementation of the iterate_donation_units function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_ITERATE_DONATION_UNITS_H -#define PG_ITERATE_DONATION_UNITS_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_iterate_donation_units (void *cls, - DONAUDB_IterateDonationUnitsCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_iterate_submitted_receipts.c b/src/donaudb/pg_iterate_submitted_receipts.c @@ -1,78 +0,0 @@ -/* - 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_iterate_submitted_receipts.c - * @brief Implementation of the iterate_submitted_receipts function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_iterate_submitted_receipts.h" -#include "pg_helper.h" -#include "donaudb_plugin.h" -#include "donau_pq_lib.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_iterate_submitted_receipts ( - void *cls, - const uint64_t donation_year, - const struct DONAU_HashDonorTaxId *h_donor_tax_id, - struct TALER_Amount *total_donations) -{ - struct PostgresClosure *pg = cls; - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&donation_year), - GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id), - GNUNET_PQ_query_param_end - }; - uint64_t valueSum = 0; - uint64_t fractionSum = 0; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("valueSum", - &valueSum), - GNUNET_PQ_result_spec_uint64 ("fractionSum", - &fractionSum), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_submitted_receipts", - "SELECT " - " CAST(SUM((donation_units.value).val) AS INT8) AS valueSum" - ",CAST(SUM(CAST((donation_units.value).frac AS INT8)) AS INT8) AS fractionSum" - " FROM receipts_submitted ref" - " JOIN donation_units USING (h_donation_unit_pub)" - " WHERE donation_year=$1" - " AND h_tax_number=$2"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_submitted_receipts", - params, - rs); - if (qs < 0) - return qs; - valueSum += fractionSum / TALER_AMOUNT_FRAC_BASE; - fractionSum %= TALER_AMOUNT_FRAC_BASE; - TALER_amount_set_zero (pg->currency, - total_donations); - total_donations->value = valueSum; - total_donations->fraction = fractionSum; - return qs; -} diff --git a/src/donaudb/pg_iterate_submitted_receipts.h b/src/donaudb/pg_iterate_submitted_receipts.h @@ -1,42 +0,0 @@ -/* - 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_iterate_donation_units.h - * @brief implementation of the iterate_donation_units function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_ITERATE_SUBMITTED_RECEIPTS_H -#define PG_ITERATE_SUBMITTED_RECEIPTS_H - -#include "donaudb_plugin.h" - -/** - * Obtain information about the enabled wire accounts of the exchange. - * - * @param cls closure - * @param donation_year donation year - * @param h_donor_tax_id hash of donor tax id - * @param[out] total_donations amount of total donations - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_iterate_submitted_receipts ( - void *cls, - const uint64_t donation_year, - const struct DONAU_HashDonorTaxId *h_donor_tax_id, - struct TALER_Amount *total_donations); - -#endif diff --git a/src/donaudb/pg_lookup_charity.c b/src/donaudb/pg_lookup_charity.c @@ -1,70 +0,0 @@ -/* - 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_donation_unit_key.c - * @brief Implementation of the lookup_donation_unit_key function for Postgres - * @author Johannes Casaburi - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_lookup_charity.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -DH_PG_lookup_charity ( - void *cls, - uint64_t charity_id, - struct DONAUDB_CharityMetaData *meta) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&charity_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - 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_uint32 ("current_year", - &meta->current_year), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "lookup_charity", - "SELECT " - " 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, - "lookup_charity", - params, - rs); -} diff --git a/src/donaudb/pg_lookup_charity.h b/src/donaudb/pg_lookup_charity.h @@ -1,41 +0,0 @@ -/* - 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_charity.h - * @brief implementation of the lookup_charity function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_GET_CHARITY_INFO_H -#define PG_GET_CHARITY_INFO_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" -/** - * Fetch information about a charity. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param charity_id the charity id - * @param meta charity meta data information - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_lookup_charity ( - void *cls, - uint64_t charity_id, - struct DONAUDB_CharityMetaData *meta); - -#endif diff --git a/src/donaudb/pg_lookup_donation_unit_amount.c b/src/donaudb/pg_lookup_donation_unit_amount.c @@ -1,61 +0,0 @@ -/* - 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 Implementation 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" -#include "pg_lookup_donation_unit_amount.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 @@ -1,43 +0,0 @@ -/* - 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/pg_lookup_issued_receipts.c b/src/donaudb/pg_lookup_issued_receipts.c @@ -1,78 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024, 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_issued_receipts.c - * @brief Implementation of the lookup_issued_receipts function for Postgres - * @author Lukas Matyja - */ -#include <donau_config.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" -#include "donau_pq_lib.h" - -enum GNUNET_DB_QueryStatus -DH_PG_lookup_issued_receipts ( - void *cls, - struct DONAU_DonationReceiptHashP *h_receipts, - struct DONAUDB_IssuedReceiptsMetaData *meta) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_receipts), - GNUNET_PQ_query_param_end - }; - struct DONAU_BlindedDonationUnitSignature *du_sigs; - size_t num_sigs; - struct GNUNET_PQ_ResultSpec rs[] = { - DONAU_PQ_result_spec_array_blinded_donation_unit_sig ( - pg->conn, - "blinded_sig", - &num_sigs, - &du_sigs), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &meta->amount), - GNUNET_PQ_result_spec_uint64 ("charity_id", - &meta->charity_id), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_issued_receipts", - "SELECT " - " blinded_sig" - " ,amount" - " ,charity_id" - " FROM receipts_issued" - " WHERE receipt_hash=$1;"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_issued_receipts", - params, - rs); - if (qs > 0) - { - /* prevent the result cleanup from freeing the signatures */ - meta->num_sig = num_sigs; - meta->blinded_sigs = du_sigs; - num_sigs = 0; - du_sigs = NULL; - } - GNUNET_PQ_cleanup_result (rs); - return qs; -} diff --git a/src/donaudb/pg_lookup_issued_receipts.h b/src/donaudb/pg_lookup_issued_receipts.h @@ -1,41 +0,0 @@ -/* - 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 h_receipts hash over the issued receipt - * @param meta 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_DonationReceiptHashP *h_receipts, - struct DONAUDB_IssuedReceiptsMetaData *meta); - -#endif diff --git a/src/donaudb/pg_lookup_signing_key.c b/src/donaudb/pg_lookup_signing_key.c @@ -1,64 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_signing_key.c - * @brief Implementation of the lookup_signing_key function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_lookup_signing_key.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_lookup_signing_key ( - void *cls, - const struct DONAU_DonauPublicKeyP *donau_pub, - struct DONAUDB_SignkeyMetaData *meta) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (donau_pub), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("valid_from", - &meta->valid_from), - GNUNET_PQ_result_spec_timestamp ("expire_sign", - &meta->expire_sign), - GNUNET_PQ_result_spec_timestamp ("expire_legal", - &meta->expire_legal), - GNUNET_PQ_result_spec_end - }; - - - PREPARE (pg, - "lookup_signing_key", - "SELECT" - " valid_from" - ",expire_sign" - ",expire_legal" - " FROM donau_sign_keys" - " WHERE donau_pub=$1"); - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_signing_key", - params, - rs); -} diff --git a/src/donaudb/pg_lookup_signing_key.h b/src/donaudb/pg_lookup_signing_key.h @@ -1,43 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_signing_key.h - * @brief implementation of the lookup_signing_key function for Postgres - * @author Johannes Casaburi - */ -#ifndef PG_LOOKUP_SIGNING_KEY_H -#define PG_LOOKUP_SIGNING_KEY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - - -/** - * 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 -DH_PG_lookup_signing_key ( - void *cls, - const struct DONAU_DonauPublicKeyP *donau_pub, - struct DONAUDB_SignkeyMetaData *meta); - -#endif diff --git a/src/donaudb/pg_preflight.c b/src/donaudb/pg_preflight.c @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_preflight.c - * @brief Implementation of the preflight function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_preflight.h" -#include "pg_helper.h" - - -enum GNUNET_GenericReturnValue -DH_PG_preflight (void *cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_execute ("ROLLBACK"), - GNUNET_PQ_EXECUTE_STATEMENT_END - }; - - if (GNUNET_OK != - DH_PG_internal_setup (pg)) - return GNUNET_SYSERR; - if (NULL == pg->transaction_name) - return GNUNET_OK; /* all good */ - if (GNUNET_OK == - GNUNET_PQ_exec_statements (pg->conn, - es)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "BUG: Preflight check rolled back transaction `%s'!\n", - pg->transaction_name); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "BUG: Preflight check failed to rollback transaction `%s'!\n", - pg->transaction_name); - } - pg->transaction_name = NULL; - return GNUNET_NO; -} diff --git a/src/donaudb/pg_preflight.h b/src/donaudb/pg_preflight.h @@ -1,56 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_preflight.h - * @brief implementation of the preflight function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_PREFLIGTH_H -#define PG_PREFLIGTH_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - - -/** - * Do a pre-flight check that we are not in an uncommitted transaction. - * If we are, try to commit the previous transaction and output a warning. - * Does not return anything, as we will continue regardless of the outcome. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @return #GNUNET_OK if everything is fine - * #GNUNET_NO if a transaction was rolled back - * #GNUNET_SYSERR on hard errors - */ -enum GNUNET_GenericReturnValue -DH_PG_preflight (void *cls); - - -struct PostgresClosure; - - -/** - * Connect to the database if the connection does not exist yet. - * - * @param pg the plugin-specific state - * @return #GNUNET_OK on success - */ -enum GNUNET_GenericReturnValue -DH_PG_internal_setup (struct PostgresClosure *pg); - - -#endif diff --git a/src/donaudb/pg_rollback.c b/src/donaudb/pg_rollback.c @@ -1,50 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_rollback.c - * @brief Implementation of the rollback function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_rollback.h" -#include "pg_helper.h" - - -void -DH_PG_rollback (void *cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_execute ("ROLLBACK"), - GNUNET_PQ_EXECUTE_STATEMENT_END - }; - - if (NULL == pg->transaction_name) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Skipping rollback, no transaction active\n"); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Rolling back transaction\n"); - GNUNET_break (GNUNET_OK == - GNUNET_PQ_exec_statements (pg->conn, - es)); - pg->transaction_name = NULL; -} diff --git a/src/donaudb/pg_rollback.h b/src/donaudb/pg_rollback.h @@ -1,36 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_rollback.h - * @brief implementation of the rollback function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_ROLLBACK_H -#define PG_ROLLBACK_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Roll back the current transaction of a database connection. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - */ -void -DH_PG_rollback (void *cls); - -#endif diff --git a/src/donaudb/pg_start.c b/src/donaudb/pg_start.c @@ -1,56 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_start.c - * @brief Implementation of the start function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_preflight.h" -#include "pg_start.h" -#include "pg_helper.h" - -enum GNUNET_GenericReturnValue -DH_PG_start (void *cls, - const char *name) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"), - GNUNET_PQ_EXECUTE_STATEMENT_END - }; - - GNUNET_assert (NULL != name); - if (GNUNET_SYSERR == - DH_PG_preflight (pg)) - return GNUNET_SYSERR; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Starting transaction `%s'\n", - name); - if (GNUNET_OK != - GNUNET_PQ_exec_statements (pg->conn, - es)) - { - TALER_LOG_ERROR ("Failed to start transaction\n"); - GNUNET_break (0); - return GNUNET_SYSERR; - } - pg->transaction_name = name; - return GNUNET_OK; -} diff --git a/src/donaudb/pg_start.h b/src/donaudb/pg_start.h @@ -1,40 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_start.h - * @brief implementation of the start function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_START_H -#define PG_START_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Start a transaction. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param name unique name identifying the transaction (for debugging) - * must point to a constant - * @return #GNUNET_OK on success - */ -enum GNUNET_GenericReturnValue -DH_PG_start (void *cls, - const char *name); - -#endif diff --git a/src/donaudb/pg_start_read_committed.c b/src/donaudb/pg_start_read_committed.c @@ -1,56 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_start_read_committed.c - * @brief Implementation of the start_read_committed function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_start_read_committed.h" -#include "pg_preflight.h" -#include "pg_helper.h" - -enum GNUNET_GenericReturnValue -DH_PG_start_read_committed (void *cls, - const char *name) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"), - GNUNET_PQ_EXECUTE_STATEMENT_END - }; - - GNUNET_assert (NULL != name); - if (GNUNET_SYSERR == - DH_PG_preflight (pg)) - return GNUNET_SYSERR; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Starting READ COMMITTED transaction `%s`\n", - name); - if (GNUNET_OK != - GNUNET_PQ_exec_statements (pg->conn, - es)) - { - TALER_LOG_ERROR ("Failed to start transaction\n"); - GNUNET_break (0); - return GNUNET_SYSERR; - } - pg->transaction_name = name; - return GNUNET_OK; -} diff --git a/src/donaudb/pg_start_read_committed.h b/src/donaudb/pg_start_read_committed.h @@ -1,39 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_start_read_committed.h - * @brief implementation of the start_read_committed function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_START_READ_COMMITTED_H -#define PG_START_READ_COMMITTED_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" -/** - * Start a READ COMMITTED transaction. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param name unique name identifying the transaction (for debugging) - * must point to a constant - * @return #GNUNET_OK on success - */ -enum GNUNET_GenericReturnValue -DH_PG_start_read_committed (void *cls, - const char *name); - -#endif diff --git a/src/donaudb/pg_start_read_only.c b/src/donaudb/pg_start_read_only.c @@ -1,57 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_start_read_only.c - * @brief Implementation of the start_read_only function for Postgres - * @author Christian Grothoff - */ -#include <donau_config.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_start_read_only.h" -#include "pg_preflight.h" -#include "pg_helper.h" - -enum GNUNET_GenericReturnValue -DH_PG_start_read_only (void *cls, - const char *name) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_execute ( - "START TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"), - GNUNET_PQ_EXECUTE_STATEMENT_END - }; - - GNUNET_assert (NULL != name); - if (GNUNET_SYSERR == - DH_PG_preflight (pg)) - return GNUNET_SYSERR; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Starting READ ONLY transaction `%s`\n", - name); - if (GNUNET_OK != - GNUNET_PQ_exec_statements (pg->conn, - es)) - { - TALER_LOG_ERROR ("Failed to start transaction\n"); - GNUNET_break (0); - return GNUNET_SYSERR; - } - pg->transaction_name = name; - return GNUNET_OK; -} diff --git a/src/donaudb/pg_start_read_only.h b/src/donaudb/pg_start_read_only.h @@ -1,40 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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_start_read_only.h - * @brief implementation of the start_read_only function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_START_READ_ONLY_H -#define PG_START_READ_ONLY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" - -/** - * Start a READ ONLY serializable transaction. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param name unique name identifying the transaction (for debugging) - * must point to a constant - * @return #GNUNET_OK on success - */ -enum GNUNET_GenericReturnValue -DH_PG_start_read_only (void *cls, - const char *name); - -#endif diff --git a/src/donaudb/pg_template.c b/src/donaudb/pg_template.c @@ -23,4 +23,4 @@ #include <taler/taler_dbevents.h> #include <taler/taler_pq_lib.h> #include "pg_template.h" -#include "pg_helper.h" +#include "helper.h" diff --git a/src/donaudb/pg_template.h b/src/donaudb/pg_template.h @@ -23,7 +23,7 @@ #include <taler/taler_util.h> #include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" +#include "donaudb_lib.h" #endif diff --git a/src/donaudb/pg_update_charity.c b/src/donaudb/pg_update_charity.c @@ -1,63 +0,0 @@ -/* - 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_update_charity.c - * @brief Implementation of the update_charity function for Postgres - * @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_update_charity.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -DH_PG_update_charity ( - void *cls, - uint64_t charity_id, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - const struct TALER_Amount *max_per_year) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&charity_id), - GNUNET_PQ_query_param_auto_from_type (charity_pub), - GNUNET_PQ_query_param_string (charity_name), - GNUNET_PQ_query_param_string (charity_url), - TALER_PQ_query_param_amount (pg->conn, - max_per_year), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "update_charity", - "UPDATE charities" - " SET charity_pub = $2" - " ,charity_name = $3" - " ,charity_url = $4" - " ,max_per_year = $5" - " WHERE charity_id = $1;"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_charity", - params); -} - - -/* end of pg_update_charity.c */ diff --git a/src/donaudb/pg_update_charity.h b/src/donaudb/pg_update_charity.h @@ -1,47 +0,0 @@ -/* - 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_update_charity.h - * @brief Implementation of the update_charity function for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef PG_UPDATE_CHARITY_H -#define PG_UPDATE_CHARITY_H - -#include <taler/taler_util.h> -#include "donaudb_plugin.h" - -/** - * Update an existing charity entry. - * - * @param cls closure - * @param charity_id identifier of the charity to update - * @param charity_pub new public key for the charity - * @param charity_name new name - * @param charity_url new landing page URL - * @param max_per_year yearly donation limit - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_update_charity ( - void *cls, - uint64_t charity_id, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - const struct TALER_Amount *max_per_year); - -#endif diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -23,39 +23,7 @@ #include <poll.h> #include <pthread.h> #include <libpq-fe.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" -#include "pg_helper.h" -#include "pg_preflight.h" -#include "pg_commit.h" -#include "pg_drop_tables.h" -#include "pg_start.h" -#include "pg_rollback.h" -#include "pg_create_tables.h" -#include "pg_event_listen.h" -#include "pg_event_listen_cancel.h" -#include "pg_event_notify.h" -#include "pg_insert_donation_unit.h" -#include "pg_iterate_donation_units.h" -#include "pg_insert_history_entry.h" -#include "pg_get_history.h" -#include "pg_insert_issued_receipt.h" -#include "pg_insert_submitted_receipts.h" -#include "pg_iterate_submitted_receipts.h" -#include "pg_insert_signing_key.h" -#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" -#include "pg_update_charity.h" -#include "pg_do_charity_delete.h" +#include "helper.h" /** * Set to 1 to enable Postgres auto_explain module. This will @@ -72,14 +40,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) @@ -90,7 +58,7 @@ * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue -DH_PG_internal_setup (struct PostgresClosure *pg) +DONAUDB_internal_setup (struct DONAUDB_PostgresContext *pg) { if (NULL == pg->conn) { @@ -141,24 +109,12 @@ DH_PG_internal_setup (struct PostgresClosure *pg) } -/** - * Initialize Postgres database subsystem. - * - * @param cls a configuration instance - * @return NULL on error, otherwise a `struct - * DONAUDB_Plugin` - */ -void * -libdonau_plugin_donaudb_postgres_init (void *cls); - -void * -libdonau_plugin_donaudb_postgres_init (void *cls) +struct DONAUDB_PostgresContext * +DONAUDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) { - const struct GNUNET_CONFIGURATION_Handle *cfg = cls; - struct PostgresClosure *pg; - struct DONAUDB_Plugin *plugin; + struct DONAUDB_PostgresContext *pg; - pg = GNUNET_new (struct PostgresClosure); + pg = GNUNET_new (struct DONAUDB_PostgresContext); pg->cfg = cfg; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, @@ -182,87 +138,22 @@ libdonau_plugin_donaudb_postgres_init (void *cls) return NULL; } if (GNUNET_OK != - DH_PG_internal_setup (pg)) + DONAUDB_internal_setup (pg)) { GNUNET_free (pg->donau_url); GNUNET_free (pg->currency); GNUNET_free (pg); return NULL; } - plugin = GNUNET_new (struct DONAUDB_Plugin); - plugin->cls = pg; - plugin->drop_tables - = &DH_PG_drop_tables; - plugin->commit - = &DH_PG_commit; - plugin->preflight - = &DH_PG_preflight; - plugin->start - = &DH_PG_start; - plugin->rollback - = &DH_PG_rollback; - plugin->create_tables - = &DH_PG_create_tables; - plugin->event_listen - = &DH_PG_event_listen; - plugin->event_listen_cancel - = &DH_PG_event_listen_cancel; - plugin->event_notify - = &DH_PG_event_notify; - plugin->insert_donation_unit - = &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 - = &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_receipts - = &DH_PG_insert_submitted_receipts; - plugin->insert_signing_key - = &DH_PG_insert_signing_key; - plugin->lookup_signing_key - = &DH_PG_lookup_signing_key; - plugin->iterate_active_signing_keys - = &DH_PG_iterate_active_signing_keys; - plugin->iterate_submitted_receipts - = &DH_PG_iterate_submitted_receipts; - plugin->lookup_charity - = &DH_PG_lookup_charity; - plugin->insert_charity - = &DH_PG_insert_charity; - plugin->update_charity - = &DH_PG_update_charity; - plugin->get_charities - = &DH_PG_get_charities; - plugin->do_charity_delete - = &DH_PG_do_charity_delete; - - return plugin; + return pg; } -/** - * Shutdown Postgres database subsystem. - * - * @param cls a `struct DONAUDB_Plugin` - * @return NULL (always) - */ -void * -libdonau_plugin_donaudb_postgres_done (void *cls); - -void * -libdonau_plugin_donaudb_postgres_done (void *cls) +void +DONAUDB_disconnect (struct DONAUDB_PostgresContext *pg) { - struct DONAUDB_Plugin *plugin = cls; - struct PostgresClosure *pg = plugin->cls; - + if (NULL == pg) + return; if (NULL != pg->conn) { GNUNET_PQ_disconnect (pg->conn); @@ -271,8 +162,6 @@ libdonau_plugin_donaudb_postgres_done (void *cls) GNUNET_free (pg->donau_url); GNUNET_free (pg->currency); GNUNET_free (pg); - GNUNET_free (plugin); - return NULL; } diff --git a/src/donaudb/preflight.c b/src/donaudb/preflight.c @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/preflight.c + * @brief Implementation of the preflight function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "preflight.h" +#include "helper.h" + + +enum GNUNET_GenericReturnValue +DONAUDB_preflight (struct DONAUDB_PostgresContext *ctx) +{ + struct GNUNET_PQ_ExecuteStatement es[] = { + GNUNET_PQ_make_execute ("ROLLBACK"), + GNUNET_PQ_EXECUTE_STATEMENT_END + }; + + if (GNUNET_OK != + DONAUDB_internal_setup (ctx)) + return GNUNET_SYSERR; + if (NULL == ctx->transaction_name) + return GNUNET_OK; /* all good */ + if (GNUNET_OK == + GNUNET_PQ_exec_statements (ctx->conn, + es)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BUG: Preflight check rolled back transaction `%s'!\n", + ctx->transaction_name); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BUG: Preflight check failed to rollback transaction `%s'!\n", + ctx->transaction_name); + } + ctx->transaction_name = NULL; + return GNUNET_NO; +} diff --git a/src/donaudb/rollback.c b/src/donaudb/rollback.c @@ -0,0 +1,49 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/rollback.c + * @brief Implementation of the rollback function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "rollback.h" +#include "helper.h" + + +void +DONAUDB_rollback (struct DONAUDB_PostgresContext *ctx) +{ + struct GNUNET_PQ_ExecuteStatement es[] = { + GNUNET_PQ_make_execute ("ROLLBACK"), + GNUNET_PQ_EXECUTE_STATEMENT_END + }; + + if (NULL == ctx->transaction_name) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Skipping rollback, no transaction active\n"); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Rolling back transaction\n"); + GNUNET_break (GNUNET_OK == + GNUNET_PQ_exec_statements (ctx->conn, + es)); + ctx->transaction_name = NULL; +} diff --git a/src/donaudb/start.c b/src/donaudb/start.c @@ -0,0 +1,53 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/start.c + * @brief Implementation of the start function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include "helper.h" +#include "preflight.h" +#include "start.h" + + +enum GNUNET_GenericReturnValue +DONAUDB_start (struct DONAUDB_PostgresContext *ctx, + const char *name) +{ + struct GNUNET_PQ_ExecuteStatement es[] = { + GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"), + GNUNET_PQ_EXECUTE_STATEMENT_END + }; + + GNUNET_assert (NULL != name); + if (GNUNET_SYSERR == + DONAUDB_preflight (ctx)) + return GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Starting transaction `%s'\n", + name); + if (GNUNET_OK != + GNUNET_PQ_exec_statements (ctx->conn, + es)) + { + TALER_LOG_ERROR ("Failed to start transaction\n"); + GNUNET_break (0); + return GNUNET_SYSERR; + } + ctx->transaction_name = name; + return GNUNET_OK; +} diff --git a/src/donaudb/start_read_committed.c b/src/donaudb/start_read_committed.c @@ -0,0 +1,55 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/start_read_committed.c + * @brief Implementation of the start_read_committed function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "start_read_committed.h" +#include "preflight.h" +#include "helper.h" + +enum GNUNET_GenericReturnValue +DONAUDB_start_read_committed (struct DONAUDB_PostgresContext *ctx, + const char *name) +{ + struct GNUNET_PQ_ExecuteStatement es[] = { + GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"), + GNUNET_PQ_EXECUTE_STATEMENT_END + }; + + GNUNET_assert (NULL != name); + if (GNUNET_SYSERR == + DONAUDB_preflight (ctx)) + return GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Starting READ COMMITTED transaction `%s`\n", + name); + if (GNUNET_OK != + GNUNET_PQ_exec_statements (ctx->conn, + es)) + { + TALER_LOG_ERROR ("Failed to start transaction\n"); + GNUNET_break (0); + return GNUNET_SYSERR; + } + ctx->transaction_name = name; + return GNUNET_OK; +} diff --git a/src/donaudb/start_read_only.c b/src/donaudb/start_read_only.c @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/donaudb/start_read_only.c + * @brief Implementation of the start_read_only function for Postgres + * @author Christian Grothoff + */ +#include <donau_config.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "start_read_only.h" +#include "preflight.h" +#include "helper.h" + +enum GNUNET_GenericReturnValue +DONAUDB_start_read_only (struct DONAUDB_PostgresContext *ctx, + const char *name) +{ + struct GNUNET_PQ_ExecuteStatement es[] = { + GNUNET_PQ_make_execute ( + "START TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"), + GNUNET_PQ_EXECUTE_STATEMENT_END + }; + + GNUNET_assert (NULL != name); + if (GNUNET_SYSERR == + DONAUDB_preflight (ctx)) + return GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Starting READ ONLY transaction `%s`\n", + name); + if (GNUNET_OK != + GNUNET_PQ_exec_statements (ctx->conn, + es)) + { + TALER_LOG_ERROR ("Failed to start transaction\n"); + GNUNET_break (0); + return GNUNET_SYSERR; + } + ctx->transaction_name = name; + return GNUNET_OK; +} diff --git a/src/donaudb/test-donau-db-postgres.conf b/src/donaudb/test-donau-db-postgres.conf @@ -15,4 +15,3 @@ CONFIG = postgres:///donaucheck SQL_DIR = ${DATADIR}sql/ [donaudb] - diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -22,7 +22,35 @@ #include <taler/taler_json_lib.h> #include "donaudb_lib.h" #include "donau_util.h" -#include "donaudb_plugin.h" +#include "donaudb_lib.h" +#include "donau-database/commit.h" +#include "donau-database/create_tables.h" +#include "donau-database/do_charity_delete.h" +#include "donau-database/drop_tables.h" +#include "donau-database/event_listen_cancel.h" +#include "donau-database/event_listen.h" +#include "donau-database/event_notify.h" +#include "donau-database/get_charities.h" +#include "donau-database/get_history.h" +#include "donau-database/insert_charity.h" +#include "donau-database/insert_donation_unit.h" +#include "donau-database/insert_history_entry.h" +#include "donau-database/insert_issued_receipt.h" +#include "donau-database/insert_signing_key.h" +#include "donau-database/insert_submitted_receipts.h" +#include "donau-database/iterate_active_signing_keys.h" +#include "donau-database/iterate_donation_units.h" +#include "donau-database/iterate_submitted_receipts.h" +#include "donau-database/lookup_charity.h" +#include "donau-database/lookup_donation_unit_amount.h" +#include "donau-database/lookup_issued_receipts.h" +#include "donau-database/lookup_signing_key.h" +#include "donau-database/preflight.h" +#include "donau-database/rollback.h" +#include "donau-database/start.h" +#include "donau-database/start_read_committed.h" +#include "donau-database/start_read_only.h" +#include "donau-database/update_charity.h" /** * Global result from the testcase. @@ -33,25 +61,25 @@ static int result; * Report line of error if @a cond is true, and jump to label "drop". */ #define FAILIF(cond) \ - do { \ - if (! (cond)) { break;} \ - GNUNET_break (0); \ - goto drop; \ - } while (0) + do { \ + if (! (cond)) { break;} \ + GNUNET_break (0); \ + goto drop; \ + } while (0) /** * Initializes @a ptr with random data. */ #define RND_BLK(ptr) \ - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ - ptr)) + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ + ptr)) /** * Initializes @a ptr with zeros. */ #define ZR_BLK(ptr) \ - memset (ptr, 0, sizeof (*ptr)) + memset (ptr, 0, sizeof (*ptr)) /** * How big do we make the RSA keys? @@ -66,7 +94,7 @@ static int result; /** * Database plugin under test. */ -static struct DONAUDB_Plugin *plugin; +static struct DONAUDB_PostgresContext *ctx; /** * Return charities information. @@ -181,25 +209,25 @@ run (void *cls) struct GNUNET_CRYPTO_RsaBlindedMessage *rsa; if (NULL == - (plugin = DONAUDB_plugin_load (cfg))) + (ctx = DONAUDB_connect (cfg))) { fprintf (stderr, "Failed to load DB plugin\n"); result = 77; return; } - (void) plugin->drop_tables (plugin->cls); + (void) DONAUDB_drop_tables (ctx); if (GNUNET_OK != - plugin->create_tables (plugin->cls)) + DONAUDB_create_tables (ctx)) { fprintf (stderr, "Failed to create DB tables\n"); result = 77; goto cleanup; } - plugin->preflight (plugin->cls); + DONAUDB_preflight (ctx); FAILIF (GNUNET_OK != - plugin->start (plugin->cls, + DONAUDB_start (ctx, "test-1")); fprintf (stderr, @@ -208,7 +236,7 @@ run (void *cls) /* test DB is empty */ charity_id = 1; FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - plugin->lookup_charity (plugin->cls, + DONAUDB_lookup_charity (ctx, charity_id, &charity_meta)); @@ -225,7 +253,7 @@ run (void *cls) &receipts_to_date)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->insert_charity (plugin->cls, + DONAUDB_insert_charity (ctx, &charity_pub, charity_name, charity_url, @@ -234,7 +262,7 @@ run (void *cls) /* test get charities */ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->get_charities (plugin->cls, + DONAUDB_get_charities (ctx, &charities_cb, charities)); @@ -254,7 +282,7 @@ run (void *cls) TALER_string_to_amount (CURRENCY ":2.000000", &updated_max)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->update_charity (plugin->cls, + DONAUDB_update_charity (ctx, charity_id, &updated_charity_pub, updated_charity_name, @@ -263,7 +291,7 @@ run (void *cls) ZR_BLK (&charity_meta); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->lookup_charity (plugin->cls, + DONAUDB_lookup_charity (ctx, charity_id, &charity_meta)); GNUNET_assert (0 == GNUNET_memcmp (&charity_meta.charity_pub, @@ -285,7 +313,7 @@ run (void *cls) /* test delete charity */ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - plugin->do_charity_delete (plugin->cls, + DONAUDB_do_charity_delete (ctx, charity_id)); /* test insert donation unit */ @@ -303,12 +331,12 @@ run (void *cls) /* test iterate donation units */ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - plugin->iterate_donation_units (plugin->cls, + DONAUDB_iterate_donation_units (ctx, &donation_unit_info_cb, NULL)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->insert_donation_unit (plugin->cls, + DONAUDB_insert_donation_unit (ctx, &h_donation_unit_pub, &du_pub, validity_year, @@ -316,7 +344,7 @@ run (void *cls) /* test iterate donation units */ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->iterate_donation_units (plugin->cls, + DONAUDB_iterate_donation_units (ctx, &donation_unit_info_cb, NULL)); @@ -330,13 +358,13 @@ run (void *cls) sk_meta.valid_from = now; FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->insert_signing_key (plugin->cls, + DONAUDB_insert_signing_key (ctx, &donau_pub, &sk_meta)); /* test iterate signing key */ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->iterate_active_signing_keys (plugin->cls, + DONAUDB_iterate_active_signing_keys (ctx, &iterate_active_signing_keys_cb, NULL)); @@ -366,7 +394,7 @@ run (void *cls) TALER_denom_priv_free (&denom_priv); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->insert_issued_receipt (plugin->cls, + DONAUDB_insert_issued_receipt (ctx, num_b_sigs, du_sigs, charity_id, @@ -376,7 +404,7 @@ run (void *cls) // FIXME // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // plugin->lookup_issued_receipts (plugin->cls, + // DONAUDB_lookup_issued_receipts (ctx, // &h_receipt, // &ir_meta)); @@ -386,24 +414,24 @@ run (void *cls) // RND_BLK (&donation_receipts[0].nonce); // RND_BLK (&donation_receipts[0].donation_unit_sig); // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // plugin->insert_submitted_receipts (plugin->cls, + // DONAUDB_insert_submitted_receipts (ctx, // &h_donor_tax_id, // num_dr, // donation_receipts, // current_year)); - plugin->preflight (plugin->cls); + DONAUDB_preflight (ctx); result = 0; drop: if (0 != result) - plugin->rollback (plugin->cls); + DONAUDB_rollback (ctx); GNUNET_break (GNUNET_OK == - plugin->drop_tables (plugin->cls)); + DONAUDB_drop_tables (ctx)); cleanup: - DONAUDB_plugin_unload (plugin); - plugin = NULL; + DONAUDB_disconnect (ctx); + ctx = NULL; } diff --git a/src/donaudb/update_charity.c b/src/donaudb/update_charity.c @@ -0,0 +1,61 @@ +/* + 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 src/donaudb/update_charity.c + * @brief Implementation of the update_charity function for Postgres + * @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 "update_charity.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_update_charity (struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id, + const struct DONAU_CharityPublicKeyP *charity_pub, + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&charity_id), + GNUNET_PQ_query_param_auto_from_type (charity_pub), + GNUNET_PQ_query_param_string (charity_name), + GNUNET_PQ_query_param_string (charity_url), + TALER_PQ_query_param_amount (ctx->conn, + max_per_year), + GNUNET_PQ_query_param_end + }; + + PREPARE (ctx, + "update_charity", + "UPDATE charities" + " SET charity_pub = $2" + " ,charity_name = $3" + " ,charity_url = $4" + " ,max_per_year = $5" + " WHERE charity_id = $1;"); + return GNUNET_PQ_eval_prepared_non_select (ctx->conn, + "update_charity", + params); +} + + +/* end of pg_update_charity.c */ diff --git a/src/include/Makefile.am b/src/include/Makefile.am @@ -4,13 +4,44 @@ donauincludedir = $(includedir)/donau donauinclude_HEADERS = \ donau_crypto_lib.h \ donaudb_lib.h \ - donaudb_plugin.h \ donau_json_lib.h \ donau_pq_lib.h \ donau_service.h \ donau_signatures.h \ donau_testing_lib.h \ - donau_util.h + donau_util.h + +donaudbincludedir = $(includedir)/donau/donau-database + +donaudbinclude_HEADERS = \ + donau-database/commit.h \ + donau-database/create_tables.h \ + donau-database/do_charity_delete.h \ + donau-database/drop_tables.h \ + donau-database/event_listen.h \ + donau-database/event_listen_cancel.h \ + donau-database/event_notify.h \ + donau-database/get_charities.h \ + donau-database/get_history.h \ + donau-database/insert_charity.h \ + donau-database/insert_donation_unit.h \ + donau-database/insert_history_entry.h \ + donau-database/insert_issued_receipt.h \ + donau-database/insert_signing_key.h \ + donau-database/insert_submitted_receipts.h \ + donau-database/iterate_active_signing_keys.h \ + donau-database/iterate_donation_units.h \ + donau-database/iterate_submitted_receipts.h \ + donau-database/lookup_charity.h \ + donau-database/lookup_donation_unit_amount.h \ + donau-database/lookup_issued_receipts.h \ + donau-database/lookup_signing_key.h \ + donau-database/preflight.h \ + donau-database/rollback.h \ + donau-database/start.h \ + donau-database/start_read_committed.h \ + donau-database/start_read_only.h \ + donau-database/update_charity.h diff --git a/src/include/donau-database/commit.h b/src/include/donau-database/commit.h @@ -0,0 +1,36 @@ +/* + 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 src/include/donau-database/commit.h + * @brief implementation of the commit function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_COMMIT_H +#define DONAU_DATABASE_COMMIT_H + +#include "donaudb_lib.h" + + +/** + * Commit the current transaction of a database connection. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @return final transaction status + */ +enum GNUNET_DB_QueryStatus +DONAUDB_commit (struct DONAUDB_PostgresContext *ctx); + +#endif diff --git a/src/include/donau-database/create_tables.h b/src/include/donau-database/create_tables.h @@ -0,0 +1,41 @@ +/* + 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 src/include/donau-database/create_tables.h + * @brief implementation of the create_tables function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_CREATE_TABLES_H +#define DONAU_DATABASE_CREATE_TABLES_H + +#include "donaudb_lib.h" + + +/** + * Create the necessary tables if they are not present + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param support_partitions true to enable partitioning support (disables foreign key constraints) + * @param num_partitions number of partitions to create, + * (0 to not actually use partitions, 1 to only + * setup a default partition, >1 for real partitions) + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure + */ +enum GNUNET_GenericReturnValue +DONAUDB_create_tables (struct DONAUDB_PostgresContext *ctx); + + +#endif diff --git a/src/include/donau-database/do_charity_delete.h b/src/include/donau-database/do_charity_delete.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 src/include/donau-database/do_charity_delete.h + * @brief implementation of the do_charity_delete function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_DO_CHARITY_DELETE_H +#define DONAU_DATABASE_DO_CHARITY_DELETE_H + +#include "donaudb_lib.h" + + +/** + * Function called to explicitly delete a charity. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param charity_id charity to delete + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_do_charity_delete ( + struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id); + +#endif diff --git a/src/include/donau-database/drop_tables.h b/src/include/donau-database/drop_tables.h @@ -0,0 +1,36 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/drop_tables.h + * @brief implementation of the drop_tables function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_DROP_TABLES_H +#define DONAU_DATABASE_DROP_TABLES_H + +#include "donaudb_lib.h" + + +/** + * Drop all Taler tables. This should only be used by testcases. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure + */ +enum GNUNET_GenericReturnValue +DONAUDB_drop_tables (struct DONAUDB_PostgresContext *ctx); + +#endif diff --git a/src/include/donau-database/event_listen.h b/src/include/donau-database/event_listen.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/event_listen.h + * @brief implementation of the event_listen function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_EVENT_LISTEN_H +#define DONAU_DATABASE_EVENT_LISTEN_H + +#include "donaudb_lib.h" + + +/** + * Register callback to be invoked on events of type @a es. + * + * @param cls database context to use + * @param timeout how long until to generate a timeout event + * @param es specification of the event to listen for + * @param cb function to call when the event happens, possibly + * multiple times (until cancel is invoked) + * @param cb_cls closure for @a cb + * @return handle useful to cancel the listener + */ +struct GNUNET_DB_EventHandler * +DONAUDB_event_listen (struct DONAUDB_PostgresContext *ctx, + struct GNUNET_TIME_Relative timeout, + const struct GNUNET_DB_EventHeaderP *es, + GNUNET_DB_EventCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/event_listen_cancel.h b/src/include/donau-database/event_listen_cancel.h @@ -0,0 +1,39 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/event_listen_cancel.h + * @brief implementation of the event_listen_cancel function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_EVENT_LISTEN_CANCEL_H +#define DONAU_DATABASE_EVENT_LISTEN_CANCEL_H + +#include "donaudb_lib.h" + + +/** + * Stop notifications. + * + * @param cls the plugin's `struct PostgresClosure` + * @param eh handle to unregister. + */ +void +DONAUDB_event_listen_cancel ( + struct DONAUDB_PostgresContext *ctx, + struct GNUNET_DB_EventHandler *eh); + + +#endif diff --git a/src/include/donau-database/event_notify.h b/src/include/donau-database/event_notify.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/event_notify.h + * @brief implementation of the event_notify function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_EVENT_NOTIFY_H +#define DONAU_DATABASE_EVENT_NOTIFY_H + +#include "donaudb_lib.h" + + +/** + * Notify all that listen on @a es of an event. + * + * @param cls database context to use + * @param es specification of the event to generate + * @param extra additional event data provided + * @param extra_size number of bytes in @a extra + */ +void +DONAUDB_event_notify (struct DONAUDB_PostgresContext *ctx, + const struct GNUNET_DB_EventHeaderP *es, + const void *extra, + size_t extra_size); + +#endif diff --git a/src/include/donau-database/get_charities.h b/src/include/donau-database/get_charities.h @@ -0,0 +1,56 @@ +/* + 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 src/include/donau-database/get_charities.h + * @brief implementation of the get_charities function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_GET_CHARITIES_H +#define DONAU_DATABASE_GET_CHARITIES_H + +#include "donaudb_lib.h" + + +/** + * Return charities. + * + * @param cls closure + */ +typedef enum GNUNET_GenericReturnValue +(*DONAUDB_GetCharitiesCallback)( + void *cls, + uint64_t charity_id, + const struct DONAU_CharityPublicKeyP *charity_pub, + const char *charity_name, + const struct TALER_Amount *max_per_year, + uint32_t current_year, + const struct TALER_Amount *receipts_to_date); + + +/** + * 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 +DONAUDB_get_charities (struct DONAUDB_PostgresContext *ctx, + DONAUDB_GetCharitiesCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/get_history.h b/src/include/donau-database/get_history.h @@ -0,0 +1,53 @@ +/* + 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 src/include/donau-database/get_history.h + * @brief implementation of the get_history function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_GET_HISTORY_H +#define DONAU_DATABASE_GET_HISTORY_H + +#include "donaudb_lib.h" + + +/** + * Return history. + * + * @param cls closure + */ +typedef enum GNUNET_GenericReturnValue +(*DONAUDB_GetHistoryCallback)( + void *cls, + unsigned long long charity_id, + struct TALER_Amount final_amount, + uint64_t donation_year); + + +/** + * Obtain history of charities. + * + * @param cls closure + * @param cb function to call on each result + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_get_history (struct DONAUDB_PostgresContext *ctx, + DONAUDB_GetHistoryCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/insert_charity.h b/src/include/donau-database/insert_charity.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/insert_charity.h + * @brief implementation of the insert_charity function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_CHARITY_H +#define DONAU_DATABASE_INSERT_CHARITY_H + +#include "donaudb_lib.h" + + +/** + * Add a new charity + * + * @param cls closure + * @param charity_pub charity public key + * @param charity_name charity name + * @param charity_url Web site of the charity + * @param max_per_year yearly donation limit + * @param[out] charity_id set to unique ID assigned to this charity + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_insert_charity (struct DONAUDB_PostgresContext *ctx, + const struct DONAU_CharityPublicKeyP *charity_pub, + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year, + uint64_t *charity_id); + +#endif diff --git a/src/include/donau-database/insert_donation_unit.h b/src/include/donau-database/insert_donation_unit.h @@ -0,0 +1,45 @@ +/* + 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 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 src/include/donau-database/insert_donation_unit.h + * @brief implementation of the insert_donation_unit function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_DONATION_UNIT_H +#define DONAU_DATABASE_INSERT_DONATION_UNIT_H + +#include "donaudb_lib.h" + + +/** + * Add donation unit key. + * + * @param cls closure + * @param donation_unit_hash hash of the public key + * @param donation_unit_pub the actual donation_unit key + * @param validity_year validity year + * @param value value that the donation unit represents + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_insert_donation_unit ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + const struct DONAU_DonationUnitPublicKey *donation_unit_pub, + const uint64_t validity_year, + const struct TALER_Amount *value); + +#endif diff --git a/src/include/donau-database/insert_history_entry.h b/src/include/donau-database/insert_history_entry.h @@ -0,0 +1,43 @@ +/* + 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 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 src/include/donau-database/insert_history_entry.h + * @brief implementation of the insert_history_entry function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_HISTORY_ENTRY_H +#define DONAU_DATABASE_INSERT_HISTORY_ENTRY_H + +#include "donaudb_lib.h" + + +/** + * 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 +DONAUDB_insert_history_entry ( + struct DONAUDB_PostgresContext *ctx, + const uint64_t charity_id, + const struct TALER_Amount *final_amount, + const uint64_t donation_year); + +#endif diff --git a/src/include/donau-database/insert_issued_receipt.h b/src/include/donau-database/insert_issued_receipt.h @@ -0,0 +1,49 @@ +/* + 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 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 src/include/donau-database/insert_issued_receipt.h + * @brief implementation of the insert_issued_receipt function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_ISSUED_RECEIPT_H +#define DONAU_DATABASE_INSERT_ISSUED_RECEIPT_H + +#include "donaudb_lib.h" + + +/** + * Insert issued blinded donation receipt to the charity. + * + * @param cls closure + * @param num_blinded_sig + * @param signatures blinded signatures + * @param charity_id identifier of the charity + * @param h_receipt hash of the donation receipt + * @param amount_receipts_request donation amount + * @param smaller_than_max_per_year new receipts to day smaller than the max? + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_insert_issued_receipt ( + struct DONAUDB_PostgresContext *ctx, + const size_t num_blinded_sig, + const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], + const uint64_t charity_id, + const struct DONAU_DonationReceiptHashP *h_receipt, + const struct TALER_Amount *amount_receipts_request, + bool *smaller_than_max_per_year); + +#endif diff --git a/src/include/donau-database/insert_signing_key.h b/src/include/donau-database/insert_signing_key.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/insert_signing_key.h + * @brief implementation of the insert_signing_key function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_SIGNING_KEY_H +#define DONAU_DATABASE_INSERT_SIGNING_KEY_H + +#include "donaudb_lib.h" + + +/** + * 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 +DONAUDB_insert_signing_key ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + +#endif diff --git a/src/include/donau-database/insert_submitted_receipts.h b/src/include/donau-database/insert_submitted_receipts.h @@ -0,0 +1,45 @@ +/* + 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 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 src/include/donau-database/insert_submitted_receipts.h + * @brief implementation of the insert_submitted_receipts function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_SUBMITTED_RECEIPTS_H +#define DONAU_DATABASE_INSERT_SUBMITTED_RECEIPTS_H + +#include "donaudb_lib.h" + + +/** + * Insert submitted donation receipt from the donor. + * + * @param cls closure + * @param h_donor_tax_id salted hash of the donors tax number + * @param num_dr number of donation receipts + * @param donation_receipts array of donation receipts + * @param donation_year year of the donation + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_insert_submitted_receipts ( + struct DONAUDB_PostgresContext *ctx, + struct DONAU_HashDonorTaxId *h_donor_tax_id, + size_t num_dr, + const struct DONAU_DonationReceipt donation_receipts[static num_dr], + uint64_t donation_year); + +#endif diff --git a/src/include/donau-database/iterate_active_signing_keys.h b/src/include/donau-database/iterate_active_signing_keys.h @@ -0,0 +1,54 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/iterate_active_signing_keys.h + * @brief implementation of the iterate_active_signing_keys function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_ITERATE_ACTIVE_SIGNING_KEYS_H +#define DONAU_DATABASE_ITERATE_ACTIVE_SIGNING_KEYS_H + +#include "donaudb_lib.h" + +/** + * Signature of a function called with information about the donau's + * signing keys. + * + * @param cls closure with a `struct DH_KeyStateHandle *` + * @param donau_pub public key of the donau + * @param meta meta data information about the signing type (expirations) + */ +typedef void +(*DONAUDB_IterateActiveSigningKeysCallback)( + void *cls, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + +/** + * 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 +DONAUDB_iterate_active_signing_keys ( + struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateActiveSigningKeysCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/iterate_donation_units.h b/src/include/donau-database/iterate_donation_units.h @@ -0,0 +1,53 @@ +/* + 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 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 src/include/donau-database/iterate_donation_units.h + * @brief implementation of the iterate_donation_units function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_ITERATE_DONATION_UNITS_H +#define DONAU_DATABASE_ITERATE_DONATION_UNITS_H + +#include "donaudb_lib.h" + +/** + * Return donation units. + * + * @param cls closure + */ +typedef enum GNUNET_GenericReturnValue +(*DONAUDB_IterateDonationUnitsCallback)( + void *cls, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + const struct DONAU_DonationUnitPublicKey *donation_unit_pub, + uint64_t validity_year, + struct TALER_Amount *value); + + +/** + * 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 +DONAUDB_iterate_donation_units (struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateDonationUnitsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/iterate_submitted_receipts.h b/src/include/donau-database/iterate_submitted_receipts.h @@ -0,0 +1,43 @@ +/* + 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_iterate_donation_units.h + * @brief implementation of the iterate_donation_units function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_ITERATE_SUBMITTED_RECEIPTS_H +#define DONAU_DATABASE_ITERATE_SUBMITTED_RECEIPTS_H + +#include "donaudb_lib.h" + + +/** + * Obtain information about the enabled wire accounts of the exchange. + * + * @param cls closure + * @param donation_year donation year + * @param h_donor_tax_id hash of donor tax id + * @param[out] total_donations amount of total donations + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_iterate_submitted_receipts ( + struct DONAUDB_PostgresContext *ctx, + const uint64_t donation_year, + const struct DONAU_HashDonorTaxId *h_donor_tax_id, + struct TALER_Amount *total_donations); + +#endif diff --git a/src/include/donau-database/lookup_charity.h b/src/include/donau-database/lookup_charity.h @@ -0,0 +1,41 @@ +/* + 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 src/include/donau-database/lookup_charity.h + * @brief implementation of the lookup_charity function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_LOOKUP_CHARITY_H +#define DONAU_DATABASE_LOOKUP_CHARITY_H + +#include "donaudb_lib.h" + + +/** + * Fetch information about a charity. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param charity_id the charity id + * @param meta charity meta data information + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_charity ( + struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id, + struct DONAUDB_CharityMetaData *meta); + +#endif diff --git a/src/include/donau-database/lookup_donation_unit_amount.h b/src/include/donau-database/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 src/include/donau-database/lookup_donation_unit_amount.h + * @brief Getting the donation unit amount + * @author Bohdan Potuzhnyi + */ +#ifndef DONAU_DATABASE_LOOKUP_DONATION_UNIT_AMOUNT_H +#define DONAU_DATABASE_LOOKUP_DONATION_UNIT_AMOUNT_H + +#include "donaudb_lib.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 DONAUDB_* lookup: + * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT (==1) on success, + * 0 if not found, negative on hard error. + */ +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_donation_unit_amount ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct TALER_Amount *value); + +#endif /* DONAU_DATABASE_LOOKUP_DONATION_UNIT_AMOUNT_H */ diff --git a/src/include/donau-database/lookup_issued_receipts.h b/src/include/donau-database/lookup_issued_receipts.h @@ -0,0 +1,41 @@ +/* + 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 src/include/donau-database/lookup_issued_receipts.h + * @brief implementation of the lookup_issued_receipts function for Postgres + * @author Lukas Matyja + */ +#ifndef DONAU_DATABASE_LOOKUP_ISSUED_RECEIPTS_H +#define DONAU_DATABASE_LOOKUP_ISSUED_RECEIPTS_H + +#include "donaudb_lib.h" + + +/** + * Fetch information about an issued receipts request. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param h_receipts hash over the issued receipt + * @param meta information with value and other info about the issued receipts + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_lookup_issued_receipts ( + struct DONAUDB_PostgresContext *ctx, + struct DONAU_DonationReceiptHashP *h_receipts, + struct DONAUDB_IssuedReceiptsMetaData *meta); + +#endif diff --git a/src/include/donau-database/lookup_signing_key.h b/src/include/donau-database/lookup_signing_key.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/lookup_signing_key.h + * @brief implementation of the lookup_signing_key function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_LOOKUP_SIGNING_KEY_H +#define DONAU_DATABASE_LOOKUP_SIGNING_KEY_H + +#include "donaudb_lib.h" + + +/** + * 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 +DONAUDB_lookup_signing_key ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + +#endif diff --git a/src/include/donau-database/preflight.h b/src/include/donau-database/preflight.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/preflight.h + * @brief implementation of the preflight function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_PREFLIGHT_H +#define DONAU_DATABASE_PREFLIGHT_H + +#include "donaudb_lib.h" + + +/** + * Do a pre-flight check that we are not in an uncommitted transaction. + * If we are, try to commit the previous transaction and output a warning. + * Does not return anything, as we will continue regardless of the outcome. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @return #GNUNET_OK if everything is fine + * #GNUNET_NO if a transaction was rolled back + * #GNUNET_SYSERR on hard errors + */ +enum GNUNET_GenericReturnValue +DONAUDB_preflight (struct DONAUDB_PostgresContext *ctx); + + +#endif diff --git a/src/include/donau-database/rollback.h b/src/include/donau-database/rollback.h @@ -0,0 +1,35 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/rollback.h + * @brief implementation of the rollback function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_ROLLBACK_H +#define DONAU_DATABASE_ROLLBACK_H + +#include "donaudb_lib.h" + + +/** + * Roll back the current transaction of a database connection. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + */ +void +DONAUDB_rollback (struct DONAUDB_PostgresContext *ctx); + +#endif diff --git a/src/include/donau-database/start.h b/src/include/donau-database/start.h @@ -0,0 +1,40 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/start.h + * @brief implementation of the start function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_START_H +#define DONAU_DATABASE_START_H + +#include "donaudb_lib.h" + + +/** + * Start a transaction. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param name unique name identifying the transaction (for debugging) + * must point to a constant + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +DONAUDB_start ( + struct DONAUDB_PostgresContext *ctx, + const char *name); + +#endif diff --git a/src/include/donau-database/start_read_committed.h b/src/include/donau-database/start_read_committed.h @@ -0,0 +1,40 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/start_read_committed.h + * @brief implementation of the start_read_committed function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_START_READ_COMMITTED_H +#define DONAU_DATABASE_START_READ_COMMITTED_H + +#include "donaudb_lib.h" + + +/** + * Start a READ COMMITTED transaction. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param name unique name identifying the transaction (for debugging) + * must point to a constant + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +DONAUDB_start_read_committed ( + struct DONAUDB_PostgresContext *ctx, + const char *name); + +#endif diff --git a/src/include/donau-database/start_read_only.h b/src/include/donau-database/start_read_only.h @@ -0,0 +1,40 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/donau-database/start_read_only.h + * @brief implementation of the start_read_only function for Postgres + * @author Christian Grothoff + */ +#ifndef DONAU_DATABASE_START_READ_ONLY_H +#define DONAU_DATABASE_START_READ_ONLY_H + +#include "donaudb_lib.h" + + +/** + * Start a READ ONLY serializable transaction. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param name unique name identifying the transaction (for debugging) + * must point to a constant + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +DONAUDB_start_read_only ( + struct DONAUDB_PostgresContext *ctx, + const char *name); + +#endif diff --git a/src/include/donau-database/update_charity.h b/src/include/donau-database/update_charity.h @@ -0,0 +1,47 @@ +/* + 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 src/include/donau-database/update_charity.h + * @brief Implementation of the update_charity function for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef DONAU_DATABASE_UPDATE_CHARITY_H +#define DONAU_DATABASE_UPDATE_CHARITY_H + +#include "donaudb_lib.h" + + +/** + * Update an existing charity entry. + * + * @param cls closure + * @param charity_id identifier of the charity to update + * @param charity_pub new public key for the charity + * @param charity_name new name + * @param charity_url new landing page URL + * @param max_per_year yearly donation limit + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_update_charity ( + struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id, + const struct DONAU_CharityPublicKeyP *charity_pub, + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year); + +#endif diff --git a/src/include/donaudb_lib.h b/src/include/donaudb_lib.h @@ -25,26 +25,156 @@ COPYING.If not, see <http: // www.gnu.org/licenses/> #ifndef DONAUDB_LIB_H #define DONAUDB_LIB_H +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "donau_util.h" #include "donau_signatures.h" -#include "donaudb_plugin.h" /** - * Initialize the plugin. + * Main handle for the database. + */ +struct DONAUDB_PostgresContext; + + +/** + * Meta data about an donau signing key. + */ +struct DONAUDB_SignkeyMetaData +{ + /** + * Start time of the validity period for this key. + */ + struct GNUNET_TIME_Timestamp valid_from; + + /** + * The donau will sign messages with this key between @e start and this time. + */ + struct GNUNET_TIME_Timestamp expire_sign; + + /** + * When do signatures with this sign key become invalid? + * After this point, these signatures cannot be used in (legal) + * disputes anymore, as the Donau is then allowed to destroy its side + * of the evidence. @e expire_legal is expected to be significantly + * larger than @e expire_sign (by a year or more). + */ + struct GNUNET_TIME_Timestamp expire_legal; + +}; + +/** + * Meta data about a charity. + */ +struct DONAUDB_CharityMetaData +{ + /** + * Charity public key + */ + struct DONAU_CharityPublicKeyP charity_pub; + + /** + * Charity name + */ + char *charity_name; + + /** + * Charity url + */ + char *charity_url; + + /** + * Charity yearly donation limit + */ + struct TALER_Amount max_per_year; + + /** + * Charity donations received in the current year + */ + struct TALER_Amount receipts_to_date; + + /** + * Current year + */ + uint32_t current_year; + +}; + +/** + * 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; + + /** + * number of signatures + */ + size_t num_sig; + + /** + * Array of blinded signatures + */ + struct DONAU_BlindedDonationUnitSignature *blinded_sigs; + +}; + +/** + * @brief All information about a donation unit key. + */ +struct DONAUDB_DonationUnitKey +{ + /** + * The private key of the donation unit. Will be NULL if the private + * key is not available. + */ + struct DONAU_DonationUnitPublicKey donation_unit_priv; + + /** + * Decoded donation unit public key. + */ + struct DONAU_DonationUnitPublicKey donation_unit_pub; + +}; + + +/** + * Connect to the database if the connection does not exist yet. + * + * @param pg the plugin-specific state + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +DONAUDB_internal_setup (struct DONAUDB_PostgresContext *pg); + + +/** + * Connect to the donau database. * * @param cfg configuration to use * @return NULL on failure */ -struct DONAUDB_Plugin * -DONAUDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg); +struct DONAUDB_PostgresContext * +DONAUDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); /** - * Shutdown the plugin. + * Disconnect from the donau database. * - * @param plugin plugin to unload + * @param pg context to disconnect and free */ void -DONAUDB_plugin_unload (struct DONAUDB_Plugin *plugin); +DONAUDB_disconnect (struct DONAUDB_PostgresContext *pg); #endif diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -1,647 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014-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 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 include/donaudb_plugin.h - * @brief Low-level (statement-level) database access for the donau - * @author Johannes Casaburi - */ -#ifndef DONAUDB_PLUGIN_H -#define DONAUDB_PLUGIN_H -// #include <jansson.h> -#include <gnunet/gnunet_db_lib.h> -#include <taler/taler_json_lib.h> -#include "donau_signatures.h" -#include "donau_util.h" - -/** - * Meta data about an donau signing key. - */ -struct DONAUDB_SignkeyMetaData -{ - /** - * Start time of the validity period for this key. - */ - struct GNUNET_TIME_Timestamp valid_from; - - /** - * The donau will sign messages with this key between @e start and this time. - */ - struct GNUNET_TIME_Timestamp expire_sign; - - /** - * When do signatures with this sign key become invalid? - * After this point, these signatures cannot be used in (legal) - * disputes anymore, as the Donau is then allowed to destroy its side - * of the evidence. @e expire_legal is expected to be significantly - * larger than @e expire_sign (by a year or more). - */ - struct GNUNET_TIME_Timestamp expire_legal; - -}; - -/** - * Meta data about a charity. - */ -struct DONAUDB_CharityMetaData -{ - /** - * Charity public key - */ - struct DONAU_CharityPublicKeyP charity_pub; - - /** - * Charity name - */ - char *charity_name; - - /** - * Charity url - */ - char *charity_url; - - /** - * Charity yearly donation limit - */ - struct TALER_Amount max_per_year; - - /** - * Charity donations received in the current year - */ - struct TALER_Amount receipts_to_date; - - /** - * Current year - */ - uint32_t current_year; - -}; - -/** - * 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; - - /** - * number of signatures - */ - size_t num_sig; - - /** - * Array of blinded signatures - */ - struct DONAU_BlindedDonationUnitSignature *blinded_sigs; - -}; - -/** - * @brief All information about a donation unit key. - */ -struct DONAUDB_DonationUnitKey -{ - /** - * The private key of the donation unit. Will be NULL if the private - * key is not available. - */ - struct DONAU_DonationUnitPublicKey donation_unit_priv; - - /** - * Decoded donation unit public key. - */ - struct DONAU_DonationUnitPublicKey donation_unit_pub; - -}; - - -/** - * Signature of a function called with information about the donau's - * signing keys. - * - * @param cls closure with a `struct DH_KeyStateHandle *` - * @param donau_pub public key of the donau - * @param meta meta data information about the signing type (expirations) - */ -typedef void -(*DONAUDB_IterateActiveSigningKeysCallback)( - void *cls, - const struct DONAU_DonauPublicKeyP *donau_pub, - struct DONAUDB_SignkeyMetaData *meta); - -/** - * Return donation units. - * - * @param cls closure - */ -typedef enum GNUNET_GenericReturnValue -(*DONAUDB_IterateDonationUnitsCallback)( - void *cls, - const struct DONAU_DonationUnitHashP *h_donation_unit_pub, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - uint64_t validity_year, - struct TALER_Amount *value); - - -/** - * Return charities. - * - * @param cls closure - */ -typedef enum GNUNET_GenericReturnValue -(*DONAUDB_GetCharitiesCallback)( - void *cls, - uint64_t charity_id, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const struct TALER_Amount *max_per_year, - uint32_t current_year, - const struct TALER_Amount *receipts_to_date); - -/** - * Return history. - * - * @param cls closure - */ -typedef enum GNUNET_GenericReturnValue -(*DONAUDB_GetHistoryCallback)( - void *cls, - unsigned long long charity_id, - struct TALER_Amount final_amount, - uint64_t donation_year); - -/** - * @brief The plugin API, returned from the plugin's "init" function. - * The argument given to "init" is simply a configuration handle. - */ -struct DONAUDB_Plugin -{ - - /** - * Closure for all callbacks. - */ - void *cls; - - /** - * Name of the library which generated this plugin. Set by the - * plugin loader. - */ - char *library_name; - - - /** - * Drop the Taler tables. This should only be used in testcases. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure - */ - enum GNUNET_GenericReturnValue - (*drop_tables)(void *cls); - - /** - * Create the necessary tables if they are not present - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param support_partitions true to enable partitioning support (disables foreign key constraints) - * @param num_partitions number of partitions to create, - * (0 to not actually use partitions, 1 to only - * setup a default partition, >1 for real partitions) - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure - */ - enum GNUNET_GenericReturnValue - (*create_tables)(void *cls); - - - /** - * Start a transaction. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param name unique name identifying the transaction (for debugging), - * must point to a constant - * @return #GNUNET_OK on success - */ - enum GNUNET_GenericReturnValue - (*start)(void *cls, - const char *name); - - - /** - * Start a READ COMMITTED transaction. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param name unique name identifying the transaction (for debugging) - * must point to a constant - * @return #GNUNET_OK on success - */ - enum GNUNET_GenericReturnValue - (*start_read_committed)(void *cls, - const char *name); - - /** - * Start a READ ONLY serializable transaction. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param name unique name identifying the transaction (for debugging) - * must point to a constant - * @return #GNUNET_OK on success - */ - enum GNUNET_GenericReturnValue - (*start_read_only)(void *cls, - const char *name); - - - /** - * Commit a transaction. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @return transaction status - */ - enum GNUNET_DB_QueryStatus - (*commit)(void *cls); - - - /** - * Do a pre-flight check that we are not in an uncommitted transaction. - * If we are, try to commit the previous transaction and output a warning. - * Does not return anything, as we will continue regardless of the outcome. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @return #GNUNET_OK if everything is fine - * #GNUNET_NO if a transaction was rolled back - * #GNUNET_SYSERR on hard errors - */ - enum GNUNET_GenericReturnValue - (*preflight)(void *cls); - - - /** - * Abort/rollback a transaction. - * - * @param cls the @e cls of this struct with the plugin-specific state - */ - void - (*rollback) (void *cls); - - - /** - * Function called to perform "garbage collection" on the - * database, expiring records we no longer require. - * - * @param cls closure - * @return #GNUNET_OK on success, - * #GNUNET_SYSERR on DB errors - */ - enum GNUNET_GenericReturnValue - (*gc)(void *cls); - - - /** - * Register callback to be invoked on events of type @a es. - * - * @param cls database context to use - * @param timeout how long to wait at most - * @param es specification of the event to listen for - * @param cb function to call when the event happens, possibly - * multiple times (until cancel is invoked) - * @param cb_cls closure for @a cb - * @return handle useful to cancel the listener - */ - struct GNUNET_DB_EventHandler * - (*event_listen)(void *cls, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_DB_EventHeaderP *es, - GNUNET_DB_EventCallback cb, - void *cb_cls); - - /** - * Stop notifications. - * - * @param cls database context to use - * @param eh handle to unregister. - */ - void - (*event_listen_cancel)(void *cls, - struct GNUNET_DB_EventHandler *eh); - - - /** - * Notify all that listen on @a es of an event. - * - * @param cls database context to use - * @param es specification of the event to generate - * @param extra additional event data provided - * @param extra_size number of bytes in @a extra - */ - void - (*event_notify)(void *cls, - const struct GNUNET_DB_EventHeaderP *es, - const void *extra, - size_t extra_size); - - /** - * Get charity. - * - * @param cls closure - * @param charity_id - * @param meta - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*lookup_charity)( - void *cls, - uint64_t charity_id, - struct DONAUDB_CharityMetaData *meta); - - /** - * Delete charity. - * - * @param cls closure - * @param charity_id - * @param[out] found set to true if the purse was found - * (if false, purse could not be deleted) - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*do_charity_delete)( - void *cls, - uint64_t charity_id); - - /** - * Get charities. - * - * @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_charities)( - void *cls, - DONAUDB_GetCharitiesCallback cb, - void *cb_cls); - - - /** - * Insert Charity - * - * @param cls closure - * @param charity_pub charity public key - * @param charity_name name of the charity - * @param charity_url Web site fo the charity - * @param max_per_year yearly donation limit - * @param[out] charity_id set to unique ID assigned to this charity, - * set to 0 on conflict (@a charity_pub exists, but with different data) - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*insert_charity)( - void *cls, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - const struct TALER_Amount *max_per_year, - uint64_t *charity_id); - - - /** - * Update existing charity meta data. - * - * @param cls closure - * @param charity_id identifier of the charity to update - * @param charity_pub new public key - * @param charity_name new human-readable name - * @param charity_url new URL of the charity - * @param max_per_year new yearly donation cap - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*update_charity)( - void *cls, - uint64_t charity_id, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - const struct TALER_Amount *max_per_year); - - - /** - * Iterate donation units. - * - * @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 - (*iterate_donation_units)( - void *cls, - DONAUDB_IterateDonationUnitsCallback 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 unsigned long long charity_id, - const struct TALER_Amount *final_amount, - const uint64_t donation_year); - - /** - * Insert donation_unit. - * - * @param cls closure - * @param donation_unit_pub - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*insert_donation_unit)( - void *cls, - const struct DONAU_DonationUnitHashP *h_donation_unit_pub, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - const uint64_t validity_year, - const struct TALER_Amount *value); - - /** - * 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 num_blinded_sig - * @param signatures blinded signatures - * @param charity_id identifier of the charity - * @param h_receipt hash of the donation receipt - * @param amount_receipts_request donation amount - * @param smaller_than_max_per_year new receipts to day smaller than the max? - * @return transaction status code - */ - enum GNUNET_DB_QueryStatus - (*insert_issued_receipt)( - void *cls, - const size_t num_blinded_sig, - const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], - const uint64_t charity_id, - const struct DONAU_DonationReceiptHashP *h_receipt, - const struct TALER_Amount *amount_receipts_request, - bool *smaller_than_max_per_year); - - /** - * Insert submitted donation receipt from the donor. - * - * @param cls closure - * @param h_donor_tax_id 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_receipts)( - void *cls, - struct DONAU_HashDonorTaxId *h_donor_tax_id, - size_t num_dr, - const struct DONAU_DonationReceipt donation_receipts[static num_dr], - uint64_t donation_year); - - /** - * Iterate submitted donation receipt. - * - * @param cls closure - * @param value - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*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 - * @param h_receipts the hash over the blinded unique identifiers - * @param meta meta data about an issued request - * @return transaction status code - */ - enum GNUNET_DB_QueryStatus - (*lookup_issued_receipts)( - void *cls, - struct DONAU_DonationReceiptHashP *h_receitps, - struct DONAUDB_IssuedReceiptsMetaData *meta); - - /** - * 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); - - /** - * Iterate donau signing 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 - (*iterate_active_signing_keys)( - void *cls, - DONAUDB_IterateActiveSigningKeysCallback cb, - void *cb_cls); - -}; - -#endif