donau

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

commit 209bfa4ebb4604fc34c36827f516960b3a351345
parent e9a074179f1647f5fbe6838de96e5d30263cd825
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 22 Jul 2026 03:02:05 +0200

donaudb: do major DB renaming

Diffstat:
Acontrib/check-db-naming.py | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontrib/ci/jobs/6-db-naming/job.sh | 4++++
Mdebian/control | 2+-
Mmeson.build | 2+-
Msrc/donau/donau-httpd_delete-charities-CHARITY_ID.c | 6+++---
Msrc/donau/donau-httpd_get-charities.c | 8++++----
Msrc/donau/donau-httpd_get-charities.h | 4++--
Msrc/donau/donau-httpd_get-charity-CHARITY_ID.c | 8++++----
Msrc/donau/donau-httpd_get-donation-statement-YEAR-HASH_DONOR_ID.c | 10+++++-----
Msrc/donau/donau-httpd_get-history.c | 8++++----
Msrc/donau/donau-httpd_get-history.h | 4++--
Msrc/donau/donau-httpd_get-keys.c | 18+++++++++---------
Msrc/donau/donau-httpd_patch-charities-CHARITY_ID.c | 10+++++-----
Msrc/donau/donau-httpd_post-batch-issue-CHARITY_ID.c | 35++++++++++++++++++-----------------
Msrc/donau/donau-httpd_post-batch-submit.c | 8++++----
Msrc/donaudb/commit.c | 5++---
Asrc/donaudb/delete_charity.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/do_charity_delete.c | 45---------------------------------------------
Asrc/donaudb/do_insert_receipt_issued.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/donaudb/donau_do_insert_issued_receipts.sql -> src/donaudb/do_insert_receipt_issued.sql | 0
Dsrc/donaudb/get_charities.c | 159-------------------------------------------------------------------------------
Asrc/donaudb/get_charity.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/get_donation_unit_amount.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/get_history.c | 139-------------------------------------------------------------------------------
Asrc/donaudb/get_receipt_issued.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/get_receipts_submitted_total.c | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/get_signkey.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/helper.h | 2+-
Rsrc/donaudb/donau_do_insert_charity.sql -> src/donaudb/insert_charity.sql | 0
Msrc/donaudb/insert_donation_unit.c | 4++--
Dsrc/donaudb/insert_issued_receipt.c | 78------------------------------------------------------------------------------
Asrc/donaudb/insert_receipts_submitted.c | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/donaudb/donau_do_insert_submitted_receipts.sql -> src/donaudb/insert_receipts_submitted.sql | 0
Dsrc/donaudb/insert_signing_key.c | 55-------------------------------------------------------
Asrc/donaudb/insert_signkey.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/insert_submitted_receipts.c | 103-------------------------------------------------------------------------------
Dsrc/donaudb/iterate_active_signing_keys.c | 138-------------------------------------------------------------------------------
Asrc/donaudb/iterate_active_signkeys.c | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/iterate_charities.c | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/iterate_history_entries.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/iterate_submitted_receipts.c | 84-------------------------------------------------------------------------------
Dsrc/donaudb/lookup_charity.c | 70----------------------------------------------------------------------
Dsrc/donaudb/lookup_donation_unit_amount.c | 56--------------------------------------------------------
Dsrc/donaudb/lookup_issued_receipts.c | 77-----------------------------------------------------------------------------
Dsrc/donaudb/lookup_signing_key.c | 62--------------------------------------------------------------
Msrc/donaudb/meson.build | 30+++++++++++++++---------------
Msrc/donaudb/pg_template.c | 2+-
Msrc/donaudb/pg_template.h | 2+-
Msrc/donaudb/plugin_donaudb_postgres.c | 2+-
Msrc/donaudb/test_donaudb.c | 82++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/donaudb/update_charity.c | 2+-
Msrc/include/Makefile.am | 24++++++++++++------------
Msrc/include/donau-database/commit.h | 2+-
Msrc/include/donau-database/create_tables.h | 2+-
Asrc/include/donau-database/delete_charity.h | 39+++++++++++++++++++++++++++++++++++++++
Dsrc/include/donau-database/do_charity_delete.h | 39---------------------------------------
Asrc/include/donau-database/do_insert_receipt_issued.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/donau-database/drop_tables.h | 2+-
Msrc/include/donau-database/event_listen.h | 2+-
Msrc/include/donau-database/event_listen_cancel.h | 2+-
Msrc/include/donau-database/event_notify.h | 2+-
Dsrc/include/donau-database/get_charities.h | 56--------------------------------------------------------
Asrc/include/donau-database/get_charity.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/get_donation_unit_amount.h | 43+++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/donau-database/get_history.h | 53-----------------------------------------------------
Asrc/include/donau-database/get_receipt_issued.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/get_receipts_submitted_total.h | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/get_signkey.h | 41+++++++++++++++++++++++++++++++++++++++++
Dsrc/include/donau-database/insert_issued_receipt.h | 51---------------------------------------------------
Asrc/include/donau-database/insert_receipts_submitted.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/donau-database/insert_signing_key.h | 41-----------------------------------------
Asrc/include/donau-database/insert_signkey.h | 41+++++++++++++++++++++++++++++++++++++++++
Dsrc/include/donau-database/insert_submitted_receipts.h | 45---------------------------------------------
Dsrc/include/donau-database/iterate_active_signing_keys.h | 54------------------------------------------------------
Asrc/include/donau-database/iterate_active_signkeys.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/iterate_charities.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/donau-database/iterate_history_entries.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/donau-database/iterate_submitted_receipts.h | 43-------------------------------------------
Dsrc/include/donau-database/lookup_charity.h | 41-----------------------------------------
Dsrc/include/donau-database/lookup_donation_unit_amount.h | 43-------------------------------------------
Dsrc/include/donau-database/lookup_issued_receipts.h | 41-----------------------------------------
Dsrc/include/donau-database/lookup_signing_key.h | 41-----------------------------------------
Msrc/include/donau-database/meson.build | 24++++++++++++------------
Msrc/include/donau-database/preflight.h | 2+-
Msrc/include/donau-database/rollback.h | 2+-
Msrc/include/donau-database/start.h | 2+-
Msrc/include/donau-database/start_read_committed.h | 2+-
Msrc/include/donau-database/start_read_only.h | 2+-
88 files changed, 1910 insertions(+), 1776 deletions(-)

diff --git a/contrib/check-db-naming.py b/contrib/check-db-naming.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +"""Enforce the database layer naming convention. + +Rules checked (see the commit series "database naming cleanup"): + + 1. every public function's name starts with the name of the file it lives in + 2. the file's own name uses a prefix from the closed set, or is exempt + 3. iterate_ iff the function takes a caller-supplied callback; get_ iff not + 4. a .h exists beside every .c, and a .sql (if any) shares the name + 5. every prepared statement is named after the function preparing it + 6. no prepared statement name is used in two files + 7. no numeric suffixes and no repeated library prefix + +Run from the top of the source tree; exits non-zero on any violation. +""" +import re +import sys +import pathlib + +# ---------------------------------------------------------------- CONFIG -- +# (impl dir, header dir, symbol prefix, .c basename prefix) +LAYERS = [ + ("src/donaudb", "src/include/donau-database", "DONAUDB_", ""), +] + +# Prefixes that describe what the caller gets. +PREFIXES = ("get_", "get_count_", "get_exists_", "iterate_", + "insert_", "update_", "update_to_", "delete_", "do_") + +# Not CRUD: transaction control, DDL, events, memory, session plumbing, +# cancellable handle APIs, and multi-function helper modules. Keep this list +# short and justified -- every entry is a rule the checker stops enforcing. +EXEMPT = { + "start", "start_read_only", "start_read_committed", "commit", "rollback", + "preflight", "create_tables", "drop_tables", + "event_listen", "event_listen_cancel", "event_notify", +} + +# Files that are not part of the API surface at all. plugin_donaudb_postgres.c +# is not a plugin vtable despite the name; it holds the connect/disconnect and +# reconnect plumbing, and is skipped by the plugin_ rule below. +SKIP = {"helper", "pg_template"} +# ------------------------------------------------------------ END CONFIG -- + +PREP = re.compile(r'PREPARE\s*\(\s*\w+\s*,\s*"([A-Za-z0-9_]+)"', re.S) + +errors = [] + + +def check_layer(impl_dir, hdr_dir, prefix, fpfx): + impl, hdr = pathlib.Path(impl_dir), pathlib.Path(hdr_dir) + if not impl.is_dir(): + return + decl = re.compile(r"^" + re.escape(prefix) + r"(\w+)\s*\((.*?)\)\s*;", + re.S | re.M) + stmt_owner = {} + + for c in sorted(impl.glob("*.c")): + if c.stem in SKIP or c.stem.startswith("test_") \ + or c.stem.startswith("plugin_"): + continue + if fpfx and not c.stem.startswith(fpfx): + continue + stem = c.stem[len(fpfx):] if fpfx else c.stem + + # 2. prefix from the closed set, or exempt + if stem not in EXEMPT and not stem.startswith(PREFIXES): + errors.append(f"{c}: '{stem}' uses no approved prefix") + + # 7. numeric suffix + if re.search(r"\d$", stem): + errors.append(f"{c}: '{stem}' ends in a digit") + + # 4. matching header + h = hdr / (stem + ".h") + if stem not in EXEMPT and not h.exists(): + errors.append(f"{c}: no matching header {h}") + + text = c.read_text(errors="replace") + + # 5. prepared statements named after the function + for s in dict.fromkeys(PREP.findall(text)): + if s != stem and not s.startswith(stem + "_"): + errors.append( + f"{c}: prepared statement '{s}' is not named after " + f"'{stem}'") + # 6. cross-file uniqueness + if s in stmt_owner and stmt_owner[s] != str(c): + errors.append( + f"{c}: prepared statement '{s}' also prepared in " + f"{stmt_owner[s]}") + stmt_owner[s] = str(c) + + if not h.exists(): + continue + htext = re.sub(r"/\*.*?\*/", "", h.read_text(errors="replace"), + flags=re.S) + for name, params in decl.findall(htext): + # 1. declared names belong to their file. Exempt entries are the + # documented multi-function modules, so this does not apply there. + if (stem not in EXEMPT + and name != stem and not name.startswith(stem + "_")): + errors.append( + f"{h}: declares '{name}', which does not belong to " + f"'{stem}'") + # 3. iterate_ iff callback + has_cb = bool(re.search(r"\w*(Callback|Iterator)\s+\w+", params)) + if name.startswith("iterate_") and not has_cb: + errors.append( + f"{h}: '{name}' is iterate_ but takes no callback") + if name.startswith("get_") and has_cb: + errors.append(f"{h}: '{name}' takes a callback; use iterate_") + + # 7. repeated library prefix anywhere in the tree + head = prefix.split("_")[0] + for f in list(impl.glob("*.[ch]")) + list(hdr.glob("*.h")): + if "unc-backup" in f.name: + continue + if re.search(r"\b" + re.escape(head) + r"_" + re.escape(prefix), + f.read_text(errors="replace")): + errors.append(f"{f}: repeated '{prefix}' prefix") + + +for a in LAYERS: + check_layer(*a) + +for e in errors: + print("ERROR:", e) +print(f"\ndb-naming: {len(errors)} violation(s)") +sys.exit(1 if errors else 0) diff --git a/contrib/ci/jobs/6-db-naming/job.sh b/contrib/ci/jobs/6-db-naming/job.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -exuo pipefail + +exec ./contrib/check-db-naming.py diff --git a/debian/control b/debian/control @@ -7,7 +7,7 @@ Build-Depends: ninja-build, bash, debhelper-compat (= 12), - libgnunet-dev (>=0.27.0), + libgnunet-dev (>=0.28.0~dev5), libtalerexchange-dev (>=1.5.0), libcurl4-gnutls-dev (>=7.35.0) | libcurl4-openssl-dev (>= 7.35.0), libgcrypt20-dev (>=1.8), diff --git a/meson.build b/meson.build @@ -302,7 +302,7 @@ if not get_option('only-doc') ['libdonaujson', '1:0:1'], ['libdonaupq', '0:0:0'], ['libdonautesting', '0:0:0'], - ['libdonaudb', '1:0:0'], + ['libdonaudb', '2:0:0'], ] solibversions = {} diff --git a/src/donau/donau-httpd_delete-charities-CHARITY_ID.c b/src/donau/donau-httpd_delete-charities-CHARITY_ID.c @@ -28,7 +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" +#include "donau-database/delete_charity.h" enum MHD_Result @@ -55,8 +55,8 @@ DH_handler_delete_charities ( { enum GNUNET_DB_QueryStatus qs; - qs = DONAUDB_do_charity_delete (DH_context, - (uint64_t) charity_id); + qs = DONAUDB_delete_charity (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 @@ -27,7 +27,7 @@ #include <taler/taler_signatures.h> #include "donau-httpd.h" #include "donau-httpd_get-charities.h" -#include "donau-database/get_charities.h" +#include "donau-database/iterate_charities.h" /** @@ -91,9 +91,9 @@ DH_handler_get_charities ( charities = json_array (); GNUNET_assert (NULL != charities); - qs = DONAUDB_get_charities (DH_context, - &charities_cb, - charities); + qs = DONAUDB_iterate_charities (DH_context, + &charities_cb, + charities); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-charities.h b/src/donau/donau-httpd_get-charities.h @@ -18,8 +18,8 @@ * @brief Handle GET /charities request * @author Johannes Casaburi */ -#ifndef DONAU_HTTPD_GET_CHARITIES_H -#define DONAU_HTTPD_GET_CHARITIES_H +#ifndef DONAU_HTTPD_ITERATE_CHARITIES_H +#define DONAU_HTTPD_ITERATE_CHARITIES_H #include <microhttpd.h> #include "donau-httpd.h" diff --git a/src/donau/donau-httpd_get-charity-CHARITY_ID.c b/src/donau/donau-httpd_get-charity-CHARITY_ID.c @@ -26,7 +26,7 @@ #include <taler/taler_mhd_lib.h> #include <taler/taler_signatures.h> #include "donau-httpd_get-charity-CHARITY_ID.h" -#include "donau-database/lookup_charity.h" +#include "donau-database/get_charity.h" /** @@ -62,9 +62,9 @@ DH_handler_get_charity ( enum GNUNET_DB_QueryStatus qs; enum MHD_Result result; - qs = DONAUDB_lookup_charity (DH_context, - (uint64_t) charity_id, - &meta); + qs = DONAUDB_get_charity (DH_context, + (uint64_t) charity_id, + &meta); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: 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 @@ -27,7 +27,7 @@ #include <taler/taler_signatures.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" +#include "donau-database/get_receipts_submitted_total.h" enum MHD_Result @@ -72,10 +72,10 @@ DH_handler_get_donation_statement ( enum GNUNET_DB_QueryStatus qs; enum MHD_Result result; - qs = DONAUDB_iterate_submitted_receipts (DH_context, - (uint64_t) donation_year, - &h_donor_tax_id, - &total_donations); + qs = DONAUDB_get_receipts_submitted_total (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-history.c b/src/donau/donau-httpd_get-history.c @@ -27,7 +27,7 @@ #include "taler/taler_signatures.h" #include "donau-httpd.h" #include "donau-httpd_get-history.h" -#include "donau-database/get_history.h" +#include "donau-database/iterate_history_entries.h" /** @@ -84,9 +84,9 @@ DH_handler_get_history ( history = json_array (); GNUNET_assert (NULL != history); - qs = DONAUDB_get_history (DH_context, - &history_cb, - history); + qs = DONAUDB_iterate_history_entries (DH_context, + &history_cb, + history); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donau/donau-httpd_get-history.h b/src/donau/donau-httpd_get-history.h @@ -18,8 +18,8 @@ * @brief Handle /history requests * @author Johannes Casaburi */ -#ifndef DONAU_HTTPD_GET_HISTORY_H -#define DONAU_HTTPD_GET_HISTORY_H +#ifndef DONAU_HTTPD_ITERATE_HISTORY_ENTRIES_H +#define DONAU_HTTPD_ITERATE_HISTORY_ENTRIES_H #include <microhttpd.h> #include "donau-httpd.h" diff --git a/src/donau/donau-httpd_get-keys.c b/src/donau/donau-httpd_get-keys.c @@ -30,9 +30,9 @@ #include "donau-httpd_get-config.h" #include "donaudb_lib.h" #include "donau-database/insert_donation_unit.h" -#include "donau-database/insert_signing_key.h" +#include "donau-database/insert_signkey.h" #include "donau-database/iterate_donation_units.h" -#include "donau-database/iterate_active_signing_keys.h" +#include "donau-database/iterate_active_signkeys.h" #include "donau-database/preflight.h" #include "donau_util.h" @@ -940,9 +940,9 @@ helper_esign_cb ( sk, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - qs = DONAUDB_insert_signing_key (DH_context, - &donau_pubkey, - &sk->meta); + qs = DONAUDB_insert_signkey (DH_context, + &donau_pubkey, + &sk->meta); if (qs < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -1058,7 +1058,7 @@ donation_unit_info_cb ( * @param meta meta data information about the denomination type (expirations) */ static void -iterate_active_signing_keys_cb ( +iterate_active_signkeys_cb ( void *cls, const struct DONAU_DonauPublicKeyP *donau_pub, struct DONAUDB_SignkeyMetaData *meta) @@ -1134,9 +1134,9 @@ build_key_state () /* NOTE: ONLY fetches active signkeys! */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fetching active signing keys from DB\n"); - qs = DONAUDB_iterate_active_signing_keys (DH_context, - &iterate_active_signing_keys_cb, - ksh); + qs = DONAUDB_iterate_active_signkeys (DH_context, + &iterate_active_signkeys_cb, + ksh); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fetched %d active signing keys from DB\n", (int) qs); diff --git a/src/donau/donau-httpd_patch-charities-CHARITY_ID.c b/src/donau/donau-httpd_patch-charities-CHARITY_ID.c @@ -28,7 +28,7 @@ #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/get_charity.h" #include "donau-database/update_charity.h" @@ -88,9 +88,9 @@ DH_handler_patch_charities (struct DH_RequestContext *rc, struct DONAUDB_CharityMetaData meta; enum GNUNET_DB_QueryStatus qs; - qs = DONAUDB_lookup_charity (DH_context, - charity_id, - &meta); + qs = DONAUDB_get_charity (DH_context, + charity_id, + &meta); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -99,7 +99,7 @@ DH_handler_patch_charities (struct DH_RequestContext *rc, return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, - "lookup_charity"); + "get_charity"); case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_NOT_FOUND, diff --git a/src/donau/donau-httpd_post-batch-issue-CHARITY_ID.c b/src/donau/donau-httpd_post-batch-issue-CHARITY_ID.c @@ -30,9 +30,9 @@ #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" +#include "donau-database/get_charity.h" +#include "donau-database/get_receipt_issued.h" +#include "donau-database/do_insert_receipt_issued.h" /** * Parse a bkp encoded in JSON. @@ -231,9 +231,9 @@ DH_handler_post_batch_issue (struct DH_RequestContext *rc, { enum GNUNET_DB_QueryStatus qs_charity; - qs_charity = DONAUDB_lookup_charity (DH_context, - charity_id, - &charity_meta); + qs_charity = DONAUDB_get_charity (DH_context, + charity_id, + &charity_meta); switch (qs_charity) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -332,9 +332,9 @@ DH_handler_post_batch_issue (struct DH_RequestContext *rc, start: qs_check_receipts - = DONAUDB_lookup_issued_receipts (DH_context, - &h_receipts, - &check_receipts_meta); + = DONAUDB_get_receipt_issued (DH_context, + &h_receipts, + &check_receipts_meta); switch (qs_check_receipts) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -486,14 +486,15 @@ 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 = DONAUDB_insert_issued_receipt (DH_context, - year, - num_bkps, - du_sigs, - (uint64_t) charity_id, - &h_receipts, - &receipts_sum, - &smaller_than_max_per_year); + qs_insert_ir + = DONAUDB_do_insert_receipt_issued (DH_context, + year, + 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 @@ -28,11 +28,11 @@ #include "taler/taler_signatures.h" #include "donau-httpd_post-batch-submit.h" #include "donau-httpd_get-keys.h" -#include "donau-database/insert_submitted_receipts.h" +#include "donau-database/insert_receipts_submitted.h" /** - * Closure for #insert_submitted_receipts() + * Closure for #DONAUDB_insert_receipts_submitted() */ struct InsertReceiptContext { @@ -246,7 +246,7 @@ DH_handler_post_batch_submit (struct DH_RequestContext *rc, { enum GNUNET_DB_QueryStatus qs; - qs = DONAUDB_insert_submitted_receipts (DH_context, + qs = DONAUDB_insert_receipts_submitted (DH_context, &irc.h_donor_tax_id, num_dr, irc.donation_receipts, @@ -258,7 +258,7 @@ DH_handler_post_batch_submit (struct DH_RequestContext *rc, return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_STORE_FAILED, - "insert_submitted_receipts"); + "insert_receipts_submitted"); } } /* Note: we do not care here about conflicts on insert, diff --git a/src/donaudb/commit.c b/src/donaudb/commit.c @@ -41,13 +41,12 @@ DONAUDB_commit (struct DONAUDB_PostgresContext *ctx) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Committing transaction `%s'\n", ctx->transaction_name); - /* used in #postgres_commit */ PREPARE (ctx, - "do_commit", + "commit", "COMMIT"); qs = GNUNET_PQ_eval_prepared_non_select (ctx->conn, - "do_commit", + "commit", params); ctx->transaction_name = NULL; return qs; diff --git a/src/donaudb/delete_charity.c b/src/donaudb/delete_charity.c @@ -0,0 +1,45 @@ +/* + 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/delete_charity.c + * @brief Implementation of the delete_charity 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 "delete_charity.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_delete_charity (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 + }; + + PREPARE (ctx, + "delete_charity", + "DELETE FROM charities " + "WHERE charity_id=$1"); + return GNUNET_PQ_eval_prepared_non_select (ctx->conn, + "delete_charity", + params); +} diff --git a/src/donaudb/do_charity_delete.c b/src/donaudb/do_charity_delete.c @@ -1,45 +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 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 - }; - - PREPARE (ctx, - "call_charity_delete", - "DELETE FROM charities " - "WHERE charity_id=$1"); - return GNUNET_PQ_eval_prepared_non_select (ctx->conn, - "call_charity_delete", - params); -} diff --git a/src/donaudb/do_insert_receipt_issued.c b/src/donaudb/do_insert_receipt_issued.c @@ -0,0 +1,78 @@ +/* + 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/do_insert_receipt_issued.c + * @brief Implementation of the do_insert_receipt_issued 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 "do_insert_receipt_issued.h" +#include "helper.h" +#include "donau_service.h" +#include "donau_pq_lib.h" + +enum GNUNET_DB_QueryStatus +DONAUDB_do_insert_receipt_issued ( + struct DONAUDB_PostgresContext *ctx, + uint32_t year, + size_t num_blinded_sig, + const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], + 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_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_uint32 (&year), + GNUNET_PQ_query_param_end + }; + 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 + }; + + enum GNUNET_DB_QueryStatus qs; + PREPARE (ctx, + "do_insert_receipt_issued", + "SELECT " + " out_smaller_than_max_per_year AS smaller_than_max_per_year" + " FROM do_insert_issued_receipts" + "($1,$2,$3,$4,$5);"); + + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "do_insert_receipt_issued", + params, + rs); + GNUNET_PQ_cleanup_query_params_closures (params); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + 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/donau_do_insert_issued_receipts.sql b/src/donaudb/do_insert_receipt_issued.sql diff --git a/src/donaudb/get_charities.c b/src/donaudb/get_charities.c @@ -1,159 +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 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_charity.c b/src/donaudb/get_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 src/donaudb/get_charity.c + * @brief Implementation of the get_charity 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_charity.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_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, + "get_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, + "get_charity", + params, + rs); +} diff --git a/src/donaudb/get_donation_unit_amount.c b/src/donaudb/get_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/get_donation_unit_amount.c + * @brief Implementation of the get_donation_unit_amount 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 "helper.h" +#include "donau_pq_lib.h" +#include "get_donation_unit_amount.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_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, + "get_donation_unit_amount", + "SELECT value" + " FROM donation_units" + " WHERE h_donation_unit_pub=$1;"); + return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "get_donation_unit_amount", + params, + rs); +} diff --git a/src/donaudb/get_history.c b/src/donaudb/get_history.c @@ -1,139 +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 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/get_receipt_issued.c b/src/donaudb/get_receipt_issued.c @@ -0,0 +1,77 @@ +/* + 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/get_receipt_issued.c + * @brief Implementation of the get_receipt_issued 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 "get_receipt_issued.h" +#include "helper.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_receipt_issued (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, + "get_receipt_issued", + "SELECT " + " blinded_sig" + " ,amount" + " ,charity_id" + " FROM receipts_issued" + " WHERE receipt_hash=$1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "get_receipt_issued", + 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/get_receipts_submitted_total.c b/src/donaudb/get_receipts_submitted_total.c @@ -0,0 +1,84 @@ +/* + 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_receipts_submitted_total.c + * @brief Implementation of the get_receipts_submitted_total 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_receipts_submitted_total.h" +#include "helper.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_receipts_submitted_total ( + 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, + "get_receipts_submitted_total", + "SELECT " + " COALESCE(CAST(SUM((donation_units.value).val) AS INT8),0) AS valueSum" + ",COALESCE(CAST(SUM(CAST((donation_units.value).frac AS INT8)) AS INT8),0) 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, + "get_receipts_submitted_total", + 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; + if (GNUNET_OK != + TALER_amount_is_valid (total_donations)) + { + /* Aggregated sum exceeds the representable amount range */ + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + if (TALER_amount_is_zero (total_donations)) + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + return qs; +} diff --git a/src/donaudb/get_signkey.c b/src/donaudb/get_signkey.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/get_signkey.c + * @brief Implementation of the get_signkey 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 "get_signkey.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_get_signkey (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, + "get_signkey", + "SELECT" + " valid_from" + ",expire_sign" + ",expire_legal" + " FROM donau_sign_keys" + " WHERE donau_pub=$1"); + + return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "get_signkey", + params, + rs); +} diff --git a/src/donaudb/helper.h b/src/donaudb/helper.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file helper.h + * @file src/donaudb/helper.h * @brief shared internal definitions for postgres DB plugin * @author Johannes Casaburi */ diff --git a/src/donaudb/donau_do_insert_charity.sql b/src/donaudb/insert_charity.sql diff --git a/src/donaudb/insert_donation_unit.c b/src/donaudb/insert_donation_unit.c @@ -46,7 +46,7 @@ DONAUDB_insert_donation_unit (struct DONAUDB_PostgresContext *ctx, }; PREPARE (ctx, - "donation_unit_insert", + "insert_donation_unit", "INSERT INTO donation_units " "(h_donation_unit_pub" ",donation_unit_pub" @@ -54,6 +54,6 @@ DONAUDB_insert_donation_unit (struct DONAUDB_PostgresContext *ctx, ",value" ") VALUES ($1, $2, $3, $4);"); return GNUNET_PQ_eval_prepared_non_select (ctx->conn, - "donation_unit_insert", + "insert_donation_unit", iparams); } diff --git a/src/donaudb/insert_issued_receipt.c b/src/donaudb/insert_issued_receipt.c @@ -1,78 +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 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, - uint32_t year, - size_t num_blinded_sig, - const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], - 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_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_uint32 (&year), - GNUNET_PQ_query_param_end - }; - 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 - }; - - 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,$5);"); - - qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, - "insert_issued_receipts_request", - params, - rs); - GNUNET_PQ_cleanup_query_params_closures (params); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) - 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_receipts_submitted.c b/src/donaudb/insert_receipts_submitted.c @@ -0,0 +1,103 @@ +/* + 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_receipts_submitted.c + * @brief Implementation of the insert_receipts_submitted 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_receipts_submitted.h" +#include "helper.h" +#include "donau_service.h" +#include "donau_pq_lib.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_receipts_submitted ( + 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, + "insert_receipts_submitted", + "SELECT " + " out_conflict AS conflicted" + " FROM do_insert_submitted_receipts" + "($1,$2,$3,$4,$5);"); + qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, + "insert_receipts_submitted", + params, + rs); + GNUNET_PQ_cleanup_query_params_closures (params); + if (qs > 0) + { + for (size_t i = 0; i < num_dr; i++) + { + if (conflicted[i]) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Submitted donation receipt at index %llu already present!\n", + (unsigned long long) i); + } + } + } + GNUNET_free (conflicted); + GNUNET_PQ_cleanup_result (rs); + return qs; +} diff --git a/src/donaudb/donau_do_insert_submitted_receipts.sql b/src/donaudb/insert_receipts_submitted.sql diff --git a/src/donaudb/insert_signing_key.c b/src/donaudb/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 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_signkey.c b/src/donaudb/insert_signkey.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_signkey.c + * @brief Implementation of the insert_signkey 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_signkey.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +DONAUDB_insert_signkey ( + 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 @@ -1,103 +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 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); - if (qs > 0) - { - for (size_t i = 0; i < num_dr; i++) - { - if (conflicted[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Submitted donation receipt at index %llu already present!\n", - (unsigned long long) 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 @@ -1,138 +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 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 - = GNUNET_TIME_absolute_get (); - 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_active_signkeys.c b/src/donaudb/iterate_active_signkeys.c @@ -0,0 +1,138 @@ +/* + 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_signkeys.c + * @brief Implementation of the iterate_active_signkeys 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_signkeys.h" +#include "helper.h" + +/** + * Closure for #signkeys_cb_helper(). + */ +struct IterateActiveSignkeysContext +{ + /** + * Function to call per result. + */ + DONAUDB_IterateActiveSignkeysCallback 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 IterateActiveSignkeysContext *` + * @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 IterateActiveSignkeysContext *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_signkeys ( + struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateActiveSignkeysCallback cb, + void *cb_cls) +{ + struct GNUNET_TIME_Absolute now + = GNUNET_TIME_absolute_get (); + struct IterateActiveSignkeysContext 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_signkeys", + "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_signkeys", + 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_charities.c b/src/donaudb/iterate_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/iterate_charities.c + * @brief Implementation of the iterate_charities 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_charities.h" +#include "helper.h" + + +/** + * Closure for #iterate_charities_cb(). + */ +struct IterateCharitiesContext +{ + /** + * Function to call per result. + */ + DONAUDB_IterateCharitiesCallback 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 IterateCharitiesContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +iterate_charities_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct IterateCharitiesContext *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_iterate_charities (struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateCharitiesCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct IterateCharitiesContext gctx = { + .cb = cb, + .cb_cls = cb_cls, + .ctx = ctx + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "iterate_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, + "iterate_charities", + params, + &iterate_charities_cb, + &gctx); + if (qs <= 0) + return qs; + return gctx.qs; +} diff --git a/src/donaudb/iterate_history_entries.c b/src/donaudb/iterate_history_entries.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/iterate_history_entries.c + * @brief Implementation of the iterate_history_entries 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_history_entries.h" +#include "helper.h" + + +/** + * Closure for #iterate_history_entries_cb(). + */ +struct IterateHistoryEntriesContext +{ + /** + * Function to call per result. + */ + DONAUDB_IterateHistoryEntriesCallback 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 IterateHistoryEntriesContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +iterate_history_entries_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct IterateHistoryEntriesContext *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_iterate_history_entries (struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateHistoryEntriesCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + struct IterateHistoryEntriesContext gctx = { + .cb = cb, + .cb_cls = cb_cls, + .ctx = ctx + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (ctx, + "iterate_history_entries", + "SELECT" + " charity_id" + ",final_amount" + ",donation_year" + " FROM history"); + qs = GNUNET_PQ_eval_prepared_multi_select (ctx->conn, + "iterate_history_entries", + params, + &iterate_history_entries_cb, + &gctx); + if (qs <= 0) + return qs; + return gctx.qs; +} diff --git a/src/donaudb/iterate_submitted_receipts.c b/src/donaudb/iterate_submitted_receipts.c @@ -1,84 +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 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 " - " COALESCE(CAST(SUM((donation_units.value).val) AS INT8),0) AS valueSum" - ",COALESCE(CAST(SUM(CAST((donation_units.value).frac AS INT8)) AS INT8),0) 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; - if (GNUNET_OK != - TALER_amount_is_valid (total_donations)) - { - /* Aggregated sum exceeds the representable amount range */ - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - if (TALER_amount_is_zero (total_donations)) - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - return qs; -} diff --git a/src/donaudb/lookup_charity.c b/src/donaudb/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 src/donaudb/lookup_charity.c - * @brief Implementation of the lookup_charity 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 @@ -1,56 +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 src/donaudb/lookup_donation_unit_amount.c - * @brief Implementation 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 @@ -1,77 +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 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 @@ -1,62 +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 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/meson.build b/src/donaudb/meson.build @@ -18,9 +18,9 @@ donau_0002 = [ procedures_sql = [ 'procedures-preamble.sql', 'donau_do_amount_specific.sql', - 'donau_do_insert_submitted_receipts.sql', - 'donau_do_insert_issued_receipts.sql', - 'donau_do_insert_charity.sql', + 'insert_receipts_submitted.sql', + 'do_insert_receipt_issued.sql', + 'insert_charity.sql', 'commit.sql', ] @@ -77,23 +77,23 @@ libdonaudb = library( 'rollback.c', 'start_read_committed.c', 'start_read_only.c', - 'insert_signing_key.c', - 'lookup_signing_key.c', - 'iterate_active_signing_keys.c', + 'insert_signkey.c', + 'get_signkey.c', + 'iterate_active_signkeys.c', 'insert_donation_unit.c', 'iterate_donation_units.c', - 'iterate_submitted_receipts.c', - 'get_history.c', - 'get_charities.c', + 'get_receipts_submitted_total.c', + 'iterate_history_entries.c', + 'iterate_charities.c', 'insert_charity.c', 'update_charity.c', - 'do_charity_delete.c', + 'delete_charity.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', + 'get_charity.c', + 'get_receipt_issued.c', + 'get_donation_unit_amount.c', + 'do_insert_receipt_issued.c', + 'insert_receipts_submitted.c', ], soversion: solibversions['libdonaudb']['soversion'], version: solibversions['libdonaudb']['soversion'], diff --git a/src/donaudb/pg_template.c b/src/donaudb/pg_template.c @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donaudb/pg_template.c + * @file src/donaudb/pg_template.c * @brief Implementation of the template function for Postgres * @author Christian Grothoff */ diff --git a/src/donaudb/pg_template.h b/src/donaudb/pg_template.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donaudb/pg_template.h + * @file src/donaudb/pg_template.h * @brief implementation of the template function for Postgres * @author Christian Grothoff */ diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -15,7 +15,7 @@ */ /** - * @file plugin_donaudb_postgres.c + * @file src/donaudb/plugin_donaudb_postgres.c * @brief Low-level (statement-level) Postgres database access for the donau * @author Johannes Casaburi */ diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donaudb/test_donaudb.c + * @file src/donaudb/test_donaudb.c * @brief test cases for DB interaction functions * @author Johannes Casaburi */ @@ -25,26 +25,26 @@ #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/delete_charity.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/iterate_charities.h" +#include "donau-database/iterate_history_entries.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/do_insert_receipt_issued.h" +#include "donau-database/insert_signkey.h" +#include "donau-database/insert_receipts_submitted.h" +#include "donau-database/iterate_active_signkeys.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/get_receipts_submitted_total.h" +#include "donau-database/get_charity.h" +#include "donau-database/get_donation_unit_amount.h" +#include "donau-database/get_receipt_issued.h" +#include "donau-database/get_signkey.h" #include "donau-database/preflight.h" #include "donau-database/rollback.h" #include "donau-database/start.h" @@ -155,7 +155,7 @@ donation_unit_info_cb ( * @param meta meta data information about the denomination type (expirations) */ static void -iterate_active_signing_keys_cb ( +iterate_active_signkeys_cb ( void *cls, const struct DONAU_DonauPublicKeyP *donau_pub, struct DONAUDB_SignkeyMetaData *meta) @@ -236,9 +236,9 @@ run (void *cls) /* test DB is empty */ charity_id = 1; FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - DONAUDB_lookup_charity (ctx, - charity_id, - &charity_meta)); + DONAUDB_get_charity (ctx, + charity_id, + &charity_meta)); /* test insert charity */ charity_name = "charity_name"; @@ -262,9 +262,9 @@ run (void *cls) /* test get charities */ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - DONAUDB_get_charities (ctx, - &charities_cb, - charities)); + DONAUDB_iterate_charities (ctx, + &charities_cb, + charities)); { /* Update the charity and verify the new key and metadata persist. */ @@ -291,9 +291,9 @@ run (void *cls) ZR_BLK (&charity_meta); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - DONAUDB_lookup_charity (ctx, - charity_id, - &charity_meta)); + DONAUDB_get_charity (ctx, + charity_id, + &charity_meta)); GNUNET_assert (0 == GNUNET_memcmp (&charity_meta.charity_pub, &updated_charity_pub)); GNUNET_assert (0 == strcmp (charity_meta.charity_name, @@ -313,8 +313,8 @@ run (void *cls) /* test delete charity */ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - DONAUDB_do_charity_delete (ctx, - charity_id)); + DONAUDB_delete_charity (ctx, + charity_id)); /* test insert donation unit */ RND_BLK (&h_donation_unit_pub); @@ -362,15 +362,15 @@ run (void *cls) FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - DONAUDB_insert_signing_key (ctx, - &donau_pub, - &sk_meta)); + DONAUDB_insert_signkey (ctx, + &donau_pub, + &sk_meta)); /* test iterate signing key */ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - DONAUDB_iterate_active_signing_keys (ctx, - &iterate_active_signing_keys_cb, - NULL)); + DONAUDB_iterate_active_signkeys (ctx, + &iterate_active_signkeys_cb, + NULL)); /* test insert issued receipt */ rp = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage); @@ -396,18 +396,18 @@ run (void *cls) TALER_denom_priv_free (&denom_priv); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - DONAUDB_insert_issued_receipt (ctx, - GNUNET_TIME_get_current_year (), - num_b_sigs, - du_sigs, - charity_id, - &h_receipt, - &amount_receipts, - &smaller_than_max_per_year)); + DONAUDB_do_insert_receipt_issued (ctx, + GNUNET_TIME_get_current_year (), + num_b_sigs, + du_sigs, + charity_id, + &h_receipt, + &amount_receipts, + &smaller_than_max_per_year)); // FIXME // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // DONAUDB_lookup_issued_receipts (ctx, + // DONAUDB_get_receipt_issued (ctx, // &h_receipt, // &ir_meta)); @@ -417,7 +417,7 @@ run (void *cls) // RND_BLK (&donation_receipts[0].nonce); // RND_BLK (&donation_receipts[0].donation_unit_sig); // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // DONAUDB_insert_submitted_receipts (ctx, + // DONAUDB_insert_receipts_submitted (ctx, // &h_donor_tax_id, // num_dr, // donation_receipts, diff --git a/src/donaudb/update_charity.c b/src/donaudb/update_charity.c @@ -58,4 +58,4 @@ DONAUDB_update_charity (struct DONAUDB_PostgresContext *ctx, } -/* end of pg_update_charity.c */ +/* end of update_charity.c */ diff --git a/src/include/Makefile.am b/src/include/Makefile.am @@ -16,26 +16,26 @@ donaudbincludedir = $(includedir)/donau/donau-database donaudbinclude_HEADERS = \ donau-database/commit.h \ donau-database/create_tables.h \ - donau-database/do_charity_delete.h \ + donau-database/delete_charity.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/iterate_charities.h \ + donau-database/iterate_history_entries.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/do_insert_receipt_issued.h \ + donau-database/insert_signkey.h \ + donau-database/insert_receipts_submitted.h \ + donau-database/iterate_active_signkeys.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/get_receipts_submitted_total.h \ + donau-database/get_charity.h \ + donau-database/get_donation_unit_amount.h \ + donau-database/get_receipt_issued.h \ + donau-database/get_signkey.h \ donau-database/preflight.h \ donau-database/rollback.h \ donau-database/start.h \ diff --git a/src/include/donau-database/commit.h b/src/include/donau-database/commit.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/commit.h + * @file src/include/donau-database/commit.h * @brief implementation of the commit function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/create_tables.h b/src/include/donau-database/create_tables.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/create_tables.h + * @file src/include/donau-database/create_tables.h * @brief implementation of the create_tables function for Postgres * @author Johannes Casaburi */ diff --git a/src/include/donau-database/delete_charity.h b/src/include/donau-database/delete_charity.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/delete_charity.h + * @brief implementation of the delete_charity function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_DELETE_CHARITY_H +#define DONAU_DATABASE_DELETE_CHARITY_H + +#include "donaudb_lib.h" + + +/** + * Function called to explicitly delete a charity. + * + * @param ctx 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_delete_charity ( + struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id); + +#endif diff --git a/src/include/donau-database/do_charity_delete.h b/src/include/donau-database/do_charity_delete.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 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 ctx 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/do_insert_receipt_issued.h b/src/include/donau-database/do_insert_receipt_issued.h @@ -0,0 +1,51 @@ +/* + 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/do_do_insert_receipt_issued.h + * @brief implementation of the do_insert_receipt_issued function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_DO_INSERT_RECEIPT_ISSUED_H +#define DONAU_DATABASE_DO_INSERT_RECEIPT_ISSUED_H + +#include "donaudb_lib.h" + + +/** + * Insert issued blinded donation receipt to the charity. + * + * @param ctx closure + * @param year the current year + * @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_do_insert_receipt_issued ( + struct DONAUDB_PostgresContext *ctx, + uint32_t year, + size_t num_blinded_sig, + const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], + 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/drop_tables.h b/src/include/donau-database/drop_tables.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/drop_tables.h + * @file src/include/donau-database/drop_tables.h * @brief implementation of the drop_tables function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/event_listen.h b/src/include/donau-database/event_listen.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/event_listen.h + * @file src/include/donau-database/event_listen.h * @brief implementation of the event_listen function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/event_listen_cancel.h b/src/include/donau-database/event_listen_cancel.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/event_listen_cancel.h + * @file src/include/donau-database/event_listen_cancel.h * @brief implementation of the event_listen_cancel function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/event_notify.h b/src/include/donau-database/event_notify.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/event_notify.h + * @file src/include/donau-database/event_notify.h * @brief implementation of the event_notify function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/get_charities.h b/src/include/donau-database/get_charities.h @@ -1,56 +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 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 ctx database context to use - * @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_charity.h b/src/include/donau-database/get_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/get_charity.h + * @brief implementation of the get_charity function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_GET_CHARITY_H +#define DONAU_DATABASE_GET_CHARITY_H + +#include "donaudb_lib.h" + + +/** + * Fetch information about a charity. + * + * @param ctx 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_get_charity ( + struct DONAUDB_PostgresContext *ctx, + uint64_t charity_id, + struct DONAUDB_CharityMetaData *meta); + +#endif diff --git a/src/include/donau-database/get_donation_unit_amount.h b/src/include/donau-database/get_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/get_donation_unit_amount.h + * @brief implementation of the get_donation_unit_amount function for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef DONAU_DATABASE_GET_DONATION_UNIT_AMOUNT_H +#define DONAU_DATABASE_GET_DONATION_UNIT_AMOUNT_H + +#include "donaudb_lib.h" + + +/** + * Look up the face value of one donation-unit entry. + * + * @param ctx plugin’s `struct DONAUDB_PostgresContext *` + * @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_get_donation_unit_amount ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + struct TALER_Amount *value); + +#endif /* DONAU_DATABASE_GET_DONATION_UNIT_AMOUNT_H */ diff --git a/src/include/donau-database/get_history.h b/src/include/donau-database/get_history.h @@ -1,53 +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 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 ctx database context to use - * @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/get_receipt_issued.h b/src/include/donau-database/get_receipt_issued.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/get_receipt_issued.h + * @brief implementation of the get_receipt_issued function for Postgres + * @author Lukas Matyja + */ +#ifndef DONAU_DATABASE_GET_RECEIPT_ISSUED_H +#define DONAU_DATABASE_GET_RECEIPT_ISSUED_H + +#include "donaudb_lib.h" + + +/** + * Fetch information about an issued receipts request. + * + * @param ctx 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_get_receipt_issued ( + struct DONAUDB_PostgresContext *ctx, + struct DONAU_DonationReceiptHashP *h_receipts, + struct DONAUDB_IssuedReceiptsMetaData *meta); + +#endif diff --git a/src/include/donau-database/get_receipts_submitted_total.h b/src/include/donau-database/get_receipts_submitted_total.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 src/include/donau-database/get_receipts_submitted_total.h + * @brief implementation of the get_receipts_submitted_total function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_GET_RECEIPTS_SUBMITTED_TOTAL_H +#define DONAU_DATABASE_GET_RECEIPTS_SUBMITTED_TOTAL_H + +#include "donaudb_lib.h" + + +/** + * Obtain the total value of the receipts a donor submitted in a year. + * + * @param ctx database context to use + * @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_get_receipts_submitted_total ( + 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/get_signkey.h b/src/include/donau-database/get_signkey.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/get_signkey.h + * @brief implementation of the get_signkey function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_GET_SIGNKEY_H +#define DONAU_DATABASE_GET_SIGNKEY_H + +#include "donaudb_lib.h" + + +/** + * Lookup signing key meta data. + * + * @param ctx 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_get_signkey ( + struct DONAUDB_PostgresContext *ctx, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + +#endif diff --git a/src/include/donau-database/insert_issued_receipt.h b/src/include/donau-database/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 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 ctx closure - * @param year the current year - * @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, - uint32_t year, - size_t num_blinded_sig, - const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], - 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_receipts_submitted.h b/src/include/donau-database/insert_receipts_submitted.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_receipts_submitted.h + * @brief implementation of the insert_receipts_submitted function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_RECEIPTS_SUBMITTED_H +#define DONAU_DATABASE_INSERT_RECEIPTS_SUBMITTED_H + +#include "donaudb_lib.h" + + +/** + * Insert submitted donation receipt from the donor. + * + * @param ctx 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_receipts_submitted ( + 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/insert_signing_key.h b/src/include/donau-database/insert_signing_key.h @@ -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 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 ctx 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_signkey.h b/src/include/donau-database/insert_signkey.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_signkey.h + * @brief implementation of the insert_signkey function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_INSERT_SIGNKEY_H +#define DONAU_DATABASE_INSERT_SIGNKEY_H + +#include "donaudb_lib.h" + + +/** + * Add signing key. + * + * @param ctx 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_signkey ( + 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 @@ -1,45 +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 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 ctx 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 @@ -1,54 +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 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 ctx database context to use - * @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_active_signkeys.h b/src/include/donau-database/iterate_active_signkeys.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_signkeys.h + * @brief implementation of the iterate_active_signkeys function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_ITERATE_ACTIVE_SIGNKEYS_H +#define DONAU_DATABASE_ITERATE_ACTIVE_SIGNKEYS_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_IterateActiveSignkeysCallback)( + void *cls, + const struct DONAU_DonauPublicKeyP *donau_pub, + struct DONAUDB_SignkeyMetaData *meta); + +/** + * Obtain information about the enabled wire accounts of the exchange. + * + * @param ctx database context to use + * @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_signkeys ( + struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateActiveSignkeysCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/iterate_charities.h b/src/include/donau-database/iterate_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/iterate_charities.h + * @brief implementation of the iterate_charities function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_ITERATE_CHARITIES_H +#define DONAU_DATABASE_ITERATE_CHARITIES_H + +#include "donaudb_lib.h" + + +/** + * Return charities. + * + * @param cls closure + */ +typedef enum GNUNET_GenericReturnValue +(*DONAUDB_IterateCharitiesCallback)( + 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 all charities. + * + * @param ctx database context to use + * @param cb function to call on each charity + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_iterate_charities (struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateCharitiesCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/donau-database/iterate_history_entries.h b/src/include/donau-database/iterate_history_entries.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/iterate_history_entries.h + * @brief implementation of the iterate_history_entries function for Postgres + * @author Johannes Casaburi + */ +#ifndef DONAU_DATABASE_ITERATE_HISTORY_ENTRIES_H +#define DONAU_DATABASE_ITERATE_HISTORY_ENTRIES_H + +#include "donaudb_lib.h" + + +/** + * Return history. + * + * @param cls closure + */ +typedef enum GNUNET_GenericReturnValue +(*DONAUDB_IterateHistoryEntriesCallback)( + void *cls, + unsigned long long charity_id, + struct TALER_Amount final_amount, + uint64_t donation_year); + + +/** + * Obtain history of charities. + * + * @param ctx database context to use + * @param cb function to call on each result + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DONAUDB_iterate_history_entries (struct DONAUDB_PostgresContext *ctx, + DONAUDB_IterateHistoryEntriesCallback 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 @@ -1,43 +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 donau-database/iterate_submitted_receipts.h - * @brief implementation of the iterate_submitted_receipts 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 ctx 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 @@ -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 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 ctx 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 @@ -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 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 ctx plugin’s `struct DONAUDB_PostgresContext *` - * @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 @@ -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 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 ctx 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 @@ -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 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 ctx 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/meson.build b/src/include/donau-database/meson.build @@ -2,26 +2,26 @@ install_headers( [ 'commit.h', 'create_tables.h', - 'do_charity_delete.h', + 'delete_charity.h', 'drop_tables.h', 'event_listen.h', 'event_listen_cancel.h', 'event_notify.h', - 'get_charities.h', - 'get_history.h', + 'iterate_charities.h', + 'iterate_history_entries.h', 'insert_charity.h', 'insert_donation_unit.h', 'insert_history_entry.h', - 'insert_issued_receipt.h', - 'insert_signing_key.h', - 'insert_submitted_receipts.h', - 'iterate_active_signing_keys.h', + 'do_insert_receipt_issued.h', + 'insert_signkey.h', + 'insert_receipts_submitted.h', + 'iterate_active_signkeys.h', 'iterate_donation_units.h', - 'iterate_submitted_receipts.h', - 'lookup_charity.h', - 'lookup_donation_unit_amount.h', - 'lookup_issued_receipts.h', - 'lookup_signing_key.h', + 'get_receipts_submitted_total.h', + 'get_charity.h', + 'get_donation_unit_amount.h', + 'get_receipt_issued.h', + 'get_signkey.h', 'preflight.h', 'rollback.h', 'start.h', diff --git a/src/include/donau-database/preflight.h b/src/include/donau-database/preflight.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/preflight.h + * @file src/include/donau-database/preflight.h * @brief implementation of the preflight function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/rollback.h b/src/include/donau-database/rollback.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/rollback.h + * @file src/include/donau-database/rollback.h * @brief implementation of the rollback function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/start.h b/src/include/donau-database/start.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/start.h + * @file src/include/donau-database/start.h * @brief implementation of the start function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/start_read_committed.h b/src/include/donau-database/start_read_committed.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/start_read_committed.h + * @file src/include/donau-database/start_read_committed.h * @brief implementation of the start_read_committed function for Postgres * @author Christian Grothoff */ diff --git a/src/include/donau-database/start_read_only.h b/src/include/donau-database/start_read_only.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-database/start_read_only.h + * @file src/include/donau-database/start_read_only.h * @brief implementation of the start_read_only function for Postgres * @author Christian Grothoff */