commit e0ffda10b58d3e5f68e744ba06da7a259bacaa24
parent ece964144ce390aac8e713c464bac50d3066838c
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 22 Jul 2026 01:40:36 +0200
exchangedb: rename functions for more consistent naming
Diffstat:
809 files changed, 36485 insertions(+), 36575 deletions(-)
diff --git a/contrib/check-db-naming.py b/contrib/check-db-naming.py
@@ -0,0 +1,126 @@
+#!/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
+import collections
+
+LAYERS = [
+ ("src/exchangedb", "src/include/exchange-database", "TALER_EXCHANGEDB_"),
+ ("src/auditordb", "src/include/auditor-database", "TALER_AUDITORDB_"),
+]
+
+# 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, shard lifecycle, and multi-function helper modules.
+EXEMPT = {
+ "start", "start_read_only", "start_read_committed",
+ "start_deferred_wire_out", "commit", "rollback", "preflight", "disconnect",
+ "create_tables", "drop_tables", "inject_auditor_triggers", "gc",
+ "event_listen", "event_listen_cancel", "event_notify",
+ "free_coin_transaction_list", "free_reserve_history",
+ "compute_shard", "enable_rules", "disable_rules", "begin_rule_update",
+ "begin_shard", "begin_revolving_shard", "complete_shard", "abort_shard",
+ "release_revolving_shard",
+ "account_history", "exchangedb_accounts", "exchangedb_transactions",
+}
+
+# Files that are not part of the API surface at all.
+SKIP = {"pg", "template", "helper", "bench_db"}
+
+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):
+ 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")):
+ stem = c.stem
+ if stem in SKIP or stem.startswith("test_"):
+ continue
+
+ # 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 '{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
+ 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(prefix.split("_")[0]) + 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/004-db-naming/job.sh b/contrib/ci/jobs/004-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
@@ -9,7 +9,7 @@ Build-Depends:
gcc,
debhelper-compat (= 12),
gettext,
- libgnunet-dev (>=0.27.0),
+ libgnunet-dev (>=0.28.0~dev5),
libcurl4-gnutls-dev (>=7.35.0) | libcurl4-openssl-dev (>= 7.35.0),
libgcrypt20-dev (>=1.8),
libgnutls28-dev (>=3.2.12),
diff --git a/meson.build b/meson.build
@@ -291,8 +291,8 @@ if not get_option('only-doc')
['libtalertemplating', '1:1:1'],
['libtalerbank', '6:0:0'],
['libtalerkyclogic', '3:0:0'],
- ['libtalerexchangedb', '1:1:0'],
- ['libtalerauditordb', '0:1:0'],
+ ['libtalerexchangedb', '2:0:0'],
+ ['libtalerauditordb', '1:0:0'],
['libtalerexchange', '22:0:0'],
['libtalerauditor', '0:0:0'],
['libtalertesting', '4:0:0'],
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-amount-arithmetic-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-amount-arithmetic-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-amount-arithmetic-inconsistency.h"
#define TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_amount_arithmetic_inconsistency.h"
+#include "auditor-database/iterate_amount_arithmetic_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -118,7 +118,7 @@ TAH_get_monitoring_amount_arithmetic_inconsistency (
}
}
- qs = TALER_AUDITORDB_get_amount_arithmetic_inconsistency (
+ qs = TALER_AUDITORDB_iterate_amount_arithmetic_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-bad-sig-losses.c b/src/auditor/taler-auditor-httpd_get-monitoring-bad-sig-losses.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-bad-sig-losses.h"
#define TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE json_t
-#include "auditor-database/get_bad_sig_losses.h"
+#include "auditor-database/iterate_bad_sig_losses.h"
#include "auditor-database/preflight.h"
@@ -122,7 +122,7 @@ TAH_get_monitoring_bad_sig_losses (
filter_spec_pub);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_bad_sig_losses (
+ qs = TALER_AUDITORDB_iterate_bad_sig_losses (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-balances.c b/src/auditor/taler-auditor-httpd_get-monitoring-balances.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-balances.h"
#define TALER_AUDITORDB_BALANCES_RESULT_CLOSURE json_t
-#include "auditor-database/get_balances.h"
+#include "auditor-database/iterate_balances.h"
#include "auditor-database/preflight.h"
/**
@@ -85,7 +85,7 @@ TAH_get_monitoring_balances (
"balance_key");
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_balances (
+ qs = TALER_AUDITORDB_iterate_balances (
TAH_apg,
balance_key,
&process_balances,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-closure-lags.c b/src/auditor/taler-auditor-httpd_get-monitoring-closure-lags.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-closure-lags.h"
#define TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE json_t
-#include "auditor-database/get_auditor_closure_lags.h"
+#include "auditor-database/iterate_auditor_closure_lags.h"
#include "auditor-database/preflight.h"
@@ -112,7 +112,7 @@ TAH_get_monitoring_closure_lags (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_auditor_closure_lags (
+ qs = TALER_AUDITORDB_iterate_auditor_closure_lags (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-coin-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-coin-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-coin-inconsistency.h"
#define TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_coin_inconsistency.h"
+#include "auditor-database/iterate_coin_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -102,7 +102,7 @@ TAH_get_monitoring_coin_inconsistency (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_coin_inconsistency (
+ qs = TALER_AUDITORDB_iterate_coin_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-denomination-key-validity-withdraw-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-denomination-key-validity-withdraw-inconsistency.c
@@ -27,7 +27,7 @@
TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE \
json_t
#include \
- "auditor-database/get_denomination_key_validity_withdraw_inconsistency.h"
+ "auditor-database/iterate_denomination_key_validity_withdraw_inconsistencies.h"
#include "auditor-database/preflight.h"
/**
@@ -117,13 +117,14 @@ TAH_get_monitoring_denomination_key_validity_withdraw_inconsistency (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_denomination_key_validity_withdraw_inconsistency (
- TAH_apg,
- limit,
- offset,
- return_suppressed,
- &process_denomination_key_validity_withdraw_inconsistency,
- ja);
+ qs =
+ TALER_AUDITORDB_iterate_denomination_key_validity_withdraw_inconsistencies (
+ TAH_apg,
+ limit,
+ offset,
+ return_suppressed,
+ &process_denomination_key_validity_withdraw_inconsistency,
+ ja);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-denomination-pending.c b/src/auditor/taler-auditor-httpd_get-monitoring-denomination-pending.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-denomination-pending.h"
#define TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE json_t
-#include "auditor-database/get_denomination_pending.h"
+#include "auditor-database/iterate_denomination_pending.h"
#include "auditor-database/preflight.h"
/**
@@ -102,7 +102,7 @@ TAH_get_monitoring_denomination_pending (
&offset);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_denomination_pending (
+ qs = TALER_AUDITORDB_iterate_denomination_pending (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-denominations-without-sigs.c b/src/auditor/taler-auditor-httpd_get-monitoring-denominations-without-sigs.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-denominations-without-sigs.h"
#define TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE json_t
-#include "auditor-database/get_denominations_without_sigs.h"
+#include "auditor-database/iterate_denominations_without_sigs.h"
#include "auditor-database/preflight.h"
@@ -112,7 +112,7 @@ TAH_get_monitoring_denominations_without_sigs (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_denominations_without_sigs (
+ qs = TALER_AUDITORDB_iterate_denominations_without_sigs (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-deposit-confirmations.c b/src/auditor/taler-auditor-httpd_get-monitoring-deposit-confirmations.c
@@ -29,7 +29,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-deposit-confirmations.h"
#define TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE json_t
-#include "auditor-database/get_deposit_confirmations.h"
+#include "auditor-database/iterate_deposit_confirmations.h"
#include "auditor-database/preflight.h"
@@ -156,7 +156,7 @@ TAH_get_monitoring_deposit_confirmations (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_deposit_confirmations (
+ qs = TALER_AUDITORDB_iterate_deposit_confirmations (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-early-aggregation.c b/src/auditor/taler-auditor-httpd_get-monitoring-early-aggregation.c
@@ -24,7 +24,7 @@
#include "taler-auditor-httpd_get-monitoring-early-aggregation.h"
#include "auditor-database/preflight.h"
#define TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE json_t
-#include "auditor-database/select_early_aggregations.h"
+#include "auditor-database/iterate_early_aggregations.h"
/**
@@ -107,7 +107,7 @@ TAH_get_monitoring_early_aggregation (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_select_early_aggregations (
+ qs = TALER_AUDITORDB_iterate_early_aggregations (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-emergency-by-count.c b/src/auditor/taler-auditor-httpd_get-monitoring-emergency-by-count.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-emergency-by-count.h"
#define TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE json_t
-#include "auditor-database/get_emergency_by_count.h"
+#include "auditor-database/iterate_emergencies_by_count.h"
#include "auditor-database/preflight.h"
/**
@@ -118,7 +118,7 @@ TAH_get_monitoring_emergency_by_count (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_emergency_by_count (
+ qs = TALER_AUDITORDB_iterate_emergencies_by_count (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-emergency.c b/src/auditor/taler-auditor-httpd_get-monitoring-emergency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-emergency.h"
#define TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_emergency.h"
+#include "auditor-database/iterate_emergencies.h"
#include "auditor-database/preflight.h"
@@ -117,7 +117,7 @@ TAH_get_monitoring_emergency (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_emergency (
+ qs = TALER_AUDITORDB_iterate_emergencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-fee-time-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-fee-time-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-fee-time-inconsistency.h"
#define TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_fee_time_inconsistency.h"
+#include "auditor-database/iterate_fee_time_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -111,7 +111,7 @@ TAH_get_monitoring_fee_time_inconsistency (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_fee_time_inconsistency (
+ qs = TALER_AUDITORDB_iterate_fee_time_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-historic-denomination-revenue.c b/src/auditor/taler-auditor-httpd_get-monitoring-historic-denomination-revenue.c
@@ -26,7 +26,7 @@
#include "taler-auditor-httpd_get-monitoring-historic-denomination-revenue.h"
#include "auditor-database/preflight.h"
#define TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE json_t
-#include "auditor-database/select_historic_denom_revenue.h"
+#include "auditor-database/iterate_historic_denom_revenue.h"
/**
@@ -112,7 +112,7 @@ TAH_get_monitoring_historic_denomination_revenue (
&offset);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_select_historic_denom_revenue (
+ qs = TALER_AUDITORDB_iterate_historic_denom_revenue (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-historic-reserve-summary.c b/src/auditor/taler-auditor-httpd_get-monitoring-historic-reserve-summary.c
@@ -26,7 +26,7 @@
#include "taler-auditor-httpd_get-monitoring-historic-reserve-summary.h"
#include "auditor-database/preflight.h"
#define TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE json_t
-#include "auditor-database/select_historic_reserve_revenue.h"
+#include "auditor-database/iterate_historic_reserve_revenue.h"
/**
* Add historic-reserve-summary to the list.
@@ -106,7 +106,7 @@ TAH_get_monitoring_historic_reserve_summary (
&offset);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_select_historic_reserve_revenue (
+ qs = TALER_AUDITORDB_iterate_historic_reserve_revenue (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-misattribution-in-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-misattribution-in-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-misattribution-in-inconsistency.h"
#define TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_misattribution_in_inconsistency.h"
+#include "auditor-database/iterate_misattribution_in_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -111,7 +111,7 @@ TAH_get_monitoring_misattribution_in_inconsistency (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_misattribution_in_inconsistency (
+ qs = TALER_AUDITORDB_iterate_misattribution_in_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-pending-deposits.c b/src/auditor/taler-auditor-httpd_get-monitoring-pending-deposits.c
@@ -24,7 +24,7 @@
#include "taler-auditor-httpd_get-monitoring-pending-deposits.h"
#include "auditor-database/preflight.h"
#define TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE json_t
-#include "auditor-database/select_pending_deposits.h"
+#include "auditor-database/iterate_pending_deposits.h"
/**
@@ -117,7 +117,7 @@ TAH_get_monitoring_pending_deposits (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_select_pending_deposits (
+ qs = TALER_AUDITORDB_iterate_pending_deposits (
TAH_apg,
GNUNET_TIME_absolute_get (),
limit,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-progress.c b/src/auditor/taler-auditor-httpd_get-monitoring-progress.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-progress.h"
#define TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE json_t
-#include "auditor-database/get_progress_points.h"
+#include "auditor-database/iterate_progress_points.h"
#include "auditor-database/preflight.h"
@@ -86,7 +86,7 @@ TAH_get_monitoring_progress (
"progress_key");
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_progress_points (
+ qs = TALER_AUDITORDB_iterate_progress_points (
TAH_apg,
progress_key,
&process_progress,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-purse-not-closed-inconsistencies.c b/src/auditor/taler-auditor-httpd_get-monitoring-purse-not-closed-inconsistencies.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-purse-not-closed-inconsistencies.h"
#define TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE json_t
-#include "auditor-database/get_purse_not_closed_inconsistencies.h"
+#include "auditor-database/iterate_purse_not_closed_inconsistencies.h"
#include "auditor-database/preflight.h"
/**
@@ -114,7 +114,7 @@ TAH_get_monitoring_purse_not_closed_inconsistencies (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_purse_not_closed_inconsistencies (
+ qs = TALER_AUDITORDB_iterate_purse_not_closed_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-purses.c b/src/auditor/taler-auditor-httpd_get-monitoring-purses.c
@@ -25,7 +25,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-purses.h"
#define TALER_AUDITORDB_PURSES_RESULT_CLOSURE json_t
-#include "auditor-database/get_purses.h"
+#include "auditor-database/iterate_purses.h"
#include "auditor-database/preflight.h"
/**
@@ -103,7 +103,7 @@ TAH_get_monitoring_purses (
&offset);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_purses (
+ qs = TALER_AUDITORDB_iterate_purses (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-reserve-balance-insufficient-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-reserve-balance-insufficient-inconsistency.c
@@ -27,7 +27,7 @@
TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE \
json_t
#include \
- "auditor-database/get_reserve_balance_insufficient_inconsistency.h"
+ "auditor-database/iterate_reserve_balance_insufficient_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -115,7 +115,7 @@ TAH_get_monitoring_reserve_balance_insufficient_inconsistency (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_reserve_balance_insufficient_inconsistency (
+ qs = TALER_AUDITORDB_iterate_reserve_balance_insufficient_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-reserve-balance-summary-wrong-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-reserve-balance-summary-wrong-inconsistency.c
@@ -27,7 +27,7 @@
TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE \
json_t
#include \
- "auditor-database/get_reserve_balance_summary_wrong_inconsistency.h"
+ "auditor-database/iterate_reserve_balance_summary_wrong_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -109,7 +109,7 @@ TAH_get_monitoring_reserve_balance_summary_wrong_inconsistency (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_reserve_balance_summary_wrong_inconsistency (
+ qs = TALER_AUDITORDB_iterate_reserve_balance_summary_wrong_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-reserve-in-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-reserve-in-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-reserve-in-inconsistency.h"
#define TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_reserve_in_inconsistency.h"
+#include "auditor-database/iterate_reserve_in_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -122,7 +122,7 @@ TAH_get_monitoring_reserve_in_inconsistency (
}
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_reserve_in_inconsistency (
+ qs = TALER_AUDITORDB_iterate_reserve_in_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-reserve-not-closed-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-reserve-not-closed-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-reserve-not-closed-inconsistency.h"
#define TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_reserve_not_closed_inconsistency.h"
+#include "auditor-database/iterate_reserve_not_closed_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -115,7 +115,7 @@ TAH_get_monitoring_reserve_not_closed_inconsistency (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_reserve_not_closed_inconsistency (
+ qs = TALER_AUDITORDB_iterate_reserve_not_closed_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-reserves.c b/src/auditor/taler-auditor-httpd_get-monitoring-reserves.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-reserves.h"
#define TALER_AUDITORDB_RESERVES_RESULT_CLOSURE json_t
-#include "auditor-database/get_reserves.h"
+#include "auditor-database/iterate_reserves.h"
#include "auditor-database/preflight.h"
@@ -115,7 +115,7 @@ TAH_get_monitoring_reserves (
&offset);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_reserves (
+ qs = TALER_AUDITORDB_iterate_reserves (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-row-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-row-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-row-inconsistency.h"
#define TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_row_inconsistency.h"
+#include "auditor-database/iterate_row_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -110,7 +110,7 @@ TAH_get_monitoring_row_inconsistency (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_row_inconsistency (
+ qs = TALER_AUDITORDB_iterate_row_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-row-minor-inconsistencies.c b/src/auditor/taler-auditor-httpd_get-monitoring-row-minor-inconsistencies.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-row-minor-inconsistencies.h"
#define TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE json_t
-#include "auditor-database/get_row_minor_inconsistencies.h"
+#include "auditor-database/iterate_row_minor_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -114,7 +114,7 @@ TAH_get_monitoring_row_minor_inconsistencies (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_row_minor_inconsistencies (
+ qs = TALER_AUDITORDB_iterate_row_minor_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-wire-format-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-wire-format-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-wire-format-inconsistency.h"
#define TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_wire_format_inconsistency.h"
+#include "auditor-database/iterate_wire_format_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -113,7 +113,7 @@ TAH_get_monitoring_wire_format_inconsistency (
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_wire_format_inconsistency (
+ qs = TALER_AUDITORDB_iterate_wire_format_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_get-monitoring-wire-out-inconsistency.c b/src/auditor/taler-auditor-httpd_get-monitoring-wire-out-inconsistency.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_get-monitoring-wire-out-inconsistency.h"
#define TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE json_t
-#include "auditor-database/get_wire_out_inconsistency.h"
+#include "auditor-database/iterate_wire_out_inconsistencies.h"
#include "auditor-database/preflight.h"
@@ -109,7 +109,7 @@ TAH_get_monitoring_wire_out_inconsistency (
&return_suppressed);
ja = json_array ();
GNUNET_break (NULL != ja);
- qs = TALER_AUDITORDB_get_wire_out_inconsistency (
+ qs = TALER_AUDITORDB_iterate_wire_out_inconsistencies (
TAH_apg,
limit,
offset,
diff --git a/src/auditor/taler-auditor-httpd_patch-generic-suppressed.c b/src/auditor/taler-auditor-httpd_patch-generic-suppressed.c
@@ -23,7 +23,7 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_patch-generic-suppressed.h"
#include "auditor-database/preflight.h"
-#include "auditor-database/update_generic_suppressed.h"
+#include "auditor-database/update_to_suppressed.h"
enum MHD_Result
@@ -101,10 +101,10 @@ TAH_patch_generic_suppressed (
}
/* execute transaction */
- qs = TALER_AUDITORDB_update_generic_suppressed (TAH_apg,
- rh->table,
- row_id,
- suppressed);
+ qs = TALER_AUDITORDB_update_to_suppressed (TAH_apg,
+ rh->table,
+ row_id,
+ suppressed);
switch (qs)
{
diff --git a/src/auditor/taler-auditor-httpd_put-deposit-confirmation.c b/src/auditor/taler-auditor-httpd_put-deposit-confirmation.c
@@ -29,7 +29,7 @@
#include "taler/taler_mhd_lib.h"
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_put-deposit-confirmation.h"
-#include "exchange-database/lookup_signkey_revocation.h"
+#include "exchange-database/get_signkey_revocation.h"
#include "auditor-database/insert_deposit_confirmation.h"
#include "auditor-database/insert_exchange_signkey.h"
#include "auditor-database/preflight.h"
@@ -191,9 +191,9 @@ verify_and_execute_deposit_confirmation (
struct TALER_MasterSignatureP master_sig;
/* check for revocation */
- qs = TALER_EXCHANGEDB_lookup_signkey_revocation (TAH_epg,
- &es->exchange_pub,
- &master_sig);
+ qs = TALER_EXCHANGEDB_get_signkey_revocation (TAH_epg,
+ &es->exchange_pub,
+ &master_sig);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
diff --git a/src/auditor/taler-auditor-sync.c b/src/auditor/taler-auditor-sync.c
@@ -21,19 +21,18 @@
#include "platform.h"
#include "exchangedb_lib.h"
#include "exchange-database/preflight.h"
-#include "exchange-database/test_aml_officer.h"
+#include "exchange-database/get_exists_aml_officer.h"
#include "exchange-database/abort_shard.h"
-#include "exchange-database/activate_signing_key.h"
-#include "exchange-database/add_denomination_key.h"
-#include "exchange-database/aggregate.h"
+#include "exchange-database/insert_signkey.h"
+#include "exchange-database/do_aggregate.h"
#include "exchange-database/begin_revolving_shard.h"
#include "exchange-database/begin_shard.h"
-#include "exchange-database/clear_aml_lock.h"
+#include "exchange-database/update_to_aml_unlocked.h"
#include "exchange-database/commit.h"
#include "exchange-database/complete_shard.h"
#include "exchange-database/compute_shard.h"
-#include "exchange-database/count_known_coins.h"
-#include "exchange-database/create_aggregation_transient.h"
+#include "exchange-database/get_count_known_coins.h"
+#include "exchange-database/insert_aggregation_transient.h"
#include "exchange-database/create_tables.h"
#include "exchange-database/delete_aggregation_transient.h"
#include "exchange-database/delete_shard_locks.h"
@@ -50,28 +49,28 @@
#include "exchange-database/do_reserve_open.h"
#include "exchange-database/do_reserve_purse.h"
#include "exchange-database/do_withdraw.h"
-#include "exchange-database/drain_kyc_alert.h"
+#include "exchange-database/do_drain_kyc_alert.h"
#include "exchange-database/drop_tables.h"
#include "exchange-database/enable_rules.h"
-#include "exchange-database/ensure_coin_known.h"
+#include "exchange-database/do_insert_known_coin.h"
#include "exchange-database/event_listen_cancel.h"
#include "exchange-database/event_listen.h"
-#include "exchange-database/expire_purse.h"
-#include "exchange-database/find_aggregation_transient.h"
+#include "exchange-database/do_expire_purse.h"
+#include "exchange-database/get_aggregation_transient_by_normalized_payto.h"
#include "exchange-database/gc.h"
#include "exchange-database/get_coin_denomination.h"
#include "exchange-database/get_coin_transactions.h"
#include "exchange-database/get_denomination_by_serial.h"
#include "exchange-database/get_denomination_info.h"
#include "exchange-database/get_denomination_revocation.h"
-#include "exchange-database/get_drain_profit.h"
-#include "exchange-database/get_expired_reserves.h"
+#include "exchange-database/get_profit_drain.h"
+#include "exchange-database/iterate_expired_reserves.h"
#include "exchange-database/get_global_fee.h"
-#include "exchange-database/get_global_fees.h"
+#include "exchange-database/iterate_global_fees.h"
#include "exchange-database/get_known_coin.h"
#include "exchange-database/get_kyc_rules.h"
#include "exchange-database/get_old_coin_by_h_blind.h"
-#include "exchange-database/get_pending_kyc_requirement_process.h"
+#include "exchange-database/get_pending_legitimization_process.h"
#include "exchange-database/get_purse_deposit.h"
#include "exchange-database/get_purse_request.h"
#include "exchange-database/get_ready_deposit.h"
@@ -80,13 +79,13 @@
#include "exchange-database/get_reserve_by_h_planchets.h"
#include "exchange-database/get_reserve_history.h"
#include "exchange-database/get_signature_for_known_coin.h"
-#include "exchange-database/get_unfinished_close_requests.h"
-#include "exchange-database/get_wire_accounts.h"
+#include "exchange-database/iterate_unfinished_close_requests.h"
+#include "exchange-database/iterate_wire_accounts.h"
#include "exchange-database/get_wire_fee.h"
-#include "exchange-database/get_wire_fees.h"
+#include "exchange-database/iterate_wire_fees.h"
#include "exchange-database/get_wire_hash_for_contract.h"
#include "exchange-database/get_withdraw.h"
-#include "exchange-database/have_deposit2.h"
+#include "exchange-database/get_exists_deposit.h"
#include "exchange-database/inject_auditor_triggers.h"
#include "exchange-database/insert_active_legitimization_measure.h"
#include "exchange-database/insert_aml_decision.h"
@@ -98,10 +97,10 @@
#include "exchange-database/insert_contract.h"
#include "exchange-database/insert_denomination_info.h"
#include "exchange-database/insert_denomination_revocation.h"
-#include "exchange-database/insert_drain_profit.h"
+#include "exchange-database/insert_profit_drain.h"
#include "exchange-database/insert_global_fee.h"
#include "exchange-database/insert_kyc_failure.h"
-#include "exchange-database/insert_kyc_requirement_process.h"
+#include "exchange-database/insert_legitimization_process.h"
#include "exchange-database/insert_partner.h"
#include "exchange-database/insert_purse_request.h"
struct InsertContext;
@@ -119,107 +118,107 @@ struct InsertContext;
#include "exchange-database/iterate_auditor_denominations.h"
#include "exchange-database/iterate_denomination_info.h"
#include "exchange-database/iterate_denominations.h"
-#include "exchange-database/iterate_kyc_reference.h"
+#include "exchange-database/iterate_kyc_references.h"
#include "exchange-database/iterate_reserve_close_info.h"
-#include "exchange-database/kycauth_in_insert.h"
-#include "exchange-database/kyc_provider_account_lookup.h"
-#include "exchange-database/lookup_active_legitimization.h"
-#include "exchange-database/lookup_aml_file_number.h"
-#include "exchange-database/lookup_aml_history.h"
-#include "exchange-database/lookup_aml_officer.h"
-#include "exchange-database/lookup_auditor_status.h"
-#include "exchange-database/lookup_auditor_timestamp.h"
-#include "exchange-database/lookup_completed_legitimization.h"
-#include "exchange-database/lookup_denomination_key.h"
-#include "exchange-database/lookup_global_fee_by_time.h"
-#include "exchange-database/lookup_h_payto_by_access_token.h"
-#include "exchange-database/lookup_kyc_history.h"
-#include "exchange-database/lookup_kyc_process_by_account.h"
-#include "exchange-database/lookup_kyc_requirement_by_row.h"
-#include "exchange-database/lookup_kyc_status_by_token.h"
-#include "exchange-database/lookup_pending_legitimization.h"
-#include "exchange-database/lookup_records_by_table.h"
-#include "exchange-database/lookup_rules_by_access_token.h"
-#include "exchange-database/lookup_serial_by_table.h"
-#include "exchange-database/lookup_signing_key.h"
-#include "exchange-database/lookup_signkey_revocation.h"
-#include "exchange-database/lookup_transfer_by_deposit.h"
-#include "exchange-database/lookup_wire_fee_by_time.h"
-#include "exchange-database/lookup_wire_timestamp.h"
-#include "exchange-database/lookup_wire_transfer.h"
-#include "exchange-database/mark_refresh_reveal_success.h"
-#include "exchange-database/persist_kyc_attributes.h"
+#include "exchange-database/insert_kycauth_in.h"
+#include "exchange-database/get_kyc_provider_account.h"
+#include "exchange-database/get_active_legitimization.h"
+#include "exchange-database/get_aml_file_number.h"
+#include "exchange-database/iterate_aml_history.h"
+#include "exchange-database/get_aml_officer.h"
+#include "exchange-database/get_auditor_status.h"
+#include "exchange-database/get_auditor_timestamp.h"
+#include "exchange-database/get_completed_legitimization.h"
+#include "exchange-database/get_denomination_meta.h"
+#include "exchange-database/get_global_fee_by_time.h"
+#include "exchange-database/get_h_payto_by_access_token.h"
+#include "exchange-database/iterate_kyc_history.h"
+#include "exchange-database/get_legitimization_process_by_account.h"
+#include "exchange-database/get_legitimization_requirement_by_row.h"
+#include "exchange-database/get_kyc_status_by_token.h"
+#include "exchange-database/get_pending_legitimization.h"
+#include "exchange-database/iterate_records_by_table.h"
+#include "exchange-database/get_rules_by_access_token.h"
+#include "exchange-database/get_serial_by_table.h"
+#include "exchange-database/get_signkey.h"
+#include "exchange-database/get_signkey_revocation.h"
+#include "exchange-database/get_transfer_by_deposit.h"
+#include "exchange-database/get_wire_fee_by_time.h"
+#include "exchange-database/get_wire_timestamp.h"
+#include "exchange-database/iterate_wire_transfers.h"
+#include "exchange-database/update_to_refresh_revealed.h"
+#include "exchange-database/do_insert_kyc_attributes.h"
#include "exchange-database/preflight.h"
-#include "exchange-database/profit_drains_get_pending.h"
-#include "exchange-database/profit_drains_set_finished.h"
+#include "exchange-database/get_pending_profit_drain.h"
+#include "exchange-database/update_to_profit_drain_finished.h"
#include "exchange-database/release_revolving_shard.h"
-#include "exchange-database/reserves_get.h"
-#include "exchange-database/reserves_get_origin.h"
-#include "exchange-database/reserves_in_insert.h"
-#include "exchange-database/reserves_update.h"
+#include "exchange-database/get_reserve.h"
+#include "exchange-database/get_reserve_origin.h"
+#include "exchange-database/do_insert_reserve_in.h"
+#include "exchange-database/update_reserve.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/select_account_merges_above_serial_id.h"
-#include "exchange-database/select_aggregation_amounts_for_kyc_check.h"
-#include "exchange-database/select_aggregations_above_serial.h"
-#include "exchange-database/select_aggregation_transient.h"
-#include "exchange-database/select_all_kyc_attributes.h"
-#include "exchange-database/select_all_purse_decisions_above_serial_id.h"
-#include "exchange-database/select_all_purse_deletions_above_serial_id.h"
-#include "exchange-database/select_aml_attributes.h"
-#include "exchange-database/select_aml_decisions.h"
-#include "exchange-database/select_aml_measures.h"
-#include "exchange-database/select_aml_statistics.h"
-#include "exchange-database/select_auditor_denom_sig.h"
-#include "exchange-database/select_batch_deposits_missing_wire.h"
-#include "exchange-database/select_coin_deposits_above_serial_id.h"
-#include "exchange-database/select_contract_by_purse.h"
-#include "exchange-database/select_contract.h"
-#include "exchange-database/select_deposit_amounts_for_kyc_check.h"
-#include "exchange-database/select_exchange_credit_transfers.h"
-#include "exchange-database/select_exchange_debit_transfers.h"
-#include "exchange-database/select_exchange_kycauth_transfers.h"
-#include "exchange-database/select_kyc_accounts.h"
-#include "exchange-database/select_kyc_attributes.h"
-#include "exchange-database/select_merge_amounts_for_kyc_check.h"
-#include "exchange-database/select_purse_by_merge_pub.h"
-#include "exchange-database/select_purse_decisions_above_serial_id.h"
-#include "exchange-database/select_purse_deposits_above_serial_id.h"
-#include "exchange-database/select_purse_deposits_by_purse.h"
-#include "exchange-database/select_purse.h"
-#include "exchange-database/select_purse_merge.h"
-#include "exchange-database/select_purse_merges_above_serial_id.h"
-#include "exchange-database/select_purse_requests_above_serial_id.h"
-#include "exchange-database/select_recoup_above_serial_id.h"
-#include "exchange-database/select_recoup_refresh_above_serial_id.h"
-#include "exchange-database/select_refreshes_above_serial_id.h"
-#include "exchange-database/select_refunds_above_serial_id.h"
-#include "exchange-database/select_refunds_by_coin.h"
-#include "exchange-database/select_reserve_closed_above_serial_id.h"
-#include "exchange-database/select_reserve_close_info.h"
-#include "exchange-database/select_reserve_open_above_serial_id.h"
-#include "exchange-database/select_reserves_in_above_serial_id.h"
-#include "exchange-database/select_wire_out_above_serial_id_by_account.h"
-#include "exchange-database/select_wire_out_above_serial_id.h"
-#include "exchange-database/select_withdrawals_above_serial_id.h"
-#include "exchange-database/select_withdraw_amounts_for_kyc_check.h"
-#include "exchange-database/set_aml_lock.h"
-#include "exchange-database/set_purse_balance.h"
+#include "exchange-database/iterate_account_merges_above_serial_id.h"
+#include "exchange-database/iterate_aggregation_amounts_for_kyc_check.h"
+#include "exchange-database/iterate_aggregations_above_serial_id.h"
+#include "exchange-database/get_aggregation_transient.h"
+#include "exchange-database/iterate_all_kyc_attributes.h"
+#include "exchange-database/iterate_all_purse_decisions_above_serial_id.h"
+#include "exchange-database/iterate_all_purse_deletions_above_serial_id.h"
+#include "exchange-database/iterate_aml_attributes.h"
+#include "exchange-database/iterate_aml_decisions.h"
+#include "exchange-database/iterate_aml_measures.h"
+#include "exchange-database/iterate_aml_statistics.h"
+#include "exchange-database/get_auditor_denom_sig.h"
+#include "exchange-database/iterate_batch_deposits_missing_wire.h"
+#include "exchange-database/iterate_coin_deposits_above_serial_id.h"
+#include "exchange-database/get_contract_by_purse.h"
+#include "exchange-database/get_contract.h"
+#include "exchange-database/iterate_deposit_amounts_for_kyc_check.h"
+#include "exchange-database/iterate_exchange_credit_transfers.h"
+#include "exchange-database/iterate_exchange_debit_transfers.h"
+#include "exchange-database/iterate_exchange_kycauth_transfers.h"
+#include "exchange-database/iterate_kyc_accounts.h"
+#include "exchange-database/iterate_kyc_attributes.h"
+#include "exchange-database/iterate_merge_amounts_for_kyc_check.h"
+#include "exchange-database/get_purse_by_merge_pub.h"
+#include "exchange-database/iterate_purse_decisions_above_serial_id.h"
+#include "exchange-database/iterate_purse_deposits_above_serial_id.h"
+#include "exchange-database/iterate_purse_deposits_by_purse.h"
+#include "exchange-database/get_purse.h"
+#include "exchange-database/get_purse_merge.h"
+#include "exchange-database/iterate_purse_merges_above_serial_id.h"
+#include "exchange-database/iterate_purse_requests_above_serial_id.h"
+#include "exchange-database/iterate_recoups_above_serial_id.h"
+#include "exchange-database/iterate_recoup_refreshes_above_serial_id.h"
+#include "exchange-database/iterate_refreshes_above_serial_id.h"
+#include "exchange-database/iterate_refunds_above_serial_id.h"
+#include "exchange-database/iterate_refunds_by_coin.h"
+#include "exchange-database/iterate_reserve_closed_above_serial_id.h"
+#include "exchange-database/get_reserve_close_info.h"
+#include "exchange-database/iterate_reserve_open_above_serial_id.h"
+#include "exchange-database/iterate_reserves_in_above_serial_id.h"
+#include "exchange-database/iterate_wire_outs_above_serial_id_by_account.h"
+#include "exchange-database/iterate_wire_outs_above_serial_id.h"
+#include "exchange-database/iterate_withdrawals_above_serial_id.h"
+#include "exchange-database/iterate_withdraw_amounts_for_kyc_check.h"
+#include "exchange-database/update_to_aml_locked.h"
+#include "exchange-database/update_purse_balance.h"
#include "exchange-database/start_deferred_wire_out.h"
#include "exchange-database/start.h"
#include "exchange-database/start_read_committed.h"
#include "exchange-database/start_read_only.h"
-#include "exchange-database/store_wire_transfer_out.h"
-#include "exchange-database/test_aml_officer.h"
-#include "exchange-database/trigger_kyc_rule_for_account.h"
+#include "exchange-database/insert_wire_out.h"
+#include "exchange-database/get_exists_aml_officer.h"
+#include "exchange-database/do_trigger_kyc_rule_for_account.h"
#include "exchange-database/update_aggregation_transient.h"
#include "exchange-database/update_auditor.h"
-#include "exchange-database/update_kyc_process_by_row.h"
+#include "exchange-database/update_legitimization_process_by_row.h"
#include "exchange-database/update_wire.h"
-#include "exchange-database/wad_in_insert.h"
-#include "exchange-database/wire_prepare_data_get.h"
-#include "exchange-database/wire_prepare_data_insert.h"
-#include "exchange-database/wire_prepare_data_mark_failed.h"
-#include "exchange-database/wire_prepare_data_mark_finished.h"
+#include "exchange-database/insert_wad_in.h"
+#include "exchange-database/iterate_prewires.h"
+#include "exchange-database/insert_prewire.h"
+#include "exchange-database/update_to_prewire_failed.h"
+#include "exchange-database/update_to_prewire_finished.h"
/**
@@ -417,18 +416,18 @@ transact (void)
"lookup src serials"))
return GNUNET_SYSERR;
for (unsigned int i = 0; ! tables[i].end; i++)
- TALER_EXCHANGEDB_lookup_serial_by_table (src,
- tables[i].rt,
- &tables[i].end_serial);
+ TALER_EXCHANGEDB_get_serial_by_table (src,
+ tables[i].rt,
+ &tables[i].end_serial);
TALER_EXCHANGEDB_rollback (src);
if (GNUNET_OK !=
TALER_EXCHANGEDB_start (dst,
"lookup dst serials"))
return GNUNET_SYSERR;
for (unsigned int i = 0; ! tables[i].end; i++)
- TALER_EXCHANGEDB_lookup_serial_by_table (dst,
- tables[i].rt,
- &tables[i].start_serial);
+ TALER_EXCHANGEDB_get_serial_by_table (dst,
+ tables[i].rt,
+ &tables[i].start_serial);
TALER_EXCHANGEDB_rollback (dst);
for (unsigned int i = 0; ! tables[i].end; i++)
{
@@ -454,11 +453,11 @@ transact (void)
TALER_EXCHANGEDB_start (dst,
"copy table (dst)"))
return GNUNET_SYSERR;
- qs = TALER_EXCHANGEDB_lookup_records_by_table (src,
- table->rt,
- table->start_serial,
- &do_insert,
- &ctx);
+ qs = TALER_EXCHANGEDB_iterate_records_by_table (src,
+ table->rt,
+ table->start_serial,
+ &do_insert,
+ &ctx);
if (ctx.qs < 0)
qs = ctx.qs;
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
diff --git a/src/auditor/taler-helper-auditor-aggregation.c b/src/auditor/taler-helper-auditor-aggregation.c
@@ -49,8 +49,8 @@ struct AggregationContext;
#include "exchange-database/get_wire_fee.h"
struct WireCheckContext;
#define TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE struct WireCheckContext
-#include "exchange-database/lookup_wire_transfer.h"
-#include "exchange-database/select_wire_out_above_serial_id.h"
+#include "exchange-database/iterate_wire_transfers.h"
+#include "exchange-database/iterate_wire_outs_above_serial_id.h"
/**
* Return value from main().
@@ -1244,10 +1244,10 @@ check_wire_out_cb (struct AggregationContext *ac,
TALER_amount_set_zero (amount->currency,
&wcc.total_deposits));
wcc.payto_uri = payto_uri;
- qs = TALER_EXCHANGEDB_lookup_wire_transfer (TALER_ARL_edb,
- wtid,
- &wire_transfer_information_cb,
- &wcc);
+ qs = TALER_EXCHANGEDB_iterate_wire_transfers (TALER_ARL_edb,
+ wtid,
+ &wire_transfer_information_cb,
+ &wcc);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -1451,7 +1451,7 @@ analyze_aggregations (void *cls)
}
ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- qs = TALER_EXCHANGEDB_select_wire_out_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_wire_outs_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id),
&check_wire_out_cb,
diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c
@@ -23,7 +23,7 @@
#include "report-lib.h"
#include "taler/taler_dbevents.h"
#include "exchangedb_lib.h"
-#include "auditor-database/del_denomination_balance.h"
+#include "auditor-database/delete_denomination_balance.h"
#include "auditor-database/event_listen.h"
#include "auditor-database/get_auditor_progress.h"
#include "auditor-database/get_balance.h"
@@ -41,7 +41,7 @@
#include "auditor-database/update_auditor_progress.h"
#include "auditor-database/update_balance.h"
#include "auditor-database/update_denomination_balance.h"
-#include "exchange-database/count_known_coins.h"
+#include "exchange-database/get_count_known_coins.h"
#include "exchange-database/get_coin_transactions.h"
#include "exchange-database/get_denomination_revocation.h"
#include "exchange-database/get_known_coin.h"
@@ -57,16 +57,16 @@ struct CoinContext;
#define TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE struct CoinContext
#define TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE struct CoinContext
#include "exchange-database/iterate_denomination_info.h"
-#include "exchange-database/select_auditor_denom_sig.h"
-#include "exchange-database/select_coin_deposits_above_serial_id.h"
-#include "exchange-database/select_purse_decisions_above_serial_id.h"
-#include "exchange-database/select_purse_deposits_above_serial_id.h"
-#include "exchange-database/select_purse_deposits_by_purse.h"
-#include "exchange-database/select_recoup_above_serial_id.h"
-#include "exchange-database/select_recoup_refresh_above_serial_id.h"
-#include "exchange-database/select_refreshes_above_serial_id.h"
-#include "exchange-database/select_refunds_above_serial_id.h"
-#include "exchange-database/select_withdrawals_above_serial_id.h"
+#include "exchange-database/get_auditor_denom_sig.h"
+#include "exchange-database/iterate_coin_deposits_above_serial_id.h"
+#include "exchange-database/iterate_purse_decisions_above_serial_id.h"
+#include "exchange-database/iterate_purse_deposits_above_serial_id.h"
+#include "exchange-database/iterate_purse_deposits_by_purse.h"
+#include "exchange-database/iterate_recoups_above_serial_id.h"
+#include "exchange-database/iterate_recoup_refreshes_above_serial_id.h"
+#include "exchange-database/iterate_refreshes_above_serial_id.h"
+#include "exchange-database/iterate_refunds_above_serial_id.h"
+#include "exchange-database/iterate_withdrawals_above_serial_id.h"
/**
@@ -861,8 +861,8 @@ sync_denomination (void *cls,
/* Denomination key has expired, book remaining balance of
outstanding coins as revenue; and reduce cc->risk exposure. */
if (ds->in_db)
- qs = TALER_AUDITORDB_del_denomination_balance (TALER_ARL_adb,
- &denom_h);
+ qs = TALER_AUDITORDB_delete_denomination_balance (TALER_ARL_adb,
+ &denom_h);
else
qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
if (qs < 0)
@@ -920,8 +920,8 @@ sync_denomination (void *cls,
GNUNET_h2s (denom_hash),
TALER_amount2s (&ds->dcd.denom_balance),
(unsigned long long) ds->dcd.num_issued);
- cnt = TALER_EXCHANGEDB_count_known_coins (TALER_ARL_edb,
- &denom_h);
+ cnt = TALER_EXCHANGEDB_get_count_known_coins (TALER_ARL_edb,
+ &denom_h);
if (0 > cnt)
{
/* Failed to obtain count? Bad database */
@@ -2014,11 +2014,11 @@ purse_refund_cb (struct CoinContext *cc,
GNUNET_assert (rowid >=
TALER_ARL_USE_PP (coins_purse_refunds_serial_id)); /* should be monotonically increasing */
TALER_ARL_USE_PP (coins_purse_refunds_serial_id) = rowid + 1;
- qs = TALER_TALER_EXCHANGEDB_select_purse_deposits_by_purse (TALER_ARL_edb,
- purse_pub,
- &
- purse_refund_coin_cb,
- cc);
+ qs = TALER_EXCHANGEDB_iterate_purse_deposits_by_purse (TALER_ARL_edb,
+ purse_pub,
+ &
+ purse_refund_coin_cb,
+ cc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -2417,10 +2417,10 @@ check_denomination (
struct TALER_AuditorSignatureP auditor_sig;
(void) denom_pub;
- qs = TALER_EXCHANGEDB_select_auditor_denom_sig (TALER_ARL_edb,
- &issue->denom_hash,
- &TALER_ARL_auditor_pub,
- &auditor_sig);
+ qs = TALER_EXCHANGEDB_get_auditor_denom_sig (TALER_ARL_edb,
+ &issue->denom_hash,
+ &TALER_ARL_auditor_pub,
+ &auditor_sig);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -2724,7 +2724,7 @@ analyze_coins (void *cls)
}
/* process withdrawals */
if (0 >
- (qs = TALER_EXCHANGEDB_select_withdrawals_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_withdrawals_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_withdraw_serial_id),
&withdraw_cb,
@@ -2740,7 +2740,7 @@ analyze_coins (void *cls)
}
/* process refreshes */
if (0 >
- (qs = TALER_EXCHANGEDB_select_refreshes_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_refreshes_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_melt_serial_id),
&refresh_session_cb,
@@ -2756,7 +2756,7 @@ analyze_coins (void *cls)
}
/* process refunds */
if (0 >
- (qs = TALER_EXCHANGEDB_select_refunds_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_refunds_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_refund_serial_id),
&refund_cb,
@@ -2773,7 +2773,7 @@ analyze_coins (void *cls)
#if FIXME_9828
/* process recoups */
if (0 >
- (qs = TALER_EXCHANGEDB_select_recoup_refresh_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_recoup_refreshes_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_recoup_refresh_serial_id),
&recoup_refresh_cb,
@@ -2790,7 +2790,7 @@ analyze_coins (void *cls)
#endif
/* process deposits */
if (0 >
- (qs = TALER_EXCHANGEDB_select_coin_deposits_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_coin_deposits_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_deposit_serial_id),
&deposit_cb,
@@ -2806,7 +2806,7 @@ analyze_coins (void *cls)
}
/* process purse_deposits */
if (0 >
- (qs = TALER_TALER_EXCHANGEDB_select_purse_deposits_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_purse_deposits_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_purse_deposits_serial_id),
&purse_deposit_cb,
@@ -2822,7 +2822,7 @@ analyze_coins (void *cls)
}
/* process purse_refunds */
if (0 >
- (qs = TALER_TALER_EXCHANGEDB_select_purse_decisions_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_purse_decisions_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_purse_refunds_serial_id),
true, /* only go for refunds! */
@@ -2838,7 +2838,7 @@ analyze_coins (void *cls)
goto cleanup;
}
if (0 >
- (qs = TALER_EXCHANGEDB_select_recoup_above_serial_id (
+ (qs = TALER_EXCHANGEDB_iterate_recoups_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (coins_recoup_serial_id),
&recoup_cb,
diff --git a/src/auditor/taler-helper-auditor-deposits.c b/src/auditor/taler-helper-auditor-deposits.c
@@ -35,12 +35,12 @@
#include "auditor-database/event_listen.h"
#include "auditor-database/get_auditor_progress.h"
#include "auditor-database/get_balance.h"
-#include "auditor-database/get_deposit_confirmations.h"
+#include "auditor-database/iterate_deposit_confirmations.h"
#include "auditor-database/insert_auditor_progress.h"
#include "auditor-database/insert_balance.h"
#include "auditor-database/update_auditor_progress.h"
#include "auditor-database/update_balance.h"
-#include "exchange-database/have_deposit2.h"
+#include "exchange-database/get_exists_deposit.h"
/*
--
@@ -132,14 +132,14 @@ test_dc (void *cls,
struct GNUNET_TIME_Timestamp exchange_timestamp;
struct TALER_Amount deposit_fee;
- qs = TALER_EXCHANGEDB_have_deposit2 (TALER_ARL_edb,
- &dc->h_contract_terms,
- &dc->h_wire,
- &dc->coin_pubs[i],
- &dc->merchant,
- dc->refund_deadline,
- &deposit_fee,
- &exchange_timestamp);
+ qs = TALER_EXCHANGEDB_get_exists_deposit (TALER_ARL_edb,
+ &dc->h_contract_terms,
+ &dc->h_wire,
+ &dc->coin_pubs[i],
+ &dc->merchant,
+ dc->refund_deadline,
+ &deposit_fee,
+ &exchange_timestamp);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Status for deposit confirmation %llu-%u is %d\n",
(unsigned long long) dc->row_id,
@@ -202,14 +202,14 @@ recheck_dc (void *cls,
struct GNUNET_TIME_Timestamp exchange_timestamp;
struct TALER_Amount deposit_fee;
- qs = TALER_EXCHANGEDB_have_deposit2 (TALER_ARL_edb,
- &dc->h_contract_terms,
- &dc->h_wire,
- &dc->coin_pubs[i],
- &dc->merchant,
- dc->refund_deadline,
- &deposit_fee,
- &exchange_timestamp);
+ qs = TALER_EXCHANGEDB_get_exists_deposit (TALER_ARL_edb,
+ &dc->h_contract_terms,
+ &dc->h_wire,
+ &dc->coin_pubs[i],
+ &dc->merchant,
+ dc->refund_deadline,
+ &deposit_fee,
+ &exchange_timestamp);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Status for deposit confirmation %llu-%u is %d on re-check\n",
(unsigned long long) dc->row_id,
@@ -311,7 +311,7 @@ analyze_deposit_confirmations (void *cls)
had_bal = (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
had_missing = ! TALER_amount_is_zero (
&TALER_ARL_USE_AB (total_missed_deposit_confirmations));
- qs = TALER_AUDITORDB_get_deposit_confirmations (
+ qs = TALER_AUDITORDB_iterate_deposit_confirmations (
TALER_ARL_adb,
INT64_MAX,
TALER_ARL_USE_PP (deposit_confirmation_serial_id),
@@ -350,7 +350,7 @@ analyze_deposit_confirmations (void *cls)
}
if (had_bal && had_pp && had_missing)
{
- qs = TALER_AUDITORDB_get_deposit_confirmations (
+ qs = TALER_AUDITORDB_iterate_deposit_confirmations (
TALER_ARL_adb,
-INT64_MAX,
pp + 1, /* previous iteration went up to 'pp', try missing again */
diff --git a/src/auditor/taler-helper-auditor-purses.c b/src/auditor/taler-helper-auditor-purses.c
@@ -40,7 +40,7 @@
#include "auditor-database/insert_row_inconsistency.h"
struct PurseContext;
#define TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE struct PurseContext
-#include "auditor-database/select_purse_expired.h"
+#include "auditor-database/iterate_purse_expired.h"
#include "auditor-database/update_auditor_progress.h"
#include "auditor-database/update_balance.h"
#include "auditor-database/update_purse_info.h"
@@ -52,13 +52,13 @@ struct PurseContext;
#define TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE struct PurseContext
#define TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE struct PurseContext
#define TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE struct PurseContext
-#include "exchange-database/select_account_merges_above_serial_id.h"
-#include "exchange-database/select_all_purse_decisions_above_serial_id.h"
-#include "exchange-database/select_all_purse_deletions_above_serial_id.h"
-#include "exchange-database/select_purse.h"
-#include "exchange-database/select_purse_deposits_above_serial_id.h"
-#include "exchange-database/select_purse_merges_above_serial_id.h"
-#include "exchange-database/select_purse_requests_above_serial_id.h"
+#include "exchange-database/iterate_account_merges_above_serial_id.h"
+#include "exchange-database/iterate_all_purse_decisions_above_serial_id.h"
+#include "exchange-database/iterate_all_purse_deletions_above_serial_id.h"
+#include "exchange-database/get_purse.h"
+#include "exchange-database/iterate_purse_deposits_above_serial_id.h"
+#include "exchange-database/iterate_purse_merges_above_serial_id.h"
+#include "exchange-database/iterate_purse_requests_above_serial_id.h"
/**
@@ -472,16 +472,16 @@ setup_purse (struct PurseContext *pc,
TALER_amount_set_zero (TALER_ARL_currency,
&ps->balance));
/* get purse meta-data from exchange DB */
- qs = TALER_EXCHANGEDB_select_purse (TALER_ARL_edb,
- purse_pub,
- &ps->creation_date,
- &ps->expiration_date,
- &ps->total_value,
- &ps->exchange_balance,
- &ps->h_contract_terms,
- &ps->merge_timestamp,
- &ps->purse_deleted,
- &ps->purse_refunded);
+ qs = TALER_EXCHANGEDB_get_purse (TALER_ARL_edb,
+ purse_pub,
+ &ps->creation_date,
+ &ps->expiration_date,
+ &ps->total_value,
+ &ps->exchange_balance,
+ &ps->h_contract_terms,
+ &ps->merge_timestamp,
+ &ps->purse_deleted,
+ &ps->purse_refunded);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Loaded purse `%s' meta-data (%d)\n",
TALER_B2S (purse_pub),
@@ -1455,7 +1455,7 @@ analyze_purses (void *cls)
pc.purses = GNUNET_CONTAINER_multihashmap_create (512,
GNUNET_NO);
- qs = TALER_TALER_EXCHANGEDB_select_purse_requests_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_purse_requests_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (purse_request_serial_id),
&handle_purse_requested,
@@ -1470,7 +1470,7 @@ analyze_purses (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == pc.qs);
return pc.qs;
}
- qs = TALER_TALER_TALER_EXCHANGEDB_select_purse_merges_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_purse_merges_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (purse_merges_serial_id),
&handle_purse_merged,
@@ -1486,7 +1486,7 @@ analyze_purses (void *cls)
return pc.qs;
}
- qs = TALER_TALER_EXCHANGEDB_select_purse_deposits_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_purse_deposits_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (purse_deposits_serial_id),
&handle_purse_deposits,
@@ -1503,7 +1503,7 @@ analyze_purses (void *cls)
}
/* Charge purse fee! */
- qs = TALER_EXCHANGEDB_select_account_merges_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_account_merges_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (purse_account_merge_serial_id),
&handle_account_merged,
@@ -1519,7 +1519,7 @@ analyze_purses (void *cls)
return pc.qs;
}
- qs = TALER_EXCHANGEDB_select_all_purse_decisions_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_all_purse_decisions_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (purse_decision_serial_id),
&handle_purse_decision,
@@ -1535,7 +1535,7 @@ analyze_purses (void *cls)
return pc.qs;
}
- qs = TALER_EXCHANGEDB_select_all_purse_deletions_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_all_purse_deletions_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (purse_deletion_serial_id),
&handle_purse_deletion,
@@ -1551,7 +1551,7 @@ analyze_purses (void *cls)
return pc.qs;
}
- qs = TALER_AUDITORDB_select_purse_expired (
+ qs = TALER_AUDITORDB_iterate_purse_expired (
TALER_ARL_adb,
&handle_purse_expired,
&pc);
diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c
@@ -28,8 +28,8 @@ struct ReserveContext;
#include "report-lib.h"
#include "taler/taler_dbevents.h"
#include "exchangedb_lib.h"
-#include "exchange-database/select_reserve_close_request_info.h"
-#include "auditor-database/del_reserve_info.h"
+#include "exchange-database/get_reserve_close_request_info.h"
+#include "auditor-database/delete_reserve_info.h"
#include "auditor-database/event_listen.h"
#include "auditor-database/get_auditor_progress.h"
#include "auditor-database/get_balance.h"
@@ -52,7 +52,7 @@ struct ReserveContext;
#include "auditor-database/update_reserve_info.h"
#include "exchange-database/get_denomination_revocation.h"
#include "exchange-database/get_wire_fee.h"
-#include "exchange-database/reserves_get.h"
+#include "exchange-database/get_reserve.h"
struct ReserveContext;
#define TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE struct ReserveContext
#define TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE struct ReserveContext
@@ -60,13 +60,13 @@ struct ReserveContext;
#define TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE struct ReserveContext
#define TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE struct ReserveContext
#define TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE struct ReserveContext
-#include "exchange-database/select_account_merges_above_serial_id.h"
-#include "exchange-database/select_purse_decisions_above_serial_id.h"
-#include "exchange-database/select_recoup_above_serial_id.h"
-#include "exchange-database/select_reserve_closed_above_serial_id.h"
-#include "exchange-database/select_reserve_open_above_serial_id.h"
-#include "exchange-database/select_reserves_in_above_serial_id.h"
-#include "exchange-database/select_withdrawals_above_serial_id.h"
+#include "exchange-database/iterate_account_merges_above_serial_id.h"
+#include "exchange-database/iterate_purse_decisions_above_serial_id.h"
+#include "exchange-database/iterate_recoups_above_serial_id.h"
+#include "exchange-database/iterate_reserve_closed_above_serial_id.h"
+#include "exchange-database/iterate_reserve_open_above_serial_id.h"
+#include "exchange-database/iterate_reserves_in_above_serial_id.h"
+#include "exchange-database/iterate_withdrawals_above_serial_id.h"
/**
* Use a 1 day grace period to deal with clocks not being perfectly synchronized.
@@ -1184,7 +1184,7 @@ handle_reserve_closed (
struct TALER_FullPayto payto_uri = { NULL };
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_select_reserve_close_request_info (
+ qs = TALER_EXCHANGEDB_get_reserve_close_request_info (
TALER_ARL_edb,
reserve_pub,
close_request_row,
@@ -1521,8 +1521,8 @@ verify_reserve_balance (void *cls,
.pub = rs->reserve_pub
};
- qs = TALER_EXCHANGEDB_reserves_get (TALER_ARL_edb,
- &reserve);
+ qs = TALER_EXCHANGEDB_get_reserve (TALER_ARL_edb,
+ &reserve);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -1780,8 +1780,8 @@ verify_reserve_balance (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Final balance of reserve `%s' is zero, dropping it\n",
TALER_B2S (&rs->reserve_pub));
- qs = TALER_AUDITORDB_del_reserve_info (TALER_ARL_adb,
- &rs->reserve_pub);
+ qs = TALER_AUDITORDB_delete_reserve_info (TALER_ARL_adb,
+ &rs->reserve_pub);
if (0 >= qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -1936,19 +1936,19 @@ analyze_reserves (void *cls)
rc.revoked = GNUNET_CONTAINER_multihashmap_create (4,
GNUNET_NO);
- qs = TALER_EXCHANGEDB_select_reserves_in_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_reserves_in_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_reserve_in_serial_id),
&handle_reserve_in,
&rc);
CHECK_DB ();
- qs = TALER_EXCHANGEDB_select_withdrawals_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_withdrawals_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_withdraw_serial_id),
&handle_withdrawals,
&rc);
CHECK_DB ();
- qs = TALER_EXCHANGEDB_select_recoup_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_recoups_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id),
&handle_recoup_by_reserve,
@@ -1961,20 +1961,20 @@ analyze_reserves (void *cls)
return qs;
}
- qs = TALER_EXCHANGEDB_select_reserve_open_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_reserve_open_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_reserve_open_serial_id),
&handle_reserve_open,
&rc);
CHECK_DB ();
- qs = TALER_EXCHANGEDB_select_reserve_closed_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_reserve_closed_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_reserve_close_serial_id),
&handle_reserve_closed,
&rc);
CHECK_DB ();
/* process purse_decisions (to credit reserve) */
- qs = TALER_TALER_EXCHANGEDB_select_purse_decisions_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_purse_decisions_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_purse_decisions_serial_id),
false, /* only go for merged purses! */
@@ -1983,7 +1983,7 @@ analyze_reserves (void *cls)
CHECK_DB ();
/* Charge purse fee! */
- qs = TALER_EXCHANGEDB_select_account_merges_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_account_merges_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (reserves_account_merges_serial_id),
&handle_account_merged,
diff --git a/src/auditor/taler-helper-auditor-transfer.c b/src/auditor/taler-helper-auditor-transfer.c
@@ -45,11 +45,11 @@
#include "exchange-database/rollback.h"
struct AggregationContext;
#define TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE struct AggregationContext
-#include "exchange-database/select_aggregations_above_serial.h"
+#include "exchange-database/iterate_aggregations_above_serial_id.h"
struct ImportMissingWireContext;
#define TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE struct \
ImportMissingWireContext
-#include "exchange-database/select_batch_deposits_missing_wire.h"
+#include "exchange-database/iterate_batch_deposits_missing_wire.h"
#include "exchange-database/start_read_only.h"
@@ -212,7 +212,7 @@ check_for_required_transfers (void)
.err = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
};
- qs = TALER_EXCHANGEDB_select_batch_deposits_missing_wire (
+ qs = TALER_EXCHANGEDB_iterate_batch_deposits_missing_wire (
TALER_ARL_edb,
TALER_ARL_USE_PP (wire_batch_deposit_id),
&import_wire_missing_cb,
@@ -326,7 +326,7 @@ check_for_completed_transfers (void)
};
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_select_aggregations_above_serial (
+ qs = TALER_EXCHANGEDB_iterate_aggregations_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (wire_aggregation_id),
&clear_finished_transfer_cb,
@@ -378,8 +378,8 @@ begin_transaction (void)
return GNUNET_DB_STATUS_HARD_ERROR;
}
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_only (TALER_ARL_edb,
- "transfer auditor"))
+ TALER_EXCHANGEDB_start_read_only (TALER_ARL_edb,
+ "transfer auditor"))
{
GNUNET_break (0);
TALER_AUDITORDB_rollback (TALER_ARL_adb);
diff --git a/src/auditor/taler-helper-auditor-wire-credit.c b/src/auditor/taler-helper-auditor-wire-credit.c
@@ -32,7 +32,7 @@
#include "report-lib.h"
#include "taler/taler_dbevents.h"
#include \
- "exchange-database/select_reserves_in_above_serial_id_by_account.h"
+ "exchange-database/iterate_reserves_in_above_serial_id_by_account.h"
#include "auditor-database/delete_reserve_in_inconsistency.h"
#include "auditor-database/event_listen.h"
#include "auditor-database/get_auditor_progress.h"
@@ -44,14 +44,14 @@
#include "auditor-database/insert_row_inconsistency.h"
#include "auditor-database/insert_row_minor_inconsistencies.h"
#include "auditor-database/preflight.h"
-#include "auditor-database/select_reserve_in_inconsistency.h"
+#include "auditor-database/get_reserve_in_inconsistency.h"
#include "auditor-database/start.h"
#include "auditor-database/update_auditor_progress.h"
#include "auditor-database/update_balance.h"
#include "exchange-database/preflight.h"
#include "exchange-database/rollback.h"
#include \
- "exchange-database/select_reserves_in_above_serial_id_by_account.h"
+ "exchange-database/iterate_reserves_in_above_serial_id_by_account.h"
#include "exchange-database/start_read_only.h"
/**
@@ -575,7 +575,7 @@ reserve_in_cb (void *cls,
enum GNUNET_DB_QueryStatus qs;
struct TALER_AUDITORDB_ReserveInInconsistency dc;
- qs = TALER_AUDITORDB_select_reserve_in_inconsistency (
+ qs = TALER_AUDITORDB_get_reserve_in_inconsistency (
TALER_ARL_adb,
wire_reference,
&dc);
@@ -1090,7 +1090,7 @@ process_credits (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Analyzing exchange's wire IN table for account `%s'\n",
wa->ai->section_name);
- qs = TALER_TALER_EXCHANGEDB_select_reserves_in_above_serial_id_by_account (
+ qs = TALER_EXCHANGEDB_iterate_reserves_in_above_serial_id_by_account (
TALER_ARL_edb,
wa->ai->section_name,
wa->last_reserve_in_serial_id,
@@ -1175,8 +1175,8 @@ begin_transaction (void)
return GNUNET_DB_STATUS_HARD_ERROR;
}
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_only (TALER_ARL_edb,
- "wire credit auditor"))
+ TALER_EXCHANGEDB_start_read_only (TALER_ARL_edb,
+ "wire credit auditor"))
{
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
diff --git a/src/auditor/taler-helper-auditor-wire-debit.c b/src/auditor/taler-helper-auditor-wire-debit.c
@@ -60,11 +60,11 @@ struct WireAccount;
#include "auditor-database/start.h"
#include "auditor-database/update_auditor_progress.h"
#include "auditor-database/update_balance.h"
-#include "exchange-database/get_drain_profit.h"
+#include "exchange-database/get_profit_drain.h"
#include "exchange-database/preflight.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/select_reserve_closed_above_serial_id.h"
-#include "exchange-database/select_wire_out_above_serial_id_by_account.h"
+#include "exchange-database/iterate_reserve_closed_above_serial_id.h"
+#include "exchange-database/iterate_wire_outs_above_serial_id_by_account.h"
#include "exchange-database/start_read_only.h"
@@ -863,7 +863,7 @@ check_profit_drain (struct WireTransferOutInfo *roi)
struct TALER_Amount amount;
struct TALER_MasterSignatureP master_sig;
- qs = TALER_EXCHANGEDB_get_drain_profit (
+ qs = TALER_EXCHANGEDB_get_profit_drain (
TALER_ARL_edb,
&roi->details.wtid,
&serial,
@@ -1323,7 +1323,7 @@ check_exchange_wire_out (struct WireAccount *wa)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Analyzing exchange's wire OUT table for account `%s'\n",
wa->ai->section_name);
- qs = TALER_TALER_EXCHANGEDB_select_wire_out_above_serial_id_by_account (
+ qs = TALER_EXCHANGEDB_iterate_wire_outs_above_serial_id_by_account (
TALER_ARL_edb,
wa->ai->section_name,
wa->last_wire_out_serial_id,
@@ -1659,8 +1659,8 @@ begin_transaction (void)
return GNUNET_DB_STATUS_HARD_ERROR;
}
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_only (TALER_ARL_edb,
- "wire debit auditor"))
+ TALER_EXCHANGEDB_start_read_only (TALER_ARL_edb,
+ "wire debit auditor"))
{
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
@@ -1742,7 +1742,7 @@ begin_transaction (void)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Iterating over reserve closures from %llu\n",
(unsigned long long) TALER_ARL_USE_PP (wire_reserve_close_id));
- qs = TALER_EXCHANGEDB_select_reserve_closed_above_serial_id (
+ qs = TALER_EXCHANGEDB_iterate_reserve_closed_above_serial_id (
TALER_ARL_edb,
TALER_ARL_USE_PP (wire_reserve_close_id),
&reserve_closed_cb,
diff --git a/src/auditordb/del_denomination_balance.c b/src/auditordb/del_denomination_balance.c
@@ -1,44 +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/auditordb/del_denomination_balance.c
- * @brief Implementation of the del_denomination_balance function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/del_denomination_balance.h"
-#include "pg_helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_del_denomination_balance (struct
- TALER_AUDITORDB_PostgresContext *pg,
- const struct TALER_DenominationHashP *
- denom_pub_hash)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_del_denomination_balance",
- "DELETE"
- " FROM auditor_denomination_pending"
- " WHERE denom_pub_hash=$1");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_del_denomination_balance",
- params);
-}
diff --git a/src/auditordb/del_reserve_info.c b/src/auditordb/del_reserve_info.c
@@ -1,44 +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 del_reserve_info.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/del_reserve_info.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_del_reserve_info (struct TALER_AUDITORDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *
- reserve_pub)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_del_reserve_info",
- "DELETE"
- " FROM auditor_reserves"
- " WHERE reserve_pub=$1");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_del_reserve_info",
- params);
-}
diff --git a/src/auditordb/delete_denomination_balance.c b/src/auditordb/delete_denomination_balance.c
@@ -0,0 +1,46 @@
+/*
+ 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/auditordb/delete_denomination_balance.c
+ * @brief Implementation of the delete_denomination_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/delete_denomination_balance.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_delete_denomination_balance (struct
+ TALER_AUDITORDB_PostgresContext *pg
+ ,
+ const struct
+ TALER_DenominationHashP *
+ denom_pub_hash)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "delete_denomination_balance",
+ "DELETE"
+ " FROM auditor_denomination_pending"
+ " WHERE denom_pub_hash=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "delete_denomination_balance",
+ params);
+}
diff --git a/src/auditordb/delete_early_aggregation.c b/src/auditordb/delete_early_aggregation.c
@@ -34,12 +34,12 @@ TALER_AUDITORDB_delete_early_aggregation (struct
};
PREPARE (pg,
- "auditor_delete_early_aggregation",
+ "delete_early_aggregation",
"DELETE"
" FROM auditor_early_aggregations"
" WHERE batch_deposit_serial_id=$1;");
return GNUNET_PQ_eval_prepared_non_select (
pg->conn,
- "auditor_delete_early_aggregation",
+ "delete_early_aggregation",
params);
}
diff --git a/src/auditordb/delete_pending_deposit.c b/src/auditordb/delete_pending_deposit.c
@@ -34,11 +34,11 @@ TALER_AUDITORDB_delete_pending_deposit (struct TALER_AUDITORDB_PostgresContext *
};
PREPARE (pg,
- "auditor_delete_pending_deposit",
+ "delete_pending_deposit",
"DELETE"
" FROM auditor_pending_deposits"
" WHERE batch_deposit_serial_id=$1;");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_delete_pending_deposit",
+ "delete_pending_deposit",
params);
}
diff --git a/src/auditordb/delete_purse_info.c b/src/auditordb/delete_purse_info.c
@@ -34,10 +34,10 @@ TALER_AUDITORDB_delete_purse_info (struct TALER_AUDITORDB_PostgresContext *pg,
};
PREPARE (pg,
- "auditor_purses_delete",
+ "delete_purse_info",
"DELETE FROM auditor_purses "
" WHERE purse_pub=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_purses_delete",
+ "delete_purse_info",
params);
}
diff --git a/src/auditordb/delete_reserve_info.c b/src/auditordb/delete_reserve_info.c
@@ -0,0 +1,44 @@
+/*
+ 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 delete_reserve_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/delete_reserve_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_delete_reserve_info (struct TALER_AUDITORDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *
+ reserve_pub)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "delete_reserve_info",
+ "DELETE"
+ " FROM auditor_reserves"
+ " WHERE reserve_pub=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "delete_reserve_info",
+ params);
+}
diff --git a/src/auditordb/delete_wire_out_inconsistency_if_matching.c b/src/auditordb/delete_wire_out_inconsistency_if_matching.c
@@ -39,7 +39,7 @@ TALER_AUDITORDB_delete_wire_out_inconsistency_if_matching (struct
};
PREPARE (ctx,
- "auditor_wire_out_inconsistency_delete_if_matching",
+ "delete_wire_out_inconsistency_if_matching",
"DELETE FROM auditor_wire_out_inconsistency "
" WHERE destination_account=$1"
" AND diagnostic=$2"
@@ -51,6 +51,6 @@ TALER_AUDITORDB_delete_wire_out_inconsistency_if_matching (struct
);
return GNUNET_PQ_eval_prepared_non_select (
ctx->conn,
- "auditor_wire_out_inconsistency_delete_if_matching",
+ "delete_wire_out_inconsistency_if_matching",
params);
}
diff --git a/src/auditordb/get_amount_arithmetic_inconsistency.c b/src/auditordb/get_amount_arithmetic_inconsistency.c
@@ -1,174 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_amount_arithmetic_inconsistency.h"
-
-/**
- * Closure for #deposit_confirmation_cb().
- */
-struct AmountArithmeticInconsistencyContext
-{
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_deposit_confirmations().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositConfirmationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-amount_arithmetic_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AmountArithmeticInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_AmountArithmeticInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_uint64 ("problem_row_id",
- &dc.problem_row_id),
- GNUNET_PQ_result_spec_string ("operation",
- &dc.operation),
- TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
- &dc.exchange_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
- &dc.auditor_amount),
- GNUNET_PQ_result_spec_bool ("profitable",
- &dc.profitable),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_amount_arithmetic_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct AmountArithmeticInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_amount_arithmetic_inconsistency_select_desc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",operation"
- ",exchange_amount"
- ",auditor_amount"
- ",profitable"
- ",suppressed"
- " FROM auditor_amount_arithmetic_inconsistency"
- " WHERE (row_id<$1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_amount_arithmetic_inconsistency_select_asc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",operation"
- ",exchange_amount"
- ",auditor_amount"
- ",profitable"
- ",suppressed"
- " FROM auditor_amount_arithmetic_inconsistency"
- " WHERE (row_id>$1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_amount_arithmetic_inconsistency_select_asc"
- : "auditor_amount_arithmetic_inconsistency_select_desc",
- params,
- &amount_arithmetic_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_auditor_closure_lags.c b/src/auditordb/get_auditor_closure_lags.c
@@ -1,173 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_dbevents.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_auditor_closure_lags.h"
-
-
-struct ClosureLagsContext
-{
-
- /**
- * Function to call for each closure lag .
- */
- TALER_AUDITORDB_ClosureLagsCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_auditor_closure_lags().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ClosureLagsContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-closure_lags_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ClosureLagsContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_ClosureLags dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_uint64 ("problem_row_id",
- &dc.problem_row_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &dc.amount),
- GNUNET_PQ_result_spec_absolute_time ("deadline",
- &dc.deadline),
- GNUNET_PQ_result_spec_auto_from_type ("wtid",
- &dc.wtid),
- GNUNET_PQ_result_spec_string ("account",
- &dc.account.full_payto),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_auditor_closure_lags (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_ClosureLagsCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct ClosureLagsContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_closure_lags_get_desc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",amount"
- ",deadline"
- ",wtid"
- ",account"
- ",suppressed"
- " FROM auditor_closure_lags"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_closure_lags_get_asc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",amount"
- ",deadline"
- ",wtid"
- ",account"
- ",suppressed"
- " FROM auditor_closure_lags"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_closure_lags_get_asc"
- : "auditor_closure_lags_get_desc",
- params,
- &closure_lags_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_bad_sig_losses.c b/src/auditordb/get_bad_sig_losses.c
@@ -1,180 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_bad_sig_losses.h"
-
-
-struct BadSigLossesContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_BadSigLossesCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_bad_sig_losses().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct BadSigLossesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-bad_sig_losses_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct BadSigLossesContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_BadSigLosses dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_uint64 ("problem_row_id",
- &dc.problem_row_id),
- GNUNET_PQ_result_spec_string ("operation",
- &dc.operation),
- TALER_PQ_RESULT_SPEC_AMOUNT ("loss",
- &dc.loss),
- GNUNET_PQ_result_spec_auto_from_type ("operation_specific_pub",
- &dc.operation_specific_pub),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_bad_sig_losses (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub,
- const char *op,
- TALER_AUDITORDB_BadSigLossesCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- NULL == op_spec_pub
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (op_spec_pub),
- NULL == op
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (op),
- GNUNET_PQ_query_param_end
- };
- struct BadSigLossesContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_bad_sig_losses_get_desc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",operation"
- ",loss"
- ",operation_specific_pub"
- ",suppressed"
- " FROM auditor_bad_sig_losses"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)"
- " AND ($5::TEXT IS NULL OR operation = $5)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_bad_sig_losses_get_asc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",operation"
- ",loss"
- ",operation_specific_pub"
- ",suppressed"
- " FROM auditor_bad_sig_losses"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)"
- " AND ($5::TEXT IS NULL OR operation = $5)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_bad_sig_losses_get_asc"
- : "auditor_bad_sig_losses_get_desc",
- params,
- &bad_sig_losses_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_balances.c b/src/auditordb/get_balances.c
@@ -1,132 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_balances.h"
-
-
-struct BalancesContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_BalancesCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_balances().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct BalancesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-balances_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct BalancesContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_Balances dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("balance_key",
- &dc.balance_key),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance_value",
- &dc.balance_value),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_balances (
- struct TALER_AUDITORDB_PostgresContext *pg,
- const char *balance_key,
- TALER_AUDITORDB_BalancesCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- NULL == balance_key
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (balance_key),
- GNUNET_PQ_query_param_end
- };
- struct BalancesContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_balances_get",
- "SELECT"
- " balance_key"
- ",balance_value"
- " FROM auditor_balances"
- " WHERE ($1::TEXT IS NULL OR balance_key = $1)"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "auditor_balances_get",
- params,
- &balances_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_coin_inconsistency.c b/src/auditordb/get_coin_inconsistency.c
@@ -1,183 +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/>
- */
-
-
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_coin_inconsistency.h"
-
-/**
- * Closure for #deposit_confirmation_cb().
- */
-struct CoinInconsistencyContext
-{
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_CoinInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_deposit_confirmations().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositConfirmationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-coin_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t serial_id;
-
- struct TALER_AUDITORDB_CoinInconsistency dc;
-
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &serial_id),
- GNUNET_PQ_result_spec_string ("operation",
- &dc.operation),
- TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
- &dc.exchange_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
- &dc.auditor_amount),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &dc.coin_pub),
- GNUNET_PQ_result_spec_bool ("profitable",
- &dc.profitable),
-
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- dcc->qs = i + 1;
-
-
- rval = dcc->cb (dcc->cb_cls,
- serial_id,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_coin_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed, // maybe not needed
- TALER_AUDITORDB_CoinInconsistencyCallback cb,
- void *cb_cls)
-{
-
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct CoinInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
-
- PREPARE (pg,
- "auditor_coin_inconsistency_select_desc",
- "SELECT"
- " row_id"
- ",operation"
- ",exchange_amount"
- ",auditor_amount"
- ",coin_pub"
- ",profitable"
- " FROM auditor_coin_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_coin_inconsistency_select_asc",
- "SELECT"
- " row_id"
- ",operation"
- ",exchange_amount"
- ",auditor_amount"
- ",coin_pub"
- ",profitable"
- " FROM auditor_coin_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- (limit > 0) ?
- "auditor_coin_inconsistency_select_asc"
- :
- "auditor_coin_inconsistency_select_desc",
- params,
- &coin_inconsistency_cb,
- &dcc);
-
-
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_denomination_balance.c b/src/auditordb/get_denomination_balance.c
@@ -48,7 +48,7 @@ TALER_AUDITORDB_get_denomination_balance (
};
PREPARE (pg,
- "auditor_denomination_pending_select",
+ "get_denomination_balance",
"SELECT"
" denom_balance"
",denom_loss"
@@ -59,7 +59,7 @@ TALER_AUDITORDB_get_denomination_balance (
" WHERE denom_pub_hash=$1");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "auditor_denomination_pending_select",
+ "get_denomination_balance",
params,
rs);
}
diff --git a/src/auditordb/get_denomination_key_validity_withdraw_inconsistency.c b/src/auditordb/get_denomination_key_validity_withdraw_inconsistency.c
@@ -1,171 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include \
- "auditor-database/get_denomination_key_validity_withdraw_inconsistency.h"
-
-
-/**
- * Closure for #denomination_key_validity_withdraw_inconsistency_cb().
- */
-struct DenominationKeyValidityWithdrawInconsistencyContext
-{
-
- /**
- * Function to call for each denomination key validity...
- */
- TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_deposit_confirmations().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositConfirmationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-denomination_key_validity_withdraw_inconsistency_cb (
- void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DenominationKeyValidityWithdrawInconsistencyContext *dcc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_uint64 ("problem_row_id",
- &dc.problem_row_id),
- GNUNET_PQ_result_spec_absolute_time ("execution_date",
- &dc.execution_date),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
- &dc.denompub_h),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_denomination_key_validity_withdraw_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct DenominationKeyValidityWithdrawInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_denomination_key_validity_withdraw_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",execution_date"
- ",reserve_pub"
- ",denompub_h"
- ",suppressed"
- " FROM auditor_denomination_key_validity_withdraw_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_denomination_key_validity_withdraw_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",execution_date"
- ",reserve_pub"
- ",denompub_h"
- ",suppressed"
- " FROM auditor_denomination_key_validity_withdraw_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_denomination_key_validity_withdraw_inconsistency_get_asc"
- : "auditor_denomination_key_validity_withdraw_inconsistency_get_desc",
- params,
- &denomination_key_validity_withdraw_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_denomination_pending.c b/src/auditordb/get_denomination_pending.c
@@ -1,169 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_denomination_pending.h"
-
-
-struct DenominationPendingContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_DenominationPendingCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_denomination_pending().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DenominationPendingContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-denomination_pending_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DenominationPendingContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t serial_id;
- struct TALER_AUDITORDB_DenominationPending dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &serial_id),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &dc.denom_pub_hash),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance",
- &dc.denom_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss",
- &dc.denom_loss),
- GNUNET_PQ_result_spec_uint64 ("num_issued",
- &dc.num_issued),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk",
- &dc.denom_risk),
- TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss",
- &dc.recoup_loss),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- serial_id,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_denomination_pending (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_DenominationPendingCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct DenominationPendingContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_denomination_pending_get_desc",
- "SELECT"
- " row_id,"
- " denom_pub_hash,"
- " denom_balance,"
- " denom_loss,"
- " num_issued,"
- " denom_risk,"
- " recoup_loss"
- " FROM auditor_denomination_pending"
- " WHERE (row_id < $1)"
- " ORDER BY row_id DESC"
- " LIMIT $2"
- );
- PREPARE (pg,
- "auditor_denomination_pending_get_asc",
- "SELECT"
- " row_id,"
- " denom_pub_hash,"
- " denom_balance,"
- " denom_loss,"
- " num_issued,"
- " denom_risk,"
- " recoup_loss"
- " FROM auditor_denomination_pending"
- " WHERE (row_id > $1)"
- " ORDER BY row_id ASC"
- " LIMIT $2"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_denomination_pending_get_asc"
- : "auditor_denomination_pending_get_desc",
- params,
- &denomination_pending_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_denominations_without_sigs.c b/src/auditordb/get_denominations_without_sigs.c
@@ -1,170 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_denominations_without_sigs.h"
-
-
-struct DenominationsWithoutSigsContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_DenominationsWithoutSigsCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_denominations_without_sigs().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DenominationsWithoutSigsContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-denominations_without_sigs_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DenominationsWithoutSigsContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_DenominationsWithoutSigs dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
- &dc.denompub_h),
- TALER_PQ_RESULT_SPEC_AMOUNT ("value",
- &dc.value),
- GNUNET_PQ_result_spec_absolute_time ("start_time",
- &dc.start_time),
- GNUNET_PQ_result_spec_absolute_time ("end_time",
- &dc.end_time),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- dcc->qs = i + 1;
-
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_denominations_without_sigs (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_DenominationsWithoutSigsCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct DenominationsWithoutSigsContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_denominations_without_sigs_get_desc",
- "SELECT"
- " row_id,"
- " denompub_h,"
- " value,"
- " start_time,"
- " end_time,"
- " suppressed"
- " FROM auditor_denominations_without_sigs"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_denominations_without_sigs_get_asc",
- "SELECT"
- " row_id,"
- " denompub_h,"
- " value,"
- " start_time,"
- " end_time,"
- " suppressed"
- " FROM auditor_denominations_without_sigs"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_denominations_without_sigs_get_asc"
- : "auditor_denominations_without_sigs_get_desc",
- params,
- &denominations_without_sigs_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_deposit_confirmations.c b/src/auditordb/get_deposit_confirmations.c
@@ -1,230 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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 get_deposit_confirmations.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/get_deposit_confirmations.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #deposit_confirmation_cb().
- */
-struct DepositConfirmationContext
-{
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_DepositConfirmationCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_deposit_confirmations().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositConfirmationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-deposit_confirmation_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DepositConfirmationContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_DepositConfirmation dc = { 0 };
- struct TALER_CoinSpendPublicKeyP *coin_pubs = NULL;
- struct TALER_CoinSpendSignatureP *coin_sigs = NULL;
- size_t num_pubs = 0;
- size_t num_sigs = 0;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &dc.h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("h_policy",
- &dc.h_policy),
- GNUNET_PQ_result_spec_auto_from_type ("h_wire",
- &dc.h_wire),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- &dc.exchange_timestamp),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &dc.refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &dc.wire_deadline),
- TALER_PQ_RESULT_SPEC_AMOUNT ("total_without_fee",
- &dc.total_without_fee),
- GNUNET_PQ_result_spec_auto_array_from_type (pg->conn,
- "coin_pubs",
- &num_pubs,
- coin_pubs),
- GNUNET_PQ_result_spec_auto_array_from_type (pg->conn,
- "coin_sigs",
- &num_sigs,
- coin_sigs),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &dc.merchant),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_sig",
- &dc.exchange_sig),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
- &dc.exchange_pub),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &dc.master_sig),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- if (num_sigs != num_pubs)
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- dcc->qs = i + 1;
- dc.coin_pubs = coin_pubs;
- dc.coin_sigs = coin_sigs;
- dc.num_coins = num_sigs;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_deposit_confirmations (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_DepositConfirmationCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct DepositConfirmationContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_deposit_confirmation_select_desc",
- "SELECT"
- " row_id"
- ",h_contract_terms"
- ",h_policy"
- ",h_wire"
- ",exchange_timestamp"
- ",wire_deadline"
- ",refund_deadline"
- ",total_without_fee"
- ",coin_pubs"
- ",coin_sigs"
- ",merchant_pub"
- ",exchange_sig"
- ",exchange_pub"
- ",master_sig"
- ",suppressed"
- " FROM auditor_deposit_confirmations"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_deposit_confirmation_select_asc",
- "SELECT"
- " row_id"
- ",h_contract_terms"
- ",h_policy"
- ",h_wire"
- ",exchange_timestamp"
- ",wire_deadline"
- ",refund_deadline"
- ",total_without_fee"
- ",coin_pubs"
- ",coin_sigs"
- ",merchant_pub"
- ",exchange_sig"
- ",exchange_pub"
- ",master_sig"
- ",suppressed"
- " FROM auditor_deposit_confirmations"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_deposit_confirmation_select_asc"
- : "auditor_deposit_confirmation_select_desc",
- params,
- &deposit_confirmation_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_emergency.c b/src/auditordb/get_emergency.c
@@ -1,178 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_emergency.h"
-
-/**
- * Closure for #emergency_cb().
- */
-struct EmergencyContext
-{
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_EmergencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_emergency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct Emergency *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-emergency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct EmergencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_Emergency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
- &dc.denompub_h),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk",
- &dc.denom_risk),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss",
- &dc.denom_loss),
- GNUNET_PQ_result_spec_absolute_time ("deposit_start",
- &dc.deposit_start),
- GNUNET_PQ_result_spec_absolute_time ("deposit_end",
- &dc.deposit_end),
- TALER_PQ_RESULT_SPEC_AMOUNT ("value",
- &dc.value),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_emergency (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_EmergencyCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct EmergencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_emergency_get_desc",
- "SELECT"
- " row_id"
- ",denompub_h"
- ",denom_risk"
- ",denom_loss"
- ",deposit_start"
- ",deposit_end"
- ",value"
- ",suppressed"
- " FROM auditor_emergency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_emergency_get_asc",
- "SELECT"
- " row_id"
- ",denompub_h"
- ",denom_risk"
- ",denom_loss"
- ",deposit_start"
- ",deposit_end"
- ",value"
- ",suppressed"
- " FROM auditor_emergency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_emergency_get_asc"
- : "auditor_emergency_get_desc",
- params,
- &emergency_cb,
- &dcc);
-
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_emergency_by_count.c b/src/auditordb/get_emergency_by_count.c
@@ -1,184 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_emergency_by_count.h"
-
-
-/**
- * Closure for #emergency_cb().
- */
-struct EmergencyByCountContext
-{
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_EmergenciesByCountCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_emergency_by_count().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct Emergency *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-emergency_by_count_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct EmergencyByCountContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_EmergenciesByCount dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
- &dc.denompub_h),
- GNUNET_PQ_result_spec_uint64 ("num_issued",
- &dc.num_issued),
- GNUNET_PQ_result_spec_uint64 ("num_known",
- &dc.num_known),
- TALER_PQ_RESULT_SPEC_AMOUNT ("risk",
- &dc.risk),
- GNUNET_PQ_result_spec_absolute_time ("start",
- &dc.start),
- GNUNET_PQ_result_spec_absolute_time ("deposit_end",
- &dc.deposit_end),
- TALER_PQ_RESULT_SPEC_AMOUNT ("value",
- &dc.value),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_emergency_by_count (struct TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_EmergenciesByCountCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct EmergencyByCountContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_emergency_by_count_get_desc",
- "SELECT"
- " row_id"
- ",denompub_h"
- ",num_issued"
- ",num_known"
- ",risk"
- ",start"
- ",deposit_end"
- ",value"
- ",suppressed"
- " FROM auditor_emergency_by_count"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_emergency_by_count_get_asc",
- "SELECT"
- " row_id"
- ",denompub_h"
- ",num_issued"
- ",num_known"
- ",risk"
- ",start"
- ",deposit_end"
- ",value"
- ",suppressed"
- " FROM auditor_emergency_by_count"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_emergency_by_count_get_asc"
- : "auditor_emergency_by_count_get_desc",
- params,
- &emergency_by_count_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_exchange_signkeys.c b/src/auditordb/get_exchange_signkeys.c
@@ -1,170 +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/>
- */
-
-
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-
-#include "auditor-database/get_exchange_signkeys.h"
-
-
-struct ExchangeSignkeysContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_ExchangeSignkeysCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_exchange_signkeys().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ExchangeSignkeysContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-exchange_signkeys_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ExchangeSignkeysContext *dcc = cls;
- // struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t serial_id;
- struct TALER_AUDITORDB_ExchangeSignkeys dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &serial_id),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
- &dc.exchange_pub),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &dc.master_sig),
- GNUNET_PQ_result_spec_absolute_time ("ep_valid_from",
- &dc.ep_valid_from),
- GNUNET_PQ_result_spec_absolute_time ("ep_expire_sign",
- &dc.ep_expire_sign),
- GNUNET_PQ_result_spec_absolute_time ("ep_expire_legal",
- &dc.ep_expire_legal),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- dcc->qs = i + 1;
-
- rval = dcc->cb (dcc->cb_cls,
- serial_id,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_exchange_signkeys (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_ExchangeSignkeysCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct ExchangeSignkeysContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_exchange_signkeys_get_desc",
- "SELECT"
- " row_id,"
- " exchange_pub,"
- " master_sig,"
- " ep_valid_from,"
- " ep_expire_sign,"
- " ep_expire_legal"
- " FROM auditor_exchange_signkeys"
- " WHERE (row_id < $1)"
- " ORDER BY row_id DESC"
- " LIMIT $2"
- );
- PREPARE (pg,
- "auditor_exchange_signkeys_get_asc",
- "SELECT"
- " row_id,"
- " exchange_pub,"
- " master_sig,"
- " ep_valid_from,"
- " ep_expire_sign,"
- " ep_expire_legal"
- " FROM auditor_exchange_signkeys"
- " WHERE (row_id > $1)"
- " ORDER BY row_id ASC"
- " LIMIT $2"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_exchange_signkeys_get_asc"
- : "auditor_exchange_signkeys_get_desc",
- params,
- &exchange_signkeys_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_fee_time_inconsistency.c b/src/auditordb/get_fee_time_inconsistency.c
@@ -1,164 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_fee_time_inconsistency.h"
-
-
-/**
- * Closure for #feetimeinconsistency_cb().
- */
-struct FeeTimeInconsistencyContext
-{
-
- /**
- * Function to call for each fee time inconsistency
- */
- TALER_AUDITORDB_FeeTimeInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_emergency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct Emergency *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-fee_time_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct FeeTimeInconsistencyContext *dcc = cls;
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_FeeTimeInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_uint64 ("problem_row_id",
- &dc.problem_row_id),
- GNUNET_PQ_result_spec_string ("fee_type",
- &dc.type),
- GNUNET_PQ_result_spec_absolute_time ("fee_time",
- &dc.time),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc.diagnostic),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_fee_time_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_FeeTimeInconsistencyCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct FeeTimeInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_fee_time_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",fee_type"
- ",fee_time"
- ",diagnostic"
- " FROM auditor_fee_time_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_fee_time_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",problem_row_id"
- ",fee_type"
- ",fee_time"
- ",diagnostic"
- " FROM auditor_fee_time_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_fee_time_inconsistency_get_asc"
- : "auditor_fee_time_inconsistency_get_desc",
- params,
- &fee_time_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_misattribution_in_inconsistency.c b/src/auditordb/get_misattribution_in_inconsistency.c
@@ -1,168 +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/>
- */
-
-
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-
-#include "auditor-database/get_misattribution_in_inconsistency.h"
-
-
-struct MisattributionInInconsistencyContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_MisattributionInInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_misattribution_in_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct MisattributionInInconsistencyContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-misattribution_in_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct MisattributionInInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_MisattributionInInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &dc.amount),
- GNUNET_PQ_result_spec_uint64 ("bank_row",
- &dc.bank_row),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_misattribution_in_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_MisattributionInInconsistencyCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct MisattributionInInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_misattribution_in_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",amount"
- ",bank_row"
- ",reserve_pub"
- ",suppressed"
- " FROM auditor_misattribution_in_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_misattribution_in_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",amount"
- ",bank_row"
- ",reserve_pub"
- ",suppressed"
- " FROM auditor_misattribution_in_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_misattribution_in_inconsistency_get_asc"
- : "auditor_misattribution_in_inconsistency_get_desc",
- params,
- &misattribution_in_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_progress_points.c b/src/auditordb/get_progress_points.c
@@ -1,136 +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/auditordb/get_progress_points.c
- * @brief Implementation of the get_progress_points function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/get_progress_points.h"
-#include "pg_helper.h"
-
-
-struct ProgressContext
-{
-
- /**
- * Function to call for each progress point.
- */
- TALER_AUDITORDB_ProgressPointsCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_progress_points().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ProgressContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-progress_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ProgressContext *dcc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_Progress dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("progress_key",
- &dc.progress_key),
- GNUNET_PQ_result_spec_uint64 ("progress_offset",
- &dc.progress_offset),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_progress_points (
- struct TALER_AUDITORDB_PostgresContext *pg,
- const char *progress_key,
- TALER_AUDITORDB_ProgressPointsCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- NULL == progress_key
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (progress_key),
- GNUNET_PQ_query_param_end
- };
- struct ProgressContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_progress_points_get",
- "SELECT"
- " progress_key"
- ",progress_offset"
- " FROM auditor_progress"
- " WHERE ($1::TEXT IS NULL OR progress_key = $1)"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "auditor_progress_points_get",
- params,
- &progress_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_purse_info.c b/src/auditordb/get_purse_info.c
@@ -45,7 +45,7 @@ TALER_AUDITORDB_get_purse_info (
};
PREPARE (pg,
- "auditor_get_purse_info",
+ "get_purse_info",
"SELECT"
" auditor_purses_rowid"
",expiration_date"
@@ -53,7 +53,7 @@ TALER_AUDITORDB_get_purse_info (
" FROM auditor_purses"
" WHERE purse_pub=$1");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_get_purse_info",
+ "get_purse_info",
params,
rs);
}
diff --git a/src/auditordb/get_purse_not_closed_inconsistencies.c b/src/auditordb/get_purse_not_closed_inconsistencies.c
@@ -1,168 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_purse_not_closed_inconsistencies.h"
-
-
-/**
- * Closure for #purse_not_closed_inconsistencies_cb().
- */
-struct PurseNotClosedInconsistenciesContext
-{
-
- /**
- * Function to call for each purse not closed_inconsistencies.
- */
- TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_purse_not_closed_inconsistencies().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseNotClosedInconsistencies *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_not_closed_inconsistencies_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseNotClosedInconsistenciesContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_PurseNotClosedInconsistencies dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &dc.purse_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &dc.amount),
- GNUNET_PQ_result_spec_absolute_time ("expiration_date",
- &dc.expiration_date),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_purse_not_closed_inconsistencies (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct PurseNotClosedInconsistenciesContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_purse_not_closed_inconsistencies_get_desc",
- "SELECT"
- " row_id"
- ",purse_pub"
- ",amount"
- ",expiration_date"
- ",suppressed"
- " FROM auditor_purse_not_closed_inconsistencies"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_purse_not_closed_inconsistencies_get_asc",
- "SELECT"
- " row_id"
- ",purse_pub"
- ",amount"
- ",expiration_date"
- ",suppressed"
- " FROM auditor_purse_not_closed_inconsistencies"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_purse_not_closed_inconsistencies_get_asc"
- : "auditor_purse_not_closed_inconsistencies_get_desc",
- params,
- &purse_not_closed_inconsistencies_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_purses.c b/src/auditordb/get_purses.c
@@ -1,160 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_purses.h"
-
-
-struct PursesContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_PursesCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_purses().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PursesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purses_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PursesContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_Purses dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("auditor_purses_rowid",
- &dc.auditor_purses_rowid),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &dc.purse_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &dc.balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("target",
- &dc.target),
- GNUNET_PQ_result_spec_absolute_time ("expiration_date",
- &dc.expiration_date),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- dc.auditor_purses_rowid,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_purses (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_PursesCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct PursesContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_purses_get_desc",
- "SELECT"
- " auditor_purses_rowid,"
- " purse_pub,"
- " balance,"
- " target,"
- " expiration_date"
- " FROM auditor_purses"
- " WHERE (auditor_purses_rowid < $1)"
- " ORDER BY auditor_purses_rowid DESC"
- " LIMIT $2"
- );
- PREPARE (pg,
- "auditor_purses_get_asc",
- "SELECT"
- " auditor_purses_rowid,"
- " purse_pub,"
- " balance,"
- " target,"
- " expiration_date"
- " FROM auditor_purses"
- " WHERE (auditor_purses_rowid > $1)"
- " ORDER BY auditor_purses_rowid ASC"
- " LIMIT $2"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_purses_get_asc"
- : "auditor_purses_get_desc",
- params,
- &purses_cb,
- &dcc);
-
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_reserve_balance_insufficient_inconsistency.c b/src/auditordb/get_reserve_balance_insufficient_inconsistency.c
@@ -1,171 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include \
- "auditor-database/get_reserve_balance_insufficient_inconsistency.h"
-
-
-/**
- * Closure for #reserve_balance_insufficient_inconsistency_cb().
- */
-struct ReserveBalanceInsufficientInconsistencyContext
-{
-
- /**
- * Function to call for each ReserveBalanceInsufficientInconsistency.
- */
- TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_reserve_balance_insufficient_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveBalanceInsufficientInconsistency *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_balance_insufficient_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveBalanceInsufficientInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- GNUNET_PQ_result_spec_bool ("inconsistency_gain",
- &dc.inconsistency_gain),
- TALER_PQ_RESULT_SPEC_AMOUNT ("inconsistency_amount",
- &dc.inconsistency_amount),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_balance_insufficient_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool
- return_suppressed
- ,
- TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct ReserveBalanceInsufficientInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_reserve_balance_insufficient_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",reserve_pub"
- ",inconsistency_gain"
- ",inconsistency_amount"
- ",suppressed"
- " FROM auditor_reserve_balance_insufficient_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_reserve_balance_insufficient_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",reserve_pub"
- ",inconsistency_gain"
- ",inconsistency_amount"
- ",suppressed"
- " FROM auditor_reserve_balance_insufficient_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_reserve_balance_insufficient_inconsistency_get_asc"
- : "auditor_reserve_balance_insufficient_inconsistency_get_desc",
- params,
- &reserve_balance_insufficient_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_reserve_balance_summary_wrong_inconsistency.c b/src/auditordb/get_reserve_balance_summary_wrong_inconsistency.c
@@ -1,169 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include \
- "auditor-database/get_reserve_balance_summary_wrong_inconsistency.h"
-
-
-struct ReserveBalanceSummaryWrongInconsistencyContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_reserve_balance_summary_wrong_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveBalanceSummaryWrongInconsistencyContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_balance_summary_wrong_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveBalanceSummaryWrongInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
- &dc.exchange_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
- &dc.auditor_amount),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_balance_summary_wrong_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset
- ,
- bool
- return_suppressed,
- TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct ReserveBalanceSummaryWrongInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_reserve_balance_summary_wrong_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",reserve_pub"
- ",exchange_amount"
- ",auditor_amount"
- ",suppressed"
- " FROM auditor_reserve_balance_summary_wrong_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_reserve_balance_summary_wrong_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",reserve_pub"
- ",exchange_amount"
- ",auditor_amount"
- ",suppressed"
- " FROM auditor_reserve_balance_summary_wrong_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_reserve_balance_summary_wrong_inconsistency_get_asc"
- : "auditor_reserve_balance_summary_wrong_inconsistency_get_desc",
- params,
- &reserve_balance_summary_wrong_inconsistency_cb,
- &dcc);
-
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_reserve_in_inconsistency.c b/src/auditordb/get_reserve_in_inconsistency.c
@@ -13,149 +13,53 @@
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/auditordb/get_reserve_in_inconsistency.c
+ * @brief Implementation of the get_reserve_in_inconsistency function for Postgres
+ * @author Christian Grothoff
+ */
#include "taler/taler_error_codes.h"
#include "taler/taler_dbevents.h"
#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
#include "auditor-database/get_reserve_in_inconsistency.h"
-
-
-struct ReserveInInconsistencyContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_ReserveInInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_reserve_in_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveInInconsistencyContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_in_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveInInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_ReserveInInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.serial_id),
- GNUNET_PQ_result_spec_uint64 ("bank_row_id",
- &dc.bank_row_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_exchange_expected",
- &dc.amount_exchange_expected),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_wired",
- &dc.amount_wired),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- GNUNET_PQ_result_spec_absolute_time ("timestamp",
- &dc.timestamp),
- GNUNET_PQ_result_spec_string ("account",
- &dc.account.full_payto),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc.diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
+#include "pg_helper.h"
enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_in_inconsistency (struct
- TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_ReserveInInconsistencyCallback
- cb,
- void *cb_cls)
+TALER_AUDITORDB_get_reserve_in_inconsistency (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ uint64_t bank_row_id,
+ struct TALER_AUDITORDB_ReserveInInconsistency *dc)
{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_uint64 (&bank_row_id),
GNUNET_PQ_query_param_end
};
- struct ReserveInInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc->serial_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_exchange_expected",
+ &dc->amount_exchange_expected),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_wired",
+ &dc->amount_wired),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc->reserve_pub),
+ GNUNET_PQ_result_spec_absolute_time ("timestamp",
+ &dc->timestamp),
+ GNUNET_PQ_result_spec_string ("account",
+ &dc->account.full_payto),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc->diagnostic),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc->suppressed),
+ GNUNET_PQ_result_spec_end
};
- enum GNUNET_DB_QueryStatus qs;
+ dc->bank_row_id = bank_row_id;
PREPARE (pg,
- "auditor_reserve_in_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",bank_row_id"
- ",amount_exchange_expected"
- ",amount_wired"
- ",reserve_pub"
- ",timestamp"
- ",account"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_reserve_in_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_reserve_in_inconsistency_get_asc",
+ "get_reserve_in_inconsistency",
"SELECT"
" row_id"
- ",bank_row_id"
",amount_exchange_expected"
",amount_wired"
",reserve_pub"
@@ -164,21 +68,11 @@ TALER_AUDITORDB_get_reserve_in_inconsistency (struct
",diagnostic"
",suppressed"
" FROM auditor_reserve_in_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
+ " WHERE (bank_row_id = $1)"
);
- qs = GNUNET_PQ_eval_prepared_multi_select (
+ return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- (limit > 0)
- ? "auditor_reserve_in_inconsistency_get_asc"
- : "auditor_reserve_in_inconsistency_get_desc",
+ "get_reserve_in_inconsistency",
params,
- &reserve_in_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
+ rs);
}
diff --git a/src/auditordb/get_reserve_info.c b/src/auditordb/get_reserve_info.c
@@ -64,7 +64,7 @@ TALER_AUDITORDB_get_reserve_info (
sender_account->full_payto = NULL;
PREPARE (pg,
- "auditor_get_reserve_info",
+ "get_reserve_info",
"SELECT"
" reserve_balance"
",reserve_loss"
@@ -80,7 +80,7 @@ TALER_AUDITORDB_get_reserve_info (
" WHERE reserve_pub=$1;");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "auditor_get_reserve_info",
+ "get_reserve_info",
params,
rs);
}
diff --git a/src/auditordb/get_reserve_not_closed_inconsistency.c b/src/auditordb/get_reserve_not_closed_inconsistency.c
@@ -1,169 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_reserve_not_closed_inconsistency.h"
-
-
-struct ReserveNotClosedInconsistencyContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_reserve_not_closed_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveNotClosedInconsistencyContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_not_closed_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveNotClosedInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_ReserveNotClosedInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &dc.balance),
- GNUNET_PQ_result_spec_absolute_time ("expiration_time",
- &dc.expiration_time),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc.diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_not_closed_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct ReserveNotClosedInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_reserve_not_closed_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",reserve_pub"
- ",balance"
- ",expiration_time"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_reserve_not_closed_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_reserve_not_closed_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",reserve_pub"
- ",balance"
- ",expiration_time"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_reserve_not_closed_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_reserve_not_closed_inconsistency_get_asc"
- : "auditor_reserve_not_closed_inconsistency_get_desc",
- params,
- &reserve_not_closed_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_reserves.c b/src/auditordb/get_reserves.c
@@ -1,186 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_reserves.h"
-
-
-struct ReservesContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_ReservesCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_reserves().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReservesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserves_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReservesContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_Reserves dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid",
- &dc.auditor_reserves_rowid),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc.reserve_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
- &dc.reserve_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_loss",
- &dc.reserve_loss),
- TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance",
- &dc.withdraw_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("close_fee_balance",
- &dc.close_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee_balance",
- &dc.purse_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("open_fee_balance",
- &dc.open_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee_balance",
- &dc.history_fee_balance),
- GNUNET_PQ_result_spec_absolute_time ("expiration_date",
- &dc.expiration_date),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("origin_account",
- &dc.origin_account.full_payto),
- NULL),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- dc.origin_account.full_payto = NULL;
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- dc.auditor_reserves_rowid,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserves (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_ReservesCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct ReservesContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_reserves_get_desc",
- "SELECT"
- " auditor_reserves_rowid,"
- " reserve_pub,"
- " reserve_balance,"
- " reserve_loss,"
- " withdraw_fee_balance,"
- " close_fee_balance,"
- " purse_fee_balance,"
- " open_fee_balance,"
- " history_fee_balance,"
- " expiration_date,"
- " origin_account"
- " FROM auditor_reserves"
- " WHERE (auditor_reserves_rowid < $1)"
- " ORDER BY auditor_reserves_rowid DESC"
- " LIMIT $2"
- );
- PREPARE (pg,
- "auditor_reserves_get_asc",
- "SELECT"
- " auditor_reserves_rowid,"
- " reserve_pub,"
- " reserve_balance,"
- " reserve_loss,"
- " withdraw_fee_balance,"
- " close_fee_balance,"
- " purse_fee_balance,"
- " open_fee_balance,"
- " history_fee_balance,"
- " expiration_date,"
- " origin_account"
- " FROM auditor_reserves"
- " WHERE (auditor_reserves_rowid > $1)"
- " ORDER BY auditor_reserves_rowid ASC"
- " LIMIT $2"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_reserves_get_asc"
- : "auditor_reserves_get_desc",
- params,
- &reserves_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_row_inconsistency.c b/src/auditordb/get_row_inconsistency.c
@@ -1,170 +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/>
- */
-
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_row_inconsistency.h"
-
-/**
- * Closure for #deposit_confirmation_cb().
- */
-struct RowInconsistencyContext
-{
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_RowInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_deposit_confirmations().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositConfirmationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-row_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RowInconsistencyContext *dcc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t serial_id;
-
- struct TALER_AUDITORDB_RowInconsistency dc;
-
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id),
-
- GNUNET_PQ_result_spec_string ("row_table", &dc.row_table),
- GNUNET_PQ_result_spec_string ("diagnostic", &dc.diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed", &dc.suppressed),
-
-
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- dcc->qs = i + 1;
-
-
- rval = dcc->cb (dcc->cb_cls,
- serial_id,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_row_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed, // maybe not needed
- TALER_AUDITORDB_RowInconsistencyCallback cb,
- void *cb_cls)
-{
-
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct RowInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
-
- PREPARE (pg,
- "auditor_row_inconsistency_select_desc",
- "SELECT"
- " row_id"
- ",row_table"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_row_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_row_inconsistency_select_asc",
- "SELECT"
- " row_id"
- ",row_table"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_row_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR suppressed is false)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_row_inconsistency_select_asc"
- : "auditor_row_inconsistency_select_desc",
- params,
- &row_inconsistency_cb,
- &dcc);
-
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_row_minor_inconsistencies.c b/src/auditordb/get_row_minor_inconsistencies.c
@@ -1,162 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_row_minor_inconsistencies.h"
-
-
-struct RowMinorInconsistenciesContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_RowMinorInconsistenciesCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_row_minor_inconsistencies().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RowMinorInconsistenciesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-row_minor_inconsistencies_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RowMinorInconsistenciesContext *dcc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_RowMinorInconsistencies dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_string ("row_table",
- &dc.row_table),
- GNUNET_PQ_result_spec_uint64 ("problem_row",
- &dc.problem_row),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc.diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_row_minor_inconsistencies (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_RowMinorInconsistenciesCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct RowMinorInconsistenciesContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_row_minor_inconsistencies_get_desc",
- "SELECT"
- " row_id"
- ",problem_row"
- ",row_table"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_row_minor_inconsistencies"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_row_minor_inconsistencies_get_asc",
- "SELECT"
- " row_id"
- ",problem_row"
- ",row_table"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_row_minor_inconsistencies"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_row_minor_inconsistencies_get_asc"
- : "auditor_row_minor_inconsistencies_get_desc",
- params,
- &row_minor_inconsistencies_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_wire_fee_summary.c b/src/auditordb/get_wire_fee_summary.c
@@ -45,13 +45,13 @@ TALER_AUDITORDB_get_wire_fee_summary (
};
PREPARE (pg,
- "auditor_wire_fee_balance_select",
+ "get_wire_fee_summary",
"SELECT"
" wire_fee_balance"
" FROM auditor_wire_fee_balance");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "auditor_wire_fee_balance_select",
+ "get_wire_fee_summary",
params,
rs);
}
diff --git a/src/auditordb/get_wire_format_inconsistency.c b/src/auditordb/get_wire_format_inconsistency.c
@@ -1,165 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_wire_format_inconsistency.h"
-
-
-struct WireFormatInconsistencyContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_WireFormatInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_wire_format_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WireFormatInconsistencyContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-wire_format_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireFormatInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_WireFormatInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &dc.amount),
- GNUNET_PQ_result_spec_uint64 ("wire_offset",
- &dc.wire_offset),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc.diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_wire_format_inconsistency (struct
- TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_WireFormatInconsistencyCallback
- cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct WireFormatInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_wire_format_inconsistency_get_desc",
- "SELECT"
- " row_id,"
- " amount,"
- " wire_offset,"
- " diagnostic,"
- " suppressed"
- " FROM auditor_wire_format_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_wire_format_inconsistency_get_asc",
- "SELECT"
- " row_id,"
- " amount,"
- " wire_offset,"
- " diagnostic,"
- " suppressed"
- " FROM auditor_wire_format_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_wire_format_inconsistency_get_asc"
- : "auditor_wire_format_inconsistency_get_desc",
- params,
- &wire_format_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/get_wire_out_inconsistency.c b/src/auditordb/get_wire_out_inconsistency.c
@@ -1,171 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/get_wire_out_inconsistency.h"
-
-
-struct WireOutInconsistencyContext
-{
-
- /**
- * Function to call for each bad sig loss.
- */
- TALER_AUDITORDB_WireOutInconsistencyCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_get_wire_out_inconsistency().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WireOutInconsistencyContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-wire_out_inconsistency_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireOutInconsistencyContext *dcc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_WireOutInconsistency dc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc.row_id),
- GNUNET_PQ_result_spec_string ("destination_account",
- &dc.destination_account.full_payto),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc.diagnostic),
- GNUNET_PQ_result_spec_uint64 ("wire_out_serial_id",
- &dc.wire_out_row_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("expected",
- &dc.expected),
- TALER_PQ_RESULT_SPEC_AMOUNT ("claimed",
- &dc.claimed),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc.suppressed),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue rval;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- rval = dcc->cb (dcc->cb_cls,
- &dc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != rval)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_wire_out_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_WireOutInconsistencyCallback cb,
- void *cb_cls)
-{
- uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct WireOutInconsistencyContext dcc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_wire_out_inconsistency_get_desc",
- "SELECT"
- " row_id"
- ",destination_account"
- ",diagnostic"
- ",wire_out_serial_id"
- ",expected"
- ",claimed"
- ",suppressed"
- " FROM auditor_wire_out_inconsistency"
- " WHERE (row_id < $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3"
- );
- PREPARE (pg,
- "auditor_wire_out_inconsistency_get_asc",
- "SELECT"
- " row_id"
- ",destination_account"
- ",diagnostic"
- ",wire_out_serial_id"
- ",expected"
- ",claimed"
- ",suppressed"
- " FROM auditor_wire_out_inconsistency"
- " WHERE (row_id > $1)"
- " AND ($2 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_wire_out_inconsistency_get_asc"
- : "auditor_wire_out_inconsistency_get_desc",
- params,
- &wire_out_inconsistency_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/insert_amount_arithmetic_inconsistency.c b/src/auditordb/insert_amount_arithmetic_inconsistency.c
@@ -38,7 +38,7 @@ TALER_AUDITORDB_insert_amount_arithmetic_inconsistency (struct
};
PREPARE (pg,
- "auditor_amount_arithmetic_inconsistency_insert",
+ "insert_amount_arithmetic_inconsistency",
"INSERT INTO auditor_amount_arithmetic_inconsistency "
"(operation"
",problem_row_id"
@@ -48,6 +48,6 @@ TALER_AUDITORDB_insert_amount_arithmetic_inconsistency (struct
") VALUES ($1,$2,$3,$4,$5);"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_amount_arithmetic_inconsistency_insert",
+ "insert_amount_arithmetic_inconsistency",
params);
}
diff --git a/src/auditordb/insert_auditor_closure_lags.c b/src/auditordb/insert_auditor_closure_lags.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_auditor_closure_lags (struct
};
PREPARE (pg,
- "auditor_closure_lags_insert",
+ "insert_auditor_closure_lags",
"INSERT INTO auditor_closure_lags "
"(amount"
",problem_row_id"
@@ -45,6 +45,6 @@ TALER_AUDITORDB_insert_auditor_closure_lags (struct
",account"
") VALUES ($1,$2,$3,$4,$5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_closure_lags_insert",
+ "insert_auditor_closure_lags",
params);
}
diff --git a/src/auditordb/insert_auditor_progress.c b/src/auditordb/insert_auditor_progress.c
@@ -76,7 +76,7 @@ TALER_AUDITORDB_insert_auditor_progress (struct
va_end (ap);
PREPARE (pg,
- "auditor_progress_insert",
+ "insert_auditor_progress",
"INSERT INTO auditor_progress "
"(progress_key"
",progress_offset"
@@ -85,7 +85,7 @@ TALER_AUDITORDB_insert_auditor_progress (struct
" CAST($2 AS INT8[]))"
" ON CONFLICT DO NOTHING;");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert",
+ "insert_auditor_progress",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
diff --git a/src/auditordb/insert_bad_sig_losses.c b/src/auditordb/insert_bad_sig_losses.c
@@ -34,7 +34,7 @@ TALER_AUDITORDB_insert_bad_sig_losses (struct TALER_AUDITORDB_PostgresContext *
};
PREPARE (pg,
- "auditor_bad_sig_losses_insert",
+ "insert_bad_sig_losses",
"INSERT INTO auditor_bad_sig_losses "
"(operation"
",problem_row_id"
@@ -43,6 +43,6 @@ TALER_AUDITORDB_insert_bad_sig_losses (struct TALER_AUDITORDB_PostgresContext *
") VALUES ($1,$2,$3,$4);"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_bad_sig_losses_insert",
+ "insert_bad_sig_losses",
params);
}
diff --git a/src/auditordb/insert_balance.c b/src/auditordb/insert_balance.c
@@ -75,7 +75,7 @@ TALER_AUDITORDB_insert_balance (struct TALER_AUDITORDB_PostgresContext *pg,
va_end (ap);
PREPARE (pg,
- "auditor_balance_insert",
+ "insert_balance",
"INSERT INTO auditor_balances "
"(balance_key"
",balance_value.val"
@@ -85,7 +85,7 @@ TALER_AUDITORDB_insert_balance (struct TALER_AUDITORDB_PostgresContext *pg,
" CAST($2 AS taler_amount[]))"
" ON CONFLICT DO NOTHING;");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_balance_insert",
+ "insert_balance",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
diff --git a/src/auditordb/insert_coin_inconsistency.c b/src/auditordb/insert_coin_inconsistency.c
@@ -37,7 +37,7 @@ TALER_AUDITORDB_insert_coin_inconsistency (struct
};
PREPARE (pg,
- "auditor_coin_inconsistency_insert",
+ "insert_coin_inconsistency",
"INSERT INTO auditor_coin_inconsistency "
"(operation"
",exchange_amount"
@@ -47,6 +47,6 @@ TALER_AUDITORDB_insert_coin_inconsistency (struct
") VALUES ($1,$2,$3,$4,$5)"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_coin_inconsistency_insert",
+ "insert_coin_inconsistency",
params);
}
diff --git a/src/auditordb/insert_denomination_balance.c b/src/auditordb/insert_denomination_balance.c
@@ -44,7 +44,7 @@ TALER_AUDITORDB_insert_denomination_balance (
};
PREPARE (pg,
- "auditor_insert_denomination_balance",
+ "insert_denomination_balance",
"INSERT INTO auditor_denomination_pending "
"(denom_pub_hash"
",denom_balance"
@@ -57,6 +57,6 @@ TALER_AUDITORDB_insert_denomination_balance (
");");
return GNUNET_PQ_eval_prepared_non_select (
pg->conn,
- "auditor_insert_denomination_balance",
+ "insert_denomination_balance",
params);
}
diff --git a/src/auditordb/insert_denomination_key_validity_withdraw_inconsistency.c b/src/auditordb/insert_denomination_key_validity_withdraw_inconsistency.c
@@ -38,7 +38,7 @@ TALER_AUDITORDB_insert_denomination_key_validity_withdraw_inconsistency (struct
};
PREPARE (ctx,
- "auditor_denomination_key_validity_withdraw_inconsistency_insert",
+ "insert_denomination_key_validity_withdraw_inconsistency",
"INSERT INTO auditor_denomination_key_validity_withdraw_inconsistency "
"(execution_date"
",problem_row_id"
@@ -46,6 +46,6 @@ TALER_AUDITORDB_insert_denomination_key_validity_withdraw_inconsistency (struct
",denompub_h"
") VALUES ($1,$2,$3,$4);");
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_denomination_key_validity_withdraw_inconsistency_insert",
+ "insert_denomination_key_validity_withdraw_inconsistency",
params);
}
diff --git a/src/auditordb/insert_denomination_pending.c b/src/auditordb/insert_denomination_pending.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_denomination_pending (
};
PREPARE (pg,
- "auditor_denomination_pending_insert",
+ "insert_denomination_pending",
"INSERT INTO auditor_denomination_pending "
"( denom_pub_hash,"
" denom_balance,"
@@ -55,6 +55,6 @@ TALER_AUDITORDB_insert_denomination_pending (
);
return GNUNET_PQ_eval_prepared_non_select (
pg->conn,
- "auditor_denomination_pending_insert",
+ "insert_denomination_pending",
params);
}
diff --git a/src/auditordb/insert_denominations_without_sigs.c b/src/auditordb/insert_denominations_without_sigs.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_denominations_without_sigs (struct
};
PREPARE (ctx,
- "auditor_denominations_without_sigs_insert",
+ "insert_denominations_without_sigs",
"INSERT INTO auditor_denominations_without_sigs "
"(denompub_h,"
" value,"
@@ -50,6 +50,6 @@ TALER_AUDITORDB_insert_denominations_without_sigs (struct
" suppressed = false"
);
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_denominations_without_sigs_insert",
+ "insert_denominations_without_sigs",
params);
}
diff --git a/src/auditordb/insert_deposit_confirmation.c b/src/auditordb/insert_deposit_confirmation.c
@@ -55,7 +55,7 @@ TALER_AUDITORDB_insert_deposit_confirmation (struct
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "auditor_deposit_confirmation_insert",
+ "insert_deposit_confirmation",
"INSERT INTO auditor_deposit_confirmations "
"(h_contract_terms"
",h_policy"
@@ -72,7 +72,7 @@ TALER_AUDITORDB_insert_deposit_confirmation (struct
",master_sig" /* master_sig could be normalized... */
") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_deposit_confirmation_insert",
+ "insert_deposit_confirmation",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
diff --git a/src/auditordb/insert_early_aggregation.c b/src/auditordb/insert_early_aggregation.c
@@ -40,7 +40,7 @@ TALER_AUDITORDB_insert_early_aggregation (struct
};
PREPARE (pg,
- "auditor_insert_early_aggregation",
+ "insert_early_aggregation",
"INSERT INTO auditor_early_aggregations"
"(batch_deposit_serial_id"
",tracking_serial_id"
@@ -48,6 +48,6 @@ TALER_AUDITORDB_insert_early_aggregation (struct
") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (
pg->conn,
- "auditor_insert_early_aggregation",
+ "insert_early_aggregation",
params);
}
diff --git a/src/auditordb/insert_emergency.c b/src/auditordb/insert_emergency.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_emergency (struct TALER_AUDITORDB_PostgresContext *pg,
};
PREPARE (pg,
- "auditor_emergency_insert",
+ "insert_emergency",
"INSERT INTO auditor_emergency "
"(denompub_h"
",denom_risk"
@@ -46,6 +46,6 @@ TALER_AUDITORDB_insert_emergency (struct TALER_AUDITORDB_PostgresContext *pg,
",value"
") VALUES ($1,$2,$3,$4,$5,$6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_emergency_insert",
+ "insert_emergency",
params);
}
diff --git a/src/auditordb/insert_emergency_by_count.c b/src/auditordb/insert_emergency_by_count.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_emergency_by_count (struct
};
PREPARE (pg,
- "auditor_emergency_by_count_insert",
+ "insert_emergency_by_count",
"INSERT INTO auditor_emergency_by_count "
"(denompub_h"
",num_issued"
@@ -47,6 +47,6 @@ TALER_AUDITORDB_insert_emergency_by_count (struct
",value"
") VALUES ($1,$2,$3,$4,$5,$6,$7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_emergency_by_count_insert",
+ "insert_emergency_by_count",
params);
}
diff --git a/src/auditordb/insert_exchange_signkey.c b/src/auditordb/insert_exchange_signkey.c
@@ -39,7 +39,7 @@ TALER_AUDITORDB_insert_exchange_signkey (struct
};
PREPARE (pg,
- "auditor_insert_exchange_signkey",
+ "insert_exchange_signkey",
"INSERT INTO auditor_exchange_signkeys "
"(ep_valid_from"
",ep_expire_sign"
@@ -49,6 +49,6 @@ TALER_AUDITORDB_insert_exchange_signkey (struct
") VALUES ($1,$2,$3,$4,$5);"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_insert_exchange_signkey",
+ "insert_exchange_signkey",
params);
}
diff --git a/src/auditordb/insert_fee_time_inconsistency.c b/src/auditordb/insert_fee_time_inconsistency.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_fee_time_inconsistency (struct
};
PREPARE (pg,
- "auditor_fee_time_inconsistency_insert",
+ "insert_fee_time_inconsistency",
"INSERT INTO auditor_fee_time_inconsistency "
"(fee_type"
",problem_row_id"
@@ -44,6 +44,6 @@ TALER_AUDITORDB_insert_fee_time_inconsistency (struct
",diagnostic"
") VALUES ($1,$2,$3,$4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_fee_time_inconsistency_insert",
+ "insert_fee_time_inconsistency",
params);
}
diff --git a/src/auditordb/insert_historic_denom_revenue.c b/src/auditordb/insert_historic_denom_revenue.c
@@ -49,7 +49,7 @@ TALER_AUDITORDB_insert_historic_denom_revenue (struct
};
PREPARE (pg,
- "auditor_historic_denomination_revenue_insert",
+ "insert_historic_denom_revenue",
"INSERT INTO auditor_historic_denomination_revenue"
"(denom_pub_hash"
",revenue_timestamp"
@@ -57,6 +57,6 @@ TALER_AUDITORDB_insert_historic_denom_revenue (struct
",loss_balance"
") VALUES ($1,$2,$3,$4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_historic_denomination_revenue_insert",
+ "insert_historic_denom_revenue",
params);
}
diff --git a/src/auditordb/insert_historic_reserve_revenue.c b/src/auditordb/insert_historic_reserve_revenue.c
@@ -44,13 +44,13 @@ TALER_AUDITORDB_insert_historic_reserve_revenue (struct
};
PREPARE (pg,
- "auditor_historic_reserve_summary_insert",
+ "insert_historic_reserve_revenue",
"INSERT INTO auditor_historic_reserve_summary"
"(start_date"
",end_date"
",reserve_profits"
") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_historic_reserve_summary_insert",
+ "insert_historic_reserve_revenue",
params);
}
diff --git a/src/auditordb/insert_misattribution_in_inconsistency.c b/src/auditordb/insert_misattribution_in_inconsistency.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_misattribution_in_inconsistency (struct
};
PREPARE (pg,
- "auditor_misattribution_in_inconsistency_insert",
+ "insert_misattribution_in_inconsistency",
"INSERT INTO auditor_misattribution_in_inconsistency "
"(amount,"
" bank_row,"
@@ -44,6 +44,6 @@ TALER_AUDITORDB_insert_misattribution_in_inconsistency (struct
") VALUES ($1,$2,$3);"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_misattribution_in_inconsistency_insert",
+ "insert_misattribution_in_inconsistency",
params);
}
diff --git a/src/auditordb/insert_pending_deposit.c b/src/auditordb/insert_pending_deposit.c
@@ -42,7 +42,7 @@ TALER_AUDITORDB_insert_pending_deposit (struct TALER_AUDITORDB_PostgresContext *
};
PREPARE (pg,
- "auditor_insert_pending_deposit",
+ "insert_pending_deposit",
"INSERT INTO auditor_pending_deposits "
"(total_amount"
",wire_target_h_payto"
@@ -51,6 +51,6 @@ TALER_AUDITORDB_insert_pending_deposit (struct TALER_AUDITORDB_PostgresContext *
") VALUES ($1,$2,$3,$4);");
return GNUNET_PQ_eval_prepared_non_select (
pg->conn,
- "auditor_insert_pending_deposit",
+ "insert_pending_deposit",
params);
}
diff --git a/src/auditordb/insert_purse_info.c b/src/auditordb/insert_purse_info.c
@@ -39,13 +39,13 @@ TALER_AUDITORDB_insert_purse_info (struct TALER_AUDITORDB_PostgresContext *pg,
};
PREPARE (pg,
- "auditor_purses_insert",
+ "insert_purse_info",
"INSERT INTO auditor_purses "
"(purse_pub"
",target"
",expiration_date"
") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_purses_insert",
+ "insert_purse_info",
params);
}
diff --git a/src/auditordb/insert_purse_not_closed_inconsistencies.c b/src/auditordb/insert_purse_not_closed_inconsistencies.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_purse_not_closed_inconsistencies (struct
};
PREPARE (ctx,
- "auditor_purse_not_closed_inconsistencies_insert",
+ "insert_purse_not_closed_inconsistencies",
"INSERT INTO auditor_purse_not_closed_inconsistencies "
"(purse_pub"
",amount"
@@ -44,6 +44,6 @@ TALER_AUDITORDB_insert_purse_not_closed_inconsistencies (struct
") VALUES ($1,$2,$3)"
);
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_purse_not_closed_inconsistencies_insert",
+ "insert_purse_not_closed_inconsistencies",
params);
}
diff --git a/src/auditordb/insert_reserve_balance_insufficient_inconsistency.c b/src/auditordb/insert_reserve_balance_insufficient_inconsistency.c
@@ -39,13 +39,13 @@ TALER_AUDITORDB_insert_reserve_balance_insufficient_inconsistency (struct
};
PREPARE (ctx,
- "auditor_reserve_balance_insufficient_inconsistency_insert",
+ "insert_reserve_balance_insufficient_inconsistency",
"INSERT INTO auditor_reserve_balance_insufficient_inconsistency "
"(reserve_pub"
",inconsistency_gain"
",inconsistency_amount"
") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_reserve_balance_insufficient_inconsistency_insert",
+ "insert_reserve_balance_insufficient_inconsistency",
params);
}
diff --git a/src/auditordb/insert_reserve_balance_summary_wrong_inconsistency.c b/src/auditordb/insert_reserve_balance_summary_wrong_inconsistency.c
@@ -39,7 +39,7 @@ TALER_AUDITORDB_insert_reserve_balance_summary_wrong_inconsistency (struct
};
PREPARE (ctx,
- "auditor_reserve_balance_summary_wrong_inconsistency_insert",
+ "insert_reserve_balance_summary_wrong_inconsistency",
"INSERT INTO auditor_reserve_balance_summary_wrong_inconsistency "
"(reserve_pub,"
" exchange_amount,"
@@ -47,6 +47,6 @@ TALER_AUDITORDB_insert_reserve_balance_summary_wrong_inconsistency (struct
") VALUES ($1,$2,$3);"
);
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_reserve_balance_summary_wrong_inconsistency_insert",
+ "insert_reserve_balance_summary_wrong_inconsistency",
params);
}
diff --git a/src/auditordb/insert_reserve_in_inconsistency.c b/src/auditordb/insert_reserve_in_inconsistency.c
@@ -41,7 +41,7 @@ TALER_AUDITORDB_insert_reserve_in_inconsistency (struct
};
PREPARE (pg,
- "auditor_reserve_in_inconsistency_insert",
+ "insert_reserve_in_inconsistency",
"INSERT INTO auditor_reserve_in_inconsistency "
"(bank_row_id,"
" amount_exchange_expected,"
@@ -53,6 +53,6 @@ TALER_AUDITORDB_insert_reserve_in_inconsistency (struct
") VALUES ($1,$2,$3,$4,$5,$6,$7);"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserve_in_inconsistency_insert",
+ "insert_reserve_in_inconsistency",
params);
}
diff --git a/src/auditordb/insert_reserve_info.c b/src/auditordb/insert_reserve_info.c
@@ -55,7 +55,7 @@ TALER_AUDITORDB_insert_reserve_info (
};
PREPARE (pg,
- "auditor_insert_reserve_info",
+ "insert_reserve_info",
"INSERT INTO auditor_reserves "
"(reserve_pub"
",reserve_balance"
@@ -70,6 +70,6 @@ TALER_AUDITORDB_insert_reserve_info (
") VALUES "
"($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_insert_reserve_info",
+ "insert_reserve_info",
params);
}
diff --git a/src/auditordb/insert_reserve_not_closed_inconsistency.c b/src/auditordb/insert_reserve_not_closed_inconsistency.c
@@ -37,7 +37,7 @@ TALER_AUDITORDB_insert_reserve_not_closed_inconsistency (struct
};
PREPARE (ctx,
- "auditor_reserve_not_closed_inconsistency_insert",
+ "insert_reserve_not_closed_inconsistency",
"INSERT INTO auditor_reserve_not_closed_inconsistency "
"(reserve_pub,"
" balance,"
@@ -47,6 +47,6 @@ TALER_AUDITORDB_insert_reserve_not_closed_inconsistency (struct
" ON CONFLICT DO NOTHING;"
);
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_reserve_not_closed_inconsistency_insert",
+ "insert_reserve_not_closed_inconsistency",
params);
}
diff --git a/src/auditordb/insert_row_inconsistency.c b/src/auditordb/insert_row_inconsistency.c
@@ -33,13 +33,13 @@ TALER_AUDITORDB_insert_row_inconsistency (struct
};
PREPARE (pg,
- "auditor_insert_row_inconsistency",
+ "insert_row_inconsistency",
"INSERT INTO auditor_row_inconsistency "
"(row_table"
",diagnostic"
",problem_row_id"
") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_insert_row_inconsistency",
+ "insert_row_inconsistency",
params);
}
diff --git a/src/auditordb/insert_row_minor_inconsistencies.c b/src/auditordb/insert_row_minor_inconsistencies.c
@@ -35,7 +35,7 @@ TALER_AUDITORDB_insert_row_minor_inconsistencies (struct
};
PREPARE (ctx,
- "auditor_row_minor_inconsistencies_insert",
+ "insert_row_minor_inconsistencies",
"INSERT INTO auditor_row_minor_inconsistencies "
"(row_table"
",problem_row"
@@ -43,6 +43,6 @@ TALER_AUDITORDB_insert_row_minor_inconsistencies (struct
") VALUES ($1,$2,$3);"
);
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_row_minor_inconsistencies_insert",
+ "insert_row_minor_inconsistencies",
params);
}
diff --git a/src/auditordb/insert_wire_format_inconsistency.c b/src/auditordb/insert_wire_format_inconsistency.c
@@ -36,7 +36,7 @@ TALER_AUDITORDB_insert_wire_format_inconsistency (struct
};
PREPARE (ctx,
- "auditor_wire_format_inconsistency_insert",
+ "insert_wire_format_inconsistency",
"INSERT INTO auditor_wire_format_inconsistency "
"(amount"
",wire_offset"
@@ -44,6 +44,6 @@ TALER_AUDITORDB_insert_wire_format_inconsistency (struct
") VALUES ($1,$2,$3);"
);
return GNUNET_PQ_eval_prepared_non_select (ctx->conn,
- "auditor_wire_format_inconsistency_insert",
+ "insert_wire_format_inconsistency",
params);
}
diff --git a/src/auditordb/insert_wire_out_inconsistency.c b/src/auditordb/insert_wire_out_inconsistency.c
@@ -41,7 +41,7 @@ TALER_AUDITORDB_insert_wire_out_inconsistency (struct
};
PREPARE (pg,
- "auditor_wire_out_inconsistency_insert",
+ "insert_wire_out_inconsistency",
"INSERT INTO auditor_wire_out_inconsistency "
"(destination_account"
",diagnostic"
@@ -51,6 +51,6 @@ TALER_AUDITORDB_insert_wire_out_inconsistency (struct
") VALUES ($1,$2,$3,$4,$5);"
);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_wire_out_inconsistency_insert",
+ "insert_wire_out_inconsistency",
params);
}
diff --git a/src/auditordb/iterate_amount_arithmetic_inconsistencies.c b/src/auditordb/iterate_amount_arithmetic_inconsistencies.c
@@ -0,0 +1,174 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_amount_arithmetic_inconsistencies.h"
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct AmountArithmeticInconsistencyContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+amount_arithmetic_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AmountArithmeticInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_AmountArithmeticInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_uint64 ("problem_row_id",
+ &dc.problem_row_id),
+ GNUNET_PQ_result_spec_string ("operation",
+ &dc.operation),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
+ &dc.exchange_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
+ &dc.auditor_amount),
+ GNUNET_PQ_result_spec_bool ("profitable",
+ &dc.profitable),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_amount_arithmetic_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct AmountArithmeticInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_amount_arithmetic_inconsistencies_inconsistency_select_desc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",operation"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",profitable"
+ ",suppressed"
+ " FROM auditor_amount_arithmetic_inconsistency"
+ " WHERE (row_id<$1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_amount_arithmetic_inconsistencies_inconsistency_select_asc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",operation"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",profitable"
+ ",suppressed"
+ " FROM auditor_amount_arithmetic_inconsistency"
+ " WHERE (row_id>$1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_amount_arithmetic_inconsistencies_inconsistency_select_asc"
+ : "iterate_amount_arithmetic_inconsistencies_inconsistency_select_desc",
+ params,
+ &amount_arithmetic_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_auditor_closure_lags.c b/src/auditordb/iterate_auditor_closure_lags.c
@@ -0,0 +1,173 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_dbevents.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_auditor_closure_lags.h"
+
+
+struct ClosureLagsContext
+{
+
+ /**
+ * Function to call for each closure lag .
+ */
+ TALER_AUDITORDB_ClosureLagsCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_auditor_closure_lags().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ClosureLagsContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+closure_lags_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ClosureLagsContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_ClosureLags dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_uint64 ("problem_row_id",
+ &dc.problem_row_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &dc.amount),
+ GNUNET_PQ_result_spec_absolute_time ("deadline",
+ &dc.deadline),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ &dc.wtid),
+ GNUNET_PQ_result_spec_string ("account",
+ &dc.account.full_payto),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_auditor_closure_lags (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_ClosureLagsCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ClosureLagsContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_auditor_closure_lags_desc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",amount"
+ ",deadline"
+ ",wtid"
+ ",account"
+ ",suppressed"
+ " FROM auditor_closure_lags"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_auditor_closure_lags_asc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",amount"
+ ",deadline"
+ ",wtid"
+ ",account"
+ ",suppressed"
+ " FROM auditor_closure_lags"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_auditor_closure_lags_asc"
+ : "iterate_auditor_closure_lags_desc",
+ params,
+ &closure_lags_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_bad_sig_losses.c b/src/auditordb/iterate_bad_sig_losses.c
@@ -0,0 +1,180 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_bad_sig_losses.h"
+
+
+struct BadSigLossesContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_BadSigLossesCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_bad_sig_losses().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct BadSigLossesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+bad_sig_losses_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct BadSigLossesContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_BadSigLosses dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_uint64 ("problem_row_id",
+ &dc.problem_row_id),
+ GNUNET_PQ_result_spec_string ("operation",
+ &dc.operation),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("loss",
+ &dc.loss),
+ GNUNET_PQ_result_spec_auto_from_type ("operation_specific_pub",
+ &dc.operation_specific_pub),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_bad_sig_losses (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub,
+ const char *op,
+ TALER_AUDITORDB_BadSigLossesCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ NULL == op_spec_pub
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (op_spec_pub),
+ NULL == op
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (op),
+ GNUNET_PQ_query_param_end
+ };
+ struct BadSigLossesContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_bad_sig_losses_desc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",operation"
+ ",loss"
+ ",operation_specific_pub"
+ ",suppressed"
+ " FROM auditor_bad_sig_losses"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)"
+ " AND ($5::TEXT IS NULL OR operation = $5)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_bad_sig_losses_asc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",operation"
+ ",loss"
+ ",operation_specific_pub"
+ ",suppressed"
+ " FROM auditor_bad_sig_losses"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)"
+ " AND ($5::TEXT IS NULL OR operation = $5)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_bad_sig_losses_asc"
+ : "iterate_bad_sig_losses_desc",
+ params,
+ &bad_sig_losses_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_balances.c b/src/auditordb/iterate_balances.c
@@ -0,0 +1,132 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_balances.h"
+
+
+struct BalancesContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_BalancesCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_balances().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct BalancesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+balances_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct BalancesContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_Balances dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("balance_key",
+ &dc.balance_key),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance_value",
+ &dc.balance_value),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_balances (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ const char *balance_key,
+ TALER_AUDITORDB_BalancesCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ NULL == balance_key
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (balance_key),
+ GNUNET_PQ_query_param_end
+ };
+ struct BalancesContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_balances",
+ "SELECT"
+ " balance_key"
+ ",balance_value"
+ " FROM auditor_balances"
+ " WHERE ($1::TEXT IS NULL OR balance_key = $1)"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_balances",
+ params,
+ &balances_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_coin_inconsistencies.c b/src/auditordb/iterate_coin_inconsistencies.c
@@ -0,0 +1,183 @@
+/*
+ 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/>
+ */
+
+
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_coin_inconsistencies.h"
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct CoinInconsistencyContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_CoinInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+coin_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+
+ struct TALER_AUDITORDB_CoinInconsistency dc;
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_string ("operation",
+ &dc.operation),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
+ &dc.exchange_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
+ &dc.auditor_amount),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &dc.coin_pub),
+ GNUNET_PQ_result_spec_bool ("profitable",
+ &dc.profitable),
+
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+
+
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_coin_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed, // maybe not needed
+ TALER_AUDITORDB_CoinInconsistencyCallback cb,
+ void *cb_cls)
+{
+
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct CoinInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "iterate_coin_inconsistencies_inconsistency_select_desc",
+ "SELECT"
+ " row_id"
+ ",operation"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",coin_pub"
+ ",profitable"
+ " FROM auditor_coin_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_coin_inconsistencies_inconsistency_select_asc",
+ "SELECT"
+ " row_id"
+ ",operation"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",coin_pub"
+ ",profitable"
+ " FROM auditor_coin_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ (limit > 0) ?
+ "iterate_coin_inconsistencies_inconsistency_select_asc"
+ :
+ "iterate_coin_inconsistencies_inconsistency_select_desc",
+ params,
+ &coin_inconsistency_cb,
+ &dcc);
+
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_denomination_key_validity_withdraw_inconsistencies.c b/src/auditordb/iterate_denomination_key_validity_withdraw_inconsistencies.c
@@ -0,0 +1,173 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include \
+ "auditor-database/iterate_denomination_key_validity_withdraw_inconsistencies.h"
+
+
+/**
+ * Closure for #denomination_key_validity_withdraw_inconsistency_cb().
+ */
+struct DenominationKeyValidityWithdrawInconsistencyContext
+{
+
+ /**
+ * Function to call for each denomination key validity...
+ */
+ TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+denomination_key_validity_withdraw_inconsistency_cb (
+ void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DenominationKeyValidityWithdrawInconsistencyContext *dcc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_uint64 ("problem_row_id",
+ &dc.problem_row_id),
+ GNUNET_PQ_result_spec_absolute_time ("execution_date",
+ &dc.execution_date),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
+ &dc.denompub_h),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_denomination_key_validity_withdraw_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct DenominationKeyValidityWithdrawInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_denomination_key_validity_withdraw_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",execution_date"
+ ",reserve_pub"
+ ",denompub_h"
+ ",suppressed"
+ " FROM auditor_denomination_key_validity_withdraw_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_denomination_key_validity_withdraw_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",execution_date"
+ ",reserve_pub"
+ ",denompub_h"
+ ",suppressed"
+ " FROM auditor_denomination_key_validity_withdraw_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ?
+ "iterate_denomination_key_validity_withdraw_inconsistencies_inconsistency_get_asc"
+ :
+ "iterate_denomination_key_validity_withdraw_inconsistencies_inconsistency_get_desc",
+ params,
+ &denomination_key_validity_withdraw_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_denomination_pending.c b/src/auditordb/iterate_denomination_pending.c
@@ -0,0 +1,169 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_denomination_pending.h"
+
+
+struct DenominationPendingContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_DenominationPendingCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_denomination_pending().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DenominationPendingContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+denomination_pending_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DenominationPendingContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+ struct TALER_AUDITORDB_DenominationPending dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &dc.denom_pub_hash),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance",
+ &dc.denom_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss",
+ &dc.denom_loss),
+ GNUNET_PQ_result_spec_uint64 ("num_issued",
+ &dc.num_issued),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk",
+ &dc.denom_risk),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss",
+ &dc.recoup_loss),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_denomination_pending (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_DenominationPendingCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct DenominationPendingContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_denomination_pending_desc",
+ "SELECT"
+ " row_id,"
+ " denom_pub_hash,"
+ " denom_balance,"
+ " denom_loss,"
+ " num_issued,"
+ " denom_risk,"
+ " recoup_loss"
+ " FROM auditor_denomination_pending"
+ " WHERE (row_id < $1)"
+ " ORDER BY row_id DESC"
+ " LIMIT $2"
+ );
+ PREPARE (pg,
+ "iterate_denomination_pending_asc",
+ "SELECT"
+ " row_id,"
+ " denom_pub_hash,"
+ " denom_balance,"
+ " denom_loss,"
+ " num_issued,"
+ " denom_risk,"
+ " recoup_loss"
+ " FROM auditor_denomination_pending"
+ " WHERE (row_id > $1)"
+ " ORDER BY row_id ASC"
+ " LIMIT $2"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_denomination_pending_asc"
+ : "iterate_denomination_pending_desc",
+ params,
+ &denomination_pending_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_denominations_without_sigs.c b/src/auditordb/iterate_denominations_without_sigs.c
@@ -0,0 +1,170 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_denominations_without_sigs.h"
+
+
+struct DenominationsWithoutSigsContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_DenominationsWithoutSigsCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_denominations_without_sigs().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DenominationsWithoutSigsContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+denominations_without_sigs_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DenominationsWithoutSigsContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_DenominationsWithoutSigs dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
+ &dc.denompub_h),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("value",
+ &dc.value),
+ GNUNET_PQ_result_spec_absolute_time ("start_time",
+ &dc.start_time),
+ GNUNET_PQ_result_spec_absolute_time ("end_time",
+ &dc.end_time),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_denominations_without_sigs (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_DenominationsWithoutSigsCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct DenominationsWithoutSigsContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_denominations_without_sigs_desc",
+ "SELECT"
+ " row_id,"
+ " denompub_h,"
+ " value,"
+ " start_time,"
+ " end_time,"
+ " suppressed"
+ " FROM auditor_denominations_without_sigs"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_denominations_without_sigs_asc",
+ "SELECT"
+ " row_id,"
+ " denompub_h,"
+ " value,"
+ " start_time,"
+ " end_time,"
+ " suppressed"
+ " FROM auditor_denominations_without_sigs"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_denominations_without_sigs_asc"
+ : "iterate_denominations_without_sigs_desc",
+ params,
+ &denominations_without_sigs_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_deposit_confirmations.c b/src/auditordb/iterate_deposit_confirmations.c
@@ -0,0 +1,230 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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 iterate_deposit_confirmations.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_deposit_confirmations.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct DepositConfirmationContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_DepositConfirmationCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+deposit_confirmation_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DepositConfirmationContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_DepositConfirmation dc = { 0 };
+ struct TALER_CoinSpendPublicKeyP *coin_pubs = NULL;
+ struct TALER_CoinSpendSignatureP *coin_sigs = NULL;
+ size_t num_pubs = 0;
+ size_t num_sigs = 0;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &dc.h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("h_policy",
+ &dc.h_policy),
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire",
+ &dc.h_wire),
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ &dc.exchange_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &dc.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &dc.wire_deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_without_fee",
+ &dc.total_without_fee),
+ GNUNET_PQ_result_spec_auto_array_from_type (pg->conn,
+ "coin_pubs",
+ &num_pubs,
+ coin_pubs),
+ GNUNET_PQ_result_spec_auto_array_from_type (pg->conn,
+ "coin_sigs",
+ &num_sigs,
+ coin_sigs),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &dc.merchant),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_sig",
+ &dc.exchange_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
+ &dc.exchange_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &dc.master_sig),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ if (num_sigs != num_pubs)
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ dcc->qs = i + 1;
+ dc.coin_pubs = coin_pubs;
+ dc.coin_sigs = coin_sigs;
+ dc.num_coins = num_sigs;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_deposit_confirmations (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_DepositConfirmationCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct DepositConfirmationContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_deposit_confirmations_confirmation_select_desc",
+ "SELECT"
+ " row_id"
+ ",h_contract_terms"
+ ",h_policy"
+ ",h_wire"
+ ",exchange_timestamp"
+ ",wire_deadline"
+ ",refund_deadline"
+ ",total_without_fee"
+ ",coin_pubs"
+ ",coin_sigs"
+ ",merchant_pub"
+ ",exchange_sig"
+ ",exchange_pub"
+ ",master_sig"
+ ",suppressed"
+ " FROM auditor_deposit_confirmations"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_deposit_confirmations_confirmation_select_asc",
+ "SELECT"
+ " row_id"
+ ",h_contract_terms"
+ ",h_policy"
+ ",h_wire"
+ ",exchange_timestamp"
+ ",wire_deadline"
+ ",refund_deadline"
+ ",total_without_fee"
+ ",coin_pubs"
+ ",coin_sigs"
+ ",merchant_pub"
+ ",exchange_sig"
+ ",exchange_pub"
+ ",master_sig"
+ ",suppressed"
+ " FROM auditor_deposit_confirmations"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_deposit_confirmations_confirmation_select_asc"
+ : "iterate_deposit_confirmations_confirmation_select_desc",
+ params,
+ &deposit_confirmation_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_early_aggregations.c b/src/auditordb/iterate_early_aggregations.c
@@ -0,0 +1,171 @@
+/*
+ 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/auditordb/iterate_early_aggregations.c
+ * @brief Implementation of the iterate_early_aggregations function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_early_aggregations.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #early_aggregation_cb().
+ */
+struct EarlyAggregationContext
+{
+
+ /**
+ * Function to call for each early aggregation.
+ */
+ TALER_AUDITORDB_EarlyAggregationsCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_purse_expired().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct EarlyAggregationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+early_aggregation_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct EarlyAggregationContext *eic = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = eic->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_EarlyAggregation ea;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &ea.row_id),
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &ea.batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_uint64 ("tracking_serial_id",
+ &ea.tracking_serial_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &ea.total),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &ea.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* just to be safe in case the structure changes */
+ memset (&ea,
+ 0,
+ sizeof (ea));
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ eic->cb (eic->cb_cls,
+ &ea);
+ }
+ eic->qs = num_results;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_early_aggregations (struct
+ TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_EarlyAggregationsCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit < 0) ? -limit : limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ struct EarlyAggregationContext eic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_early_aggregations_asc",
+ "SELECT"
+ " row_id"
+ ",batch_deposit_serial_id"
+ ",tracking_serial_id"
+ ",amount"
+ ",suppressed"
+ " FROM auditor_early_aggregations"
+ " WHERE row_id > $1"
+ " AND ($3 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $2;");
+ PREPARE (pg,
+ "iterate_early_aggregations_desc",
+ "SELECT"
+ " row_id"
+ ",batch_deposit_serial_id"
+ ",tracking_serial_id"
+ ",amount"
+ ",suppressed"
+ " FROM auditor_early_aggregations"
+ " WHERE row_id < $1"
+ " AND ($3 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $2;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit < 0)
+ ? "iterate_early_aggregations_desc"
+ : "iterate_early_aggregations_asc",
+ params,
+ &early_aggregation_cb,
+ &eic);
+ if (0 > qs)
+ return qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != eic.qs);
+ return eic.qs;
+}
diff --git a/src/auditordb/iterate_emergencies.c b/src/auditordb/iterate_emergencies.c
@@ -0,0 +1,178 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_emergencies.h"
+
+/**
+ * Closure for #emergency_cb().
+ */
+struct EmergencyContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_EmergencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_emergencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct Emergency *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+emergency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct EmergencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_Emergency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
+ &dc.denompub_h),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk",
+ &dc.denom_risk),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss",
+ &dc.denom_loss),
+ GNUNET_PQ_result_spec_absolute_time ("deposit_start",
+ &dc.deposit_start),
+ GNUNET_PQ_result_spec_absolute_time ("deposit_end",
+ &dc.deposit_end),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("value",
+ &dc.value),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_emergencies (struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_EmergencyCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct EmergencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_emergencies_emergency_get_desc",
+ "SELECT"
+ " row_id"
+ ",denompub_h"
+ ",denom_risk"
+ ",denom_loss"
+ ",deposit_start"
+ ",deposit_end"
+ ",value"
+ ",suppressed"
+ " FROM auditor_emergency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_emergencies_emergency_get_asc",
+ "SELECT"
+ " row_id"
+ ",denompub_h"
+ ",denom_risk"
+ ",denom_loss"
+ ",deposit_start"
+ ",deposit_end"
+ ",value"
+ ",suppressed"
+ " FROM auditor_emergency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_emergencies_emergency_get_asc"
+ : "iterate_emergencies_emergency_get_desc",
+ params,
+ &emergency_cb,
+ &dcc);
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_emergencies_by_count.c b/src/auditordb/iterate_emergencies_by_count.c
@@ -0,0 +1,185 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_emergencies_by_count.h"
+
+
+/**
+ * Closure for #emergency_cb().
+ */
+struct EmergencyByCountContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_EmergenciesByCountCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_emergencies_by_count().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct Emergency *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+emergency_by_count_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct EmergencyByCountContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_EmergenciesByCount dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("denompub_h",
+ &dc.denompub_h),
+ GNUNET_PQ_result_spec_uint64 ("num_issued",
+ &dc.num_issued),
+ GNUNET_PQ_result_spec_uint64 ("num_known",
+ &dc.num_known),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("risk",
+ &dc.risk),
+ GNUNET_PQ_result_spec_absolute_time ("start",
+ &dc.start),
+ GNUNET_PQ_result_spec_absolute_time ("deposit_end",
+ &dc.deposit_end),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("value",
+ &dc.value),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_emergencies_by_count (struct
+ TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_EmergenciesByCountCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct EmergencyByCountContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_emergencies_by_count_emergency_by_count_get_desc",
+ "SELECT"
+ " row_id"
+ ",denompub_h"
+ ",num_issued"
+ ",num_known"
+ ",risk"
+ ",start"
+ ",deposit_end"
+ ",value"
+ ",suppressed"
+ " FROM auditor_emergency_by_count"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_emergencies_by_count_emergency_by_count_get_asc",
+ "SELECT"
+ " row_id"
+ ",denompub_h"
+ ",num_issued"
+ ",num_known"
+ ",risk"
+ ",start"
+ ",deposit_end"
+ ",value"
+ ",suppressed"
+ " FROM auditor_emergency_by_count"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_emergencies_by_count_emergency_by_count_get_asc"
+ : "iterate_emergencies_by_count_emergency_by_count_get_desc",
+ params,
+ &emergency_by_count_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_exchange_signkeys.c b/src/auditordb/iterate_exchange_signkeys.c
@@ -0,0 +1,170 @@
+/*
+ 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/>
+ */
+
+
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+
+#include "auditor-database/iterate_exchange_signkeys.h"
+
+
+struct ExchangeSignkeysContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_ExchangeSignkeysCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_exchange_signkeys().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ExchangeSignkeysContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+exchange_signkeys_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ExchangeSignkeysContext *dcc = cls;
+ // struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+ struct TALER_AUDITORDB_ExchangeSignkeys dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
+ &dc.exchange_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &dc.master_sig),
+ GNUNET_PQ_result_spec_absolute_time ("ep_valid_from",
+ &dc.ep_valid_from),
+ GNUNET_PQ_result_spec_absolute_time ("ep_expire_sign",
+ &dc.ep_expire_sign),
+ GNUNET_PQ_result_spec_absolute_time ("ep_expire_legal",
+ &dc.ep_expire_legal),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_exchange_signkeys (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_ExchangeSignkeysCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ExchangeSignkeysContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_exchange_signkeys_desc",
+ "SELECT"
+ " row_id,"
+ " exchange_pub,"
+ " master_sig,"
+ " ep_valid_from,"
+ " ep_expire_sign,"
+ " ep_expire_legal"
+ " FROM auditor_exchange_signkeys"
+ " WHERE (row_id < $1)"
+ " ORDER BY row_id DESC"
+ " LIMIT $2"
+ );
+ PREPARE (pg,
+ "iterate_exchange_signkeys_asc",
+ "SELECT"
+ " row_id,"
+ " exchange_pub,"
+ " master_sig,"
+ " ep_valid_from,"
+ " ep_expire_sign,"
+ " ep_expire_legal"
+ " FROM auditor_exchange_signkeys"
+ " WHERE (row_id > $1)"
+ " ORDER BY row_id ASC"
+ " LIMIT $2"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_exchange_signkeys_asc"
+ : "iterate_exchange_signkeys_desc",
+ params,
+ &exchange_signkeys_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_fee_time_inconsistencies.c b/src/auditordb/iterate_fee_time_inconsistencies.c
@@ -0,0 +1,164 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_fee_time_inconsistencies.h"
+
+
+/**
+ * Closure for #feetimeinconsistency_cb().
+ */
+struct FeeTimeInconsistencyContext
+{
+
+ /**
+ * Function to call for each fee time inconsistency
+ */
+ TALER_AUDITORDB_FeeTimeInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_emergencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct Emergency *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+fee_time_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct FeeTimeInconsistencyContext *dcc = cls;
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_FeeTimeInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_uint64 ("problem_row_id",
+ &dc.problem_row_id),
+ GNUNET_PQ_result_spec_string ("fee_type",
+ &dc.type),
+ GNUNET_PQ_result_spec_absolute_time ("fee_time",
+ &dc.time),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_fee_time_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_FeeTimeInconsistencyCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct FeeTimeInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_fee_time_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",fee_type"
+ ",fee_time"
+ ",diagnostic"
+ " FROM auditor_fee_time_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_fee_time_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",problem_row_id"
+ ",fee_type"
+ ",fee_time"
+ ",diagnostic"
+ " FROM auditor_fee_time_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_fee_time_inconsistencies_inconsistency_get_asc"
+ : "iterate_fee_time_inconsistencies_inconsistency_get_desc",
+ params,
+ &fee_time_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_historic_denom_revenue.c b/src/auditordb/iterate_historic_denom_revenue.c
@@ -0,0 +1,170 @@
+/*
+ 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 iterate_historic_denom_revenue.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_historic_denom_revenue.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #historic_denom_revenue_cb().
+ */
+struct HistoricDenomRevenueContext
+{
+ /**
+ * Function to call for each result.
+ */
+ TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Number of results processed.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_historic_denom_revenue().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct HistoricRevenueContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+historic_denom_revenue_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct HistoricDenomRevenueContext *hrc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = hrc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_DenominationHashP denom_pub_hash;
+ struct GNUNET_TIME_Timestamp revenue_timestamp;
+ struct TALER_Amount revenue_balance;
+ struct TALER_Amount loss;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &denom_pub_hash),
+ GNUNET_PQ_result_spec_timestamp ("revenue_timestamp",
+ &revenue_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance",
+ &revenue_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance",
+ &loss),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ hrc->qs = i + 1;
+ if (GNUNET_OK !=
+ hrc->cb (hrc->cb_cls,
+ rowid,
+ &denom_pub_hash,
+ revenue_timestamp,
+ &revenue_balance,
+ &loss))
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_historic_denom_revenue (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct HistoricDenomRevenueContext hrc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_historic_denom_revenue_denomination_revenue_select_inc",
+ "SELECT"
+ " row_id"
+ ",denom_pub_hash"
+ ",revenue_timestamp"
+ ",revenue_balance"
+ ",loss_balance"
+ " FROM auditor_historic_denomination_revenue"
+ " WHERE row_id > $1"
+ " ORDER BY row_id ASC"
+ " LIMIT $2;");
+ PREPARE (pg,
+ "iterate_historic_denom_revenue_denomination_revenue_select_dec",
+ "SELECT"
+ " row_id"
+ ",denom_pub_hash"
+ ",revenue_timestamp"
+ ",revenue_balance"
+ ",loss_balance"
+ " FROM auditor_historic_denomination_revenue"
+ " WHERE row_id < $1"
+ " ORDER BY row_id DESC"
+ " LIMIT $2;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ limit > 0
+ ? "iterate_historic_denom_revenue_denomination_revenue_select_inc"
+ : "iterate_historic_denom_revenue_denomination_revenue_select_dec",
+ params,
+ &historic_denom_revenue_cb,
+ &hrc);
+ if (qs <= 0)
+ return qs;
+ return hrc.qs;
+}
diff --git a/src/auditordb/iterate_historic_reserve_revenue.c b/src/auditordb/iterate_historic_reserve_revenue.c
@@ -0,0 +1,163 @@
+/*
+ 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 iterate_historic_reserve_revenue.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_historic_reserve_revenue.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #historic_reserve_revenue_cb().
+ */
+struct HistoricReserveRevenueContext
+{
+ /**
+ * Function to call for each result.
+ */
+ TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Number of results processed.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_historic_reserve_revenue().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct HistoricRevenueContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+historic_reserve_revenue_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct HistoricReserveRevenueContext *hrc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = hrc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_Amount reserve_profits;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits",
+ &reserve_profits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ hrc->qs = i + 1;
+ if (GNUNET_OK !=
+ hrc->cb (hrc->cb_cls,
+ rowid,
+ start_date,
+ end_date,
+ &reserve_profits))
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_historic_reserve_revenue (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ struct HistoricReserveRevenueContext hrc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "iterate_historic_reserve_revenue_summary_select_inc",
+ "SELECT"
+ " row_id"
+ ",start_date"
+ ",end_date"
+ ",reserve_profits"
+ " FROM auditor_historic_reserve_summary"
+ " WHERE row_id > $1"
+ " ORDER BY row_id ASC"
+ " LIMIT $2");
+ PREPARE (pg,
+ "iterate_historic_reserve_revenue_summary_select_dec",
+ "SELECT"
+ " row_id"
+ ",start_date"
+ ",end_date"
+ ",reserve_profits"
+ " FROM auditor_historic_reserve_summary"
+ " WHERE row_id < $1"
+ " ORDER BY row_id DESC"
+ " LIMIT $2");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ limit > 0
+ ? "iterate_historic_reserve_revenue_summary_select_inc"
+ : "iterate_historic_reserve_revenue_summary_select_dec",
+ params,
+ &historic_reserve_revenue_cb,
+ &hrc);
+ if (0 >= qs)
+ return qs;
+ return hrc.qs;
+}
diff --git a/src/auditordb/iterate_misattribution_in_inconsistencies.c b/src/auditordb/iterate_misattribution_in_inconsistencies.c
@@ -0,0 +1,169 @@
+/*
+ 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/>
+ */
+
+
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+
+#include "auditor-database/iterate_misattribution_in_inconsistencies.h"
+
+
+struct MisattributionInInconsistencyContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_MisattributionInInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_misattribution_in_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct MisattributionInInconsistencyContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+misattribution_in_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct MisattributionInInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_MisattributionInInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &dc.amount),
+ GNUNET_PQ_result_spec_uint64 ("bank_row",
+ &dc.bank_row),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_misattribution_in_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_MisattributionInInconsistencyCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct MisattributionInInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_misattribution_in_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",amount"
+ ",bank_row"
+ ",reserve_pub"
+ ",suppressed"
+ " FROM auditor_misattribution_in_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_misattribution_in_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",amount"
+ ",bank_row"
+ ",reserve_pub"
+ ",suppressed"
+ " FROM auditor_misattribution_in_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_misattribution_in_inconsistencies_inconsistency_get_asc"
+ : "iterate_misattribution_in_inconsistencies_inconsistency_get_desc",
+ params,
+ &misattribution_in_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_pending_deposits.c b/src/auditordb/iterate_pending_deposits.c
@@ -0,0 +1,184 @@
+/*
+ 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/auditordb/iterate_pending_deposits.c
+ * @brief Implementation of the iterate_pending_deposits function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_pending_deposits.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #wire_missing_cb().
+ */
+struct WireMissingContext
+{
+
+ /**
+ * Function to call for each pending deposit.
+ */
+ TALER_AUDITORDB_WireMissingCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_purse_expired().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireMissingContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_missing_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireMissingContext *eic = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = eic->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t row_id;
+ uint64_t batch_deposit_serial_id;
+ struct TALER_Amount total_amount;
+ struct TALER_FullPaytoHashP wire_target_h_payto;
+ struct GNUNET_TIME_Timestamp deadline;
+ bool suppressed;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &row_id),
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &batch_deposit_serial_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
+ &total_amount),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
+ &wire_target_h_payto),
+ GNUNET_PQ_result_spec_timestamp ("deadline",
+ &deadline),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ eic->cb (eic->cb_cls,
+ row_id,
+ batch_deposit_serial_id,
+ &total_amount,
+ &wire_target_h_payto,
+ deadline,
+ suppressed);
+ }
+ eic->qs = num_results;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_pending_deposits (struct
+ TALER_AUDITORDB_PostgresContext *pg,
+ struct GNUNET_TIME_Absolute deadline,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_WireMissingCallback cb
+ ,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit < 0) ? -limit : limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&deadline),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireMissingContext eic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_pending_deposits_asc",
+ "SELECT"
+ " row_id"
+ ",total_amount"
+ ",wire_target_h_payto"
+ ",batch_deposit_serial_id"
+ ",deadline"
+ ",suppressed"
+ " FROM auditor_pending_deposits"
+ " WHERE deadline<$1"
+ " AND (row_id > $2)"
+ " AND ($4 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3;");
+ PREPARE (pg,
+ "iterate_pending_deposits_desc",
+ "SELECT"
+ " row_id"
+ ",total_amount"
+ ",wire_target_h_payto"
+ ",batch_deposit_serial_id"
+ ",deadline"
+ ",suppressed"
+ " FROM auditor_pending_deposits"
+ " WHERE deadline<$1"
+ " AND (row_id < $2)"
+ " AND ($4 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_pending_deposits_asc"
+ : "iterate_pending_deposits_desc",
+ params,
+ &wire_missing_cb,
+ &eic);
+ if (0 > qs)
+ return qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != eic.qs);
+ return eic.qs;
+}
diff --git a/src/auditordb/iterate_progress_points.c b/src/auditordb/iterate_progress_points.c
@@ -0,0 +1,136 @@
+/*
+ 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/auditordb/iterate_progress_points.c
+ * @brief Implementation of the iterate_progress_points function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_progress_points.h"
+#include "pg_helper.h"
+
+
+struct ProgressContext
+{
+
+ /**
+ * Function to call for each progress point.
+ */
+ TALER_AUDITORDB_ProgressPointsCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_progress_points().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ProgressContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+progress_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ProgressContext *dcc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_Progress dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("progress_key",
+ &dc.progress_key),
+ GNUNET_PQ_result_spec_uint64 ("progress_offset",
+ &dc.progress_offset),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_progress_points (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ const char *progress_key,
+ TALER_AUDITORDB_ProgressPointsCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ NULL == progress_key
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (progress_key),
+ GNUNET_PQ_query_param_end
+ };
+ struct ProgressContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_progress_points",
+ "SELECT"
+ " progress_key"
+ ",progress_offset"
+ " FROM auditor_progress"
+ " WHERE ($1::TEXT IS NULL OR progress_key = $1)"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_progress_points",
+ params,
+ &progress_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_purse_expired.c b/src/auditordb/iterate_purse_expired.c
@@ -0,0 +1,143 @@
+/*
+ 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/auditordb/iterate_purse_expired.c
+ * @brief Implementation of the iterate_purse_expired function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "auditor-database/iterate_purse_expired.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #purse_expired_cb().
+ */
+struct PurseExpiredContext
+{
+
+ /**
+ * Function to call for each expired purse.
+ */
+ TALER_AUDITORDB_ExpiredPurseCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_purse_expired().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseExpiredContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_expired_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseExpiredContext *eic = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = eic->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct GNUNET_TIME_Timestamp expiration_date;
+ struct TALER_Amount balance;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &balance),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &expiration_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ eic->qs = i + 1;
+ if (GNUNET_OK !=
+ eic->cb (eic->cb_cls,
+ &purse_pub,
+ &balance,
+ expiration_date))
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_purse_expired (struct TALER_AUDITORDB_PostgresContext *
+ pg
+ ,
+ TALER_AUDITORDB_ExpiredPurseCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_TIME_Timestamp now
+ = GNUNET_TIME_timestamp_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseExpiredContext eic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_expired",
+ "SELECT"
+ " purse_pub"
+ ",expiration_date"
+ ",balance"
+ " FROM auditor_purses"
+ " WHERE expiration_date<$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_purse_expired",
+ params,
+ &purse_expired_cb,
+ &eic);
+ if (qs > 0)
+ return eic.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_purse_not_closed_inconsistencies.c b/src/auditordb/iterate_purse_not_closed_inconsistencies.c
@@ -0,0 +1,169 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_purse_not_closed_inconsistencies.h"
+
+
+/**
+ * Closure for #purse_not_closed_inconsistencies_cb().
+ */
+struct PurseNotClosedInconsistenciesContext
+{
+
+ /**
+ * Function to call for each purse not closed_inconsistencies.
+ */
+ TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_purse_not_closed_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseNotClosedInconsistencies *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_not_closed_inconsistencies_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseNotClosedInconsistenciesContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_PurseNotClosedInconsistencies dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &dc.purse_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &dc.amount),
+ GNUNET_PQ_result_spec_absolute_time ("expiration_date",
+ &dc.expiration_date),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_purse_not_closed_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed
+ ,
+ TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseNotClosedInconsistenciesContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_not_closed_inconsistencies_desc",
+ "SELECT"
+ " row_id"
+ ",purse_pub"
+ ",amount"
+ ",expiration_date"
+ ",suppressed"
+ " FROM auditor_purse_not_closed_inconsistencies"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_purse_not_closed_inconsistencies_asc",
+ "SELECT"
+ " row_id"
+ ",purse_pub"
+ ",amount"
+ ",expiration_date"
+ ",suppressed"
+ " FROM auditor_purse_not_closed_inconsistencies"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_purse_not_closed_inconsistencies_asc"
+ : "iterate_purse_not_closed_inconsistencies_desc",
+ params,
+ &purse_not_closed_inconsistencies_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_purses.c b/src/auditordb/iterate_purses.c
@@ -0,0 +1,160 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_purses.h"
+
+
+struct PursesContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_PursesCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_purses().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PursesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purses_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PursesContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_Purses dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("auditor_purses_rowid",
+ &dc.auditor_purses_rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &dc.purse_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &dc.balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("target",
+ &dc.target),
+ GNUNET_PQ_result_spec_absolute_time ("expiration_date",
+ &dc.expiration_date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ dc.auditor_purses_rowid,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_purses (struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_PursesCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct PursesContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purses_desc",
+ "SELECT"
+ " auditor_purses_rowid,"
+ " purse_pub,"
+ " balance,"
+ " target,"
+ " expiration_date"
+ " FROM auditor_purses"
+ " WHERE (auditor_purses_rowid < $1)"
+ " ORDER BY auditor_purses_rowid DESC"
+ " LIMIT $2"
+ );
+ PREPARE (pg,
+ "iterate_purses_asc",
+ "SELECT"
+ " auditor_purses_rowid,"
+ " purse_pub,"
+ " balance,"
+ " target,"
+ " expiration_date"
+ " FROM auditor_purses"
+ " WHERE (auditor_purses_rowid > $1)"
+ " ORDER BY auditor_purses_rowid ASC"
+ " LIMIT $2"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_purses_asc"
+ : "iterate_purses_desc",
+ params,
+ &purses_cb,
+ &dcc);
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_reserve_balance_insufficient_inconsistencies.c b/src/auditordb/iterate_reserve_balance_insufficient_inconsistencies.c
@@ -0,0 +1,176 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include \
+ "auditor-database/iterate_reserve_balance_insufficient_inconsistencies.h"
+
+
+/**
+ * Closure for #reserve_balance_insufficient_inconsistency_cb().
+ */
+struct ReserveBalanceInsufficientInconsistencyContext
+{
+
+ /**
+ * Function to call for each ReserveBalanceInsufficientInconsistency.
+ */
+ TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_reserve_balance_insufficient_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveBalanceInsufficientInconsistency *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_balance_insufficient_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveBalanceInsufficientInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ GNUNET_PQ_result_spec_bool ("inconsistency_gain",
+ &dc.inconsistency_gain),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("inconsistency_amount",
+ &dc.inconsistency_amount),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_balance_insufficient_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t
+ limit,
+ uint64_t
+ offset,
+ bool
+ return_suppressed
+ ,
+ TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback
+ cb,
+ void *
+ cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveBalanceInsufficientInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserve_balance_insufficient_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",reserve_pub"
+ ",inconsistency_gain"
+ ",inconsistency_amount"
+ ",suppressed"
+ " FROM auditor_reserve_balance_insufficient_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_reserve_balance_insufficient_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",reserve_pub"
+ ",inconsistency_gain"
+ ",inconsistency_amount"
+ ",suppressed"
+ " FROM auditor_reserve_balance_insufficient_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ?
+ "iterate_reserve_balance_insufficient_inconsistencies_inconsistency_get_asc"
+ :
+ "iterate_reserve_balance_insufficient_inconsistencies_inconsistency_get_desc",
+ params,
+ &reserve_balance_insufficient_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_reserve_balance_summary_wrong_inconsistencies.c b/src/auditordb/iterate_reserve_balance_summary_wrong_inconsistencies.c
@@ -0,0 +1,174 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include \
+ "auditor-database/iterate_reserve_balance_summary_wrong_inconsistencies.h"
+
+
+struct ReserveBalanceSummaryWrongInconsistencyContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_reserve_balance_summary_wrong_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveBalanceSummaryWrongInconsistencyContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_balance_summary_wrong_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveBalanceSummaryWrongInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
+ &dc.exchange_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
+ &dc.auditor_amount),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_balance_summary_wrong_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t
+ limit,
+ uint64_t
+ offset
+ ,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback
+ cb,
+ void *
+ cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveBalanceSummaryWrongInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserve_balance_summary_wrong_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",reserve_pub"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",suppressed"
+ " FROM auditor_reserve_balance_summary_wrong_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_reserve_balance_summary_wrong_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",reserve_pub"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",suppressed"
+ " FROM auditor_reserve_balance_summary_wrong_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ?
+ "iterate_reserve_balance_summary_wrong_inconsistencies_inconsistency_get_asc"
+ :
+ "iterate_reserve_balance_summary_wrong_inconsistencies_inconsistency_get_desc",
+ params,
+ &reserve_balance_summary_wrong_inconsistency_cb,
+ &dcc);
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_reserve_in_inconsistencies.c b/src/auditordb/iterate_reserve_in_inconsistencies.c
@@ -0,0 +1,185 @@
+/*
+ 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/>
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_dbevents.h"
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_reserve_in_inconsistencies.h"
+
+
+struct ReserveInInconsistencyContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_ReserveInInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_reserve_in_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveInInconsistencyContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_in_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveInInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_ReserveInInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.serial_id),
+ GNUNET_PQ_result_spec_uint64 ("bank_row_id",
+ &dc.bank_row_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_exchange_expected",
+ &dc.amount_exchange_expected),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_wired",
+ &dc.amount_wired),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ GNUNET_PQ_result_spec_absolute_time ("timestamp",
+ &dc.timestamp),
+ GNUNET_PQ_result_spec_string ("account",
+ &dc.account.full_payto),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_in_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_ReserveInInconsistencyCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveInInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserve_in_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",bank_row_id"
+ ",amount_exchange_expected"
+ ",amount_wired"
+ ",reserve_pub"
+ ",timestamp"
+ ",account"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_reserve_in_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_reserve_in_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",bank_row_id"
+ ",amount_exchange_expected"
+ ",amount_wired"
+ ",reserve_pub"
+ ",timestamp"
+ ",account"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_reserve_in_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_reserve_in_inconsistencies_inconsistency_get_asc"
+ : "iterate_reserve_in_inconsistencies_inconsistency_get_desc",
+ params,
+ &reserve_in_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_reserve_not_closed_inconsistencies.c b/src/auditordb/iterate_reserve_not_closed_inconsistencies.c
@@ -0,0 +1,170 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_reserve_not_closed_inconsistencies.h"
+
+
+struct ReserveNotClosedInconsistencyContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_reserve_not_closed_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveNotClosedInconsistencyContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_not_closed_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveNotClosedInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_ReserveNotClosedInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &dc.balance),
+ GNUNET_PQ_result_spec_absolute_time ("expiration_time",
+ &dc.expiration_time),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_not_closed_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveNotClosedInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserve_not_closed_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",reserve_pub"
+ ",balance"
+ ",expiration_time"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_reserve_not_closed_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_reserve_not_closed_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",reserve_pub"
+ ",balance"
+ ",expiration_time"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_reserve_not_closed_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_reserve_not_closed_inconsistencies_inconsistency_get_asc"
+ : "iterate_reserve_not_closed_inconsistencies_inconsistency_get_desc",
+ params,
+ &reserve_not_closed_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_reserves.c b/src/auditordb/iterate_reserves.c
@@ -0,0 +1,186 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_reserves.h"
+
+
+struct ReservesContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_ReservesCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_reserves().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReservesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserves_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReservesContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_Reserves dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid",
+ &dc.auditor_reserves_rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &dc.reserve_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
+ &dc.reserve_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_loss",
+ &dc.reserve_loss),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance",
+ &dc.withdraw_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("close_fee_balance",
+ &dc.close_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee_balance",
+ &dc.purse_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("open_fee_balance",
+ &dc.open_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee_balance",
+ &dc.history_fee_balance),
+ GNUNET_PQ_result_spec_absolute_time ("expiration_date",
+ &dc.expiration_date),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("origin_account",
+ &dc.origin_account.full_payto),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ dc.origin_account.full_payto = NULL;
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ dc.auditor_reserves_rowid,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserves (struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_ReservesCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReservesContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserves_desc",
+ "SELECT"
+ " auditor_reserves_rowid,"
+ " reserve_pub,"
+ " reserve_balance,"
+ " reserve_loss,"
+ " withdraw_fee_balance,"
+ " close_fee_balance,"
+ " purse_fee_balance,"
+ " open_fee_balance,"
+ " history_fee_balance,"
+ " expiration_date,"
+ " origin_account"
+ " FROM auditor_reserves"
+ " WHERE (auditor_reserves_rowid < $1)"
+ " ORDER BY auditor_reserves_rowid DESC"
+ " LIMIT $2"
+ );
+ PREPARE (pg,
+ "iterate_reserves_asc",
+ "SELECT"
+ " auditor_reserves_rowid,"
+ " reserve_pub,"
+ " reserve_balance,"
+ " reserve_loss,"
+ " withdraw_fee_balance,"
+ " close_fee_balance,"
+ " purse_fee_balance,"
+ " open_fee_balance,"
+ " history_fee_balance,"
+ " expiration_date,"
+ " origin_account"
+ " FROM auditor_reserves"
+ " WHERE (auditor_reserves_rowid > $1)"
+ " ORDER BY auditor_reserves_rowid ASC"
+ " LIMIT $2"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_reserves_asc"
+ : "iterate_reserves_desc",
+ params,
+ &reserves_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_row_inconsistencies.c b/src/auditordb/iterate_row_inconsistencies.c
@@ -0,0 +1,170 @@
+/*
+ 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/>
+ */
+
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_row_inconsistencies.h"
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct RowInconsistencyContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_RowInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+row_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RowInconsistencyContext *dcc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+
+ struct TALER_AUDITORDB_RowInconsistency dc;
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id),
+
+ GNUNET_PQ_result_spec_string ("row_table", &dc.row_table),
+ GNUNET_PQ_result_spec_string ("diagnostic", &dc.diagnostic),
+ GNUNET_PQ_result_spec_bool ("suppressed", &dc.suppressed),
+
+
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+
+
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_row_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed, // maybe not needed
+ TALER_AUDITORDB_RowInconsistencyCallback cb,
+ void *cb_cls)
+{
+
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct RowInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "iterate_row_inconsistencies_inconsistency_select_desc",
+ "SELECT"
+ " row_id"
+ ",row_table"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_row_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_row_inconsistencies_inconsistency_select_asc",
+ "SELECT"
+ " row_id"
+ ",row_table"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_row_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR suppressed is false)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_row_inconsistencies_inconsistency_select_asc"
+ : "iterate_row_inconsistencies_inconsistency_select_desc",
+ params,
+ &row_inconsistency_cb,
+ &dcc);
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_row_minor_inconsistencies.c b/src/auditordb/iterate_row_minor_inconsistencies.c
@@ -0,0 +1,162 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_row_minor_inconsistencies.h"
+
+
+struct RowMinorInconsistenciesContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_RowMinorInconsistenciesCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_row_minor_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RowMinorInconsistenciesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+row_minor_inconsistencies_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RowMinorInconsistenciesContext *dcc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_RowMinorInconsistencies dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_string ("row_table",
+ &dc.row_table),
+ GNUNET_PQ_result_spec_uint64 ("problem_row",
+ &dc.problem_row),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_row_minor_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_RowMinorInconsistenciesCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct RowMinorInconsistenciesContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_row_minor_inconsistencies_desc",
+ "SELECT"
+ " row_id"
+ ",problem_row"
+ ",row_table"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_row_minor_inconsistencies"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_row_minor_inconsistencies_asc",
+ "SELECT"
+ " row_id"
+ ",problem_row"
+ ",row_table"
+ ",diagnostic"
+ ",suppressed"
+ " FROM auditor_row_minor_inconsistencies"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_row_minor_inconsistencies_asc"
+ : "iterate_row_minor_inconsistencies_desc",
+ params,
+ &row_minor_inconsistencies_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_wire_format_inconsistencies.c b/src/auditordb/iterate_wire_format_inconsistencies.c
@@ -0,0 +1,166 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_wire_format_inconsistencies.h"
+
+
+struct WireFormatInconsistencyContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_WireFormatInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_wire_format_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireFormatInconsistencyContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_format_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireFormatInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_WireFormatInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &dc.amount),
+ GNUNET_PQ_result_spec_uint64 ("wire_offset",
+ &dc.wire_offset),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_wire_format_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_WireFormatInconsistencyCallback
+ cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireFormatInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_format_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id,"
+ " amount,"
+ " wire_offset,"
+ " diagnostic,"
+ " suppressed"
+ " FROM auditor_wire_format_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_wire_format_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id,"
+ " amount,"
+ " wire_offset,"
+ " diagnostic,"
+ " suppressed"
+ " FROM auditor_wire_format_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_wire_format_inconsistencies_inconsistency_get_asc"
+ : "iterate_wire_format_inconsistencies_inconsistency_get_desc",
+ params,
+ &wire_format_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/iterate_wire_out_inconsistencies.c b/src/auditordb/iterate_wire_out_inconsistencies.c
@@ -0,0 +1,171 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/iterate_wire_out_inconsistencies.h"
+
+
+struct WireOutInconsistencyContext
+{
+
+ /**
+ * Function to call for each bad sig loss.
+ */
+ TALER_AUDITORDB_WireOutInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TALER_AUDITORDB_iterate_wire_out_inconsistencies().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireOutInconsistencyContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_out_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireOutInconsistencyContext *dcc = cls;
+ struct TALER_AUDITORDB_PostgresContext *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_AUDITORDB_WireOutInconsistency dc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &dc.row_id),
+ GNUNET_PQ_result_spec_string ("destination_account",
+ &dc.destination_account.full_payto),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+ GNUNET_PQ_result_spec_uint64 ("wire_out_serial_id",
+ &dc.wire_out_row_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("expected",
+ &dc.expected),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("claimed",
+ &dc.claimed),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ dcc->qs = i + 1;
+ rval = dcc->cb (dcc->cb_cls,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_wire_out_inconsistencies (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_WireOutInconsistencyCallback cb,
+ void *cb_cls)
+{
+ uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireOutInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_out_inconsistencies_inconsistency_get_desc",
+ "SELECT"
+ " row_id"
+ ",destination_account"
+ ",diagnostic"
+ ",wire_out_serial_id"
+ ",expected"
+ ",claimed"
+ ",suppressed"
+ " FROM auditor_wire_out_inconsistency"
+ " WHERE (row_id < $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id DESC"
+ " LIMIT $3"
+ );
+ PREPARE (pg,
+ "iterate_wire_out_inconsistencies_inconsistency_get_asc",
+ "SELECT"
+ " row_id"
+ ",destination_account"
+ ",diagnostic"
+ ",wire_out_serial_id"
+ ",expected"
+ ",claimed"
+ ",suppressed"
+ " FROM auditor_wire_out_inconsistency"
+ " WHERE (row_id > $1)"
+ " AND ($2 OR NOT suppressed)"
+ " ORDER BY row_id ASC"
+ " LIMIT $3"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_wire_out_inconsistencies_inconsistency_get_asc"
+ : "iterate_wire_out_inconsistencies_inconsistency_get_desc",
+ params,
+ &wire_out_inconsistency_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/lookup_reserve_in_inconsistency.c b/src/auditordb/lookup_reserve_in_inconsistency.c
@@ -1,73 +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/>
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_dbevents.h"
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/lookup_reserve_in_inconsistency.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_lookup_reserve_in_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- uint64_t bank_row_id,
- struct TALER_AUDITORDB_ReserveInInconsistency *dc)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&bank_row_id),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc->serial_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_exchange_expected",
- &dc->amount_exchange_expected),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_wired",
- &dc->amount_wired),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc->reserve_pub),
- GNUNET_PQ_result_spec_absolute_time ("timestamp",
- &dc->timestamp),
- GNUNET_PQ_result_spec_string ("account",
- &dc->account.full_payto),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc->diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc->suppressed),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_lookup_reserve_in_inconsistency",
- "SELECT"
- " row_id"
- ",amount_exchange_expected"
- ",amount_wired"
- ",reserve_pub"
- ",timestamp"
- ",account"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_reserve_in_inconsistency"
- " WHERE (bank_row_id = $1)"
- );
- dc->bank_row_id = bank_row_id;
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "auditor_lookup_reserve_in_inconsistency",
- params,
- rs);
-}
diff --git a/src/auditordb/meson.build b/src/auditordb/meson.build
@@ -74,7 +74,7 @@ libtalerauditordb = library(
'talerauditordb',
[
'create_tables.c',
- 'del_denomination_balance.c',
+ 'delete_denomination_balance.c',
'delete_auditor_closure_lag.c',
'delete_early_aggregation.c',
'delete_generic.c',
@@ -82,43 +82,43 @@ libtalerauditordb = library(
'delete_purse_info.c',
'delete_reserve_in_inconsistency.c',
'delete_wire_out_inconsistency_if_matching.c',
- 'del_reserve_info.c',
+ 'delete_reserve_info.c',
'drop_tables.c',
'event_listen.c',
'event_notify.c',
'gc.c',
- 'get_amount_arithmetic_inconsistency.c',
- 'get_auditor_closure_lags.c',
+ 'iterate_amount_arithmetic_inconsistencies.c',
+ 'iterate_auditor_closure_lags.c',
'get_auditor_progress.c',
- 'get_bad_sig_losses.c',
+ 'iterate_bad_sig_losses.c',
'get_balance.c',
- 'get_balances.c',
- 'get_coin_inconsistency.c',
+ 'iterate_balances.c',
+ 'iterate_coin_inconsistencies.c',
'get_denomination_balance.c',
- 'get_denomination_key_validity_withdraw_inconsistency.c',
- 'get_denomination_pending.c',
- 'get_denominations_without_sigs.c',
- 'get_deposit_confirmations.c',
- 'get_emergency_by_count.c',
- 'get_emergency.c',
- 'get_exchange_signkeys.c',
- 'get_fee_time_inconsistency.c',
- 'get_misattribution_in_inconsistency.c',
- 'get_progress_points.c',
+ 'iterate_denomination_key_validity_withdraw_inconsistencies.c',
+ 'iterate_denomination_pending.c',
+ 'iterate_denominations_without_sigs.c',
+ 'iterate_deposit_confirmations.c',
+ 'iterate_emergencies_by_count.c',
+ 'iterate_emergencies.c',
+ 'iterate_exchange_signkeys.c',
+ 'iterate_fee_time_inconsistencies.c',
+ 'iterate_misattribution_in_inconsistencies.c',
+ 'iterate_progress_points.c',
'get_purse_info.c',
- 'get_purse_not_closed_inconsistencies.c',
- 'get_purses.c',
- 'get_reserve_balance_insufficient_inconsistency.c',
- 'get_reserve_balance_summary_wrong_inconsistency.c',
+ 'iterate_purse_not_closed_inconsistencies.c',
+ 'iterate_purses.c',
+ 'iterate_reserve_balance_insufficient_inconsistencies.c',
+ 'iterate_reserve_balance_summary_wrong_inconsistencies.c',
'get_reserve_info.c',
- 'get_reserve_in_inconsistency.c',
- 'get_reserve_not_closed_inconsistency.c',
- 'get_reserves.c',
- 'get_row_inconsistency.c',
- 'get_row_minor_inconsistencies.c',
+ 'iterate_reserve_in_inconsistencies.c',
+ 'iterate_reserve_not_closed_inconsistencies.c',
+ 'iterate_reserves.c',
+ 'iterate_row_inconsistencies.c',
+ 'iterate_row_minor_inconsistencies.c',
'get_wire_fee_summary.c',
- 'get_wire_format_inconsistency.c',
- 'get_wire_out_inconsistency.c',
+ 'iterate_wire_format_inconsistencies.c',
+ 'iterate_wire_out_inconsistencies.c',
'helper.c',
'insert_amount_arithmetic_inconsistency.c',
'insert_auditor_closure_lags.c',
@@ -151,20 +151,19 @@ libtalerauditordb = library(
'insert_row_minor_inconsistencies.c',
'insert_wire_format_inconsistency.c',
'insert_wire_out_inconsistency.c',
- 'lookup_reserve_in_inconsistency.c',
'pg.c',
'preflight.c',
- 'select_early_aggregations.c',
- 'select_historic_denom_revenue.c',
- 'select_historic_reserve_revenue.c',
- 'select_pending_deposits.c',
- 'select_purse_expired.c',
- 'select_reserve_in_inconsistency.c',
+ 'iterate_early_aggregations.c',
+ 'iterate_historic_denom_revenue.c',
+ 'iterate_historic_reserve_revenue.c',
+ 'iterate_pending_deposits.c',
+ 'iterate_purse_expired.c',
+ 'get_reserve_in_inconsistency.c',
'start.c',
'update_auditor_progress.c',
'update_balance.c',
'update_denomination_balance.c',
- 'update_generic_suppressed.c',
+ 'update_to_suppressed.c',
'update_purse_info.c',
'update_reserve_info.c',
'update_wire_fee_summary.c',
diff --git a/src/auditordb/select_early_aggregations.c b/src/auditordb/select_early_aggregations.c
@@ -1,171 +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/auditordb/select_early_aggregations.c
- * @brief Implementation of the select_early_aggregations function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/select_early_aggregations.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #early_aggregation_cb().
- */
-struct EarlyAggregationContext
-{
-
- /**
- * Function to call for each early aggregation.
- */
- TALER_AUDITORDB_EarlyAggregationsCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_select_purse_expired().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct EarlyAggregationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-early_aggregation_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct EarlyAggregationContext *eic = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = eic->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_AUDITORDB_EarlyAggregation ea;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &ea.row_id),
- GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
- &ea.batch_deposit_serial_id),
- GNUNET_PQ_result_spec_uint64 ("tracking_serial_id",
- &ea.tracking_serial_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &ea.total),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &ea.suppressed),
- GNUNET_PQ_result_spec_end
- };
-
- /* just to be safe in case the structure changes */
- memset (&ea,
- 0,
- sizeof (ea));
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- eic->cb (eic->cb_cls,
- &ea);
- }
- eic->qs = num_results;
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_early_aggregations (struct
- TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_EarlyAggregationsCallback
- cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit < 0) ? -limit : limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_end
- };
- struct EarlyAggregationContext eic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_select_early_aggregations_asc",
- "SELECT"
- " row_id"
- ",batch_deposit_serial_id"
- ",tracking_serial_id"
- ",amount"
- ",suppressed"
- " FROM auditor_early_aggregations"
- " WHERE row_id > $1"
- " AND ($3 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $2;");
- PREPARE (pg,
- "auditor_select_early_aggregations_desc",
- "SELECT"
- " row_id"
- ",batch_deposit_serial_id"
- ",tracking_serial_id"
- ",amount"
- ",suppressed"
- " FROM auditor_early_aggregations"
- " WHERE row_id < $1"
- " AND ($3 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $2;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit < 0)
- ? "auditor_select_early_aggregations_desc"
- : "auditor_select_early_aggregations_asc",
- params,
- &early_aggregation_cb,
- &eic);
- if (0 > qs)
- return qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != eic.qs);
- return eic.qs;
-}
diff --git a/src/auditordb/select_historic_denom_revenue.c b/src/auditordb/select_historic_denom_revenue.c
@@ -1,170 +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 select_historic_denom_revenue.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/select_historic_denom_revenue.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #historic_denom_revenue_cb().
- */
-struct HistoricDenomRevenueContext
-{
- /**
- * Function to call for each result.
- */
- TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Number of results processed.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_select_historic_denom_revenue().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct HistoricRevenueContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-historic_denom_revenue_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct HistoricDenomRevenueContext *hrc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = hrc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t rowid;
- struct TALER_DenominationHashP denom_pub_hash;
- struct GNUNET_TIME_Timestamp revenue_timestamp;
- struct TALER_Amount revenue_balance;
- struct TALER_Amount loss;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &denom_pub_hash),
- GNUNET_PQ_result_spec_timestamp ("revenue_timestamp",
- &revenue_timestamp),
- TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance",
- &revenue_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance",
- &loss),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- hrc->qs = i + 1;
- if (GNUNET_OK !=
- hrc->cb (hrc->cb_cls,
- rowid,
- &denom_pub_hash,
- revenue_timestamp,
- &revenue_balance,
- &loss))
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_historic_denom_revenue (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_end
- };
- struct HistoricDenomRevenueContext hrc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_historic_denomination_revenue_select_inc",
- "SELECT"
- " row_id"
- ",denom_pub_hash"
- ",revenue_timestamp"
- ",revenue_balance"
- ",loss_balance"
- " FROM auditor_historic_denomination_revenue"
- " WHERE row_id > $1"
- " ORDER BY row_id ASC"
- " LIMIT $2;");
- PREPARE (pg,
- "auditor_historic_denomination_revenue_select_dec",
- "SELECT"
- " row_id"
- ",denom_pub_hash"
- ",revenue_timestamp"
- ",revenue_balance"
- ",loss_balance"
- " FROM auditor_historic_denomination_revenue"
- " WHERE row_id < $1"
- " ORDER BY row_id DESC"
- " LIMIT $2;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- limit > 0
- ? "auditor_historic_denomination_revenue_select_inc"
- : "auditor_historic_denomination_revenue_select_dec",
- params,
- &historic_denom_revenue_cb,
- &hrc);
- if (qs <= 0)
- return qs;
- return hrc.qs;
-}
diff --git a/src/auditordb/select_historic_reserve_revenue.c b/src/auditordb/select_historic_reserve_revenue.c
@@ -1,163 +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 select_historic_reserve_revenue.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/select_historic_reserve_revenue.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #historic_reserve_revenue_cb().
- */
-struct HistoricReserveRevenueContext
-{
- /**
- * Function to call for each result.
- */
- TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Number of results processed.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_select_historic_reserve_revenue().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct HistoricRevenueContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-historic_reserve_revenue_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct HistoricReserveRevenueContext *hrc = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = hrc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t rowid;
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct TALER_Amount reserve_profits;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits",
- &reserve_profits),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- hrc->qs = i + 1;
- if (GNUNET_OK !=
- hrc->cb (hrc->cb_cls,
- rowid,
- start_date,
- end_date,
- &reserve_profits))
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_historic_reserve_revenue (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
- struct HistoricReserveRevenueContext hrc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
-
- PREPARE (pg,
- "auditor_historic_reserve_summary_select_inc",
- "SELECT"
- " row_id"
- ",start_date"
- ",end_date"
- ",reserve_profits"
- " FROM auditor_historic_reserve_summary"
- " WHERE row_id > $1"
- " ORDER BY row_id ASC"
- " LIMIT $2");
- PREPARE (pg,
- "auditor_historic_reserve_summary_select_dec",
- "SELECT"
- " row_id"
- ",start_date"
- ",end_date"
- ",reserve_profits"
- " FROM auditor_historic_reserve_summary"
- " WHERE row_id < $1"
- " ORDER BY row_id DESC"
- " LIMIT $2");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- limit > 0
- ? "auditor_historic_reserve_summary_select_inc"
- : "auditor_historic_reserve_summary_select_dec",
- params,
- &historic_reserve_revenue_cb,
- &hrc);
- if (0 >= qs)
- return qs;
- return hrc.qs;
-}
diff --git a/src/auditordb/select_pending_deposits.c b/src/auditordb/select_pending_deposits.c
@@ -1,183 +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/auditordb/select_pending_deposits.c
- * @brief Implementation of the select_pending_deposits function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/select_pending_deposits.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #wire_missing_cb().
- */
-struct WireMissingContext
-{
-
- /**
- * Function to call for each pending deposit.
- */
- TALER_AUDITORDB_WireMissingCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_select_purse_expired().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WireMissingContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-wire_missing_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireMissingContext *eic = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = eic->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t row_id;
- uint64_t batch_deposit_serial_id;
- struct TALER_Amount total_amount;
- struct TALER_FullPaytoHashP wire_target_h_payto;
- struct GNUNET_TIME_Timestamp deadline;
- bool suppressed;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &row_id),
- GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
- &batch_deposit_serial_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
- &total_amount),
- GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
- &wire_target_h_payto),
- GNUNET_PQ_result_spec_timestamp ("deadline",
- &deadline),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &suppressed),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- eic->cb (eic->cb_cls,
- row_id,
- batch_deposit_serial_id,
- &total_amount,
- &wire_target_h_payto,
- deadline,
- suppressed);
- }
- eic->qs = num_results;
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_pending_deposits (struct
- TALER_AUDITORDB_PostgresContext *pg,
- struct GNUNET_TIME_Absolute deadline,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_WireMissingCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit < 0) ? -limit : limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&deadline),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_bool (return_suppressed),
- GNUNET_PQ_query_param_end
- };
- struct WireMissingContext eic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_select_pending_deposits_asc",
- "SELECT"
- " row_id"
- ",total_amount"
- ",wire_target_h_payto"
- ",batch_deposit_serial_id"
- ",deadline"
- ",suppressed"
- " FROM auditor_pending_deposits"
- " WHERE deadline<$1"
- " AND (row_id > $2)"
- " AND ($4 OR NOT suppressed)"
- " ORDER BY row_id ASC"
- " LIMIT $3;");
- PREPARE (pg,
- "auditor_select_pending_deposits_desc",
- "SELECT"
- " row_id"
- ",total_amount"
- ",wire_target_h_payto"
- ",batch_deposit_serial_id"
- ",deadline"
- ",suppressed"
- " FROM auditor_pending_deposits"
- " WHERE deadline<$1"
- " AND (row_id < $2)"
- " AND ($4 OR NOT suppressed)"
- " ORDER BY row_id DESC"
- " LIMIT $3;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "auditor_select_pending_deposits_asc"
- : "auditor_select_pending_deposits_desc",
- params,
- &wire_missing_cb,
- &eic);
- if (0 > qs)
- return qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != eic.qs);
- return eic.qs;
-}
diff --git a/src/auditordb/select_purse_expired.c b/src/auditordb/select_purse_expired.c
@@ -1,142 +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/auditordb/select_purse_expired.c
- * @brief Implementation of the select_purse_expired function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/select_purse_expired.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #purse_expired_cb().
- */
-struct PurseExpiredContext
-{
-
- /**
- * Function to call for each expired purse.
- */
- TALER_AUDITORDB_ExpiredPurseCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TALER_AUDITORDB_select_purse_expired().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseExpiredContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_expired_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseExpiredContext *eic = cls;
- struct TALER_AUDITORDB_PostgresContext *pg = eic->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct GNUNET_TIME_Timestamp expiration_date;
- struct TALER_Amount balance;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &balance),
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &expiration_date),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- eic->qs = i + 1;
- if (GNUNET_OK !=
- eic->cb (eic->cb_cls,
- &purse_pub,
- &balance,
- expiration_date))
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_purse_expired (struct TALER_AUDITORDB_PostgresContext *pg
- ,
- TALER_AUDITORDB_ExpiredPurseCallback cb,
- void *cb_cls)
-{
- struct GNUNET_TIME_Timestamp now
- = GNUNET_TIME_timestamp_get ();
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_end
- };
- struct PurseExpiredContext eic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_select_expired_purses",
- "SELECT"
- " purse_pub"
- ",expiration_date"
- ",balance"
- " FROM auditor_purses"
- " WHERE expiration_date<$1;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "auditor_select_expired_purses",
- params,
- &purse_expired_cb,
- &eic);
- if (qs > 0)
- return eic.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/select_reserve_in_inconsistency.c b/src/auditordb/select_reserve_in_inconsistency.c
@@ -1,78 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/auditordb/select_reserve_in_inconsistency.c
- * @brief Implementation of the select_reserve_in_inconsistency function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_dbevents.h"
-#include "taler/taler_pq_lib.h"
-#include "auditor-database/select_reserve_in_inconsistency.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_reserve_in_inconsistency (
- struct TALER_AUDITORDB_PostgresContext *pg,
- uint64_t bank_row_id,
- struct TALER_AUDITORDB_ReserveInInconsistency *dc)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&bank_row_id),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("row_id",
- &dc->serial_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_exchange_expected",
- &dc->amount_exchange_expected),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_wired",
- &dc->amount_wired),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &dc->reserve_pub),
- GNUNET_PQ_result_spec_absolute_time ("timestamp",
- &dc->timestamp),
- GNUNET_PQ_result_spec_string ("account",
- &dc->account.full_payto),
- GNUNET_PQ_result_spec_string ("diagnostic",
- &dc->diagnostic),
- GNUNET_PQ_result_spec_bool ("suppressed",
- &dc->suppressed),
- GNUNET_PQ_result_spec_end
- };
-
- dc->bank_row_id = bank_row_id;
- PREPARE (pg,
- "select_reserve_in_inconsistency",
- "SELECT"
- " row_id"
- ",amount_exchange_expected"
- ",amount_wired"
- ",reserve_pub"
- ",timestamp"
- ",account"
- ",diagnostic"
- ",suppressed"
- " FROM auditor_reserve_in_inconsistency"
- " WHERE (bank_row_id = $1)"
- );
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "select_reserve_in_inconsistency",
- params,
- rs);
-}
diff --git a/src/auditordb/start.c b/src/auditordb/start.c
@@ -72,10 +72,10 @@ TALER_AUDITORDB_commit (struct TALER_AUDITORDB_PostgresContext *pg)
};
PREPARE (pg,
- "do_commit",
+ "start",
"COMMIT");
pg->transaction_name = NULL;
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "do_commit",
+ "start",
params);
}
diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c
@@ -22,7 +22,7 @@
#include <gnunet/gnunet_db_lib.h>
#include "auditordb_lib.h"
#include "auditor-database/create_tables.h"
-#include "auditor-database/del_reserve_info.h"
+#include "auditor-database/delete_reserve_info.h"
#include "auditor-database/delete_auditor_closure_lag.h"
#include "auditor-database/drop_tables.h"
#include "auditor-database/gc.h"
@@ -34,8 +34,8 @@
#include "auditor-database/insert_historic_reserve_revenue.h"
#include "auditor-database/insert_reserve_info.h"
#include "auditor-database/preflight.h"
-#include "auditor-database/select_historic_denom_revenue.h"
-#include "auditor-database/select_historic_reserve_revenue.h"
+#include "auditor-database/iterate_historic_denom_revenue.h"
+#include "auditor-database/iterate_historic_reserve_revenue.h"
#include "auditor-database/start.h"
#include "auditor-database/update_denomination_balance.h"
#include "auditor-database/update_reserve_info.h"
@@ -464,7 +464,7 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: select_historic_denom_revenue\n");
FAILIF (0 >=
- TALER_AUDITORDB_select_historic_denom_revenue (
+ TALER_AUDITORDB_iterate_historic_denom_revenue (
pg,
1024, /* limit */
0, /* offset */
@@ -488,7 +488,7 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: select_historic_reserve_revenue\n");
FAILIF (0 >=
- TALER_AUDITORDB_select_historic_reserve_revenue (
+ TALER_AUDITORDB_iterate_historic_reserve_revenue (
pg,
1024, /* limit */
0, /* offset */
@@ -499,8 +499,8 @@ run (void *cls)
TALER_AUDITORDB_commit (pg));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- TALER_AUDITORDB_del_reserve_info (pg,
- &reserve_pub));
+ TALER_AUDITORDB_delete_reserve_info (pg,
+ &reserve_pub));
#if GC_IMPLEMENTED
FAILIF (GNUNET_OK !=
diff --git a/src/auditordb/update_auditor_progress.c b/src/auditordb/update_auditor_progress.c
@@ -76,7 +76,7 @@ TALER_AUDITORDB_update_auditor_progress (struct
va_end (ap);
PREPARE (pg,
- "auditor_progress_update",
+ "update_auditor_progress",
"UPDATE auditor_progress"
" SET progress_offset=data.off"
" FROM ("
@@ -87,7 +87,7 @@ TALER_AUDITORDB_update_auditor_progress (struct
" ) AS data"
" WHERE auditor_progress.progress_key=data.key;");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update",
+ "update_auditor_progress",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
diff --git a/src/auditordb/update_balance.c b/src/auditordb/update_balance.c
@@ -75,7 +75,7 @@ TALER_AUDITORDB_update_balance (struct TALER_AUDITORDB_PostgresContext *pg,
va_end (ap);
PREPARE (pg,
- "auditor_balance_update",
+ "update_balance",
"UPDATE auditor_balances"
" SET balance_value.val=data.val"
" ,balance_value.frac=data.frac"
@@ -87,7 +87,7 @@ TALER_AUDITORDB_update_balance (struct TALER_AUDITORDB_PostgresContext *pg,
" ) AS data"
" WHERE auditor_balances.balance_key=data.key;");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_balance_update",
+ "update_balance",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
diff --git a/src/auditordb/update_denomination_balance.c b/src/auditordb/update_denomination_balance.c
@@ -49,7 +49,7 @@ TALER_AUDITORDB_update_denomination_balance (struct
};
PREPARE (pg,
- "auditor_denomination_pending_update",
+ "update_denomination_balance",
"UPDATE auditor_denomination_pending SET"
" denom_balance=$1"
",denom_loss=$2"
@@ -58,6 +58,6 @@ TALER_AUDITORDB_update_denomination_balance (struct
",recoup_loss=$5"
" WHERE denom_pub_hash=$6");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_denomination_pending_update",
+ "update_denomination_balance",
params);
}
diff --git a/src/auditordb/update_generic_suppressed.c b/src/auditordb/update_generic_suppressed.c
@@ -1,91 +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/>
- */
-#include "taler/taler_pq_lib.h"
-#include "pg_helper.h"
-#include "auditor-database/update_generic_suppressed.h"
-
-struct Preparations
-{
- /**
- * Database reconnect counter.
- */
- unsigned long long cnt;
-
- /**
- * Which DB did we do prepare for.
- */
- struct TALER_AUDITORDB_PostgresContext *pg;
-
-};
-
-
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_update_generic_suppressed (
- struct TALER_AUDITORDB_PostgresContext *pg,
- enum TALER_AUDITORDB_DeletableSuppressableTables table,
- uint64_t row_id,
- bool suppressed)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&row_id),
- GNUNET_PQ_query_param_bool (suppressed),
- GNUNET_PQ_query_param_end
- };
- static struct Preparations preps[
- TALER_AUDITORDB_DELETABLESUPPRESSABLE_TABLES_MAX];
-
- struct Preparations *prep = &preps[table];
- const char *table_name
- = TALER_AUDITORDB_get_deletable_suppressable_table_name (
- table);
- char statement_name[256];
-
- if (NULL == table_name)
- return GNUNET_DB_STATUS_HARD_ERROR;
- GNUNET_snprintf (statement_name,
- sizeof (statement_name),
- "update_%s",
- table_name);
- if ( (pg != prep->pg) ||
- (prep->cnt < pg->prep_gen) )
- {
- char sql[256];
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare (statement_name,
- sql),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
-
- GNUNET_snprintf (sql,
- sizeof (sql),
- "UPDATE %s SET"
- " suppressed=$2"
- " WHERE row_id=$1",
- table_name);
- if (GNUNET_OK !=
- GNUNET_PQ_prepare_statements (pg->conn,
- ps))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- prep->pg = pg;
- prep->cnt = pg->prep_gen;
- }
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- statement_name,
- params);
-}
diff --git a/src/auditordb/update_purse_info.c b/src/auditordb/update_purse_info.c
@@ -37,11 +37,11 @@ TALER_AUDITORDB_update_purse_info (struct TALER_AUDITORDB_PostgresContext *pg,
};
PREPARE (pg,
- "auditor_purses_update",
+ "update_purse_info",
"UPDATE auditor_purses"
" SET balance=$2"
" WHERE purse_pub=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_purses_update",
+ "update_purse_info",
params);
}
diff --git a/src/auditordb/update_reserve_info.c b/src/auditordb/update_reserve_info.c
@@ -51,7 +51,7 @@ TALER_AUDITORDB_update_reserve_info (
};
PREPARE (pg,
- "auditor_update_reserve_info",
+ "update_reserve_info",
"UPDATE auditor_reserves SET"
" reserve_balance=$1"
",reserve_loss=$2"
@@ -63,6 +63,6 @@ TALER_AUDITORDB_update_reserve_info (
",expiration_date=$8"
" WHERE reserve_pub=$9");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_update_reserve_info",
+ "update_reserve_info",
params);
}
diff --git a/src/auditordb/update_to_suppressed.c b/src/auditordb/update_to_suppressed.c
@@ -0,0 +1,91 @@
+/*
+ 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/>
+ */
+#include "taler/taler_pq_lib.h"
+#include "pg_helper.h"
+#include "auditor-database/update_to_suppressed.h"
+
+struct Preparations
+{
+ /**
+ * Database reconnect counter.
+ */
+ unsigned long long cnt;
+
+ /**
+ * Which DB did we do prepare for.
+ */
+ struct TALER_AUDITORDB_PostgresContext *pg;
+
+};
+
+
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_update_to_suppressed (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ enum TALER_AUDITORDB_DeletableSuppressableTables table,
+ uint64_t row_id,
+ bool suppressed)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&row_id),
+ GNUNET_PQ_query_param_bool (suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ static struct Preparations preps[
+ TALER_AUDITORDB_DELETABLESUPPRESSABLE_TABLES_MAX];
+
+ struct Preparations *prep = &preps[table];
+ const char *table_name
+ = TALER_AUDITORDB_get_deletable_suppressable_table_name (
+ table);
+ char statement_name[256];
+
+ if (NULL == table_name)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ GNUNET_snprintf (statement_name,
+ sizeof (statement_name),
+ "update_%s",
+ table_name);
+ if ( (pg != prep->pg) ||
+ (prep->cnt < pg->prep_gen) )
+ {
+ char sql[256];
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ GNUNET_PQ_make_prepare (statement_name,
+ sql),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
+
+ GNUNET_snprintf (sql,
+ sizeof (sql),
+ "UPDATE %s SET"
+ " suppressed=$2"
+ " WHERE row_id=$1",
+ table_name);
+ if (GNUNET_OK !=
+ GNUNET_PQ_prepare_statements (pg->conn,
+ ps))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ prep->pg = pg;
+ prep->cnt = pg->prep_gen;
+ }
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ statement_name,
+ params);
+}
diff --git a/src/auditordb/update_wire_fee_summary.c b/src/auditordb/update_wire_fee_summary.c
@@ -36,10 +36,10 @@ TALER_AUDITORDB_update_wire_fee_summary (struct
};
PREPARE (pg,
- "auditor_wire_fee_balance_update",
+ "update_wire_fee_summary",
"UPDATE auditor_wire_fee_balance SET"
" wire_fee_balance=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_wire_fee_balance_update",
+ "update_wire_fee_summary",
params);
}
diff --git a/src/benchmark/taler-aggregator-benchmark.c b/src/benchmark/taler-aggregator-benchmark.c
@@ -38,7 +38,7 @@
#include "exchange-database/do_deposit.h"
#include "exchange-database/insert_wire_fee.h"
#include "exchange-database/insert_denomination_info.h"
-#include "exchange-database/ensure_coin_known.h"
+#include "exchange-database/do_insert_known_coin.h"
/**
* Exit code.
@@ -301,11 +301,11 @@ add_deposit (const struct Merchant *m)
sizeof (d.coin.h_age_commitment));
if (0 >=
- TALER_EXCHANGEDB_ensure_coin_known (pg,
- &d.coin,
- &known_coin_id,
- &dph,
- &agh))
+ TALER_EXCHANGEDB_do_insert_known_coin (pg,
+ &d.coin,
+ &known_coin_id,
+ &dph,
+ &agh))
{
GNUNET_break (0);
global_ret = EXIT_FAILURE;
@@ -605,12 +605,12 @@ run (void *cls,
0,
sizeof (master_sig));
if (0 >
- TALER_TALER_EXCHANGEDB_insert_wire_fee (pg,
- "x-taler-bank",
- ws,
- we,
- &fees,
- &master_sig))
+ TALER_EXCHANGEDB_insert_wire_fee (pg,
+ "x-taler-bank",
+ ws,
+ we,
+ &fees,
+ &master_sig))
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
@@ -34,25 +34,25 @@
#include "exchange-database/preflight.h"
#include "exchange-database/commit.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/drain_kyc_alert.h"
+#include "exchange-database/do_drain_kyc_alert.h"
#include "exchange-database/get_ready_deposit.h"
#include "exchange-database/start_deferred_wire_out.h"
-#include "exchange-database/aggregate.h"
-#include "exchange-database/create_aggregation_transient.h"
-#include "exchange-database/select_aggregation_transient.h"
-#include "exchange-database/find_aggregation_transient.h"
+#include "exchange-database/do_aggregate.h"
+#include "exchange-database/insert_aggregation_transient.h"
+#include "exchange-database/get_aggregation_transient.h"
+#include "exchange-database/get_aggregation_transient_by_normalized_payto.h"
#include "exchange-database/get_wire_fee.h"
-#include "exchange-database/trigger_kyc_rule_for_account.h"
-#include "exchange-database/select_aggregation_amounts_for_kyc_check.h"
-#include "exchange-database/wire_prepare_data_insert.h"
-#include "exchange-database/store_wire_transfer_out.h"
+#include "exchange-database/do_trigger_kyc_rule_for_account.h"
+#include "exchange-database/iterate_aggregation_amounts_for_kyc_check.h"
+#include "exchange-database/insert_prewire.h"
+#include "exchange-database/insert_wire_out.h"
#include "exchange-database/delete_aggregation_transient.h"
#include "exchange-database/update_aggregation_transient.h"
#include "exchange-database/event_notify.h"
-#include "exchange-database/wire_prepare_data_insert.h"
+#include "exchange-database/insert_prewire.h"
struct AggregationUnit;
#define TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE struct AggregationUnit
-#include "exchange-database/update_rules.h"
+#include "exchange-database/begin_rule_update.h"
/**
* How often do we retry after serialization failures?
@@ -297,7 +297,7 @@ cleanup_au (struct AggregationUnit *au)
if (NULL != au->ru)
{
GNUNET_break (0);
- TALER_EXCHANGEDB_update_rules_cancel (au->ru);
+ TALER_EXCHANGEDB_begin_rule_update_cancel (au->ru);
au->ru = NULL;
}
GNUNET_free (au->payto_uri.full_payto);
@@ -573,7 +573,7 @@ return_relevant_amounts (void *cls,
&au->total_amount,
GNUNET_TIME_absolute_get ()))
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_EXCHANGEDB_select_aggregation_amounts_for_kyc_check (
+ qs = TALER_EXCHANGEDB_iterate_aggregation_amounts_for_kyc_check (
pg,
&au->h_normalized_payto,
limit,
@@ -688,7 +688,7 @@ commit_aggregation (struct AggregationUnit *au)
if (au->legi_check)
{
au->legi_check = false;
- au->ru = TALER_EXCHANGEDB_update_rules (
+ au->ru = TALER_EXCHANGEDB_begin_rule_update (
pg,
&attribute_key,
&au->h_normalized_payto,
@@ -740,10 +740,10 @@ trigger_wire_transfer (struct AggregationUnit *au)
"Storing %u bytes of wire prepare data\n",
(unsigned int) buf_size);
/* Commit our intention to execute the wire transfer! */
- qs = TALER_EXCHANGEDB_wire_prepare_data_insert (pg,
- au->wa->method,
- buf,
- buf_size);
+ qs = TALER_EXCHANGEDB_insert_prewire (pg,
+ au->wa->method,
+ buf,
+ buf_size);
GNUNET_log (qs >= 0
? GNUNET_ERROR_TYPE_DEBUG
: GNUNET_ERROR_TYPE_WARNING,
@@ -754,7 +754,7 @@ trigger_wire_transfer (struct AggregationUnit *au)
/* Commit the WTID data to 'wire_out' */
if (qs >= 0)
{
- qs = TALER_EXCHANGEDB_store_wire_transfer_out (
+ qs = TALER_EXCHANGEDB_insert_wire_out (
pg,
au->execution_time,
&au->wtid,
@@ -824,14 +824,14 @@ evaluate_rules (
TALER_KYCLOGIC_rules_free (lrs);
}
/* Rollback just in case, should have already been done
- before by the TALER_EXCHANGEDB_update_rules() logic. */
+ before by the TALER_EXCHANGEDB_begin_rule_update() logic. */
TALER_EXCHANGEDB_rollback (pg);
if ( (TALER_EC_GENERIC_DB_SOFT_FAILURE == rur->ec) &&
(au->retries++ < MAX_RETRIES) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Serialization failure, trying again!\n");
- au->ru = TALER_EXCHANGEDB_update_rules (
+ au->ru = TALER_EXCHANGEDB_begin_rule_update (
pg,
&attribute_key,
&au->h_normalized_payto,
@@ -887,7 +887,7 @@ evaluate_rules (
json_t *jrule;
jrule = TALER_KYCLOGIC_rule_to_measures (requirement);
- qs = TALER_EXCHANGEDB_trigger_kyc_rule_for_account (
+ qs = TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (
pg,
au->payto_uri,
&au->h_normalized_payto,
@@ -974,7 +974,7 @@ commit_to_transient (struct AggregationUnit *au)
au->requirement_row,
&au->total_amount);
else
- qs = TALER_EXCHANGEDB_create_aggregation_transient (pg,
+ qs = TALER_EXCHANGEDB_insert_aggregation_transient (pg,
&au->h_full_payto,
au->wa->section_name,
&au->merchant_pub,
@@ -1090,12 +1090,12 @@ do_aggregate (struct AggregationUnit *au)
"Found ready deposit for %s, aggregating by target %s\n",
TALER_B2S (&au->merchant_pub),
au->payto_uri.full_payto);
- qs = TALER_EXCHANGEDB_select_aggregation_transient (pg,
- &au->h_full_payto,
- &au->merchant_pub,
- au->wa->section_name,
- &au->wtid,
- &au->trans);
+ qs = TALER_EXCHANGEDB_get_aggregation_transient (pg,
+ &au->h_full_payto,
+ &au->merchant_pub,
+ au->wa->section_name,
+ &au->wtid,
+ &au->trans);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -1124,11 +1124,11 @@ do_aggregate (struct AggregationUnit *au)
TALER_B2S (&au->wtid));
break;
}
- qs = TALER_EXCHANGEDB_aggregate (pg,
- &au->h_full_payto,
- &au->merchant_pub,
- &au->wtid,
- &au->total_amount);
+ qs = TALER_EXCHANGEDB_do_aggregate (pg,
+ &au->h_full_payto,
+ &au->merchant_pub,
+ &au->wtid,
+ &au->total_amount);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1191,7 +1191,7 @@ run_aggregation (void *cls)
au->execution_time = GNUNET_TIME_timestamp_get ();
au->shard = s;
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_deferred_wire_out (pg))
+ TALER_EXCHANGEDB_start_deferred_wire_out (pg))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start database transaction!\n");
@@ -1362,9 +1362,9 @@ drain_kyc_alerts (void *cls)
}
while (1)
{
- qs = TALER_EXCHANGEDB_drain_kyc_alert (pg,
- 1,
- &au->h_normalized_payto);
+ qs = TALER_EXCHANGEDB_do_drain_kyc_alert (pg,
+ 1,
+ &au->h_normalized_payto);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Found %d KYC alerts\n",
(int) qs);
@@ -1396,7 +1396,7 @@ drain_kyc_alerts (void *cls)
/* handled below */
break;
}
- qs = TALER_EXCHANGEDB_find_aggregation_transient (
+ qs = TALER_EXCHANGEDB_get_aggregation_transient_by_normalized_payto (
pg,
&au->h_normalized_payto,
&au->payto_uri,
diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c
@@ -32,10 +32,10 @@
#include "exchange-database/rollback.h"
#include "exchange-database/get_wire_fee.h"
#include "exchange-database/insert_reserve_closed.h"
-#include "exchange-database/get_unfinished_close_requests.h"
-#include "exchange-database/get_expired_reserves.h"
-#include "exchange-database/wire_prepare_data_insert.h"
-#include "exchange-database/wire_prepare_data_insert.h"
+#include "exchange-database/iterate_unfinished_close_requests.h"
+#include "exchange-database/iterate_expired_reserves.h"
+#include "exchange-database/insert_prewire.h"
+#include "exchange-database/insert_prewire.h"
/**
@@ -374,10 +374,10 @@ expired_reserve_cb (void *cls,
&buf,
&buf_size);
/* Commit our intention to execute the wire transfer! */
- qs = TALER_EXCHANGEDB_wire_prepare_data_insert (pg,
- wa->method,
- buf,
- buf_size);
+ qs = TALER_EXCHANGEDB_insert_prewire (pg,
+ wa->method,
+ buf,
+ buf_size);
GNUNET_free (buf);
switch (qs)
{
@@ -440,13 +440,13 @@ run_reserve_closures (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for reserves to close by date %s\n",
GNUNET_TIME_timestamp2s (now));
- qs = TALER_EXCHANGEDB_get_unfinished_close_requests (pg,
- &expired_reserve_cb,
- NULL);
+ qs = TALER_EXCHANGEDB_iterate_unfinished_close_requests (pg,
+ &expired_reserve_cb,
+ NULL);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
{
/* Try expired reserves as well */
- qs = TALER_EXCHANGEDB_get_expired_reserves (
+ qs = TALER_EXCHANGEDB_iterate_expired_reserves (
pg,
now,
&expired_reserve_cb,
diff --git a/src/exchange/taler-exchange-drain.c b/src/exchange/taler-exchange-drain.c
@@ -30,10 +30,10 @@
#include "exchange-database/preflight.h"
#include "exchange-database/commit.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/profit_drains_get_pending.h"
-#include "exchange-database/wire_prepare_data_insert.h"
-#include "exchange-database/profit_drains_set_finished.h"
-#include "exchange-database/wire_prepare_data_insert.h"
+#include "exchange-database/get_pending_profit_drain.h"
+#include "exchange-database/insert_prewire.h"
+#include "exchange-database/update_to_profit_drain_finished.h"
+#include "exchange-database/insert_prewire.h"
/**
* The exchange's configuration.
@@ -211,14 +211,14 @@ run_drain (void *cls)
GNUNET_SCHEDULER_shutdown ();
return;
}
- qs = TALER_EXCHANGEDB_profit_drains_get_pending (pg,
- &serial,
- &wtid,
- &account_section,
- &payto_uri,
- &request_timestamp,
- &amount,
- &master_sig);
+ qs = TALER_EXCHANGEDB_get_pending_profit_drain (pg,
+ &serial,
+ &wtid,
+ &account_section,
+ &payto_uri,
+ &request_timestamp,
+ &amount,
+ &master_sig);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -312,10 +312,10 @@ run_drain (void *cls)
&buf,
&buf_size);
method = TALER_payto_get_method (payto_uri.full_payto);
- qs = TALER_EXCHANGEDB_wire_prepare_data_insert (pg,
- method,
- buf,
- buf_size);
+ qs = TALER_EXCHANGEDB_insert_prewire (pg,
+ method,
+ buf,
+ buf_size);
GNUNET_free (method);
GNUNET_free (buf);
}
@@ -346,8 +346,8 @@ run_drain (void *cls)
/* continued below */
break;
}
- qs = TALER_EXCHANGEDB_profit_drains_set_finished (pg,
- serial);
+ qs = TALER_EXCHANGEDB_update_to_profit_drain_finished (pg,
+ serial);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-expire.c b/src/exchange/taler-exchange-expire.c
@@ -33,7 +33,7 @@
#include "exchange-database/complete_shard.h"
#include "exchange-database/abort_shard.h"
#include "exchange-database/begin_shard.h"
-#include "exchange-database/expire_purse.h"
+#include "exchange-database/do_expire_purse.h"
#include "exchange-database/start.h"
@@ -288,9 +288,9 @@ run_expire (void *cls)
GNUNET_SCHEDULER_shutdown ();
return;
}
- qs = TALER_EXCHANGEDB_expire_purse (pg,
- s->shard_start,
- s->shard_end);
+ qs = TALER_EXCHANGEDB_do_expire_purse (pg,
+ s->shard_start,
+ s->shard_end);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
@@ -81,7 +81,7 @@
#include "taler-exchange-httpd_get-TERMS.h"
#include "taler-exchange-httpd_get-transfers-WTID.h"
#include <gnunet/gnunet_mhd_compat.h>
-#include "exchange-database/test_aml_officer.h"
+#include "exchange-database/get_exists_aml_officer.h"
#include "exchange-database/preflight.h"
/**
@@ -487,9 +487,9 @@ handle_post_aml (struct TEH_RequestContext *rc,
enum GNUNET_DB_QueryStatus qs;
bool ro;
- qs = TALER_EXCHANGEDB_test_aml_officer (TEH_pg,
- &officer_pub,
- &ro);
+ qs = TALER_EXCHANGEDB_get_exists_aml_officer (TEH_pg,
+ &officer_pub,
+ &ro);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -689,9 +689,9 @@ handle_get_aml (struct TEH_RequestContext *rc,
enum GNUNET_DB_QueryStatus qs;
bool ro;
- qs = TALER_EXCHANGEDB_test_aml_officer (TEH_pg,
- &officer_pub,
- &ro);
+ qs = TALER_EXCHANGEDB_get_exists_aml_officer (TEH_pg,
+ &officer_pub,
+ &ro);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.c b/src/exchange/taler-exchange-httpd_common_kyc.c
@@ -19,7 +19,7 @@
* @author Christian Grothoff
*/
#include "taler-exchange-httpd.h"
-#include "exchange-database/trigger_kyc_rule_for_account.h"
+#include "exchange-database/do_trigger_kyc_rule_for_account.h"
#include "taler-exchange-httpd_common_kyc.h"
#include "taler/taler_attributes.h"
#include "taler/taler_error_codes.h"
@@ -30,18 +30,18 @@
#include "exchange-database/get_kyc_rules.h"
#include "exchange-database/insert_aml_decision.h"
#include "exchange-database/insert_kyc_failure.h"
-#include "exchange-database/insert_kyc_requirement_process.h"
-#include "exchange-database/lookup_active_legitimization.h"
-#include "exchange-database/persist_kyc_attributes.h"
+#include "exchange-database/insert_legitimization_process.h"
+#include "exchange-database/get_active_legitimization.h"
+#include "exchange-database/do_insert_kyc_attributes.h"
#include "exchange-database/preflight.h"
#include "exchange-database/rollback.h"
#include "exchange-database/start.h"
struct TEH_LegitimizationCheckHandle;
#define TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE \
struct TEH_LegitimizationCheckHandle
-#include "exchange-database/update_rules.h"
+#include "exchange-database/begin_rule_update.h"
#include "exchange-database/account_history.h"
-#include "exchange-database/persist_aml_program_result.h"
+#include "exchange-database/do_persist_aml_program_result.h"
/**
@@ -206,7 +206,7 @@ kyc_aml_finished (
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"AML program finished with status %d\n",
(int) apr->status);
- qs = TALER_EXCHANGEDB_persist_aml_program_result (
+ qs = TALER_EXCHANGEDB_do_persist_aml_program_result (
TEH_pg,
kat->process_row,
&kat->account_id,
@@ -371,7 +371,7 @@ TEH_kyc_store_attributes (
&ea,
&eas);
}
- qs = TALER_EXCHANGEDB_persist_kyc_attributes (
+ qs = TALER_EXCHANGEDB_do_insert_kyc_attributes (
TEH_pg,
process_row,
account_id,
@@ -425,7 +425,7 @@ TEH_kyc_run_measure_for_attributes (
kat->is_wallet = is_wallet;
kat->cb = cb;
kat->cb_cls = cb_cls;
- qs = TALER_EXCHANGEDB_lookup_active_legitimization (
+ qs = TALER_EXCHANGEDB_get_active_legitimization (
TEH_pg,
process_row,
&kat->measure_index,
@@ -537,7 +537,7 @@ TEH_kyc_run_measure_directly (
GNUNET_assert (NULL != kat->jmeasures);
- qs = TALER_EXCHANGEDB_trigger_kyc_rule_for_account (
+ qs = TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (
TEH_pg,
null_account,
account_id,
@@ -575,7 +575,7 @@ TEH_kyc_run_measure_directly (
return kat;
}
- qs = TALER_EXCHANGEDB_insert_kyc_requirement_process (
+ qs = TALER_EXCHANGEDB_insert_legitimization_process (
TEH_pg,
account_id,
0, /* measure index */
@@ -884,7 +884,7 @@ TEH_kyc_fallback (
};
jmeasures = TALER_KYCLOGIC_check_to_jmeasures (&kcc);
- qs = TALER_EXCHANGEDB_trigger_kyc_rule_for_account (
+ qs = TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (
TEH_pg,
null_account, /* account_id is already in wire targets */
account_id,
@@ -1503,7 +1503,7 @@ current_rules_cb (
json_t *jmeasures;
jmeasures = TALER_KYCLOGIC_rule_to_measures (requirement);
- qs = TALER_EXCHANGEDB_trigger_kyc_rule_for_account (
+ qs = TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (
TEH_pg,
lch->payto_uri,
&lch->h_payto,
@@ -1607,7 +1607,7 @@ legitimization_check_run (
bool no_account_pub;
bool no_reserve_pub;
- qs = TALER_EXCHANGEDB_get_kyc_rules (
+ qs = TALER_EXCHANGEDB_get_kyc_rules_with_account (
TEH_pg,
&lch->h_payto,
lch->have_merchant_pub
@@ -1626,7 +1626,7 @@ legitimization_check_run (
TALER_EXCHANGEDB_rollback (TEH_pg);
legi_fail (lch,
TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_kyc_rules");
+ "get_kyc_rules_with_account");
GNUNET_async_scope_restore (&old_scope);
return;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
@@ -1710,12 +1710,12 @@ legitimization_check_run (
fetch the rules for the account. */
TALER_EXCHANGEDB_rollback (TEH_pg);
TALER_KYCLOGIC_rules_free (lrs);
- lch->ru = TALER_EXCHANGEDB_update_rules (TEH_pg,
- &TEH_attribute_key,
- &lch->h_payto,
- lch->is_wallet,
- ¤t_rules_cb,
- lch);
+ lch->ru = TALER_EXCHANGEDB_begin_rule_update (TEH_pg,
+ &TEH_attribute_key,
+ &lch->h_payto,
+ lch->is_wallet,
+ ¤t_rules_cb,
+ lch);
}
else
{
diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c
@@ -30,7 +30,7 @@
#include "taler-exchange-httpd_responses.h"
#include "exchange-database/start.h"
#include "exchange-database/commit.h"
-#include "exchange-database/ensure_coin_known.h"
+#include "exchange-database/do_insert_known_coin.h"
#include "exchange-database/get_signature_for_known_coin.h"
#include "exchange-database/preflight.h"
#include "exchange-database/rollback.h"
@@ -47,11 +47,11 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
struct TALER_AgeCommitmentHashP h_age_commitment = {{{0}}};
/* make sure coin is 'known' in database */
- cks = TALER_EXCHANGEDB_ensure_coin_known (TEH_pg,
- coin,
- known_coin_id,
- &h_denom_pub,
- &h_age_commitment);
+ cks = TALER_EXCHANGEDB_do_insert_known_coin (TEH_pg,
+ coin,
+ known_coin_id,
+ &h_denom_pub,
+ &h_age_commitment);
switch (cks)
{
case TALER_EXCHANGEDB_CKS_ADDED:
diff --git a/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-accounts.c b/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-accounts.c
@@ -28,7 +28,7 @@
#include "taler-exchange-httpd.h"
struct ResponseContext;
#define TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE struct ResponseContext
-#include "exchange-database/select_kyc_accounts.h"
+#include "exchange-database/iterate_kyc_accounts.h"
#include "taler-exchange-httpd_get-aml-OFFICER_PUB-accounts.h"
@@ -407,7 +407,7 @@ TEH_handler_aml_accounts_get (
limit = MAX_RECORDS;
if (limit < -MAX_RECORDS)
limit = -MAX_RECORDS;
- qs = TALER_EXCHANGEDB_select_kyc_accounts (
+ qs = TALER_EXCHANGEDB_iterate_kyc_accounts (
TEH_pg,
investigation_filter,
open_filter,
diff --git a/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-attributes-H_NORMALIZED_PAYTO.c b/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-attributes-H_NORMALIZED_PAYTO.c
@@ -30,12 +30,12 @@
struct ResponseContext;
#define TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE struct ResponseContext
#define TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE struct ResponseContext
-#include "exchange-database/select_aml_attributes.h"
+#include "exchange-database/iterate_aml_attributes.h"
#include \
"taler-exchange-httpd_get-aml-OFFICER_PUB-attributes-H_NORMALIZED_PAYTO.h"
#include "taler-exchange-httpd_get-metrics.h"
-#include "exchange-database/lookup_aml_file_number.h"
-#include "exchange-database/lookup_aml_history.h"
+#include "exchange-database/get_aml_file_number.h"
+#include "exchange-database/iterate_aml_history.h"
/**
* Maximum number of records we return in one request.
@@ -614,10 +614,10 @@ TEH_handler_aml_attributes_get (
{
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_lookup_aml_file_number (TEH_pg,
- &h_payto,
- &file_number,
- &rctx->is_wallet);
+ qs = TALER_EXCHANGEDB_get_aml_file_number (TEH_pg,
+ &h_payto,
+ &file_number,
+ &rctx->is_wallet);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -673,12 +673,12 @@ TEH_handler_aml_attributes_get (
json_integer (file_number)));
/* Lookup latest AML decision & account rules & properties
to build the cover page */
- qs = TALER_EXCHANGEDB_lookup_aml_history (TEH_pg,
- &h_payto,
- UINT64_MAX, /* offset */
- -1, /* latest decision only */
- &build_cover_page,
- rctx);
+ qs = TALER_EXCHANGEDB_iterate_aml_history (TEH_pg,
+ &h_payto,
+ UINT64_MAX, /* offset */
+ -1, /* latest decision only */
+ &build_cover_page,
+ rctx);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -725,7 +725,7 @@ TEH_handler_aml_attributes_get (
limit = MAX_RECORDS;
if (limit < -MAX_RECORDS)
limit = -MAX_RECORDS;
- qs = TALER_EXCHANGEDB_select_aml_attributes (
+ qs = TALER_EXCHANGEDB_iterate_aml_attributes (
TEH_pg,
&h_payto,
offset,
diff --git a/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-decisions.c b/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-decisions.c
@@ -26,7 +26,7 @@
#include "taler/taler_mhd_lib.h"
#include "taler-exchange-httpd.h"
#define TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE json_t
-#include "exchange-database/select_aml_decisions.h"
+#include "exchange-database/iterate_aml_decisions.h"
#include "taler-exchange-httpd_post-aml-OFFICER_PUB-decision.h"
#include "taler-exchange-httpd_get-metrics.h"
@@ -157,7 +157,7 @@ TEH_handler_aml_decisions_get (
limit = MAX_RECORDS;
if (limit < -MAX_RECORDS)
limit = -MAX_RECORDS;
- qs = TALER_EXCHANGEDB_select_aml_decisions (
+ qs = TALER_EXCHANGEDB_iterate_aml_decisions (
TEH_pg,
have_payto
? &h_payto
diff --git a/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-kyc-statistics-NAMES.c b/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-kyc-statistics-NAMES.c
@@ -26,7 +26,7 @@
#include "taler/taler_mhd_lib.h"
#include "taler-exchange-httpd.h"
#define TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE json_t
-#include "exchange-database/select_aml_statistics.h"
+#include "exchange-database/iterate_aml_statistics.h"
#include "taler-exchange-httpd_get-aml-OFFICER_PUB-kyc-statistics-NAMES.h"
#include "taler-exchange-httpd_get-metrics.h"
@@ -129,7 +129,7 @@ TEH_handler_aml_kyc_statistics_get (
GNUNET_assert (num_names < max_names);
names[num_names++] = tok;
}
- qs = TALER_EXCHANGEDB_select_aml_statistics (
+ qs = TALER_EXCHANGEDB_iterate_aml_statistics (
TEH_pg,
num_names,
names,
diff --git a/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-legitimizations.c b/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-legitimizations.c
@@ -26,7 +26,7 @@
#include "taler/taler_mhd_lib.h"
#include "taler-exchange-httpd.h"
#define TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE json_t
-#include "exchange-database/select_aml_measures.h"
+#include "exchange-database/iterate_aml_measures.h"
#include "taler-exchange-httpd_get-aml-OFFICER_PUB-legitimizations.h"
#include "taler-exchange-httpd_get-metrics.h"
@@ -132,7 +132,7 @@ TEH_handler_aml_legitimization_measures_get (
limit = MAX_MEASURES;
if (limit < -MAX_MEASURES)
limit = -MAX_MEASURES;
- qs = TALER_EXCHANGEDB_select_aml_measures (
+ qs = TALER_EXCHANGEDB_iterate_aml_measures (
TEH_pg,
have_payto
? &h_payto
diff --git a/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-transfers.c b/src/exchange/taler-exchange-httpd_get-aml-OFFICER_PUB-transfers.c
@@ -30,12 +30,12 @@
TALER_EXCHANGEDB_AmlTransferCallback typedef lives. */
#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE json_t
#include "taler-exchange-httpd.h"
-#include "exchange-database/select_exchange_kycauth_transfers.h"
+#include "exchange-database/iterate_exchange_kycauth_transfers.h"
#include "taler-exchange-httpd_get-aml-OFFICER_PUB-transfers.h"
#include "taler-exchange-httpd_get-metrics.h"
-#include "exchange-database/select_exchange_credit_transfers.h"
-#include "exchange-database/select_exchange_debit_transfers.h"
-#include "exchange-database/select_wallet_merges.h"
+#include "exchange-database/iterate_exchange_credit_transfers.h"
+#include "exchange-database/iterate_exchange_debit_transfers.h"
+#include "exchange-database/iterate_wallet_merges.h"
enum TransferType
@@ -158,7 +158,7 @@ aml_transfer_get (
switch (tt)
{
case TT_DEBIT:
- qs = TALER_EXCHANGEDB_select_exchange_debit_transfers (
+ qs = TALER_EXCHANGEDB_iterate_exchange_debit_transfers (
TEH_pg,
&threshold,
offset,
@@ -169,7 +169,7 @@ aml_transfer_get (
query = "select_exchange_debit_transfers";
break;
case TT_CREDIT:
- qs = TALER_EXCHANGEDB_select_exchange_credit_transfers (
+ qs = TALER_EXCHANGEDB_iterate_exchange_credit_transfers (
TEH_pg,
&threshold,
offset,
@@ -180,7 +180,7 @@ aml_transfer_get (
query = "select_exchange_credit_transfers";
break;
case TT_KYCAUTH:
- qs = TALER_EXCHANGEDB_select_exchange_kycauth_transfers (
+ qs = TALER_EXCHANGEDB_iterate_exchange_kycauth_transfers (
TEH_pg,
&threshold,
offset,
@@ -191,7 +191,7 @@ aml_transfer_get (
query = "select_exchange_kycauth_transfers";
break;
case TT_WALLET:
- qs = TALER_EXCHANGEDB_select_wallet_merges (
+ qs = TALER_EXCHANGEDB_iterate_wallet_merges (
TEH_pg,
&threshold,
offset,
diff --git a/src/exchange/taler-exchange-httpd_get-contracts-CONTRACT_PUB.c b/src/exchange/taler-exchange-httpd_get-contracts-CONTRACT_PUB.c
@@ -25,7 +25,7 @@
#include "taler-exchange-httpd_get-contracts-CONTRACT_PUB.h"
#include "taler-exchange-httpd_mhd.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/select_contract.h"
+#include "exchange-database/get_contract.h"
enum MHD_Result
@@ -53,12 +53,12 @@ TEH_handler_contracts_get (struct TEH_RequestContext *rc,
args[0]);
}
- qs = TALER_EXCHANGEDB_select_contract (TEH_pg,
- &contract_pub,
- &purse_pub,
- &econtract_sig,
- &econtract_size,
- &econtract);
+ qs = TALER_EXCHANGEDB_get_contract (TEH_pg,
+ &contract_pub,
+ &purse_pub,
+ &econtract_sig,
+ &econtract_size,
+ &econtract);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-httpd_get-deposits.c b/src/exchange/taler-exchange-httpd_get-deposits.c
@@ -31,7 +31,7 @@
#include "taler-exchange-httpd_get-keys.h"
#include "taler-exchange-httpd_get-deposits.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/lookup_transfer_by_deposit.h"
+#include "exchange-database/get_transfer_by_deposit.h"
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
@@ -279,7 +279,7 @@ handle_track_transaction_request (
bool pending;
struct TALER_Amount fee;
- qs = TALER_EXCHANGEDB_lookup_transfer_by_deposit (
+ qs = TALER_EXCHANGEDB_get_transfer_by_deposit (
TEH_pg,
&ctx->h_contract_terms,
&ctx->h_wire,
@@ -392,8 +392,8 @@ dwc_cleaner (struct TEH_RequestContext *rc)
GNUNET_assert (GNUNET_YES != ctx->suspended);
if (NULL != ctx->eh)
{
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- ctx->eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ ctx->eh);
ctx->eh = NULL;
}
GNUNET_free (ctx);
diff --git a/src/exchange/taler-exchange-httpd_get-keys.c b/src/exchange/taler-exchange-httpd_get-keys.c
@@ -44,9 +44,9 @@ struct AddContext;
#define TALER_EXCHANGEDB_AUDITOR_DENOMINATIONS_RESULT_CLOSURE struct \
TEH_KeyStateHandle
#define TALER_EXCHANGEDB_DENOMINATIONS_RESULT_CLOSURE struct TEH_KeyStateHandle
-#include "exchange-database/get_global_fees.h"
-#include "exchange-database/get_wire_accounts.h"
-#include "exchange-database/get_wire_fees.h"
+#include "exchange-database/iterate_global_fees.h"
+#include "exchange-database/iterate_wire_accounts.h"
+#include "exchange-database/iterate_wire_fees.h"
#include "exchange-database/iterate_active_auditors.h"
#include "exchange-database/iterate_active_signkeys.h"
#include "exchange-database/iterate_auditor_denominations.h"
@@ -681,9 +681,9 @@ build_wire_state (void)
wsh->wire_generation = wg;
wire_accounts_array = json_array ();
GNUNET_assert (NULL != wire_accounts_array);
- qs = TALER_EXCHANGEDB_get_wire_accounts (TEH_pg,
- &add_wire_account,
- wire_accounts_array);
+ qs = TALER_EXCHANGEDB_iterate_wire_accounts (TEH_pg,
+ &add_wire_account,
+ wire_accounts_array);
if (0 > qs)
{
GNUNET_break (0);
@@ -732,10 +732,10 @@ build_wire_state (void)
};
GNUNET_assert (NULL != ac.a);
- qs = TALER_TALER_EXCHANGEDB_get_wire_fees (TEH_pg,
- wire_method,
- &add_wire_fee,
- &ac);
+ qs = TALER_EXCHANGEDB_iterate_wire_fees (TEH_pg,
+ wire_method,
+ &add_wire_fee,
+ &ac);
if (0 > qs)
{
GNUNET_break (0);
@@ -1246,8 +1246,8 @@ TEH_keys_finished ()
}
if (NULL != wire_eh)
{
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- wire_eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ wire_eh);
wire_eh = NULL;
}
if (NULL != keys_tt)
@@ -1259,8 +1259,8 @@ TEH_keys_finished ()
destroy_key_state (key_state);
if (NULL != keys_eh)
{
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- keys_eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ keys_eh);
keys_eh = NULL;
}
TEH_SECMOD_destroy_key_helpers ();
@@ -2588,9 +2588,9 @@ build_key_state (bool management_only)
if (NULL != ksh->global_fees)
json_decref (ksh->global_fees);
ksh->global_fees = json_array ();
- qs = TALER_TALER_EXCHANGEDB_get_global_fees (TEH_pg,
- &global_fee_info_cb,
- ksh);
+ qs = TALER_EXCHANGEDB_iterate_global_fees (TEH_pg,
+ &global_fee_info_cb,
+ ksh);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Loading global fees from DB: %d\n",
qs);
diff --git a/src/exchange/taler-exchange-httpd_get-kyc-check-H_NORMALIZED_PAYTO.c b/src/exchange/taler-exchange-httpd_get-kyc-check-H_NORMALIZED_PAYTO.c
@@ -31,7 +31,7 @@
#include "taler-exchange-httpd_get-kyc-check-H_NORMALIZED_PAYTO.h"
#include "taler-exchange-httpd_post-kyc-wallet.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/lookup_kyc_requirement_by_row.h"
+#include "exchange-database/get_legitimization_requirement_by_row.h"
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
@@ -160,8 +160,8 @@ kyp_cleanup (struct TEH_RequestContext *rc)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Cancelling DB event listening (KYP cleanup)\n");
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- kyp->eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ kyp->eh);
kyp->eh = NULL;
}
GNUNET_free (kyp);
@@ -326,7 +326,7 @@ TEH_handler_kyc_check (
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Looking up KYC requirements for account %s\n",
TALER_B2S (&kyp->h_payto));
- qs = TALER_EXCHANGEDB_lookup_kyc_requirement_by_row (
+ qs = TALER_EXCHANGEDB_get_legitimization_requirement_by_row (
TEH_pg,
&kyp->h_payto,
&kyp->account_pub,
diff --git a/src/exchange/taler-exchange-httpd_get-kyc-info-ACCESS_TOKEN.c b/src/exchange/taler-exchange-httpd_get-kyc-info-ACCESS_TOKEN.c
@@ -39,11 +39,11 @@
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
#include "exchange-database/insert_active_legitimization_measure.h"
-#include "exchange-database/lookup_h_payto_by_access_token.h"
-#include "exchange-database/lookup_kyc_status_by_token.h"
+#include "exchange-database/get_h_payto_by_access_token.h"
+#include "exchange-database/get_kyc_status_by_token.h"
struct KycPoller;
#define TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE struct KycPoller
-#include "exchange-database/update_rules.h"
+#include "exchange-database/begin_rule_update.h"
/**
@@ -200,13 +200,13 @@ kyp_cleanup (struct TEH_RequestContext *rc)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Cancelling DB event listening\n");
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- kyp->eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ kyp->eh);
kyp->eh = NULL;
}
if (NULL != kyp->ru)
{
- TALER_EXCHANGEDB_update_rules_cancel (kyp->ru);
+ TALER_EXCHANGEDB_begin_rule_update_cancel (kyp->ru);
kyp->ru = NULL;
}
if (NULL != kyp->response)
@@ -526,7 +526,7 @@ current_rules_cb (
: "custom rules");
/* Check if there is an unfinished legitimization measure */
- qs = TALER_EXCHANGEDB_lookup_kyc_status_by_token (
+ qs = TALER_EXCHANGEDB_get_kyc_status_by_token (
TEH_pg,
&kyp->access_token,
&legitimization_measure_last_row,
@@ -751,7 +751,7 @@ TEH_handler_kyc_info (
/* Check access token */
kyp->is_wallet = GNUNET_SYSERR;
- qs = TALER_EXCHANGEDB_lookup_h_payto_by_access_token (
+ qs = TALER_EXCHANGEDB_get_h_payto_by_access_token (
TEH_pg,
&kyp->access_token,
&kyp->h_payto,
@@ -801,12 +801,12 @@ TEH_handler_kyc_info (
kyp->response);
}
- kyp->ru = TALER_EXCHANGEDB_update_rules (TEH_pg,
- &TEH_attribute_key,
- &kyp->h_payto,
- kyp->is_wallet,
- ¤t_rules_cb,
- kyp);
+ kyp->ru = TALER_EXCHANGEDB_begin_rule_update (TEH_pg,
+ &TEH_attribute_key,
+ &kyp->h_payto,
+ kyp->is_wallet,
+ ¤t_rules_cb,
+ kyp);
kyp->suspended = true;
GNUNET_CONTAINER_DLL_insert (kyp_head,
kyp_tail,
diff --git a/src/exchange/taler-exchange-httpd_get-kyc-proof-PROVIDER_NAME.c b/src/exchange/taler-exchange-httpd_get-kyc-proof-PROVIDER_NAME.c
@@ -29,7 +29,7 @@
#include "taler-exchange-httpd_common_kyc.h"
#include "taler-exchange-httpd_get-kyc-proof-PROVIDER_NAME.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/lookup_kyc_process_by_account.h"
+#include "exchange-database/get_legitimization_process_by_account.h"
/**
@@ -554,7 +554,7 @@ TEH_handler_kyc_proof (
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Looking for KYC process at %s\n",
kpc->provider_name);
- qs = TALER_EXCHANGEDB_lookup_kyc_process_by_account (
+ qs = TALER_EXCHANGEDB_get_legitimization_process_by_account (
TEH_pg,
kpc->provider_name,
&kpc->h_payto,
diff --git a/src/exchange/taler-exchange-httpd_get-purses-PURSE_PUB-merge.c b/src/exchange/taler-exchange-httpd_get-purses-PURSE_PUB-merge.c
@@ -27,7 +27,7 @@
#include "taler-exchange-httpd_get-purses-PURSE_PUB-merge.h"
#include "taler-exchange-httpd_mhd.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/select_purse.h"
+#include "exchange-database/get_purse.h"
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
@@ -157,14 +157,14 @@ gc_cleanup (struct TEH_RequestContext *rc)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Cancelling DB event listening\n");
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- gc->eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ gc->eh);
gc->eh = NULL;
}
if (NULL != gc->ehr)
{
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- gc->ehr);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ gc->ehr);
gc->ehr = NULL;
}
GNUNET_free (gc);
@@ -308,16 +308,16 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_TIME_Timestamp create_timestamp;
- qs = TALER_EXCHANGEDB_select_purse (TEH_pg,
- &gc->purse_pub,
- &create_timestamp,
- &gc->purse_expiration,
- &gc->amount,
- &gc->deposited,
- &gc->h_contract,
- &gc->merge_timestamp,
- &purse_deleted,
- &purse_refunded);
+ qs = TALER_EXCHANGEDB_get_purse (TEH_pg,
+ &gc->purse_pub,
+ &create_timestamp,
+ &gc->purse_expiration,
+ &gc->amount,
+ &gc->deposited,
+ &gc->h_contract,
+ &gc->merge_timestamp,
+ &purse_deleted,
+ &purse_refunded);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"select_purse %s returned %d (%s)\n",
args[0],
diff --git a/src/exchange/taler-exchange-httpd_get-reserves-RESERVE_PUB-attest.c b/src/exchange/taler-exchange-httpd_get-reserves-RESERVE_PUB-attest.c
@@ -28,7 +28,7 @@
#include "taler-exchange-httpd_responses.h"
struct ReserveAttestContext;
#define TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE struct ReserveAttestContext
-#include "exchange-database/select_kyc_attributes.h"
+#include "exchange-database/iterate_kyc_attributes.h"
/**
@@ -131,10 +131,10 @@ TEH_handler_get_reserves_attest (
rsc.attributes = json_array ();
GNUNET_assert (NULL != rsc.attributes);
- qs = TALER_EXCHANGEDB_select_kyc_attributes (TEH_pg,
- &rsc.h_payto,
- &kyc_process_cb,
- &rsc);
+ qs = TALER_EXCHANGEDB_iterate_kyc_attributes (TEH_pg,
+ &rsc.h_payto,
+ &kyc_process_cb,
+ &rsc);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-httpd_get-reserves-RESERVE_PUB.c b/src/exchange/taler-exchange-httpd_get-reserves-RESERVE_PUB.c
@@ -136,8 +136,8 @@ rp_cleanup (struct TEH_RequestContext *rc)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Cancelling DB event listening on cleanup (odd unless during shutdown)\n");
- TALER_TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
- rp->eh);
+ TALER_EXCHANGEDB_event_listen_cancel (TEH_pg,
+ rp->eh);
rp->eh = NULL;
}
GNUNET_CONTAINER_DLL_remove (rp_head,
diff --git a/src/exchange/taler-exchange-httpd_get-transfers-WTID.c b/src/exchange/taler-exchange-httpd_get-transfers-WTID.c
@@ -28,12 +28,12 @@
#include "taler/taler_json_lib.h"
#include "taler/taler_mhd_lib.h"
#define TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE struct TALER_Amount
-#include "exchange-database/select_refunds_by_coin.h"
+#include "exchange-database/iterate_refunds_by_coin.h"
#include "exchange-database/get_wire_fee.h"
struct WtidTransactionContext;
#define TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE \
struct WtidTransactionContext
-#include "exchange-database/lookup_wire_transfer.h"
+#include "exchange-database/iterate_wire_transfers.h"
/**
@@ -338,12 +338,12 @@ handle_deposit_data (
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (deposit_value->currency,
&total_refunds));
- qs = TALER_EXCHANGEDB_select_refunds_by_coin (TEH_pg,
- coin_pub,
- merchant_pub,
- h_contract_terms,
- &add_refunds,
- &total_refunds);
+ qs = TALER_EXCHANGEDB_iterate_refunds_by_coin (TEH_pg,
+ coin_pub,
+ merchant_pub,
+ h_contract_terms,
+ &add_refunds,
+ &total_refunds);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -519,10 +519,10 @@ get_transfer_deposits (void *cls,
free_ctx (ctx);
ctx->is_valid = GNUNET_NO;
ctx->qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_EXCHANGEDB_lookup_wire_transfer (TEH_pg,
- &ctx->wtid,
- &handle_deposit_data,
- ctx);
+ qs = TALER_EXCHANGEDB_iterate_wire_transfers (TEH_pg,
+ &ctx->wtid,
+ &handle_deposit_data,
+ ctx);
if (0 > qs)
{
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_kyc-webhook.c b/src/exchange/taler-exchange-httpd_kyc-webhook.c
@@ -29,7 +29,7 @@
#include "taler-exchange-httpd_common_kyc.h"
#include "taler-exchange-httpd_kyc-webhook.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/kyc_provider_account_lookup.h"
+#include "exchange-database/get_kyc_provider_account.h"
/**
@@ -396,7 +396,7 @@ handler_kyc_webhook_generic (
kwh->wh = kwh->plugin->webhook (
kwh->plugin->cls,
kwh->pd,
- TALER_EXCHANGEDB_kyc_provider_account_lookup,
+ TALER_EXCHANGEDB_get_kyc_provider_account,
TEH_pg,
method,
&args[1],
diff --git a/src/exchange/taler-exchange-httpd_post-auditors-AUDITOR_PUB-H_DENOM_PUB.c b/src/exchange/taler-exchange-httpd_post-auditors-AUDITOR_PUB-H_DENOM_PUB.c
@@ -27,9 +27,9 @@
#include "taler/taler_mhd_lib.h"
#include "taler-exchange-httpd_post-auditors-AUDITOR_PUB-H_DENOM_PUB.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/lookup_denomination_key.h"
+#include "exchange-database/get_denomination_meta.h"
#include "exchange-database/insert_auditor_denom_sig.h"
-#include "exchange-database/lookup_auditor_status.h"
+#include "exchange-database/get_auditor_status.h"
/**
@@ -81,7 +81,7 @@ add_auditor_denom_sig (void *cls,
char *auditor_url;
bool enabled;
- qs = TALER_EXCHANGEDB_lookup_denomination_key (
+ qs = TALER_EXCHANGEDB_get_denomination_meta (
TEH_pg,
awc->h_denom_pub,
&meta);
@@ -104,7 +104,7 @@ add_auditor_denom_sig (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
- qs = TALER_EXCHANGEDB_lookup_auditor_status (
+ qs = TALER_EXCHANGEDB_get_auditor_status (
TEH_pg,
awc->auditor_pub,
&auditor_url,
@@ -166,10 +166,10 @@ add_auditor_denom_sig (void *cls,
}
GNUNET_free (auditor_url);
- qs = TALER_TALER_EXCHANGEDB_insert_auditor_denom_sig (TEH_pg,
- awc->h_denom_pub,
- awc->auditor_pub,
- &awc->auditor_sig);
+ qs = TALER_EXCHANGEDB_insert_auditor_denom_sig (TEH_pg,
+ awc->h_denom_pub,
+ awc->auditor_pub,
+ &awc->auditor_sig);
if (qs < 0)
{
GNUNET_break (0);
diff --git a/src/exchange/taler-exchange-httpd_post-batch-deposit.c b/src/exchange/taler-exchange-httpd_post-batch-deposit.c
@@ -34,7 +34,7 @@
#include "taler-exchange-httpd_responses.h"
#include "exchangedb_lib.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/select_deposit_amounts_for_kyc_check.h"
+#include "exchange-database/iterate_deposit_amounts_for_kyc_check.h"
#include "exchange-database/do_check_deposit_idempotent.h"
#include "exchange-database/do_deposit.h"
#include "exchange-database/get_wire_hash_for_contract.h"
@@ -548,7 +548,7 @@ deposit_amount_cb (
GNUNET_break (GNUNET_SYSERR != ret);
if (GNUNET_OK != ret)
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_EXCHANGEDB_select_deposit_amounts_for_kyc_check (
+ qs = TALER_EXCHANGEDB_iterate_deposit_amounts_for_kyc_check (
TEH_pg,
&bdc->nph,
limit,
diff --git a/src/exchange/taler-exchange-httpd_post-kyc-start-ID.c b/src/exchange/taler-exchange-httpd_post-kyc-start-ID.c
@@ -29,10 +29,10 @@
#include "taler-exchange-httpd_get-keys.h"
#include "taler-exchange-httpd_post-kyc-start-ID.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/update_kyc_process_by_row.h"
-#include "exchange-database/get_pending_kyc_requirement_process.h"
-#include "exchange-database/insert_kyc_requirement_process.h"
-#include "exchange-database/lookup_pending_legitimization.h"
+#include "exchange-database/update_legitimization_process_by_row.h"
+#include "exchange-database/get_pending_legitimization_process.h"
+#include "exchange-database/insert_legitimization_process.h"
+#include "exchange-database/get_pending_legitimization.h"
/**
@@ -234,7 +234,7 @@ initiate_cb (
{
kyp->hint = GNUNET_strdup (error_msg_hint);
}
- qs = TALER_EXCHANGEDB_update_kyc_process_by_row (
+ qs = TALER_EXCHANGEDB_update_legitimization_process_by_row (
TEH_pg,
kyp->process_row,
kyp->provider_name,
@@ -328,7 +328,7 @@ TEH_handler_kyc_start (
"ID is malformed");
}
}
- qs = TALER_EXCHANGEDB_lookup_pending_legitimization (
+ qs = TALER_EXCHANGEDB_get_pending_legitimization (
TEH_pg,
kyp->legitimization_measure_serial_id,
&kyp->access_token,
@@ -446,7 +446,7 @@ TEH_handler_kyc_start (
/* FIXME-#9419: the next two DB interactions should be ONE
transaction */
/* Check if we already initiated this process */
- qs = TALER_EXCHANGEDB_get_pending_kyc_requirement_process (
+ qs = TALER_EXCHANGEDB_get_pending_legitimization_process (
TEH_pg,
&kyp->h_payto,
kyp->provider_name,
@@ -467,7 +467,7 @@ TEH_handler_kyc_start (
(in next call to this function) */
/* set up new requirement process */
- qs = TALER_EXCHANGEDB_insert_kyc_requirement_process (
+ qs = TALER_EXCHANGEDB_insert_legitimization_process (
TEH_pg,
&kyp->h_payto,
kyp->measure_index,
diff --git a/src/exchange/taler-exchange-httpd_post-kyc-upload-ID.c b/src/exchange/taler-exchange-httpd_post-kyc-upload-ID.c
@@ -21,9 +21,9 @@
#include "taler-exchange-httpd_common_kyc.h"
#include "taler-exchange-httpd_post-kyc-upload-ID.h"
#include "exchange-database/preflight.h"
-#include "exchange-database/insert_kyc_requirement_process.h"
-#include "exchange-database/lookup_completed_legitimization.h"
-#include "exchange-database/lookup_pending_legitimization.h"
+#include "exchange-database/insert_legitimization_process.h"
+#include "exchange-database/get_completed_legitimization.h"
+#include "exchange-database/get_pending_legitimization.h"
#define DEBUG 0
@@ -227,7 +227,7 @@ transact (void *cls,
char *form_name;
enum TALER_ErrorCode ec;
- qs = TALER_EXCHANGEDB_lookup_completed_legitimization (
+ qs = TALER_EXCHANGEDB_get_completed_legitimization (
TEH_pg,
uc->legitimization_measure_serial_id,
uc->measure_index,
@@ -254,7 +254,7 @@ transact (void *cls,
case GNUNET_DB_STATUS_SOFT_ERROR:
return qs;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- qs = TALER_EXCHANGEDB_lookup_pending_legitimization (
+ qs = TALER_EXCHANGEDB_get_pending_legitimization (
TEH_pg,
uc->legitimization_measure_serial_id,
&uc->access_token,
@@ -370,7 +370,7 @@ transact (void *cls,
json_decref (jmeasures);
/* Setup KYC process (which we will then immediately 'finish') */
- qs = TALER_EXCHANGEDB_insert_kyc_requirement_process (
+ qs = TALER_EXCHANGEDB_insert_legitimization_process (
TEH_pg,
&uc->h_payto,
uc->measure_index,
diff --git a/src/exchange/taler-exchange-httpd_post-management-auditors-AUDITOR_PUB-disable.c b/src/exchange/taler-exchange-httpd_post-management-auditors-AUDITOR_PUB-disable.c
@@ -29,7 +29,7 @@
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_get-keys.h"
#include "exchange-database/update_auditor.h"
-#include "exchange-database/lookup_auditor_timestamp.h"
+#include "exchange-database/get_auditor_timestamp.h"
/**
@@ -79,9 +79,9 @@ del_auditor (void *cls,
struct GNUNET_TIME_Timestamp last_date;
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_lookup_auditor_timestamp (TEH_pg,
- &dac->auditor_pub,
- &last_date);
+ qs = TALER_EXCHANGEDB_get_auditor_timestamp (TEH_pg,
+ &dac->auditor_pub,
+ &last_date);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_post-management-auditors.c b/src/exchange/taler-exchange-httpd_post-management-auditors.c
@@ -30,7 +30,7 @@
#include "taler-exchange-httpd_get-keys.h"
#include "exchange-database/update_auditor.h"
#include "exchange-database/insert_auditor.h"
-#include "exchange-database/lookup_auditor_timestamp.h"
+#include "exchange-database/get_auditor_timestamp.h"
/**
@@ -89,9 +89,9 @@ add_auditor (void *cls,
struct GNUNET_TIME_Timestamp last_date;
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_lookup_auditor_timestamp (TEH_pg,
- &aac->auditor_pub,
- &last_date);
+ qs = TALER_EXCHANGEDB_get_auditor_timestamp (TEH_pg,
+ &aac->auditor_pub,
+ &last_date);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_post-management-drain.c b/src/exchange/taler-exchange-httpd_post-management-drain.c
@@ -28,7 +28,7 @@
#include "taler-exchange-httpd_get-keys.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/insert_drain_profit.h"
+#include "exchange-database/insert_profit_drain.h"
/**
@@ -91,7 +91,7 @@ drain (void *cls,
struct DrainContext *dc = cls;
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_insert_drain_profit (
+ qs = TALER_EXCHANGEDB_insert_profit_drain (
TEH_pg,
&dc->wtid,
dc->account_section,
diff --git a/src/exchange/taler-exchange-httpd_post-management-global-fees.c b/src/exchange/taler-exchange-httpd_post-management-global-fees.c
@@ -28,7 +28,7 @@
#include "taler-exchange-httpd_get-keys.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/lookup_global_fee_by_time.h"
+#include "exchange-database/get_global_fee_by_time.h"
#include "exchange-database/insert_global_fee.h"
@@ -101,7 +101,7 @@ add_fee (void *cls,
struct GNUNET_TIME_Relative history_expiration;
uint32_t purse_account_limit;
- qs = TALER_EXCHANGEDB_lookup_global_fee_by_time (
+ qs = TALER_EXCHANGEDB_get_global_fee_by_time (
TEH_pg,
afc->start_time,
afc->end_time,
diff --git a/src/exchange/taler-exchange-httpd_post-management-keys.c b/src/exchange/taler-exchange-httpd_post-management-keys.c
@@ -29,10 +29,10 @@
#include "taler-exchange-httpd_secmod-helpers.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/lookup_signing_key.h"
-#include "exchange-database/activate_signing_key.h"
-#include "exchange-database/add_denomination_key.h"
-#include "exchange-database/lookup_denomination_key.h"
+#include "exchange-database/get_signkey.h"
+#include "exchange-database/insert_signkey.h"
+#include "exchange-database/insert_denomination_info.h"
+#include "exchange-database/get_denomination_meta.h"
/**
@@ -216,7 +216,7 @@ add_keys (void *cls,
struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
/* For idempotency, check if the key is already active */
- qs = TALER_EXCHANGEDB_lookup_denomination_key (
+ qs = TALER_EXCHANGEDB_get_denomination_meta (
TEH_pg,
&d->h_denom_pub,
&meta);
@@ -250,12 +250,24 @@ add_keys (void *cls,
continue; /* skip, already known */
}
- qs = TALER_EXCHANGEDB_add_denomination_key (
- TEH_pg,
- &d->h_denom_pub,
- &d->denom_pub,
- &d->meta,
- &d->master_sig);
+ {
+ struct TALER_EXCHANGEDB_DenominationKeyInformation issue = {
+ .signature = d->master_sig,
+ .start = d->meta.start,
+ .expire_withdraw = d->meta.expire_withdraw,
+ .expire_deposit = d->meta.expire_deposit,
+ .expire_legal = d->meta.expire_legal,
+ .value = d->meta.value,
+ .fees = d->meta.fees,
+ .denom_hash = d->h_denom_pub,
+ .age_mask = d->meta.age_mask
+ };
+
+ qs = TALER_EXCHANGEDB_insert_denomination_info (
+ TEH_pg,
+ &d->denom_pub,
+ &issue);
+ }
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -279,7 +291,7 @@ add_keys (void *cls,
enum GNUNET_DB_QueryStatus qs;
struct TALER_EXCHANGEDB_SignkeyMetaData meta;
- qs = TALER_EXCHANGEDB_lookup_signing_key (
+ qs = TALER_EXCHANGEDB_get_signkey (
TEH_pg,
&s->exchange_pub,
&meta);
@@ -312,7 +324,7 @@ add_keys (void *cls,
TALER_B2S (&s->exchange_pub));
continue; /* skip, already known */
}
- qs = TALER_EXCHANGEDB_activate_signing_key (
+ qs = TALER_EXCHANGEDB_insert_signkey (
TEH_pg,
&s->exchange_pub,
&s->meta,
diff --git a/src/exchange/taler-exchange-httpd_post-management-wire-disable.c b/src/exchange/taler-exchange-httpd_post-management-wire-disable.c
@@ -29,7 +29,7 @@
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_get-keys.h"
#include "exchange-database/update_wire.h"
-#include "exchange-database/lookup_wire_timestamp.h"
+#include "exchange-database/get_wire_timestamp.h"
/**
@@ -79,9 +79,9 @@ del_wire (void *cls,
struct GNUNET_TIME_Timestamp last_date;
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_lookup_wire_timestamp (TEH_pg,
- awc->payto_uri,
- &last_date);
+ qs = TALER_EXCHANGEDB_get_wire_timestamp (TEH_pg,
+ awc->payto_uri,
+ &last_date);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_post-management-wire-fee.c b/src/exchange/taler-exchange-httpd_post-management-wire-fee.c
@@ -28,7 +28,7 @@
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/lookup_wire_fee_by_time.h"
+#include "exchange-database/get_wire_fee_by_time.h"
#include "exchange-database/insert_wire_fee.h"
@@ -88,7 +88,7 @@ add_fee (void *cls,
enum GNUNET_DB_QueryStatus qs;
struct TALER_WireFeeSet fees;
- qs = TALER_EXCHANGEDB_lookup_wire_fee_by_time (
+ qs = TALER_EXCHANGEDB_get_wire_fee_by_time (
TEH_pg,
afc->wire_method,
afc->start_time,
@@ -127,7 +127,7 @@ add_fee (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
- qs = TALER_TALER_EXCHANGEDB_insert_wire_fee (
+ qs = TALER_EXCHANGEDB_insert_wire_fee (
TEH_pg,
afc->wire_method,
afc->start_time,
diff --git a/src/exchange/taler-exchange-httpd_post-management-wire.c b/src/exchange/taler-exchange-httpd_post-management-wire.c
@@ -30,7 +30,7 @@
#include "taler-exchange-httpd_get-keys.h"
#include "exchange-database/update_wire.h"
#include "exchange-database/insert_wire.h"
-#include "exchange-database/lookup_wire_timestamp.h"
+#include "exchange-database/get_wire_timestamp.h"
/**
@@ -121,9 +121,9 @@ add_wire (void *cls,
struct GNUNET_TIME_Timestamp last_date;
enum GNUNET_DB_QueryStatus qs;
- qs = TALER_EXCHANGEDB_lookup_wire_timestamp (TEH_pg,
- awc->payto_uri,
- &last_date);
+ qs = TALER_EXCHANGEDB_get_wire_timestamp (TEH_pg,
+ awc->payto_uri,
+ &last_date);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_post-purses-PURSE_PUB-create.c b/src/exchange/taler-exchange-httpd_post-purses-PURSE_PUB-create.c
@@ -31,7 +31,7 @@
#include "taler-exchange-httpd_responses.h"
#include "exchangedb_lib.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/select_contract_by_purse.h"
+#include "exchange-database/get_contract_by_purse.h"
#include "exchange-database/do_purse_deposit.h"
#include "exchange-database/get_purse_deposit.h"
#include "exchange-database/get_purse_request.h"
@@ -337,7 +337,7 @@ create_transaction (void *cls,
struct TALER_EncryptedContract econtract;
struct GNUNET_HashCode h_econtract;
- qs = TALER_TALER_EXCHANGEDB_select_contract_by_purse (
+ qs = TALER_EXCHANGEDB_get_contract_by_purse (
TEH_pg,
&pcc->pd.purse_pub,
&econtract);
diff --git a/src/exchange/taler-exchange-httpd_post-purses-PURSE_PUB-deposit.c b/src/exchange/taler-exchange-httpd_post-purses-PURSE_PUB-deposit.c
@@ -33,7 +33,7 @@
#include "taler-exchange-httpd_responses.h"
#include "exchangedb_lib.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/select_purse.h"
+#include "exchange-database/get_purse.h"
#include "exchange-database/do_purse_deposit.h"
#include "exchange-database/event_notify.h"
#include "exchange-database/get_purse_deposit.h"
@@ -383,7 +383,7 @@ TEH_handler_purses_deposit (
bool was_deleted;
bool was_refunded;
- qs = TALER_EXCHANGEDB_select_purse (
+ qs = TALER_EXCHANGEDB_get_purse (
TEH_pg,
pcc.purse_pub,
&create_timestamp,
diff --git a/src/exchange/taler-exchange-httpd_post-purses-PURSE_PUB-merge.c b/src/exchange/taler-exchange-httpd_post-purses-PURSE_PUB-merge.c
@@ -35,11 +35,11 @@
#include "taler-exchange-httpd_responses.h"
#include "exchangedb_lib.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/select_purse_merge.h"
+#include "exchange-database/get_purse_merge.h"
#include "exchange-database/do_purse_merge.h"
#include "exchange-database/event_notify.h"
#include "exchange-database/get_purse_request.h"
-#include "exchange-database/select_merge_amounts_for_kyc_check.h"
+#include "exchange-database/iterate_merge_amounts_for_kyc_check.h"
/**
@@ -347,7 +347,7 @@ amount_iterator (void *cls,
GNUNET_break (GNUNET_SYSERR != ret);
if (GNUNET_OK != ret)
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_EXCHANGEDB_select_merge_amounts_for_kyc_check (
+ qs = TALER_EXCHANGEDB_iterate_merge_amounts_for_kyc_check (
TEH_pg,
&pmc->h_payto,
limit,
@@ -435,13 +435,13 @@ merge_transaction (void *cls,
struct TALER_ReservePublicKeyP reserve_pub;
bool refunded;
- qs = TALER_TALER_EXCHANGEDB_select_purse_merge (TEH_pg,
- &pmc->purse_pub,
- &merge_sig,
- &merge_timestamp,
- &partner_url,
- &reserve_pub,
- &refunded);
+ qs = TALER_EXCHANGEDB_get_purse_merge (TEH_pg,
+ &pmc->purse_pub,
+ &merge_sig,
+ &merge_timestamp,
+ &partner_url,
+ &reserve_pub,
+ &refunded);
if (qs <= 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_post-recoup-refresh.c b/src/exchange/taler-exchange-httpd_post-recoup-refresh.c
@@ -111,16 +111,16 @@ recoup_refresh_transaction (void *cls,
/* Finally, store new refund data */
pc->now = GNUNET_TIME_timestamp_get ();
- qs = TALER_TALER_EXCHANGEDB_do_recoup_refresh (TEH_pg,
- &pc->old_coin_pub,
- pc->rrc_serial,
- pc->coin_bks,
- &pc->coin->coin_pub,
- pc->known_coin_id,
- pc->coin_sig,
- &pc->now,
- &recoup_ok,
- &internal_failure);
+ qs = TALER_EXCHANGEDB_do_recoup_refresh (TEH_pg,
+ &pc->old_coin_pub,
+ pc->rrc_serial,
+ pc->coin_bks,
+ &pc->coin->coin_pub,
+ pc->known_coin_id,
+ pc->coin_sig,
+ &pc->now,
+ &recoup_ok,
+ &internal_failure);
if (0 > qs)
{
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_post-reserves-RESERVE_PUB-attest.c b/src/exchange/taler-exchange-httpd_post-reserves-RESERVE_PUB-attest.c
@@ -30,7 +30,7 @@
#include "taler-exchange-httpd_responses.h"
struct ReserveAttestContext;
#define TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE struct ReserveAttestContext
-#include "exchange-database/select_kyc_attributes.h"
+#include "exchange-database/iterate_kyc_attributes.h"
/**
@@ -257,10 +257,10 @@ reserve_attest_transaction (void *cls,
GNUNET_assert (0 ==
json_object_clear (rsc->json_attest));
- qs = TALER_EXCHANGEDB_select_kyc_attributes (TEH_pg,
- &rsc->h_payto,
- &kyc_process_cb,
- rsc);
+ qs = TALER_EXCHANGEDB_iterate_kyc_attributes (TEH_pg,
+ &rsc->h_payto,
+ &kyc_process_cb,
+ rsc);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-httpd_post-reserves-RESERVE_PUB-close.c b/src/exchange/taler-exchange-httpd_post-reserves-RESERVE_PUB-close.c
@@ -29,7 +29,7 @@
#include "taler-exchange-httpd_get-keys.h"
#include "taler-exchange-httpd_post-reserves-RESERVE_PUB-close.h"
#include "taler-exchange-httpd_responses.h"
-#include "exchange-database/select_reserve_close_info.h"
+#include "exchange-database/get_reserve_close_info.h"
#include "exchange-database/insert_close_request.h"
#include "exchange-database/iterate_reserve_close_info.h"
@@ -286,7 +286,7 @@ reserve_close_transaction (
};
const struct TALER_WireFeeSet *wf;
- qs = TALER_EXCHANGEDB_select_reserve_close_info (
+ qs = TALER_EXCHANGEDB_get_reserve_close_info (
TEH_pg,
&rcc->reserve_pub,
&rcc->balance,
diff --git a/src/exchange/taler-exchange-httpd_post-reserves-RESERVE_PUB-purse.c b/src/exchange/taler-exchange-httpd_post-reserves-RESERVE_PUB-purse.c
@@ -33,14 +33,14 @@
#include "taler-exchange-httpd_responses.h"
#include "exchangedb_lib.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/select_purse_merge.h"
+#include "exchange-database/get_purse_merge.h"
#include "exchange-database/do_reserve_purse.h"
#include "exchange-database/get_purse_request.h"
#include "exchange-database/insert_contract.h"
#include "exchange-database/insert_purse_request.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/select_contract_by_purse.h"
-#include "exchange-database/select_merge_amounts_for_kyc_check.h"
+#include "exchange-database/get_contract_by_purse.h"
+#include "exchange-database/iterate_merge_amounts_for_kyc_check.h"
/**
@@ -231,7 +231,7 @@ amount_iterator (void *cls,
GNUNET_break (GNUNET_SYSERR != ret);
if (GNUNET_OK != ret)
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_EXCHANGEDB_select_merge_amounts_for_kyc_check (
+ qs = TALER_EXCHANGEDB_iterate_merge_amounts_for_kyc_check (
TEH_pg,
&rpc->h_payto,
limit,
@@ -428,7 +428,7 @@ purse_transaction (void *cls,
bool refunded;
TALER_EXCHANGEDB_rollback (TEH_pg);
- qs = TALER_TALER_EXCHANGEDB_select_purse_merge (
+ qs = TALER_EXCHANGEDB_get_purse_merge (
TEH_pg,
&purse_pub,
&merge_sig,
@@ -531,7 +531,7 @@ purse_transaction (void *cls,
struct TALER_EncryptedContract econtract;
struct GNUNET_HashCode h_econtract;
- qs = TALER_TALER_EXCHANGEDB_select_contract_by_purse (
+ qs = TALER_EXCHANGEDB_get_contract_by_purse (
TEH_pg,
&rpc->pd.purse_pub,
&econtract);
diff --git a/src/exchange/taler-exchange-httpd_post-reveal-melt.c b/src/exchange/taler-exchange-httpd_post-reveal-melt.c
@@ -29,7 +29,7 @@
#include "taler-exchange-httpd_post-reveal-melt.h"
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_get-keys.h"
-#include "exchange-database/mark_refresh_reveal_success.h"
+#include "exchange-database/update_to_refresh_revealed.h"
#include "exchange-database/get_refresh.h"
#define KAPPA_MINUS_1 (TALER_CNC_KAPPA - 1)
@@ -700,7 +700,7 @@ commit_reveal (
for (unsigned int retry = 0; retry < 3; retry++)
{
- qs = TALER_EXCHANGEDB_mark_refresh_reveal_success (
+ qs = TALER_EXCHANGEDB_update_to_refresh_revealed (
TEH_pg,
rc);
switch (qs)
diff --git a/src/exchange/taler-exchange-httpd_post-withdraw.c b/src/exchange/taler-exchange-httpd_post-withdraw.c
@@ -26,7 +26,7 @@
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
#include "taler-exchange-httpd.h"
-#include "exchange-database/select_withdraw_amounts_for_kyc_check.h"
+#include "exchange-database/iterate_withdraw_amounts_for_kyc_check.h"
#include "taler/taler_json_lib.h"
#include "taler/taler_kyclogic_lib.h"
#include "taler/taler_mhd_lib.h"
@@ -38,7 +38,7 @@
#include "taler/taler_util.h"
#include "exchange-database/do_withdraw.h"
#include "exchange-database/get_withdraw.h"
-#include "exchange-database/reserves_get_origin.h"
+#include "exchange-database/get_reserve_origin.h"
#include "exchange-database/rollback.h"
/**
@@ -785,7 +785,7 @@ withdraw_amount_cb (
if (GNUNET_OK != ret)
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- qs = TALER_EXCHANGEDB_select_withdraw_amounts_for_kyc_check (
+ qs = TALER_EXCHANGEDB_iterate_withdraw_amounts_for_kyc_check (
TEH_pg,
&wc->h_normalized_payto,
limit,
@@ -813,7 +813,7 @@ phase_run_legi_check (struct WithdrawContext *wc)
struct TALER_FullPaytoHashP h_full_payto;
/* Check if the money came from a wire transfer */
- qs = TALER_TALER_EXCHANGEDB_reserves_get_origin (
+ qs = TALER_EXCHANGEDB_get_reserve_origin (
TEH_pg,
&wc->request.withdraw.reserve_pub,
&h_full_payto,
diff --git a/src/exchange/taler-exchange-httpd_responses.h b/src/exchange/taler-exchange-httpd_responses.h
@@ -32,7 +32,7 @@
#include "taler-exchange-httpd.h"
#include "taler-exchange-httpd_db.h"
#include "exchangedb_lib.h"
-#include "exchange-database/ensure_coin_known.h"
+#include "exchange-database/do_insert_known_coin.h"
/**
diff --git a/src/exchange/taler-exchange-sanctionscheck.c b/src/exchange/taler-exchange-sanctionscheck.c
@@ -34,7 +34,7 @@
#include "exchange-database/insert_sanction_list_hit.h"
#include "exchange-database/start.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/select_all_kyc_attributes.h"
+#include "exchange-database/iterate_all_kyc_attributes.h"
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
#include "exchange-database/start.h"
@@ -233,8 +233,8 @@ shutdown_task (void *cls)
}
if (NULL != eh)
{
- TALER_TALER_EXCHANGEDB_event_listen_cancel (pg,
- eh);
+ TALER_EXCHANGEDB_event_listen_cancel (pg,
+ eh);
eh = NULL;
}
if (NULL != sr)
@@ -570,10 +570,10 @@ begin_transaction ()
in_transaction = true;
/* FIXME-10063: we may want to eventually limit the number of
records we process in a single transaction. */
- qs = TALER_EXCHANGEDB_select_all_kyc_attributes (pg,
- min_row_id,
- &account_cb,
- NULL);
+ qs = TALER_EXCHANGEDB_iterate_all_kyc_attributes (pg,
+ min_row_id,
+ &account_cb,
+ NULL);
if (qs < 0)
{
global_ret = EXIT_FAILURE;
diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c
@@ -32,12 +32,12 @@
#include "exchange-database/insert_sanction_list_hit.h"
#include "exchange-database/start_read_committed.h"
#include "exchange-database/rollback.h"
-#include "exchange-database/wire_prepare_data_mark_finished.h"
-#include "exchange-database/wire_prepare_data_mark_failed.h"
-#include "exchange-database/wire_prepare_data_get.h"
+#include "exchange-database/update_to_prewire_finished.h"
+#include "exchange-database/update_to_prewire_failed.h"
+#include "exchange-database/iterate_prewires.h"
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
-#include "exchange-database/wire_prepare_data_mark_finished.h"
+#include "exchange-database/update_to_prewire_finished.h"
/**
@@ -435,8 +435,8 @@ wire_confirm_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Wire transfer %llu completed successfully\n",
(unsigned long long) wpd->row_id);
- qs = TALER_EXCHANGEDB_wire_prepare_data_mark_finished (pg,
- wpd->row_id);
+ qs = TALER_EXCHANGEDB_update_to_prewire_finished (pg,
+ wpd->row_id);
/* continued below */
break;
case MHD_HTTP_NOT_FOUND:
@@ -446,8 +446,8 @@ wire_confirm_cb (void *cls,
(unsigned long long) wpd->row_id,
tr->http_status,
tr->ec);
- qs = TALER_EXCHANGEDB_wire_prepare_data_mark_failed (pg,
- wpd->row_id);
+ qs = TALER_EXCHANGEDB_update_to_prewire_failed (pg,
+ wpd->row_id);
/* continued below */
break;
case 0:
@@ -674,8 +674,8 @@ run_transfers (void *cls)
(long long) limit,
(unsigned long long) shard->batch_start);
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_committed (pg,
- "aggregator run transfer"))
+ TALER_EXCHANGEDB_start_read_committed (pg,
+ "aggregator run transfer"))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start database transaction!\n");
@@ -684,11 +684,11 @@ run_transfers (void *cls)
return;
}
GNUNET_assert (NULL == task);
- qs = TALER_EXCHANGEDB_wire_prepare_data_get (pg,
- shard->batch_start,
- limit,
- &wire_prepare_cb,
- NULL);
+ qs = TALER_EXCHANGEDB_iterate_prewires (pg,
+ shard->batch_start,
+ limit,
+ &wire_prepare_cb,
+ NULL);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c
@@ -31,13 +31,13 @@
#include "exchange-database/complete_shard.h"
#include "exchange-database/commit.h"
#include "exchange-database/preflight.h"
-#include "exchange-database/kycauth_in_insert.h"
-#include "exchange-database/wad_in_insert.h"
-#include "exchange-database/reserves_in_insert.h"
+#include "exchange-database/insert_kycauth_in.h"
+#include "exchange-database/insert_wad_in.h"
+#include "exchange-database/do_insert_reserve_in.h"
#include "exchange-database/rollback.h"
#include "exchange-database/event_listen.h"
#include "exchange-database/event_listen_cancel.h"
-#include "exchange-database/wad_in_insert.h"
+#include "exchange-database/insert_wad_in.h"
/**
* How long to wait for an HTTP reply if there
@@ -642,7 +642,7 @@ process_reply (const struct TALER_BANK_CreditDetails *details,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Importing KYC auth transfer over %s\n",
TALER_amount2s (&cd->amount));
- qs = TALER_EXCHANGEDB_kycauth_in_insert (
+ qs = TALER_EXCHANGEDB_insert_kycauth_in (
pg,
&cd->details.kycauth.account_pub,
&cd->amount,
@@ -672,7 +672,7 @@ process_reply (const struct TALER_BANK_CreditDetails *details,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Importing WAD transfer over %s\n",
TALER_amount2s (&cd->amount));
- qs = TALER_EXCHANGEDB_wad_in_insert (
+ qs = TALER_EXCHANGEDB_insert_wad_in (
pg,
&cd->details.wad.wad_id,
cd->details.wad.origin_exchange_url,
@@ -702,10 +702,10 @@ process_reply (const struct TALER_BANK_CreditDetails *details,
}
if (j > 0)
{
- qs = TALER_EXCHANGEDB_reserves_in_insert (pg,
- reserves,
- j,
- qss);
+ qs = TALER_EXCHANGEDB_do_insert_reserve_in (pg,
+ reserves,
+ j,
+ qss);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/exchangedb/account_history.c b/src/exchangedb/account_history.c
@@ -22,10 +22,10 @@
#include "exchangedb_lib.h"
#include "taler/taler_kyclogic_lib.h"
#include "taler/taler_json_lib.h"
-#include "exchange-database/lookup_aml_history.h"
-#include "exchange-database/lookup_kyc_history.h"
+#include "exchange-database/iterate_aml_history.h"
+#include "exchange-database/iterate_kyc_history.h"
#include "exchange-database/get_kyc_rules.h"
-#include "exchange-database/select_aml_attributes.h"
+#include "exchange-database/iterate_aml_attributes.h"
#include "exchange-database/account_history.h"
#include <gnunet/gnunet_common.h>
@@ -90,7 +90,7 @@ TALER_EXCHANGEDB_aml_history_builder (void *cls)
aml_history = json_array ();
GNUNET_assert (NULL != aml_history);
- qs = TALER_EXCHANGEDB_lookup_aml_history (
+ qs = TALER_EXCHANGEDB_iterate_aml_history (
hbc->pg,
acc,
UINT64_MAX, /* offset */
@@ -226,7 +226,7 @@ TALER_EXCHANGEDB_kyc_history_builder (void *cls)
};
GNUNET_assert (NULL != kc.kyc_history);
- qs = TALER_EXCHANGEDB_lookup_kyc_history (
+ qs = TALER_EXCHANGEDB_iterate_kyc_history (
hbc->pg,
acc,
&add_kyc_history_entry,
@@ -256,7 +256,7 @@ TALER_EXCHANGEDB_current_rule_builder (void *cls)
enum GNUNET_DB_QueryStatus qs;
json_t *jlrs;
- qs = TALER_TALER_EXCHANGEDB_get_kyc_rules2 (
+ qs = TALER_EXCHANGEDB_get_kyc_rules (
hbc->pg,
acc,
&jlrs);
@@ -338,7 +338,7 @@ TALER_EXCHANGEDB_current_attributes_builder (void *cls)
.hbc = hbc
};
- qs = TALER_EXCHANGEDB_select_aml_attributes (
+ qs = TALER_EXCHANGEDB_iterate_aml_attributes (
hbc->pg,
acc,
INT64_MAX,
diff --git a/src/exchangedb/activate_signing_key.c b/src/exchangedb/activate_signing_key.c
@@ -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 exchangedb/activate_signing_key.c
- * @brief Implementation of the activate_signing_key function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/activate_signing_key.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_activate_signing_key (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_EXCHANGEDB_SignkeyMetaData *meta,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct GNUNET_PQ_QueryParam iparams[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_timestamp (&meta->start),
- GNUNET_PQ_query_param_timestamp (&meta->expire_sign),
- GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "insert_signkey",
- "INSERT INTO exchange_sign_keys "
- "(exchange_pub"
- ",valid_from"
- ",expire_sign"
- ",expire_legal"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_signkey",
- iparams);
-}
diff --git a/src/exchangedb/add_denomination_key.c b/src/exchangedb/add_denomination_key.c
@@ -1,83 +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 exchangedb/add_denomination_key.c
- * @brief Implementation of the add_denomination_key function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/add_denomination_key.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_add_denomination_key (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct GNUNET_PQ_QueryParam iparams[] = {
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- TALER_PQ_query_param_denom_pub (denom_pub),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_timestamp (&meta->start),
- GNUNET_PQ_query_param_timestamp (&meta->expire_withdraw),
- GNUNET_PQ_query_param_timestamp (&meta->expire_deposit),
- GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
- TALER_PQ_query_param_amount (pg->conn,
- &meta->value),
- TALER_PQ_query_param_amount (pg->conn,
- &meta->fees.withdraw),
- TALER_PQ_query_param_amount (pg->conn,
- &meta->fees.deposit),
- TALER_PQ_query_param_amount (pg->conn,
- &meta->fees.refresh),
- TALER_PQ_query_param_amount (pg->conn,
- &meta->fees.refund),
- GNUNET_PQ_query_param_uint32 (&meta->age_mask.bits),
- GNUNET_PQ_query_param_end
- };
-
- /* Sanity check: ensure fees match coin currency */
- GNUNET_assert (GNUNET_YES ==
- TALER_denom_fee_check_currency (meta->value.currency,
- &meta->fees));
- PREPARE (pg,
- "denomination_insert",
- "INSERT INTO denominations "
- "(denom_pub_hash"
- ",denom_pub"
- ",master_sig"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin" /* value of this denom */
- ",fee_withdraw"
- ",fee_deposit"
- ",fee_refresh"
- ",fee_refund"
- ",age_mask"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
- " $11, $12, $13);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "denomination_insert",
- iparams);
-}
diff --git a/src/exchangedb/aggregate.c b/src/exchangedb/aggregate.c
@@ -1,201 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 exchangedb/aggregate.c
- * @brief Implementation of the aggregate function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/compute_shard.h"
-#include "exchange-database/aggregate.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_aggregate (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPaytoHashP *h_payto,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- struct TALER_Amount *total)
-{
- uint64_t deposit_shard = TALER_EXCHANGEDB_compute_shard (merchant_pub);
- struct GNUNET_TIME_Absolute now = {0};
- uint64_t sum_deposit_value;
- uint64_t sum_deposit_frac;
- uint64_t sum_refund_value;
- uint64_t sum_refund_frac;
- uint64_t sum_fee_value;
- uint64_t sum_fee_frac;
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount sum_deposit;
- struct TALER_Amount sum_refund;
- struct TALER_Amount sum_fee;
- struct TALER_Amount delta;
-
- now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
- pg->aggregator_shift);
- PREPARE (pg,
- "aggregate",
- "WITH bdep AS (" /* restrict to our merchant and account and mark as done */
- " UPDATE batch_deposits"
- " SET done=TRUE"
- " WHERE NOT (done OR policy_blocked)" /* only actually executable deposits */
- " AND refund_deadline<$1"
- " AND shard=$5" /* only for efficiency, merchant_pub is what we really filter by */
- " AND merchant_pub=$2" /* filter by target merchant */
- " AND wire_target_h_payto=$3" /* merchant could have a 2nd bank account */
- " RETURNING"
- " batch_deposit_serial_id)"
- " ,cdep AS ("
- " SELECT"
- " coin_deposit_serial_id"
- " ,batch_deposit_serial_id"
- " ,coin_pub"
- " ,amount_with_fee AS amount"
- " FROM coin_deposits"
- " WHERE batch_deposit_serial_id IN (SELECT batch_deposit_serial_id FROM bdep))"
- " ,ref AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
- " SELECT"
- " amount_with_fee AS refund"
- " ,coin_pub"
- " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
- " FROM refunds"
- " WHERE coin_pub IN (SELECT coin_pub FROM cdep)"
- " AND batch_deposit_serial_id IN (SELECT batch_deposit_serial_id FROM bdep))"
- " ,ref_by_coin AS (" /* total up refunds by coin */
- " SELECT"
- " SUM((ref.refund).val) AS sum_refund_val"
- " ,SUM((ref.refund).frac) AS sum_refund_frac"
- " ,coin_pub"
- " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
- " FROM ref"
- " GROUP BY coin_pub, batch_deposit_serial_id)"
- " ,norm_ref_by_coin AS (" /* normalize */
- " SELECT"
- " sum_refund_val + sum_refund_frac / 100000000 AS norm_refund_val"
- " ,sum_refund_frac % 100000000 AS norm_refund_frac"
- " ,coin_pub"
- " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
- " FROM ref_by_coin)"
- " ,fully_refunded_coins AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
- " SELECT"
- " cdep.coin_pub"
- " FROM norm_ref_by_coin norm"
- " JOIN cdep"
- " ON (norm.coin_pub = cdep.coin_pub"
- " AND norm.batch_deposit_serial_id = cdep.batch_deposit_serial_id"
- " AND norm.norm_refund_val = (cdep.amount).val"
- " AND norm.norm_refund_frac = (cdep.amount).frac))"
- " ,fees AS (" /* find deposit fees for not fully refunded deposits */
- " SELECT"
- " denom.fee_deposit AS fee"
- " ,cs.batch_deposit_serial_id" /* ensures we get the fee for each coin, not once per denomination */
- " FROM cdep cs"
- " JOIN known_coins kc" /* NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
- " USING (coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " WHERE coin_pub NOT IN (SELECT coin_pub FROM fully_refunded_coins))"
- " ,dummy AS (" /* add deposits to aggregation_tracking */
- " INSERT INTO aggregation_tracking"
- " (batch_deposit_serial_id"
- " ,wtid_raw)"
- " SELECT batch_deposit_serial_id,$4"
- " FROM bdep)"
- "SELECT" /* calculate totals (deposits, refunds and fees) */
- " CAST(COALESCE(SUM((cdep.amount).val),0) AS INT8) AS sum_deposit_value"
- /* cast needed, otherwise we get NUMBER */
- " ,COALESCE(SUM((cdep.amount).frac),0) AS sum_deposit_fraction" /* SUM over INT returns INT8 */
- " ,CAST(COALESCE(SUM((ref.refund).val),0) AS INT8) AS sum_refund_value"
- " ,COALESCE(SUM((ref.refund).frac),0) AS sum_refund_fraction"
- " ,CAST(COALESCE(SUM((fees.fee).val),0) AS INT8) AS sum_fee_value"
- " ,COALESCE(SUM((fees.fee).frac),0) AS sum_fee_fraction"
- " FROM cdep "
- " FULL OUTER JOIN ref ON (FALSE)" /* We just want all sums */
- " FULL OUTER JOIN fees ON (FALSE);");
-
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_uint64 (&deposit_shard),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("sum_deposit_value",
- &sum_deposit_value),
- GNUNET_PQ_result_spec_uint64 ("sum_deposit_fraction",
- &sum_deposit_frac),
- GNUNET_PQ_result_spec_uint64 ("sum_refund_value",
- &sum_refund_value),
- GNUNET_PQ_result_spec_uint64 ("sum_refund_fraction",
- &sum_refund_frac),
- GNUNET_PQ_result_spec_uint64 ("sum_fee_value",
- &sum_fee_value),
- GNUNET_PQ_result_spec_uint64 ("sum_fee_fraction",
- &sum_fee_frac),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "aggregate",
- params,
- rs);
- }
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- {
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- total));
- return qs;
- }
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &sum_deposit));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &sum_refund));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &sum_fee));
- sum_deposit.value = sum_deposit_frac / TALER_AMOUNT_FRAC_BASE
- + sum_deposit_value;
- sum_deposit.fraction = sum_deposit_frac % TALER_AMOUNT_FRAC_BASE;
- sum_refund.value = sum_refund_frac / TALER_AMOUNT_FRAC_BASE
- + sum_refund_value;
- sum_refund.fraction = sum_refund_frac % TALER_AMOUNT_FRAC_BASE;
- sum_fee.value = sum_fee_frac / TALER_AMOUNT_FRAC_BASE
- + sum_fee_value;
- sum_fee.fraction = sum_fee_frac % TALER_AMOUNT_FRAC_BASE; \
- GNUNET_assert (0 <=
- TALER_amount_subtract (&delta,
- &sum_deposit,
- &sum_refund));
- GNUNET_assert (0 <=
- TALER_amount_subtract (total,
- &delta,
- &sum_fee));
- return qs;
-}
diff --git a/src/exchangedb/begin_revolving_shard.c b/src/exchangedb/begin_revolving_shard.c
@@ -62,7 +62,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
};
PREPARE (pg,
- "get_last_revolving_shard",
+ "begin_revolving_shard_last_revolving_shard",
"SELECT"
" end_row"
" FROM revolving_work_shards"
@@ -70,7 +70,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
" ORDER BY end_row DESC"
" LIMIT 1;");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_last_revolving_shard",
+ "begin_revolving_shard_last_revolving_shard",
params,
rs);
switch (qs)
@@ -114,7 +114,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
/* Used in #postgres_claim_revolving_shard() */
PREPARE (pg,
- "create_revolving_shard",
+ "begin_revolving_shard_create_revolving_shard",
"INSERT INTO revolving_work_shards"
"(job_name"
",last_attempt"
@@ -124,7 +124,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
") VALUES "
"($1, $2, $3, $4, TRUE);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "create_revolving_shard",
+ "begin_revolving_shard_create_revolving_shard",
params);
switch (qs)
{
@@ -162,7 +162,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
};
PREPARE (pg,
- "get_open_revolving_shard",
+ "begin_revolving_shard_open_revolving_shard",
"SELECT"
" start_row"
",end_row"
@@ -172,7 +172,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
" ORDER BY last_attempt ASC"
" LIMIT 1;");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_open_revolving_shard",
+ "begin_revolving_shard_open_revolving_shard",
params,
rs);
switch (qs)
@@ -202,7 +202,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
now = GNUNET_TIME_timestamp_get ();
PREPARE (pg,
- "reclaim_revolving_shard",
+ "begin_revolving_shard_reclaim_revolving_shard",
"UPDATE revolving_work_shards"
" SET last_attempt=$2"
" ,active=TRUE"
@@ -210,7 +210,7 @@ TALER_EXCHANGEDB_begin_revolving_shard (
" AND start_row=$3"
" AND end_row=$4");
qsz = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reclaim_revolving_shard",
+ "begin_revolving_shard_reclaim_revolving_shard",
iparams);
switch (qsz)
{
diff --git a/src/exchangedb/begin_rule_update.c b/src/exchangedb/begin_rule_update.c
@@ -0,0 +1,672 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file begin_rule_update.c
+ * @brief helper function to handle AML programs
+ * @author Christian Grothoff
+ */
+#include "exchangedb_lib.h"
+#include "taler/taler_kyclogic_lib.h"
+#include "taler/taler_dbevents.h"
+#include "exchange-database/start.h"
+#include "exchange-database/rollback.h"
+#include "exchange-database/commit.h"
+#include "exchange-database/update_to_aml_locked.h"
+#include "exchange-database/update_to_aml_unlocked.h"
+#include "exchange-database/do_persist_aml_program_result.h"
+#include "exchange-database/insert_successor_measure.h"
+#include "exchange-database/event_notify.h"
+#include "exchange-database/event_listen.h"
+#include "exchange-database/event_listen_cancel.h"
+#include "exchange-database/get_rules_by_access_token.h"
+#include "exchange-database/begin_rule_update.h"
+#include "exchange-database/account_history.h"
+#include "helper.h"
+#include <gnunet/gnunet_common.h>
+
+/**
+ * Maximum recursion depth we allow for AML programs.
+ * Basically, after this number of "skip" processes
+ * we forcefully terminate the recursion and fail hard.
+ */
+#define MAX_DEPTH 16
+
+
+struct TALER_EXCHANGEDB_RuleUpdater
+{
+ /**
+ * database pg to use
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * key to use to decrypt attributes
+ */
+ struct TALER_AttributeEncryptionKeyP attribute_key;
+
+ /**
+ * account to get the rule set for
+ */
+ struct TALER_NormalizedPaytoHashP account;
+
+ /**
+ * function to call with the result
+ */
+ TALER_EXCHANGEDB_CurrentRulesCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Current rule set we are working on.
+ */
+ struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs;
+
+ /**
+ * Task for asynchronous continuations.
+ */
+ struct GNUNET_SCHEDULER_Task *t;
+
+ /**
+ * Handler waiting notification that (previous) AML program
+ * finished.
+ */
+ struct GNUNET_DB_EventHandler *eh;
+
+ /**
+ * Handle to running AML program.
+ */
+ struct TALER_KYCLOGIC_AmlProgramRunnerHandle *amlh;
+
+ /**
+ * Name of the AML program we were running asynchronously,
+ * for diagnostics.
+ */
+ char *aml_program_name;
+
+ /**
+ * Error hint to return with @e ec.
+ */
+ const char *hint;
+
+ /**
+ * Row the rule set in @a lrs is based on.
+ */
+ uint64_t legitimization_outcome_last_row;
+
+ /**
+ * Taler error code to return.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Counter used to limit recursion depth.
+ */
+ unsigned int depth;
+
+ /**
+ * True if @e account is for a wallet.
+ */
+ bool is_wallet;
+};
+
+
+/**
+ * Function that finally returns the result to the application and cleans
+ * up. Called with an open database transaction on success; on failure, the
+ * transaction will have already been rolled back.
+ *
+ * @param[in,out] ru rule updater to return result for
+ */
+static void
+return_result (struct TALER_EXCHANGEDB_RuleUpdater *ru)
+{
+ struct TALER_EXCHANGEDB_RuleUpdaterResult rur = {
+ .legitimization_outcome_last_row = ru->legitimization_outcome_last_row,
+ .lrs = ru->lrs,
+ .ec = ru->ec,
+ };
+
+ ru->cb (ru->cb_cls,
+ &rur);
+ ru->lrs = NULL;
+ TALER_EXCHANGEDB_begin_rule_update_cancel (ru);
+}
+
+
+/**
+ * Fail the update with the given @a ec and @a hint.
+ * Called with an open database transaction, which will
+ * be rolled back (!).
+ *
+ * @param[in,out] ru account we are processing
+ * @param ec error code to fail with
+ * @param hint hint to return, can be NULL
+ */
+static void
+fail_update (struct TALER_EXCHANGEDB_RuleUpdater *ru,
+ enum TALER_ErrorCode ec,
+ const char *hint)
+{
+ GNUNET_assert (NULL == ru->t);
+ TALER_EXCHANGEDB_rollback (ru->pg);
+ ru->ec = ec;
+ ru->hint = hint;
+ return_result (ru);
+}
+
+
+/**
+ * Check the rules in @a ru to see if they are current, and
+ * if not begin the updating process. Called with an open
+ * database transaction.
+ *
+ * @param[in] ru rule updater context
+ */
+static void
+check_rules (struct TALER_EXCHANGEDB_RuleUpdater *ru);
+
+
+/**
+ * Run the measure @a m in the context of the legitimisation rules
+ * of @a ru. Called with an open database transaction.
+ *
+ * @param ru updating context we are using
+ * @param m measure we need to run next
+ */
+static void
+run_measure (struct TALER_EXCHANGEDB_RuleUpdater *ru,
+ const struct TALER_KYCLOGIC_Measure *m);
+
+
+/**
+ * Function called after AML program was run. Called
+ * without an open database transaction, will start one!
+ *
+ * @param cls the `struct TALER_EXCHANGEDB_RuleUpdater *`
+ * @param apr result of the AML program.
+ */
+static void
+aml_result_callback (
+ void *cls,
+ const struct TALER_KYCLOGIC_AmlProgramResult *apr)
+{
+ struct TALER_EXCHANGEDB_RuleUpdater *ru = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ enum GNUNET_GenericReturnValue res;
+ enum TALER_EXCHANGEDB_PersistProgramResultStatus pprs;
+
+ ru->amlh = NULL;
+ res = TALER_EXCHANGEDB_start (ru->pg,
+ "aml-persist-aml-program-result");
+ if (GNUNET_OK != res)
+ {
+ GNUNET_break (0);
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_START_FAILED,
+ "aml-persist-aml-program-result");
+ return;
+ }
+ /* Update database update based on result */
+ qs = TALER_EXCHANGEDB_do_persist_aml_program_result (
+ ru->pg,
+ 0LLU, /* 0: no existing legitimization process, creates new row */
+ &ru->account,
+ apr,
+ &pprs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "persist_aml_program_result");
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ /* Bad, couldn't persist AML result. Try again... */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Serialization issue persisting result of AML program. Restarting.\n");
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ "persist_aml_program_result");
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* Strange, but let's just continue */
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* normal case */
+ break;
+ }
+ switch (pprs)
+ {
+ case TALER_EXCHANGEDB_PPRS_OK:
+ break;
+ case TALER_EXCHANGEDB_PPRS_BAD_OUTCOME:
+ fail_update (ru,
+ TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT,
+ "persist_aml_program_result");
+ return;
+ }
+ switch (apr->status)
+ {
+ case TALER_KYCLOGIC_AMLR_SUCCESS:
+ TALER_KYCLOGIC_rules_free (ru->lrs);
+ ru->lrs = NULL;
+ ru->lrs = TALER_KYCLOGIC_rules_parse (apr->details.success.new_rules);
+ /* Fall back to default rules on parse error! */
+ GNUNET_break (NULL != ru->lrs);
+ check_rules (ru);
+ return;
+ case TALER_KYCLOGIC_AMLR_FAILURE:
+ {
+ const char *fmn = apr->details.failure.fallback_measure;
+ const struct TALER_KYCLOGIC_Measure *m;
+
+ m = TALER_KYCLOGIC_get_measure (ru->lrs,
+ fmn);
+ if (NULL == m)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Fallback measure `%s' does not exist (anymore?).\n",
+ fmn);
+ TALER_KYCLOGIC_rules_free (ru->lrs);
+ ru->lrs = NULL;
+ return_result (ru);
+ return;
+ }
+ run_measure (ru,
+ m);
+ return;
+ }
+ }
+ /* This should be impossible */
+ GNUNET_assert (0);
+}
+
+
+/**
+ * Entrypoint that fetches the latest rules from the database
+ * and starts processing them. Called without an open database
+ * transaction, will start one.
+ *
+ * @param[in] cls the `struct TALER_EXCHANGEDB_RuleUpdater *` to run
+ */
+static void
+fetch_latest_rules (void *cls);
+
+
+/**
+ * Notification called when we either timeout on the AML program lock
+ * or when the (previous) AML program finished and we can thus try again.
+ *
+ * @param cls the `struct TALER_EXCHANGEDB_RuleUpdater *` to continue
+ * @param extra additional event data provided (unused)
+ * @param extra_size number of bytes in @a extra (unused)
+ */
+static void
+trigger_fetch_latest_rules (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+ struct TALER_EXCHANGEDB_RuleUpdater *ru = cls;
+
+ (void) extra;
+ (void) extra_size;
+ if (NULL != ru->t)
+ return; /* multiple events triggered us, ignore */
+ ru->t = GNUNET_SCHEDULER_add_now (&fetch_latest_rules,
+ ru);
+}
+
+
+static void
+run_measure (struct TALER_EXCHANGEDB_RuleUpdater *ru,
+ const struct TALER_KYCLOGIC_Measure *m)
+{
+ if (NULL == m)
+ {
+ /* fall back to default rules */
+ TALER_KYCLOGIC_rules_free (ru->lrs);
+ ru->lrs = NULL;
+ return_result (ru);
+ return;
+ }
+ ru->depth++;
+ if (ru->depth > MAX_DEPTH)
+ {
+ fail_update (ru,
+ TALER_EC_EXCHANGE_GENERIC_AML_PROGRAM_RECURSION_DETECTED,
+ NULL);
+ return;
+ }
+ if ( (NULL == m->check_name) ||
+ (0 ==
+ strcasecmp ("SKIP",
+ m->check_name)) )
+ {
+ struct TALER_EXCHANGEDB_HistoryBuilderContext hbc = {
+ .account = &ru->account,
+ .is_wallet = ru->is_wallet,
+ .pg = ru->pg,
+ .attribute_key = &ru->attribute_key
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Absolute xlock;
+
+ /* Free previous one, in case we are iterating... */
+ GNUNET_free (ru->aml_program_name);
+ if (NULL != m->prog_name)
+ {
+ ru->aml_program_name = GNUNET_strdup (m->prog_name);
+ }
+ else
+ {
+ /* How do we get to run a measure if the check type
+ is INFO (which is the only case where prog_name
+ is allowed to be NULL?) */
+ GNUNET_break (0);
+ ru->aml_program_name = NULL;
+ }
+ qs = TALER_EXCHANGEDB_update_to_aml_locked (
+ ru->pg,
+ &ru->account,
+ GNUNET_TIME_relative_multiply (ru->pg->max_aml_program_runtime,
+ 2),
+ &xlock);
+ if (qs <= 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ fail_update (ru,
+ GNUNET_DB_STATUS_SOFT_ERROR == qs
+ ? TALER_EC_GENERIC_DB_SOFT_FAILURE
+ : TALER_EC_GENERIC_DB_STORE_FAILED,
+ "set_aml_lock");
+ return;
+ }
+ if (GNUNET_TIME_absolute_is_future (xlock))
+ {
+ struct TALER_EXCHANGEDB_KycCompletedEventP eh = {
+ .header.size = htons (sizeof (eh)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = ru->account
+ };
+ /* Wait for either timeout or notification */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "AML program already running, waiting for it to finish\n");
+ TALER_EXCHANGEDB_rollback (ru->pg);
+ ru->eh
+ = TALER_EXCHANGEDB_event_listen (
+ ru->pg,
+ GNUNET_TIME_absolute_get_remaining (xlock),
+ &eh.header,
+ &trigger_fetch_latest_rules,
+ ru);
+ return;
+ }
+ qs = TALER_EXCHANGEDB_commit (ru->pg);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ fail_update (ru,
+ GNUNET_DB_STATUS_SOFT_ERROR == qs
+ ? TALER_EC_GENERIC_DB_SOFT_FAILURE
+ : TALER_EC_GENERIC_DB_COMMIT_FAILED,
+ "current-aml-rule-fetch");
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Check is of type 'SKIP', running AML program %s.\n",
+ m->prog_name);
+ GNUNET_assert (NULL == ru->t);
+ ru->amlh = TALER_KYCLOGIC_run_aml_program3 (
+ ru->is_wallet,
+ m,
+ &TALER_EXCHANGEDB_current_attributes_builder,
+ &hbc,
+ &TALER_EXCHANGEDB_current_rule_builder,
+ &hbc,
+ &TALER_EXCHANGEDB_aml_history_builder,
+ &hbc,
+ &TALER_EXCHANGEDB_kyc_history_builder,
+ &hbc,
+ ru->pg->max_aml_program_runtime,
+ &aml_result_callback,
+ ru);
+ return;
+ }
+
+ /* User MUST pass interactive check */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Measure %s involves check %s\n",
+ m->measure_name,
+ m->check_name);
+ {
+ /* activate the measure/check */
+ json_t *succ_jmeasures
+ = TALER_KYCLOGIC_get_jmeasures (
+ ru->lrs,
+ m->measure_name);
+ bool unknown_account;
+ struct GNUNET_TIME_Timestamp last_date;
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Inserting LEGI OUTCOME as successor measure\n");
+ qs = TALER_EXCHANGEDB_insert_successor_measure (
+ ru->pg,
+ &ru->account,
+ GNUNET_TIME_timestamp_get (),
+ m->measure_name,
+ succ_jmeasures,
+ &unknown_account,
+ &last_date);
+ json_decref (succ_jmeasures);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ "Serialization issue!\n");
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ "insert_successor_measure");
+ return;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_successor_measure");
+ return;
+ default:
+ break;
+ }
+
+ if (unknown_account)
+ {
+ fail_update (ru,
+ TALER_EC_EXCHANGE_GENERIC_BANK_ACCOUNT_UNKNOWN,
+ NULL);
+ return;
+ }
+ }
+ /* The rules remain these rules until the user passes the check */
+ return_result (ru);
+}
+
+
+/**
+ * Update the expired legitimization rules in @a ru, checking for expiration
+ * first. Called with an open database transaction.
+ *
+ * @param[in,out] ru account we are processing
+ */
+static void
+update_rules (struct TALER_EXCHANGEDB_RuleUpdater *ru)
+{
+ const struct TALER_KYCLOGIC_Measure *m;
+
+ GNUNET_assert (NULL != ru->lrs);
+ GNUNET_assert (GNUNET_TIME_absolute_is_past (
+ TALER_KYCLOGIC_rules_get_expiration (ru->lrs).abs_time));
+ m = TALER_KYCLOGIC_rules_get_successor (ru->lrs);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Successor measure is %s.\n",
+ (NULL != m) ? m->measure_name : "(null)");
+ run_measure (ru,
+ m);
+}
+
+
+static void
+check_rules (struct TALER_EXCHANGEDB_RuleUpdater *ru)
+{
+ ru->depth++;
+ if (ru->depth > MAX_DEPTH)
+ {
+ fail_update (ru,
+ TALER_EC_EXCHANGE_GENERIC_AML_PROGRAM_RECURSION_DETECTED,
+ NULL);
+ return;
+ }
+ if (NULL == ru->lrs)
+ {
+ /* return NULL, aka default rules */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Default rules apply\n");
+ return_result (ru);
+ return;
+ }
+ if (! GNUNET_TIME_absolute_is_past
+ (TALER_KYCLOGIC_rules_get_expiration (ru->lrs).abs_time) )
+ {
+ /* Rules did not expire, return them! */
+ return_result (ru);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Custom rules expired, updating...\n");
+ update_rules (ru);
+}
+
+
+static void
+fetch_latest_rules (void *cls)
+{
+ struct TALER_EXCHANGEDB_RuleUpdater *ru = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ json_t *jnew_rules;
+ enum GNUNET_GenericReturnValue res;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Fetching latest rules.");
+
+ ru->t = NULL;
+ if (NULL != ru->eh)
+ {
+ /* cancel event listener, if we have one */
+ TALER_EXCHANGEDB_event_listen_cancel (ru->pg,
+ ru->eh);
+ ru->eh = NULL;
+ }
+ GNUNET_break (NULL == ru->lrs);
+ res = TALER_EXCHANGEDB_start (ru->pg,
+ "aml-begin-lookup-rules-by-access-token");
+ if (GNUNET_OK != res)
+ {
+ GNUNET_break (0);
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_START_FAILED,
+ "aml-begin-lookup-rules-by-access-token");
+ return;
+ }
+ qs = TALER_EXCHANGEDB_get_rules_by_access_token (
+ ru->pg,
+ &ru->account,
+ &jnew_rules,
+ &ru->legitimization_outcome_last_row);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ fail_update (ru,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "lookup_rules_by_access_token");
+ return;
+ }
+ if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) &&
+ (NULL != jnew_rules) )
+ {
+ ru->lrs = TALER_KYCLOGIC_rules_parse (jnew_rules);
+ GNUNET_break (NULL != ru->lrs);
+ json_decref (jnew_rules);
+ }
+ check_rules (ru);
+}
+
+
+struct TALER_EXCHANGEDB_RuleUpdater *
+TALER_EXCHANGEDB_begin_rule_update (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AttributeEncryptionKeyP *attribute_key,
+ const struct TALER_NormalizedPaytoHashP *account,
+ bool is_wallet,
+ TALER_EXCHANGEDB_CurrentRulesCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGEDB_RuleUpdater *ru;
+
+ ru = GNUNET_new (struct TALER_EXCHANGEDB_RuleUpdater);
+ ru->pg = pg;
+ ru->attribute_key = *attribute_key;
+ ru->account = *account;
+ ru->is_wallet = is_wallet;
+ ru->cb = cb;
+ ru->cb_cls = cb_cls;
+ ru->t = GNUNET_SCHEDULER_add_now (&fetch_latest_rules,
+ ru);
+ return ru;
+}
+
+
+void
+TALER_EXCHANGEDB_begin_rule_update_cancel (
+ struct TALER_EXCHANGEDB_RuleUpdater *ru)
+{
+ if (NULL != ru->t)
+ {
+ GNUNET_SCHEDULER_cancel (ru->t);
+ ru->t = NULL;
+ }
+ if (NULL != ru->amlh)
+ {
+ TALER_KYCLOGIC_run_aml_program_cancel (ru->amlh);
+ ru->amlh = NULL;
+ }
+ if (NULL != ru->lrs)
+ {
+ TALER_KYCLOGIC_rules_free (ru->lrs);
+ ru->lrs = NULL;
+ }
+ if (NULL != ru->eh)
+ {
+ TALER_EXCHANGEDB_event_listen_cancel (ru->pg,
+ ru->eh);
+ ru->eh = NULL;
+ }
+ GNUNET_free (ru->aml_program_name);
+ GNUNET_free (ru);
+}
diff --git a/src/exchangedb/begin_shard.c b/src/exchangedb/begin_shard.c
@@ -63,7 +63,7 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
past = GNUNET_TIME_absolute_get ();
PREPARE (pg,
- "get_open_shard",
+ "begin_shard_open_shard",
"SELECT"
" start_row"
",end_row"
@@ -74,7 +74,7 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
" ORDER BY last_attempt ASC"
" LIMIT 1;");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_open_shard",
+ "begin_shard_open_shard",
params,
rs);
switch (qs)
@@ -102,14 +102,14 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
now = GNUNET_TIME_relative_to_absolute (delay);
PREPARE (pg,
- "reclaim_shard",
+ "begin_shard_reclaim_shard",
"UPDATE work_shards"
" SET last_attempt=$2"
" WHERE job_name=$1"
" AND start_row=$3"
" AND end_row=$4");
qsz = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reclaim_shard",
+ "begin_shard_reclaim_shard",
iparams);
switch (qsz)
{
@@ -150,7 +150,7 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "get_last_shard",
+ "begin_shard_last_shard",
"SELECT"
" end_row"
" FROM work_shards"
@@ -158,7 +158,7 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
" ORDER BY end_row DESC"
" LIMIT 1;");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_last_shard",
+ "begin_shard_last_shard",
params,
rs);
switch (qs)
@@ -200,7 +200,7 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
(unsigned long long) *end_row);
PREPARE (pg,
- "claim_next_shard",
+ "begin_shard_claim_next_shard",
"INSERT INTO work_shards"
"(job_name"
",last_attempt"
@@ -209,7 +209,7 @@ TALER_EXCHANGEDB_begin_shard (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "claim_next_shard",
+ "begin_shard_claim_next_shard",
params);
switch (qs)
{
diff --git a/src/exchangedb/clear_aml_lock.c b/src/exchangedb/clear_aml_lock.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 exchangedb/clear_aml_lock.c
- * @brief Implementation of the clear_aml_lock function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/clear_aml_lock.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_clear_aml_lock (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
-
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "clear_aml_lock",
- "UPDATE kyc_targets"
- " SET aml_program_lock_timeout=NULL"
- " WHERE h_normalized_payto=$1");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "clear_aml_lock",
- params);
-}
diff --git a/src/exchangedb/commit.c b/src/exchangedb/commit.c
@@ -42,10 +42,10 @@ TALER_EXCHANGEDB_commit (struct TALER_EXCHANGEDB_PostgresContext *pg)
"Committing transaction `%s'\n",
pg->transaction_name);
PREPARE (pg,
- "do_commit",
+ "commit",
"COMMIT");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "do_commit",
+ "commit",
params);
pg->transaction_name = NULL;
return qs;
diff --git a/src/exchangedb/count_known_coins.c b/src/exchangedb/count_known_coins.c
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/count_known_coins.c
- * @brief Implementation of the count_known_coins function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/count_known_coins.h"
-#include "helper.h"
-
-long long
-TALER_EXCHANGEDB_count_known_coins (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_DenominationHashP *denom_pub_hash)
-{
- uint64_t count;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("count",
- &count),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
-
- PREPARE (pg,
- "count_known_coins",
- "SELECT"
- " COUNT(*) AS count"
- " FROM known_coins"
- " WHERE denominations_serial="
- " (SELECT denominations_serial"
- " FROM denominations"
- " WHERE denom_pub_hash=$1);");
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "count_known_coins",
- params,
- rs);
- if (0 > qs)
- return (long long) qs;
- return (long long) count;
-}
diff --git a/src/exchangedb/create_aggregation_transient.c b/src/exchangedb/create_aggregation_transient.c
@@ -1,61 +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 exchangedb/create_aggregation_transient.c
- * @brief Implementation of the create_aggregation_transient function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/create_aggregation_transient.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_create_aggregation_transient (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPaytoHashP *h_payto,
- const char *exchange_account_section,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- uint64_t kyc_requirement_row,
- const struct TALER_Amount *total)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (pg->conn,
- total),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
- GNUNET_PQ_query_param_string (exchange_account_section),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "create_aggregation_transient",
- "INSERT INTO aggregation_transient"
- " (amount"
- " ,merchant_pub"
- " ,wire_target_h_payto"
- " ,legitimization_requirement_serial_id"
- " ,exchange_account_section"
- " ,wtid_raw)"
- " VALUES ($1, $2, $3, $4, $5, $6);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "create_aggregation_transient",
- params);
-}
diff --git a/src/exchangedb/disable_rules.c b/src/exchangedb/disable_rules.c
@@ -41,12 +41,12 @@ TALER_EXCHANGEDB_disable_rules (
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "call_exchange_drop_customization",
+ "disable_rules",
"SELECT out_found"
" FROM exchange_drop_customization"
" ($1);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_exchange_drop_customization",
+ "disable_rules",
params,
rs);
if (qs < 0)
diff --git a/src/exchangedb/do_aggregate.c b/src/exchangedb/do_aggregate.c
@@ -0,0 +1,201 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 exchangedb/do_aggregate.c
+ * @brief Implementation of the do_aggregate function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/compute_shard.h"
+#include "exchange-database/do_aggregate.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_aggregate (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_Amount *total)
+{
+ uint64_t deposit_shard = TALER_EXCHANGEDB_compute_shard (merchant_pub);
+ struct GNUNET_TIME_Absolute now = {0};
+ uint64_t sum_deposit_value;
+ uint64_t sum_deposit_frac;
+ uint64_t sum_refund_value;
+ uint64_t sum_refund_frac;
+ uint64_t sum_fee_value;
+ uint64_t sum_fee_frac;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_Amount sum_deposit;
+ struct TALER_Amount sum_refund;
+ struct TALER_Amount sum_fee;
+ struct TALER_Amount delta;
+
+ now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
+ pg->aggregator_shift);
+ PREPARE (pg,
+ "do_aggregate",
+ "WITH bdep AS (" /* restrict to our merchant and account and mark as done */
+ " UPDATE batch_deposits"
+ " SET done=TRUE"
+ " WHERE NOT (done OR policy_blocked)" /* only actually executable deposits */
+ " AND refund_deadline<$1"
+ " AND shard=$5" /* only for efficiency, merchant_pub is what we really filter by */
+ " AND merchant_pub=$2" /* filter by target merchant */
+ " AND wire_target_h_payto=$3" /* merchant could have a 2nd bank account */
+ " RETURNING"
+ " batch_deposit_serial_id)"
+ " ,cdep AS ("
+ " SELECT"
+ " coin_deposit_serial_id"
+ " ,batch_deposit_serial_id"
+ " ,coin_pub"
+ " ,amount_with_fee AS amount"
+ " FROM coin_deposits"
+ " WHERE batch_deposit_serial_id IN (SELECT batch_deposit_serial_id FROM bdep))"
+ " ,ref AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
+ " SELECT"
+ " amount_with_fee AS refund"
+ " ,coin_pub"
+ " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
+ " FROM refunds"
+ " WHERE coin_pub IN (SELECT coin_pub FROM cdep)"
+ " AND batch_deposit_serial_id IN (SELECT batch_deposit_serial_id FROM bdep))"
+ " ,ref_by_coin AS (" /* total up refunds by coin */
+ " SELECT"
+ " SUM((ref.refund).val) AS sum_refund_val"
+ " ,SUM((ref.refund).frac) AS sum_refund_frac"
+ " ,coin_pub"
+ " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
+ " FROM ref"
+ " GROUP BY coin_pub, batch_deposit_serial_id)"
+ " ,norm_ref_by_coin AS (" /* normalize */
+ " SELECT"
+ " sum_refund_val + sum_refund_frac / 100000000 AS norm_refund_val"
+ " ,sum_refund_frac % 100000000 AS norm_refund_frac"
+ " ,coin_pub"
+ " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
+ " FROM ref_by_coin)"
+ " ,fully_refunded_coins AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
+ " SELECT"
+ " cdep.coin_pub"
+ " FROM norm_ref_by_coin norm"
+ " JOIN cdep"
+ " ON (norm.coin_pub = cdep.coin_pub"
+ " AND norm.batch_deposit_serial_id = cdep.batch_deposit_serial_id"
+ " AND norm.norm_refund_val = (cdep.amount).val"
+ " AND norm.norm_refund_frac = (cdep.amount).frac))"
+ " ,fees AS (" /* find deposit fees for not fully refunded deposits */
+ " SELECT"
+ " denom.fee_deposit AS fee"
+ " ,cs.batch_deposit_serial_id" /* ensures we get the fee for each coin, not once per denomination */
+ " FROM cdep cs"
+ " JOIN known_coins kc" /* NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE coin_pub NOT IN (SELECT coin_pub FROM fully_refunded_coins))"
+ " ,dummy AS (" /* add deposits to aggregation_tracking */
+ " INSERT INTO aggregation_tracking"
+ " (batch_deposit_serial_id"
+ " ,wtid_raw)"
+ " SELECT batch_deposit_serial_id,$4"
+ " FROM bdep)"
+ "SELECT" /* calculate totals (deposits, refunds and fees) */
+ " CAST(COALESCE(SUM((cdep.amount).val),0) AS INT8) AS sum_deposit_value"
+ /* cast needed, otherwise we get NUMBER */
+ " ,COALESCE(SUM((cdep.amount).frac),0) AS sum_deposit_fraction" /* SUM over INT returns INT8 */
+ " ,CAST(COALESCE(SUM((ref.refund).val),0) AS INT8) AS sum_refund_value"
+ " ,COALESCE(SUM((ref.refund).frac),0) AS sum_refund_fraction"
+ " ,CAST(COALESCE(SUM((fees.fee).val),0) AS INT8) AS sum_fee_value"
+ " ,COALESCE(SUM((fees.fee).frac),0) AS sum_fee_fraction"
+ " FROM cdep "
+ " FULL OUTER JOIN ref ON (FALSE)" /* We just want all sums */
+ " FULL OUTER JOIN fees ON (FALSE);");
+
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_uint64 (&deposit_shard),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("sum_deposit_value",
+ &sum_deposit_value),
+ GNUNET_PQ_result_spec_uint64 ("sum_deposit_fraction",
+ &sum_deposit_frac),
+ GNUNET_PQ_result_spec_uint64 ("sum_refund_value",
+ &sum_refund_value),
+ GNUNET_PQ_result_spec_uint64 ("sum_refund_fraction",
+ &sum_refund_frac),
+ GNUNET_PQ_result_spec_uint64 ("sum_fee_value",
+ &sum_fee_value),
+ GNUNET_PQ_result_spec_uint64 ("sum_fee_fraction",
+ &sum_fee_frac),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_aggregate",
+ params,
+ rs);
+ }
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ total));
+ return qs;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &sum_deposit));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &sum_refund));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &sum_fee));
+ sum_deposit.value = sum_deposit_frac / TALER_AMOUNT_FRAC_BASE
+ + sum_deposit_value;
+ sum_deposit.fraction = sum_deposit_frac % TALER_AMOUNT_FRAC_BASE;
+ sum_refund.value = sum_refund_frac / TALER_AMOUNT_FRAC_BASE
+ + sum_refund_value;
+ sum_refund.fraction = sum_refund_frac % TALER_AMOUNT_FRAC_BASE;
+ sum_fee.value = sum_fee_frac / TALER_AMOUNT_FRAC_BASE
+ + sum_fee_value;
+ sum_fee.fraction = sum_fee_frac % TALER_AMOUNT_FRAC_BASE; \
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (&delta,
+ &sum_deposit,
+ &sum_refund));
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (total,
+ &delta,
+ &sum_fee));
+ return qs;
+}
diff --git a/src/exchangedb/do_check_deposit_idempotent.c b/src/exchangedb/do_check_deposit_idempotent.c
@@ -94,14 +94,14 @@ TALER_EXCHANGEDB_do_check_deposit_idempotent (
TALER_B2S (&cdi->coin.coin_pub));
}
PREPARE (pg,
- "call_check_deposit_idempotent",
+ "do_check_deposit_idempotent",
"SELECT "
" out_exchange_timestamp AS exchange_timestamp"
",out_is_idempotent AS is_idempotent"
" FROM exchange_do_check_deposit_idempotent"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_check_deposit_idempotent",
+ "do_check_deposit_idempotent",
params,
rs);
GNUNET_PQ_cleanup_query_params_closures (params);
diff --git a/src/exchangedb/do_deposit.c b/src/exchangedb/do_deposit.c
@@ -148,7 +148,7 @@ TALER_EXCHANGEDB_do_deposit (
TALER_B2S (&cdi->coin.coin_pub));
}
PREPARE (pg,
- "call_deposit",
+ "do_deposit",
"SELECT "
" out_exchange_timestamp AS exchange_timestamp"
",out_accumulated_total_without_fee AS accumulated_total_without_fee"
@@ -159,7 +159,7 @@ TALER_EXCHANGEDB_do_deposit (
",$11,$12,$13,$14,$15,$16,$17,$18,$19,$20"
",$21,$22,$23);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_deposit",
+ "do_deposit",
params,
rs);
GNUNET_PQ_cleanup_query_params_closures (params);
diff --git a/src/exchangedb/do_drain_kyc_alert.c b/src/exchangedb/do_drain_kyc_alert.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/do_drain_kyc_alert.c
+ * @brief Implementation of the do_drain_kyc_alert function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/do_drain_kyc_alert.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_drain_kyc_alert (struct TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ uint32_t trigger_type,
+ struct TALER_NormalizedPaytoHashP *h_payto)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint32 (&trigger_type),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "do_drain_kyc_alert",
+ "DELETE FROM kyc_alerts"
+ " WHERE trigger_type=$1"
+ " AND h_payto = "
+ " (SELECT h_payto "
+ " FROM kyc_alerts"
+ " WHERE trigger_type=$1"
+ " LIMIT 1)"
+ " RETURNING h_payto;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_drain_kyc_alert",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/do_expire_purse.c b/src/exchangedb/do_expire_purse.c
@@ -0,0 +1,65 @@
+/*
+ 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 exchangedb/do_expire_purse.c
+ * @brief Implementation of the do_expire_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/do_expire_purse.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_expire_purse (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct GNUNET_TIME_Absolute start_time,
+ struct GNUNET_TIME_Absolute end_time)
+{
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&start_time),
+ GNUNET_PQ_query_param_absolute_time (&end_time),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ bool found = false;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("found",
+ &found),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "do_expire_purse",
+ "SELECT "
+ " out_found AS found"
+ " FROM exchange_do_expire_purse"
+ " ($1,$2,$3);");
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_expire_purse",
+ params,
+ rs);
+ if (qs < 0)
+ return qs;
+ GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
+ return found
+ ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+ : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+}
diff --git a/src/exchangedb/expire_purse.sql b/src/exchangedb/do_expire_purse.sql
diff --git a/src/exchangedb/do_insert_known_coin.c b/src/exchangedb/do_insert_known_coin.c
@@ -0,0 +1,166 @@
+/*
+ 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 exchangedb/do_insert_known_coin.c
+ * @brief Implementation of the do_insert_known_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#include "exchangedb_lib.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/do_insert_known_coin.h"
+#include "helper.h"
+
+
+enum TALER_EXCHANGEDB_CoinKnownStatus
+TALER_EXCHANGEDB_do_insert_known_coin (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_CoinPublicInfo *coin,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *denom_hash,
+ struct TALER_AgeCommitmentHashP *h_age_commitment)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ bool existed;
+ bool no_denom_pub_hash;
+ bool no_age_commitment_hash;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin->denom_pub_hash),
+ coin->no_age_commitment
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (&coin->h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin->denom_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("existed",
+ &existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id",
+ known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ denom_hash),
+ &no_denom_pub_hash),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ h_age_commitment),
+ &no_age_commitment_hash),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /*
+ See also:
+ https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/37543015#37543015
+ */
+ PREPARE (pg,
+ "do_insert_known_coin",
+ "WITH dd"
+ " (denominations_serial"
+ " ,coin"
+ " ) AS ("
+ " SELECT "
+ " denominations_serial"
+ " ,coin"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$2"
+ " ), input_rows"
+ " (coin_pub) AS ("
+ " VALUES ($1::BYTEA)"
+ " ), ins AS ("
+ " INSERT INTO known_coins "
+ " (coin_pub"
+ " ,denominations_serial"
+ " ,age_commitment_hash"
+ " ,denom_sig"
+ " ,remaining"
+ " ) SELECT "
+ " $1"
+ " ,denominations_serial"
+ " ,$3"
+ " ,$4"
+ " ,coin"
+ " FROM dd"
+ " ON CONFLICT DO NOTHING" /* CONFLICT on (coin_pub) */
+ " RETURNING "
+ " known_coin_id"
+ " ) "
+ "SELECT "
+ " FALSE AS existed"
+ " ,known_coin_id"
+ " ,NULL AS denom_pub_hash"
+ " ,NULL AS age_commitment_hash"
+ " FROM ins "
+ "UNION ALL "
+ "SELECT "
+ " TRUE AS existed"
+ " ,known_coin_id"
+ " ,denom_pub_hash"
+ " ,kc.age_commitment_hash"
+ " FROM input_rows"
+ " JOIN known_coins kc USING (coin_pub)"
+ " JOIN denominations USING (denominations_serial)"
+ " LIMIT 1");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_insert_known_coin",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return TALER_EXCHANGEDB_CKS_HARD_FAIL;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return TALER_EXCHANGEDB_CKS_SOFT_FAIL;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* should be impossible */
+ return TALER_EXCHANGEDB_CKS_HARD_FAIL;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ if (! existed)
+ return TALER_EXCHANGEDB_CKS_ADDED;
+ break; /* continued below */
+ }
+
+ if ( (! no_denom_pub_hash) &&
+ (0 != GNUNET_memcmp (denom_hash,
+ &coin->denom_pub_hash)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_DENOM_CONFLICT;
+ }
+
+ if (no_age_commitment_hash != coin->no_age_commitment)
+ {
+ if (no_age_commitment_hash)
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL;
+ }
+ else
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL;
+ }
+ }
+ else if ( (! no_age_commitment_hash) &&
+ (0 != GNUNET_memcmp (h_age_commitment,
+ &coin->h_age_commitment)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS;
+ }
+
+ return TALER_EXCHANGEDB_CKS_PRESENT;
+}
diff --git a/src/exchangedb/do_insert_kyc_attributes.c b/src/exchangedb/do_insert_kyc_attributes.c
@@ -0,0 +1,103 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/do_insert_kyc_attributes.c
+ * @brief Implementation of the do_insert_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/do_insert_kyc_attributes.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_insert_kyc_attributes (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t process_row,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_name,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ uint32_t birthday,
+ struct GNUNET_TIME_Absolute expiration_time,
+ const char *form_name,
+ size_t enc_attributes_size,
+ const void *enc_attributes)
+{
+ struct GNUNET_TIME_Timestamp collection_time
+ = GNUNET_TIME_timestamp_get ();
+ struct GNUNET_TIME_Timestamp expiration
+ = GNUNET_TIME_absolute_to_timestamp (expiration_time);
+ struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ char *kyc_completed_notify_s
+ = GNUNET_PQ_get_event_notify_channel (&rep.header);
+ struct GNUNET_PQ_QueryParam params[] = {
+ (0 == process_row)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (&process_row),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint32 (&birthday),
+ GNUNET_PQ_query_param_string (provider_name),
+ (NULL == provider_account_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (provider_account_id),
+ (NULL == provider_legitimization_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (provider_legitimization_id),
+ GNUNET_PQ_query_param_timestamp (&collection_time),
+ GNUNET_PQ_query_param_absolute_time (&expiration_time),
+ GNUNET_PQ_query_param_timestamp (&expiration),
+ (NULL == enc_attributes)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_fixed_size (enc_attributes,
+ enc_attributes_size),
+ GNUNET_PQ_query_param_string (kyc_completed_notify_s),
+ (NULL == form_name)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (form_name),
+ GNUNET_PQ_query_param_end
+ };
+ bool ok;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("out_ok",
+ &ok),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Inserting KYC attributes, wake up on %s\n",
+ kyc_completed_notify_s);
+ GNUNET_break (NULL != h_payto);
+ PREPARE (pg,
+ "do_insert_kyc_attributes",
+ "SELECT "
+ " out_ok"
+ " FROM exchange_do_persist_kyc_attributes "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_insert_kyc_attributes",
+ params,
+ rs);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ GNUNET_free (kyc_completed_notify_s);
+ GNUNET_PQ_event_do_poll (pg->conn);
+ return qs;
+}
diff --git a/src/exchangedb/persist_kyc_attributes.sql b/src/exchangedb/do_insert_kyc_attributes.sql
diff --git a/src/exchangedb/do_insert_reserve_in.c b/src/exchangedb/do_insert_reserve_in.c
@@ -0,0 +1,374 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/do_insert_reserve_in.c
+ * @brief Implementation of the do_insert_reserve_in function for Postgres
+ * @author Christian Grothoff
+ * @author Joseph Xu
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/do_insert_reserve_in.h"
+#include "helper.h"
+#include "exchange-database/start.h"
+#include "exchange-database/start_read_committed.h"
+#include "exchange-database/commit.h"
+#include "exchange-database/preflight.h"
+#include "exchange-database/rollback.h"
+
+
+/**
+ * Generate event notification for the reserve change.
+ *
+ * @param reserve_pub reserve to notfiy on
+ * @return string to pass to postgres for the notification
+ */
+static char *
+compute_notify_on_reserve (const struct TALER_ReservePublicKeyP *reserve_pub)
+{
+ struct TALER_EXCHANGEDB_ReserveEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING),
+ .reserve_pub = *reserve_pub
+ };
+
+ return GNUNET_PQ_get_event_notify_channel (&rep.header);
+}
+
+
+/**
+ * Closure for our helper_cb()
+ */
+struct Context
+{
+ /**
+ * Array of reserve UUIDs to initialize.
+ */
+ uint64_t *reserve_uuids;
+
+ /**
+ * Array with entries set to 'true' for duplicate transactions.
+ */
+ bool *transaction_duplicates;
+
+ /**
+ * Array with entries set to 'true' for rows with conflicts.
+ */
+ bool *conflicts;
+
+ /**
+ * Set to #GNUNET_SYSERR on failures.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+ /**
+ * Single value (no array) set to true if we need
+ * to follow-up with an update.
+ */
+ bool needs_update;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct Context *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct Context *ctx = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool (
+ "transaction_duplicate",
+ &ctx->transaction_duplicates[i]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("ruuid",
+ &ctx->reserve_uuids[i]),
+ &ctx->conflicts[i]),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (! ctx->transaction_duplicates[i])
+ ctx->needs_update |= ctx->conflicts[i];
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_insert_reserve_in (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_EXCHANGEDB_ReserveInInfo *reserves,
+ unsigned int reserves_length,
+ enum GNUNET_DB_QueryStatus *results)
+{
+ unsigned int dups = 0;
+
+ struct TALER_FullPaytoHashP h_full_paytos[
+ GNUNET_NZL (reserves_length)];
+ struct TALER_NormalizedPaytoHashP h_normalized_paytos[
+ GNUNET_NZL (reserves_length)];
+ char *notify_s[GNUNET_NZL (reserves_length)];
+ struct TALER_ReservePublicKeyP reserve_pubs[GNUNET_NZL (reserves_length)];
+ struct TALER_Amount balances[GNUNET_NZL (reserves_length)];
+ struct GNUNET_TIME_Timestamp execution_times[GNUNET_NZL (reserves_length)];
+ const char *sender_account_details[GNUNET_NZL (reserves_length)];
+ const char *exchange_account_names[GNUNET_NZL (reserves_length)];
+ uint64_t wire_references[GNUNET_NZL (reserves_length)];
+ uint64_t reserve_uuids[GNUNET_NZL (reserves_length)];
+ bool transaction_duplicates[GNUNET_NZL (reserves_length)];
+ bool conflicts[GNUNET_NZL (reserves_length)];
+ struct GNUNET_TIME_Timestamp reserve_expiration
+ = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
+ struct GNUNET_TIME_Timestamp gc
+ = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
+ enum GNUNET_DB_QueryStatus qs;
+ bool need_update;
+
+ for (unsigned int i = 0; i<reserves_length; i++)
+ {
+ const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i];
+
+ TALER_full_payto_hash (reserve->sender_account_details,
+ &h_full_paytos[i]);
+ TALER_full_payto_normalize_and_hash (reserve->sender_account_details,
+ &h_normalized_paytos[i]);
+ notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub);
+ reserve_pubs[i] = *reserve->reserve_pub;
+ balances[i] = *reserve->balance;
+ execution_times[i] = reserve->execution_time;
+ sender_account_details[i] = reserve->sender_account_details.full_payto;
+ exchange_account_names[i] = reserve->exchange_account_name;
+ wire_references[i] = reserve->wire_reference;
+ }
+
+ /* NOTE: kind-of pointless to explicitly start a transaction here... */
+ if (GNUNET_OK !=
+ TALER_EXCHANGEDB_preflight (pg))
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto finished;
+ }
+ if (GNUNET_OK !=
+ TALER_EXCHANGEDB_start_read_committed (pg,
+ "READ_COMMITED"))
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto finished;
+ }
+ PREPARE (pg,
+ "do_insert_reserve_in_reserves_insert_with_array",
+ "SELECT"
+ " transaction_duplicate"
+ ",ruuid"
+ " FROM exchange_do_array_reserves_insert"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);");
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&gc),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_array_auto_from_type (reserves_length,
+ reserve_pubs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (reserves_length,
+ wire_references,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (
+ reserves_length,
+ balances,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_string (
+ reserves_length,
+ (const char **) exchange_account_names,
+ pg->conn),
+ GNUNET_PQ_query_param_array_timestamp (
+ reserves_length,
+ execution_times,
+ pg->conn),
+ GNUNET_PQ_query_param_array_auto_from_type (
+ reserves_length,
+ h_full_paytos,
+ pg->conn),
+ GNUNET_PQ_query_param_array_auto_from_type (
+ reserves_length,
+ h_normalized_paytos,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_string (
+ reserves_length,
+ (const char **) sender_account_details,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_string (
+ reserves_length,
+ (const char **) notify_s,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct Context ctx = {
+ .reserve_uuids = reserve_uuids,
+ .transaction_duplicates = transaction_duplicates,
+ .conflicts = conflicts,
+ .needs_update = false,
+ .status = GNUNET_OK
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "do_insert_reserve_in_reserves_insert_with_array",
+ params,
+ &helper_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if ( (qs < 0) ||
+ (GNUNET_OK != ctx.status) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to insert into reserves (%d)\n",
+ qs);
+ goto finished;
+ }
+ need_update = ctx.needs_update;
+ }
+
+ {
+ enum GNUNET_DB_QueryStatus cs;
+
+ cs = TALER_EXCHANGEDB_commit (pg);
+ if (cs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to commit\n");
+ qs = cs;
+ goto finished;
+ }
+ }
+
+ for (unsigned int i = 0; i<reserves_length; i++)
+ {
+ if (transaction_duplicates[i])
+ dups++;
+ results[i] = transaction_duplicates[i]
+ ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+
+ if (! need_update)
+ {
+ qs = reserves_length;
+ goto finished;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reserve update needed for some reserves in the batch\n");
+ PREPARE (pg,
+ "do_insert_reserve_in_reserves_update",
+ "SELECT"
+ " out_duplicate AS duplicate "
+ "FROM exchange_do_batch_reserves_update"
+ " ($1,$2,$3,$4,$5,$6,$7);");
+
+ if (GNUNET_OK !=
+ TALER_EXCHANGEDB_start (pg,
+ "reserve-insert-continued"))
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto finished;
+ }
+
+ for (unsigned int i = 0; i<reserves_length; i++)
+ {
+ if (transaction_duplicates[i])
+ continue;
+ if (! conflicts[i])
+ continue;
+ {
+ bool duplicate;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&reserve_pubs[i]),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_uint64 (&wire_references[i]),
+ TALER_PQ_query_param_amount (pg->conn,
+ &balances[i]),
+ GNUNET_PQ_query_param_string (exchange_account_names[i]),
+ GNUNET_PQ_query_param_auto_from_type (&h_full_paytos[i]),
+ GNUNET_PQ_query_param_string (notify_s[i]),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("duplicate",
+ &duplicate),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qsi;
+
+ qsi = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_insert_reserve_in_reserves_update",
+ params,
+ rs);
+ if (qsi < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to update reserves (%d)\n",
+ qsi);
+ results[i] = qsi;
+ goto finished;
+ }
+ results[i] = duplicate
+ ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ }
+ {
+ enum GNUNET_DB_QueryStatus cs;
+
+ cs = TALER_EXCHANGEDB_commit (pg);
+ if (cs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to commit\n");
+ qs = cs;
+ goto finished;
+ }
+ }
+finished:
+ for (unsigned int i = 0; i<reserves_length; i++)
+ GNUNET_free (notify_s[i]);
+ if (qs < 0)
+ return qs;
+ GNUNET_PQ_event_do_poll (pg->conn);
+ if (0 != dups)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%u/%u duplicates among incoming transactions. Try increasing WIREWATCH_IDLE_SLEEP_INTERVAL in the [exchange] configuration section (if this happens a lot).\n",
+ dups,
+ reserves_length);
+ return qs;
+}
diff --git a/src/exchangedb/reserves_in_insert.sql b/src/exchangedb/do_insert_reserve_in.sql
diff --git a/src/exchangedb/do_persist_aml_program_result.c b/src/exchangedb/do_persist_aml_program_result.c
@@ -0,0 +1,154 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file do_persist_aml_program_result.c
+ * @brief helper function store results of AML programs
+ * @author Christian Grothoff
+ */
+#include "exchangedb_lib.h"
+#include "taler/taler_kyclogic_lib.h"
+#include "exchange-database/insert_aml_decision.h"
+#include "exchange-database/insert_aml_program_failure.h"
+#include "exchange-database/insert_successor_measure.h"
+#include "exchange-database/do_persist_aml_program_result.h"
+#include "helper.h"
+#include <gnunet/gnunet_common.h>
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_persist_aml_program_result (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t process_row,
+ const struct TALER_NormalizedPaytoHashP *account_id,
+ const struct TALER_KYCLOGIC_AmlProgramResult *apr,
+ enum TALER_EXCHANGEDB_PersistProgramResultStatus *ret_pprs)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ json_t *jmeasures = NULL;
+ struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs = NULL;
+
+ GNUNET_assert (NULL != ret_pprs);
+
+ *ret_pprs = TALER_EXCHANGEDB_PPRS_OK;
+
+ if ( (TALER_KYCLOGIC_AMLR_SUCCESS == apr->status) &&
+ (NULL != apr->details.success.new_measures) )
+ {
+ lrs = TALER_KYCLOGIC_rules_parse (apr->details.success.new_rules);
+ if (NULL == lrs)
+ {
+ qs = TALER_EXCHANGEDB_insert_aml_program_failure (
+ pg,
+ process_row,
+ account_id,
+ "Failed to parse AML program output",
+ TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT);
+ GNUNET_break (qs > 0);
+ return qs;
+ }
+ jmeasures = TALER_KYCLOGIC_get_jmeasures (
+ lrs,
+ apr->details.success.new_measures);
+ if (NULL == jmeasures)
+ {
+ char *err;
+
+ GNUNET_break (0);
+ GNUNET_asprintf (&err,
+ "Failed to find measures `%s' specified in AML program output",
+ apr->details.success.new_measures);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "AML program specified invalid measures `%s'\n",
+ apr->details.success.new_measures);
+ qs = TALER_EXCHANGEDB_insert_aml_program_failure (
+ pg,
+ process_row,
+ account_id,
+ err,
+ TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT);
+ *ret_pprs = TALER_EXCHANGEDB_PPRS_BAD_OUTCOME;
+ TALER_KYCLOGIC_rules_free (lrs);
+ GNUNET_free (err);
+ GNUNET_break (qs > 0);
+ return qs;
+ }
+ }
+
+ qs = TALER_EXCHANGEDB_update_to_aml_unlocked (
+ pg,
+ account_id);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ switch (apr->status)
+ {
+ case TALER_KYCLOGIC_AMLR_FAILURE:
+ qs = TALER_EXCHANGEDB_insert_aml_program_failure (
+ pg,
+ process_row,
+ account_id,
+ apr->details.failure.error_message,
+ apr->details.failure.ec);
+ GNUNET_break (qs > 0);
+ goto cleanup;
+ case TALER_KYCLOGIC_AMLR_SUCCESS:
+ {
+ struct TALER_FullPayto null_payto_uri = { 0 };
+ bool invalid_officer;
+ bool unknown_account;
+ struct GNUNET_TIME_Timestamp last_date;
+ uint64_t legitimization_measure_serial_id;
+ bool is_wallet;
+
+ qs = TALER_EXCHANGEDB_insert_aml_decision (
+ pg,
+ null_payto_uri,
+ account_id,
+ GNUNET_TIME_timestamp_get (),
+ apr->details.success.expiration_time,
+ apr->details.success.account_properties,
+ apr->details.success.new_rules,
+ apr->details.success.to_investigate,
+ apr->details.success.new_measures,
+ jmeasures,
+ NULL, /* justification */
+ NULL, /* decider_pub */
+ NULL, /* decider_sig */
+ apr->details.success.num_events,
+ apr->details.success.events,
+ NULL, /* form ID */
+ 0, /* enc_attributes_size*/
+ NULL, /* enc_attributes*/
+ NULL, /* attributes_hash */
+ GNUNET_TIME_UNIT_ZERO_TS, /* attributes_expiration_time */
+ &invalid_officer,
+ &unknown_account,
+ &last_date,
+ &legitimization_measure_serial_id,
+ &is_wallet);
+ GNUNET_break (qs > 0);
+ goto cleanup;
+ }
+ }
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+cleanup:
+ TALER_KYCLOGIC_rules_free (lrs);
+ json_decref (jmeasures);
+ return qs;
+}
diff --git a/src/exchangedb/do_purse_delete.c b/src/exchangedb/do_purse_delete.c
@@ -47,14 +47,14 @@ TALER_EXCHANGEDB_do_purse_delete (
};
PREPARE (pg,
- "call_purse_delete",
+ "do_purse_delete",
"SELECT "
" out_decided AS decided"
",out_found AS found"
" FROM exchange_do_purse_delete"
" ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_purse_delete",
+ "do_purse_delete",
params,
rs);
}
diff --git a/src/exchangedb/do_purse_deposit.c b/src/exchangedb/do_purse_deposit.c
@@ -71,7 +71,7 @@ TALER_EXCHANGEDB_do_purse_deposit (
pg->legal_reserve_expiration_time));
PREPARE (pg,
- "call_purse_deposit",
+ "do_purse_deposit",
"SELECT "
" out_balance_ok AS balance_ok"
",out_conflict AS conflict"
@@ -80,7 +80,7 @@ TALER_EXCHANGEDB_do_purse_deposit (
" ($1,$2,$3,$4,$5,$6,$7,$8);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_purse_deposit",
+ "do_purse_deposit",
params,
rs);
}
diff --git a/src/exchangedb/do_purse_merge.c b/src/exchangedb/do_purse_merge.c
@@ -72,7 +72,7 @@ TALER_EXCHANGEDB_do_purse_merge (
GNUNET_free (payto_uri.normalized_payto);
}
PREPARE (pg,
- "call_purse_merge",
+ "do_purse_merge",
"SELECT"
" out_no_partner AS no_partner"
",out_no_balance AS no_balance"
@@ -81,7 +81,7 @@ TALER_EXCHANGEDB_do_purse_merge (
" ($1, $2, $3, $4, $5, $6, $7, $8);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_purse_merge",
+ "do_purse_merge",
params,
rs);
}
diff --git a/src/exchangedb/do_recoup.c b/src/exchangedb/do_recoup.c
@@ -67,7 +67,7 @@ TALER_EXCHANGEDB_do_recoup (
PREPARE (pg,
- "call_recoup",
+ "do_recoup",
"SELECT "
" out_recoup_timestamp AS recoup_timestamp"
",out_recoup_ok AS recoup_ok"
@@ -75,7 +75,7 @@ TALER_EXCHANGEDB_do_recoup (
" FROM exchange_do_recoup_to_reserve"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_recoup",
+ "do_recoup",
params,
rs);
}
diff --git a/src/exchangedb/do_recoup_refresh.c b/src/exchangedb/do_recoup_refresh.c
@@ -24,7 +24,7 @@
#include "helper.h"
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_do_recoup_refresh (
+TALER_EXCHANGEDB_do_recoup_refresh (
struct TALER_EXCHANGEDB_PostgresContext *pg,
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
uint64_t refresh_id,
@@ -61,7 +61,7 @@ TALER_TALER_EXCHANGEDB_do_recoup_refresh (
PREPARE (pg,
- "call_recoup_refresh",
+ "do_recoup_refresh",
"SELECT "
" out_recoup_timestamp AS recoup_timestamp"
",out_recoup_ok AS recoup_ok"
@@ -70,7 +70,7 @@ TALER_TALER_EXCHANGEDB_do_recoup_refresh (
" ($1,$2,$3,$4,$5,$6,$7);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_recoup_refresh",
+ "do_recoup_refresh",
params,
rs);
}
diff --git a/src/exchangedb/do_refresh.c b/src/exchangedb/do_refresh.c
@@ -99,7 +99,7 @@ TALER_EXCHANGEDB_do_refresh (
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "call_refresh",
+ "do_refresh",
"SELECT "
" out_coin_found AS coin_found"
",out_balance_ok AS balance_ok"
@@ -111,7 +111,7 @@ TALER_EXCHANGEDB_do_refresh (
" FROM exchange_do_refresh"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_refresh",
+ "do_refresh",
params,
rs);
GNUNET_PQ_cleanup_query_params_closures (params);
diff --git a/src/exchangedb/do_refund.c b/src/exchangedb/do_refund.c
@@ -76,7 +76,7 @@ TALER_EXCHANGEDB_do_refund (
return GNUNET_DB_STATUS_HARD_ERROR;
}
PREPARE (pg,
- "call_refund",
+ "do_refund",
"SELECT "
" out_not_found AS not_found"
",out_refund_ok AS refund_ok"
@@ -85,7 +85,7 @@ TALER_EXCHANGEDB_do_refund (
" FROM exchange_do_refund"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_refund",
+ "do_refund",
params,
rs);
}
diff --git a/src/exchangedb/do_reserve_purse.c b/src/exchangedb/do_reserve_purse.c
@@ -103,7 +103,7 @@ TALER_EXCHANGEDB_do_reserve_purse (
TALER_amount_set_zero (pg->currency,
&zero_fee));
PREPARE (pg,
- "call_reserve_purse",
+ "do_reserve_purse",
"SELECT"
" out_no_funds AS insufficient_funds"
",out_no_reserve AS no_reserve"
@@ -112,7 +112,7 @@ TALER_EXCHANGEDB_do_reserve_purse (
" ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_reserve_purse",
+ "do_reserve_purse",
params,
rs);
}
diff --git a/src/exchangedb/do_trigger_kyc_rule_for_account.c b/src/exchangedb/do_trigger_kyc_rule_for_account.c
@@ -0,0 +1,98 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/do_trigger_kyc_rule_for_account.c
+ * @brief Implementation of the do_trigger_kyc_rule_for_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/do_trigger_kyc_rule_for_account.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPayto payto_uri,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const union TALER_AccountPublicKeyP *set_account_pub,
+ const struct TALER_MerchantPublicKeyP *check_merchant_pub,
+ const json_t *jmeasures,
+ uint32_t display_priority,
+ uint64_t *requirement_row,
+ bool *bad_kyc_auth)
+{
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ char *notify_str
+ = GNUNET_PQ_get_event_notify_channel (&rep.header);
+ struct TALER_FullPaytoHashP h_full_payto;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ NULL == set_account_pub
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (set_account_pub),
+ NULL == check_merchant_pub
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (check_merchant_pub),
+ NULL == payto_uri.full_payto
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (payto_uri.full_payto),
+ NULL == payto_uri.full_payto
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ TALER_PQ_query_param_json (jmeasures),
+ GNUNET_PQ_query_param_uint32 (&display_priority),
+ GNUNET_PQ_query_param_string (notify_str),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "legitimization_measure_serial_id",
+ requirement_row),
+ GNUNET_PQ_result_spec_bool (
+ "bad_kyc_auth",
+ bad_kyc_auth),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "do_trigger_kyc_rule_for_account",
+ "SELECT"
+ " out_legitimization_measure_serial_id"
+ " AS legitimization_measure_serial_id"
+ " ,out_bad_kyc_auth"
+ " AS bad_kyc_auth"
+ " FROM exchange_do_trigger_kyc_rule_for_account"
+ "($1, $2, $3, $4, $5, $6, $7::TEXT::JSONB, $8, $9);");
+ if (NULL != payto_uri.full_payto)
+ TALER_full_payto_hash (payto_uri,
+ &h_full_payto);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "do_trigger_kyc_rule_for_account",
+ params,
+ rs);
+ GNUNET_free (notify_str);
+ return qs;
+}
diff --git a/src/exchangedb/trigger_kyc_rule_for_account.sql b/src/exchangedb/do_trigger_kyc_rule_for_account.sql
diff --git a/src/exchangedb/do_withdraw.c b/src/exchangedb/do_withdraw.c
@@ -110,7 +110,7 @@ TALER_EXCHANGEDB_do_withdraw (
GNUNET_TIME_absolute_add (timestamp->abs_time,
pg->legal_reserve_expiration_time));
PREPARE (pg,
- "call_withdraw",
+ "do_withdraw",
"SELECT "
" out_reserve_found"
",out_balance_ok"
@@ -124,7 +124,7 @@ TALER_EXCHANGEDB_do_withdraw (
" FROM exchange_do_withdraw"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_withdraw",
+ "do_withdraw",
params,
rs);
GNUNET_PQ_cleanup_query_params_closures (params);
diff --git a/src/exchangedb/drain_kyc_alert.c b/src/exchangedb/drain_kyc_alert.c
@@ -1,55 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/drain_kyc_alert.c
- * @brief Implementation of the drain_kyc_alert function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/drain_kyc_alert.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_drain_kyc_alert (struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint32_t trigger_type,
- struct TALER_NormalizedPaytoHashP *h_payto)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint32 (&trigger_type),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("h_payto",
- h_payto),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "drain_kyc_alert",
- "DELETE FROM kyc_alerts"
- " WHERE trigger_type=$1"
- " AND h_payto = "
- " (SELECT h_payto "
- " FROM kyc_alerts"
- " WHERE trigger_type=$1"
- " LIMIT 1)"
- " RETURNING h_payto;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "drain_kyc_alert",
- params,
- rs);
-}
diff --git a/src/exchangedb/ensure_coin_known.c b/src/exchangedb/ensure_coin_known.c
@@ -1,166 +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 exchangedb/ensure_coin_known.c
- * @brief Implementation of the ensure_coin_known function for Postgres
- * @author Christian Grothoff
- */
-#include "exchangedb_lib.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/ensure_coin_known.h"
-#include "helper.h"
-
-
-enum TALER_EXCHANGEDB_CoinKnownStatus
-TALER_EXCHANGEDB_ensure_coin_known (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_CoinPublicInfo *coin,
- uint64_t *known_coin_id,
- struct TALER_DenominationHashP *denom_hash,
- struct TALER_AgeCommitmentHashP *h_age_commitment)
-{
- enum GNUNET_DB_QueryStatus qs;
- bool existed;
- bool no_denom_pub_hash;
- bool no_age_commitment_hash;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&coin->denom_pub_hash),
- coin->no_age_commitment
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (&coin->h_age_commitment),
- TALER_PQ_query_param_denom_sig (&coin->denom_sig),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("existed",
- &existed),
- GNUNET_PQ_result_spec_uint64 ("known_coin_id",
- known_coin_id),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- denom_hash),
- &no_denom_pub_hash),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- h_age_commitment),
- &no_age_commitment_hash),
- GNUNET_PQ_result_spec_end
- };
-
- /*
- See also:
- https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/37543015#37543015
- */
- PREPARE (pg,
- "insert_known_coin",
- "WITH dd"
- " (denominations_serial"
- " ,coin"
- " ) AS ("
- " SELECT "
- " denominations_serial"
- " ,coin"
- " FROM denominations"
- " WHERE denom_pub_hash=$2"
- " ), input_rows"
- " (coin_pub) AS ("
- " VALUES ($1::BYTEA)"
- " ), ins AS ("
- " INSERT INTO known_coins "
- " (coin_pub"
- " ,denominations_serial"
- " ,age_commitment_hash"
- " ,denom_sig"
- " ,remaining"
- " ) SELECT "
- " $1"
- " ,denominations_serial"
- " ,$3"
- " ,$4"
- " ,coin"
- " FROM dd"
- " ON CONFLICT DO NOTHING" /* CONFLICT on (coin_pub) */
- " RETURNING "
- " known_coin_id"
- " ) "
- "SELECT "
- " FALSE AS existed"
- " ,known_coin_id"
- " ,NULL AS denom_pub_hash"
- " ,NULL AS age_commitment_hash"
- " FROM ins "
- "UNION ALL "
- "SELECT "
- " TRUE AS existed"
- " ,known_coin_id"
- " ,denom_pub_hash"
- " ,kc.age_commitment_hash"
- " FROM input_rows"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations USING (denominations_serial)"
- " LIMIT 1");
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "insert_known_coin",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- return TALER_EXCHANGEDB_CKS_HARD_FAIL;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- return TALER_EXCHANGEDB_CKS_SOFT_FAIL;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- GNUNET_break (0); /* should be impossible */
- return TALER_EXCHANGEDB_CKS_HARD_FAIL;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- if (! existed)
- return TALER_EXCHANGEDB_CKS_ADDED;
- break; /* continued below */
- }
-
- if ( (! no_denom_pub_hash) &&
- (0 != GNUNET_memcmp (denom_hash,
- &coin->denom_pub_hash)) )
- {
- GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_DENOM_CONFLICT;
- }
-
- if (no_age_commitment_hash != coin->no_age_commitment)
- {
- if (no_age_commitment_hash)
- {
- GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL;
- }
- else
- {
- GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL;
- }
- }
- else if ( (! no_age_commitment_hash) &&
- (0 != GNUNET_memcmp (h_age_commitment,
- &coin->h_age_commitment)) )
- {
- GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS;
- }
-
- return TALER_EXCHANGEDB_CKS_PRESENT;
-}
diff --git a/src/exchangedb/event_listen_cancel.c b/src/exchangedb/event_listen_cancel.c
@@ -23,10 +23,10 @@
void
-TALER_TALER_EXCHANGEDB_event_listen_cancel (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- struct GNUNET_DB_EventHandler *eh)
+TALER_EXCHANGEDB_event_listen_cancel (struct
+ TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ struct GNUNET_DB_EventHandler *eh)
{
(void) pg;
diff --git a/src/exchangedb/expire_purse.c b/src/exchangedb/expire_purse.c
@@ -1,65 +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 exchangedb/expire_purse.c
- * @brief Implementation of the expire_purse function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/expire_purse.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_expire_purse (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct GNUNET_TIME_Absolute start_time,
- struct GNUNET_TIME_Absolute end_time)
-{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&start_time),
- GNUNET_PQ_query_param_absolute_time (&end_time),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_end
- };
- bool found = false;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("found",
- &found),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
-
- PREPARE (pg,
- "call_expire_purse",
- "SELECT "
- " out_found AS found"
- " FROM exchange_do_expire_purse"
- " ($1,$2,$3);");
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_expire_purse",
- params,
- rs);
- if (qs < 0)
- return qs;
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
- return found
- ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
- : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
-}
diff --git a/src/exchangedb/find_aggregation_transient.c b/src/exchangedb/find_aggregation_transient.c
@@ -1,69 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 exchangedb/find_aggregation_transient.c
- * @brief Implementation of the find_aggregation_transient function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/find_aggregation_transient.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_find_aggregation_transient (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct TALER_FullPayto *payto_uri,
- struct TALER_WireTransferIdentifierRawP *wtid,
- struct TALER_MerchantPublicKeyP *merchant_pub,
- struct TALER_Amount *total)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- merchant_pub),
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- wtid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri->full_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- total),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "find_transient_aggregations",
- "SELECT"
- " atr.amount"
- " ,atr.wtid_raw"
- " ,atr.merchant_pub"
- " ,wt.payto_uri"
- " FROM wire_targets wt"
- " JOIN aggregation_transient atr"
- " USING (wire_target_h_payto)"
- " WHERE wt.h_normalized_payto=$1"
- " LIMIT 1;"); /* Note: there should really be only 1 match */
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "find_transient_aggregations",
- params,
- rs);
-}
diff --git a/src/exchangedb/get_active_legitimization.c b/src/exchangedb/get_active_legitimization.c
@@ -0,0 +1,62 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/lookup_pending_legitimization.c
+ * @brief Implementation of the lookup_pending_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_active_legitimization.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_active_legitimization (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t legitimization_process_serial_id,
+ uint32_t *measure_index,
+ json_t **jmeasures)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&legitimization_process_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_json (
+ "jmeasures",
+ jmeasures),
+ GNUNET_PQ_result_spec_uint32 (
+ "measure_index",
+ measure_index),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_active_legitimization",
+ "SELECT "
+ " lm.jmeasures::TEXT"
+ ",lp.measure_index"
+ " FROM legitimization_processes lp"
+ " JOIN legitimization_measures lm"
+ " USING (legitimization_measure_serial_id)"
+ " WHERE lp.legitimization_process_serial_id=$1"
+ " AND NOT lm.is_finished;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_active_legitimization",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_aggregation_transient.c b/src/exchangedb/get_aggregation_transient.c
@@ -0,0 +1,63 @@
+/*
+ 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 exchangedb/get_aggregation_transient.c
+ * @brief Implementation of the get_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_aggregation_transient.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aggregation_transient (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const char *exchange_account_section,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_Amount *total)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ total),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ wtid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_aggregation_transient",
+ "SELECT"
+ " amount"
+ " ,wtid_raw"
+ " FROM aggregation_transient"
+ " WHERE wire_target_h_payto=$1"
+ " AND merchant_pub=$2"
+ " AND exchange_account_section=$3;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_aggregation_transient",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_aggregation_transient_by_normalized_payto.c b/src/exchangedb/get_aggregation_transient_by_normalized_payto.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 exchangedb/get_aggregation_transient_by_normalized_payto.c
+ * @brief Implementation of the get_aggregation_transient_by_normalized_payto function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_aggregation_transient_by_normalized_payto.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aggregation_transient_by_normalized_payto (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct TALER_FullPayto *payto_uri,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_MerchantPublicKeyP *merchant_pub,
+ struct TALER_Amount *total)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ merchant_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ wtid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri->full_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ total),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_aggregation_transient_by_normalized_payto",
+ "SELECT"
+ " atr.amount"
+ " ,atr.wtid_raw"
+ " ,atr.merchant_pub"
+ " ,wt.payto_uri"
+ " FROM wire_targets wt"
+ " JOIN aggregation_transient atr"
+ " USING (wire_target_h_payto)"
+ " WHERE wt.h_normalized_payto=$1"
+ " LIMIT 1;"); /* Note: there should really be only 1 match */
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_aggregation_transient_by_normalized_payto",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_aml_file_number.c b/src/exchangedb/get_aml_file_number.c
@@ -0,0 +1,59 @@
+/*
+ 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 exchangedb/get_aml_file_number.c
+ * @brief Implementation of the get_aml_file_number function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_aml_file_number.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aml_file_number (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ uint64_t *kyc_target_row,
+ bool *is_wallet)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "kyc_target_serial_id",
+ kyc_target_row),
+ GNUNET_PQ_result_spec_bool (
+ "is_wallet",
+ is_wallet),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_aml_file_number",
+ "SELECT "
+ " kyc_target_serial_id"
+ ",is_wallet"
+ " FROM kyc_targets"
+ " WHERE h_normalized_payto=$1");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_aml_file_number",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_aml_officer.c b/src/exchangedb/get_aml_officer.c
@@ -0,0 +1,68 @@
+/*
+ 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 exchangedb/get_aml_officer.c
+ * @brief Implementation of the get_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_aml_officer.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aml_officer (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ struct TALER_MasterSignatureP *master_sig,
+ char **decider_name,
+ bool *is_active,
+ bool *read_only,
+ struct GNUNET_TIME_Absolute *last_change)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (decider_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_string ("decider_name",
+ decider_name),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ is_active),
+ GNUNET_PQ_result_spec_bool ("read_only",
+ read_only),
+ GNUNET_PQ_result_spec_absolute_time ("last_change",
+ last_change),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_aml_officer",
+ "SELECT "
+ " master_sig"
+ ",decider_name"
+ ",is_active"
+ ",read_only"
+ ",last_change"
+ " FROM aml_staff"
+ " WHERE decider_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_aml_officer",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_auditor_denom_sig.c b/src/exchangedb/get_auditor_denom_sig.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 exchangedb/get_auditor_denom_sig.c
+ * @brief Implementation of the get_auditor_denom_sig function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_auditor_denom_sig.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_auditor_denom_sig (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct TALER_AuditorSignatureP *auditor_sig)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("auditor_sig",
+ auditor_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_auditor_denom_sig",
+ "SELECT"
+ " auditor_sig"
+ " FROM auditor_denom_sigs"
+ " WHERE auditor_uuid="
+ " (SELECT auditor_uuid"
+ " FROM auditors"
+ " WHERE auditor_pub=$1)"
+ " AND denominations_serial="
+ " (SELECT denominations_serial"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$2);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_auditor_denom_sig",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_auditor_status.c b/src/exchangedb/get_auditor_status.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_auditor_status.c
+ * @brief Implementation of the get_auditor_status function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_auditor_status.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_auditor_status (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ char **auditor_url,
+ bool *enabled)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("auditor_url",
+ auditor_url),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ enabled),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* Used in #postgres_lookup_auditor_status() */
+ PREPARE (pg,
+ "get_auditor_status",
+ "SELECT"
+ " auditor_url"
+ ",is_active"
+ " FROM auditors"
+ " WHERE auditor_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_auditor_status",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_auditor_timestamp.c b/src/exchangedb/get_auditor_timestamp.c
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_auditor_timestamp.c
+ * @brief Implementation of the get_auditor_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_auditor_timestamp.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_auditor_timestamp (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct GNUNET_TIME_Timestamp *last_date)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("last_change",
+ last_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* Used in #postgres_lookup_auditor_timestamp() */
+ PREPARE (pg,
+ "get_auditor_timestamp",
+ "SELECT"
+ " last_change"
+ " FROM auditors"
+ " WHERE auditor_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_auditor_timestamp",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_coin_transactions.c b/src/exchangedb/get_coin_transactions.c
@@ -729,39 +729,39 @@ handle_history_entry (void *cls,
static const struct Work work[] = {
[TALER_EXCHANGEDB_TT_DEPOSIT] =
{ "coin_deposits",
- "get_deposit_with_coin_pub",
+ "get_coin_transactions_deposit_with_coin_pub",
&add_coin_deposit },
[TALER_EXCHANGEDB_TT_MELT] =
{ "refresh",
- "get_refresh_by_coin",
+ "get_coin_transactions_refresh_by_coin",
&add_coin_melt },
[TALER_EXCHANGEDB_TT_PURSE_DEPOSIT] =
{ "purse_deposits",
- "get_purse_deposit_by_coin_pub",
+ "get_coin_transactions_purse_deposit_by_coin_pub",
&add_coin_purse_deposit },
[TALER_EXCHANGEDB_TT_PURSE_REFUND] =
{ "purse_decision",
- "get_purse_decision_by_coin_pub",
+ "get_coin_transactions_purse_decision_by_coin_pub",
&add_coin_purse_decision },
[TALER_EXCHANGEDB_TT_REFUND] =
{ "refunds",
- "get_refunds_by_coin",
+ "get_coin_transactions_refunds_by_coin",
&add_coin_refund },
[TALER_EXCHANGEDB_TT_RECOUP_WITHDRAW] =
{ "recoup",
- "recoup_by_coin",
+ "get_coin_transactions_recoup_by_coin",
&add_coin_recoup },
[TALER_EXCHANGEDB_TT_RECOUP_REFRESH] =
{ "recoup_refresh::NEW",
- "recoup_by_refreshed_coin",
+ "get_coin_transactions_recoup_by_refreshed_coin",
&add_coin_recoup_refresh },
[TALER_EXCHANGEDB_TT_RECOUP_REFRESH_RECEIVER] =
{ "recoup_refresh::OLD",
- "recoup_by_old_coin",
+ "get_coin_transactions_recoup_by_old_coin",
&add_old_coin_recoup },
[TALER_EXCHANGEDB_TT_RESERVE_OPEN] =
{ "reserves_open_deposits",
- "reserve_open_by_coin",
+ "get_coin_transactions_reserve_open_by_coin",
&add_coin_reserve_open },
{ NULL, NULL, NULL }
};
@@ -866,7 +866,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
"Getting transactions for coin %s\n",
TALER_B2S (coin_pub));
PREPARE (pg,
- "get_coin_history_etag_balance",
+ "get_coin_transactions_history_etag_balance",
"SELECT"
" ch.coin_history_serial_id"
",kc.remaining"
@@ -880,7 +880,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" ORDER BY coin_history_serial_id DESC"
" LIMIT 1;");
PREPARE (pg,
- "get_coin_history",
+ "get_coin_transactions_history",
"SELECT"
" table_name"
",serial_id"
@@ -890,7 +890,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" AND coin_history_serial_id > $2"
" ORDER BY coin_history_serial_id DESC;");
PREPARE (pg,
- "get_deposit_with_coin_pub",
+ "get_coin_transactions_deposit_with_coin_pub",
"SELECT"
" cdep.amount_with_fee"
",denoms.fee_deposit"
@@ -919,7 +919,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" WHERE cdep.coin_pub=$1"
" AND cdep.coin_deposit_serial_id=$2;");
PREPARE (pg,
- "get_refresh_by_coin",
+ "get_coin_transactions_refresh_by_coin",
"SELECT"
" rc"
",refresh_seed"
@@ -938,7 +938,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" WHERE old_coin_pub=$1"
" AND refresh_id=$2;");
PREPARE (pg,
- "get_purse_deposit_by_coin_pub",
+ "get_coin_transactions_purse_deposit_by_coin_pub",
"SELECT"
" partner_base_url"
",pd.amount_with_fee"
@@ -963,7 +963,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" WHERE pd.purse_deposit_serial_id=$2"
" AND pd.coin_pub=$1;");
PREPARE (pg,
- "get_purse_decision_by_coin_pub",
+ "get_coin_transactions_purse_decision_by_coin_pub",
"SELECT"
" pdes.purse_pub"
",pd.amount_with_fee"
@@ -980,7 +980,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" AND pdes.purse_decision_serial_id=$2"
" AND pdes.refunded;");
PREPARE (pg,
- "get_refunds_by_coin",
+ "get_coin_transactions_refunds_by_coin",
"SELECT"
" bdep.merchant_pub"
",ref.merchant_sig"
@@ -1001,7 +1001,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" WHERE ref.coin_pub=$1"
" AND ref.refund_serial_id=$2;");
PREPARE (pg,
- "recoup_by_old_coin",
+ "get_coin_transactions_recoup_by_old_coin",
"SELECT"
" coins.coin_pub"
",rr.coin_sig"
@@ -1022,7 +1022,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" FROM refresh"
" WHERE refresh.old_coin_pub=$1);");
PREPARE (pg,
- "recoup_by_coin",
+ "get_coin_transactions_recoup_by_coin",
"SELECT"
" res.reserve_pub"
",denoms.denom_pub_hash"
@@ -1045,7 +1045,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
/* Used to obtain recoup transactions
for a refreshed coin */
PREPARE (pg,
- "recoup_by_refreshed_coin",
+ "get_coin_transactions_recoup_by_refreshed_coin",
"SELECT"
" old_coins.coin_pub AS old_coin_pub"
",rr.coin_sig"
@@ -1067,7 +1067,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
" WHERE rr.recoup_refresh_uuid=$2"
" AND coins.coin_pub=$1;");
PREPARE (pg,
- "reserve_open_by_coin",
+ "get_coin_transactions_reserve_open_by_coin",
"SELECT"
" rod.reserve_open_deposit_uuid"
",rod.coin_sig"
@@ -1098,8 +1098,8 @@ TALER_EXCHANGEDB_get_coin_transactions (
if (begin_transaction)
{
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_committed (pg,
- "get-coin-transactions"))
+ TALER_EXCHANGEDB_start_read_committed (pg,
+ "get-coin-transactions"))
{
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
@@ -1109,7 +1109,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
we even need to iterate */
qs = GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "get_coin_history_etag_balance",
+ "get_coin_transactions_history_etag_balance",
params,
rs);
switch (qs)
@@ -1139,7 +1139,7 @@ TALER_EXCHANGEDB_get_coin_transactions (
qs = GNUNET_PQ_eval_prepared_multi_select (
pg->conn,
- "get_coin_history",
+ "get_coin_transactions_history",
lparams,
&handle_history_entry,
&chc);
diff --git a/src/exchangedb/get_completed_legitimization.c b/src/exchangedb/get_completed_legitimization.c
@@ -0,0 +1,95 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_completed_legitimization.c
+ * @brief Implementation of the lookup_pending_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_completed_legitimization.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_completed_legitimization (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t legitimization_measure_serial_id,
+ uint32_t measure_index,
+ struct TALER_AccountAccessTokenP *access_token,
+ struct TALER_NormalizedPaytoHashP *h_payto,
+ bool *is_wallet,
+ json_t **jmeasures,
+ bool *is_finished,
+ size_t *encrypted_attributes_len,
+ void **encrypted_attributes
+ )
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&legitimization_measure_serial_id),
+ GNUNET_PQ_query_param_uint32 (&measure_index),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_json (
+ "jmeasures",
+ jmeasures),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_normalized_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "access_token",
+ access_token),
+ GNUNET_PQ_result_spec_bool (
+ "is_finished",
+ is_finished),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_variable_size (
+ "encrypted_attributes",
+ encrypted_attributes,
+ encrypted_attributes_len),
+ NULL),
+ GNUNET_PQ_result_spec_bool (
+ "is_wallet",
+ is_wallet),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *encrypted_attributes_len = 0;
+ *encrypted_attributes = NULL;
+ PREPARE (pg,
+ "get_completed_legitimization",
+ "SELECT "
+ " lm.jmeasures::TEXT"
+ ",kt.h_normalized_payto"
+ ",kt.is_wallet"
+ ",lm.access_token"
+ ",lm.is_finished"
+ ",ka.encrypted_attributes"
+ " FROM legitimization_measures lm"
+ " JOIN kyc_targets kt"
+ " ON (lm.access_token = kt.access_token)"
+ " LEFT JOIN legitimization_processes lp"
+ " ON (lm.legitimization_measure_serial_id = lp.legitimization_measure_serial_id)"
+ " LEFT JOIN kyc_attributes ka"
+ " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
+ " WHERE lm.legitimization_measure_serial_id=$1"
+ " AND lp.measure_index=$2;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_completed_legitimization",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_contract.c b/src/exchangedb/get_contract.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 exchangedb/get_contract.c
+ * @brief Implementation of the get_contract function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_contract.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_contract (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ContractDiffiePublicP *pub_ckey,
+ struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseContractSignatureP *econtract_sig,
+ size_t *econtract_size,
+ void **econtract)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (pub_ckey),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
+ econtract_sig),
+ GNUNET_PQ_result_spec_variable_size ("e_contract",
+ econtract,
+ econtract_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_contract",
+ "SELECT "
+ " purse_pub"
+ ",e_contract"
+ ",contract_sig"
+ " FROM contracts"
+ " WHERE pub_ckey=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_contract",
+ params,
+ rs);
+
+}
diff --git a/src/exchangedb/get_contract_by_purse.c b/src/exchangedb/get_contract_by_purse.c
@@ -0,0 +1,59 @@
+/*
+ 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 exchangedb/get_contract_by_purse.c
+ * @brief Implementation of the get_contract_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_contract_by_purse.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_contract_by_purse (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_EncryptedContract *econtract)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("pub_ckey",
+ &econtract->contract_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
+ &econtract->econtract_sig),
+ GNUNET_PQ_result_spec_variable_size ("e_contract",
+ &econtract->econtract,
+ &econtract->econtract_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_contract_by_purse",
+ "SELECT "
+ " pub_ckey"
+ ",e_contract"
+ ",contract_sig"
+ " FROM contracts"
+ " WHERE purse_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_contract_by_purse",
+ params,
+ rs);
+
+}
diff --git a/src/exchangedb/get_count_known_coins.c b/src/exchangedb/get_count_known_coins.c
@@ -0,0 +1,60 @@
+/*
+ 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 exchangedb/get_count_known_coins.c
+ * @brief Implementation of the get_count_known_coins function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_count_known_coins.h"
+#include "helper.h"
+
+long long
+TALER_EXCHANGEDB_get_count_known_coins (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_DenominationHashP *denom_pub_hash)
+{
+ uint64_t count;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("count",
+ &count),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "get_count_known_coins",
+ "SELECT"
+ " COUNT(*) AS count"
+ " FROM known_coins"
+ " WHERE denominations_serial="
+ " (SELECT denominations_serial"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_count_known_coins",
+ params,
+ rs);
+ if (0 > qs)
+ return (long long) qs;
+ return (long long) count;
+}
diff --git a/src/exchangedb/get_denomination_by_serial.c b/src/exchangedb/get_denomination_by_serial.c
@@ -63,7 +63,7 @@ TALER_EXCHANGEDB_get_denomination_by_serial (
};
PREPARE (pg,
- "denomination_get_by_serial",
+ "get_denomination_by_serial",
"SELECT"
" master_sig"
",denom_pub_hash"
@@ -81,7 +81,7 @@ TALER_EXCHANGEDB_get_denomination_by_serial (
" WHERE denominations_serial=$1;");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "denomination_get_by_serial",
+ "get_denomination_by_serial",
params,
rs);
}
diff --git a/src/exchangedb/get_denomination_info.c b/src/exchangedb/get_denomination_info.c
@@ -67,7 +67,7 @@ TALER_EXCHANGEDB_get_denomination_info (
};
PREPARE (pg,
- "denomination_get",
+ "get_denomination_info",
"SELECT"
" denominations_serial"
",master_sig"
@@ -84,7 +84,7 @@ TALER_EXCHANGEDB_get_denomination_info (
" FROM denominations"
" WHERE denom_pub_hash=$1;");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "denomination_get",
+ "get_denomination_info",
params,
rs);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
diff --git a/src/exchangedb/get_denomination_meta.c b/src/exchangedb/get_denomination_meta.c
@@ -0,0 +1,79 @@
+/*
+ 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 exchangedb/get_denomination_meta.c
+ * @brief Implementation of the get_denomination_meta function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_denomination_meta.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_denomination_meta (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &meta->start),
+ GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
+ &meta->expire_withdraw),
+ GNUNET_PQ_result_spec_timestamp ("expire_deposit",
+ &meta->expire_deposit),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &meta->expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &meta->value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &meta->fees.withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &meta->fees.deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &meta->fees.refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &meta->fees.refund),
+ GNUNET_PQ_result_spec_uint32 ("age_mask",
+ &meta->age_mask.bits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_denomination_meta",
+ "SELECT"
+ " valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin"
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_denomination_meta",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_denomination_revocation.c b/src/exchangedb/get_denomination_revocation.c
@@ -42,7 +42,7 @@ TALER_EXCHANGEDB_get_denomination_revocation (
};
PREPARE (pg,
- "denomination_revocation_get",
+ "get_denomination_revocation",
"SELECT"
" master_sig"
",denom_revocations_serial_id"
@@ -53,7 +53,7 @@ TALER_EXCHANGEDB_get_denomination_revocation (
" WHERE denom_pub_hash=$1);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "denomination_revocation_get",
+ "get_denomination_revocation",
params,
rs);
}
diff --git a/src/exchangedb/get_drain_profit.c b/src/exchangedb/get_drain_profit.c
@@ -1,72 +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 exchangedb/get_drain_profit.c
- * @brief Implementation of the get_drain_profit function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_drain_profit.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_drain_profit (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- uint64_t *serial,
- char **account_section,
- struct TALER_FullPayto *payto_uri,
- struct GNUNET_TIME_Timestamp *request_timestamp,
- struct TALER_Amount *amount,
- struct TALER_MasterSignatureP *master_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
- serial),
- GNUNET_PQ_result_spec_string ("account_section",
- account_section),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri->full_payto),
- GNUNET_PQ_result_spec_timestamp ("trigger_date",
- request_timestamp),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- amount),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "get_profit_drain",
- "SELECT"
- " profit_drain_serial_id"
- ",account_section"
- ",payto_uri"
- ",trigger_date"
- ",amount"
- ",master_sig"
- " FROM profit_drains"
- " WHERE wtid=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_profit_drain",
- params,
- rs);
-}
diff --git a/src/exchangedb/get_exists_aml_officer.c b/src/exchangedb/get_exists_aml_officer.c
@@ -0,0 +1,52 @@
+/*
+ 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 exchangedb/get_exists_aml_officer.c
+ * @brief Implementation of the get_exists_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_exists_aml_officer.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_exists_aml_officer (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ bool *read_only)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (decider_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("read_only",
+ read_only),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_exists_aml_officer",
+ "SELECT read_only"
+ " FROM aml_staff"
+ " WHERE decider_pub=$1"
+ " AND is_active;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_exists_aml_officer",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_exists_deposit.c b/src/exchangedb/get_exists_deposit.c
@@ -0,0 +1,113 @@
+/*
+ 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 exchangedb/get_exists_deposit.c
+ * @brief Implementation of the get_exists_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_exists_deposit.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_exists_deposit (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ struct TALER_Amount *deposit_fee,
+ struct GNUNET_TIME_Timestamp *exchange_timestamp)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (merchant),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_EXCHANGEDB_Deposit deposit2;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit2.amount_with_fee),
+ GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
+ &deposit2.timestamp),
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ exchange_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &deposit2.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &deposit2.wire_deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &deposit2.wire_salt),
+ GNUNET_PQ_result_spec_string ("receiver_wire_account",
+ &deposit2.receiver_wire_account.full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_MerchantWireHashP h_wire2;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting deposits for coin %s\n",
+ TALER_B2S (coin_pub));
+ PREPARE (pg,
+ "get_exists_deposit",
+ "SELECT"
+ " cdep.amount_with_fee"
+ ",denominations.fee_deposit"
+ ",bdep.wallet_timestamp"
+ ",bdep.exchange_timestamp"
+ ",bdep.refund_deadline"
+ ",bdep.wire_deadline"
+ ",bdep.h_contract_terms"
+ ",bdep.wire_salt"
+ ",wt.payto_uri AS receiver_wire_account"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep USING (batch_deposit_serial_id)"
+ " JOIN known_coins kc ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations USING (denominations_serial)"
+ " JOIN wire_targets wt USING (wire_target_h_payto)"
+ " WHERE cdep.coin_pub=$1"
+ " AND bdep.merchant_pub=$3"
+ " AND bdep.h_contract_terms=$2;");
+ /* Note: query might be made more efficient if we computed the 'shard'
+ from merchant_pub and included that as a constraint on bdep! */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_exists_deposit",
+ params,
+ rs);
+ if (0 >= qs)
+ return qs;
+ TALER_merchant_wire_signature_hash (deposit2.receiver_wire_account,
+ &deposit2.wire_salt,
+ &h_wire2);
+ GNUNET_free (deposit2.receiver_wire_account.full_payto);
+ /* Now we check that the other information in @a deposit
+ also matches, and if not report inconsistencies. */
+ if ( (GNUNET_TIME_timestamp_cmp (refund_deadline,
+ !=,
+ deposit2.refund_deadline)) ||
+ (0 != GNUNET_memcmp (h_wire,
+ &h_wire2) ) )
+ {
+ /* Inconsistencies detected! Does not match! */
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
diff --git a/src/exchangedb/get_expired_reserves.c b/src/exchangedb/get_expired_reserves.c
@@ -1,169 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 get_expired_reserves.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_expired_reserves.h"
-#include "helper.h"
-
-
-/**
- * Closure for #reserve_expired_cb().
- */
-struct ExpiredReserveContext
-{
- /**
- * Function to call for each expired reserve.
- */
- TALER_EXCHANGEDB_ReserveExpiredCallback rec;
-
- /**
- * Closure to give to @e rec.
- */
- void *rec_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_expired_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ExpiredReserveContext *erc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = erc->pg;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_TIME_Timestamp exp_date;
- struct TALER_FullPayto account_details;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount remaining_balance;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &exp_date),
- GNUNET_PQ_result_spec_string ("account_details",
- &account_details.full_payto),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- TALER_PQ_result_spec_amount ("current_balance",
- pg->currency,
- &remaining_balance),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ret = GNUNET_SYSERR;
- break;
- }
- ret = erc->rec (erc->rec_cls,
- &reserve_pub,
- &remaining_balance,
- account_details,
- exp_date,
- 0);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
- erc->status = ret;
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_expired_reserves (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct GNUNET_TIME_Timestamp now,
- TALER_EXCHANGEDB_ReserveExpiredCallback rec,
- void *rec_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_end
- };
- struct ExpiredReserveContext ectx = {
- .rec = rec,
- .rec_cls = rec_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "get_expired_reserves",
- "WITH ed AS MATERIALIZED ( "
- " SELECT expiration_date"
- " ,wire_source_h_payto"
- " ,current_balance"
- " ,r.reserve_pub"
- " FROM reserves r"
- " JOIN reserves_in"
- " USING (reserve_pub)"
- " WHERE expiration_date <= $1 "
- " AND ((current_balance).val != 0 OR (current_balance).frac != 0) "
- " ORDER BY expiration_date ASC "
- " LIMIT 1 "
- ") "
- "SELECT"
- " wt.payto_uri AS account_details"
- " ,ed.expiration_date"
- " ,ed.reserve_pub"
- " ,ed.current_balance"
- " FROM wire_targets wt"
- " JOIN ed"
- " ON (ed.wire_source_h_payto=wt.wire_target_h_payto);");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_expired_reserves",
- params,
- &reserve_expired_cb,
- &ectx);
- switch (ectx.status)
- {
- case GNUNET_SYSERR:
- return GNUNET_DB_STATUS_HARD_ERROR;
- case GNUNET_NO:
- return GNUNET_DB_STATUS_SOFT_ERROR;
- case GNUNET_OK:
- break;
- }
- return qs;
-}
diff --git a/src/exchangedb/get_global_fee_by_time.c b/src/exchangedb/get_global_fee_by_time.c
@@ -0,0 +1,180 @@
+/*
+ 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 exchangedb/get_global_fee_by_time.c
+ * @brief Implementation of the get_global_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_dbevents.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_global_fee_by_time.h"
+#include "helper.h"
+
+/**
+ * Closure for #global_fee_by_time_helper()
+ */
+struct GlobalFeeLookupContext
+{
+
+ /**
+ * Set to the wire fees. Set to invalid if fees conflict over
+ * the given time period.
+ */
+ struct TALER_GlobalFeeSet *fees;
+
+ /**
+ * Set to timeout of unmerged purses
+ */
+ struct GNUNET_TIME_Relative *purse_timeout;
+
+ /**
+ * Set to history expiration for reserves.
+ */
+ struct GNUNET_TIME_Relative *history_expiration;
+
+ /**
+ * Set to number of free purses per account.
+ */
+ uint32_t *purse_account_limit;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+};
+
+
+/**
+ * Helper function for #TALER_EXCHANGEDB_get_global_fee_by_time().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct GlobalFeeLookupContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+global_fee_by_time_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GlobalFeeLookupContext *wlc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = wlc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_GlobalFeeSet fs;
+ struct GNUNET_TIME_Relative purse_timeout;
+ struct GNUNET_TIME_Relative history_expiration;
+ uint32_t purse_account_limit;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
+ &fs.history),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
+ &fs.account),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &fs.purse),
+ GNUNET_PQ_result_spec_relative_time ("purse_timeout",
+ &purse_timeout),
+ GNUNET_PQ_result_spec_relative_time ("history_expiration",
+ &history_expiration),
+ GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
+ &purse_account_limit),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_GlobalFeeSet));
+ return;
+ }
+ if (0 == i)
+ {
+ *wlc->fees = fs;
+ *wlc->purse_timeout = purse_timeout;
+ *wlc->history_expiration = history_expiration;
+ *wlc->purse_account_limit = purse_account_limit;
+ continue;
+ }
+ if ( (0 !=
+ TALER_global_fee_set_cmp (&fs,
+ wlc->fees)) ||
+ (purse_account_limit != *wlc->purse_account_limit) ||
+ (GNUNET_TIME_relative_cmp (purse_timeout,
+ !=,
+ *wlc->purse_timeout)) ||
+ (GNUNET_TIME_relative_cmp (history_expiration,
+ !=,
+ *wlc->history_expiration)) )
+ {
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_GlobalFeeSet));
+ return;
+ }
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_global_fee_by_time (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative *purse_timeout,
+ struct GNUNET_TIME_Relative *history_expiration,
+ uint32_t *purse_account_limit)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&start_time),
+ GNUNET_PQ_query_param_timestamp (&end_time),
+ GNUNET_PQ_query_param_end
+ };
+ struct GlobalFeeLookupContext wlc = {
+ .fees = fees,
+ .purse_timeout = purse_timeout,
+ .history_expiration = history_expiration,
+ .purse_account_limit = purse_account_limit,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "get_global_fee_by_time",
+ "SELECT"
+ " history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ " FROM global_fee"
+ " WHERE end_date > $1"
+ " AND start_date < $2;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_global_fee_by_time",
+ params,
+ &global_fee_by_time_helper,
+ &wlc);
+}
diff --git a/src/exchangedb/get_global_fees.c b/src/exchangedb/get_global_fees.c
@@ -1,168 +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 exchangedb/get_global_fees.c
- * @brief Implementation of the get_global_fees function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_dbevents.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_global_fees.h"
-#include "helper.h"
-
-
-/**
- * Closure for #global_fees_cb().
- */
-struct GlobalFeeContext
-{
- /**
- * Function to call for each global fee block.
- */
- TALER_EXCHANGEDB_GlobalFeeCallback cb;
-
- /**
- * Closure to give to @e rec.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-global_fees_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GlobalFeeContext *gctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = gctx->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_GlobalFeeSet fees;
- struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative history_expiration;
- uint32_t purse_account_limit;
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &fees.history),
- TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
- &fees.account),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &fees.purse),
- GNUNET_PQ_result_spec_relative_time ("purse_timeout",
- &purse_timeout),
- GNUNET_PQ_result_spec_relative_time ("history_expiration",
- &history_expiration),
- GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
- &purse_account_limit),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_end
- };
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- gctx->status = GNUNET_SYSERR;
- break;
- }
- gctx->cb (gctx->cb_cls,
- &fees,
- purse_timeout,
- history_expiration,
- purse_account_limit,
- start_date,
- end_date,
- &master_sig);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_get_global_fees (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- TALER_EXCHANGEDB_GlobalFeeCallback cb,
- void *cb_cls)
-{
- struct GNUNET_TIME_Timestamp date
- = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_subtract (
- GNUNET_TIME_absolute_get (),
- GNUNET_TIME_UNIT_YEARS));
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&date),
- GNUNET_PQ_query_param_end
- };
- struct GlobalFeeContext gctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "get_global_fees",
- "SELECT "
- " start_date"
- ",end_date"
- ",history_fee"
- ",account_fee"
- ",purse_fee"
- ",purse_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- " FROM global_fee"
- " WHERE start_date >= $1");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_global_fees",
- params,
- &global_fees_cb,
- &gctx);
- if (GNUNET_OK != gctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/get_h_payto_by_access_token.c b/src/exchangedb/get_h_payto_by_access_token.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_h_payto_by_access_token.c
+ * @brief Implementation of the get_h_payto_by_access_token function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_h_payto_by_access_token.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_h_payto_by_access_token (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AccountAccessTokenP *access_token,
+ struct TALER_NormalizedPaytoHashP *h_payto,
+ bool *is_wallet)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (access_token),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_normalized_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_bool (
+ "is_wallet",
+ is_wallet),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_h_payto_by_access_token",
+ "SELECT "
+ " h_normalized_payto"
+ " ,is_wallet"
+ " FROM kyc_targets"
+ " WHERE (access_token = $1);");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_h_payto_by_access_token",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_kyc_provider_account.c b/src/exchangedb/get_kyc_provider_account.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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 exchangedb/get_kyc_provider_account.c
+ * @brief Implementation of the get_kyc_provider_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_kyc_provider_account.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_kyc_provider_account (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *provider_name,
+ const char *provider_legitimization_id,
+ struct TALER_NormalizedPaytoHashP *h_payto,
+ bool *is_wallet,
+ uint64_t *process_row)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (provider_legitimization_id),
+ GNUNET_PQ_query_param_string (provider_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_bool ("is_wallet",
+ is_wallet),
+ GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
+ process_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_kyc_provider_account",
+ "SELECT "
+ " lp.h_payto"
+ ",kt.is_wallet"
+ ",lp.legitimization_process_serial_id"
+ " FROM legitimization_processes lp"
+ " JOIN kyc_targets kt"
+ " ON (lp.h_payto = kt.h_normalized_payto)"
+ " WHERE provider_legitimization_id=$1"
+ " AND provider_name=$2;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_kyc_provider_account",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_kyc_rules.c b/src/exchangedb/get_kyc_rules.c
@@ -24,7 +24,7 @@
enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_kyc_rules (
+TALER_EXCHANGEDB_get_kyc_rules_with_account (
struct TALER_EXCHANGEDB_PostgresContext *pg,
const struct TALER_NormalizedPaytoHashP *h_payto,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -70,7 +70,7 @@ TALER_EXCHANGEDB_get_kyc_rules (
0,
sizeof (*reserve_pub));
PREPARE (pg,
- "get_kyc_rules",
+ "get_kyc_rules_with_account",
"SELECT"
" out_target_pub AS target_pub"
" ,out_jnew_rules::TEXT AS jnew_rules"
@@ -78,14 +78,14 @@ TALER_EXCHANGEDB_get_kyc_rules (
" FROM exchange_do_get_kyc_rules ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "get_kyc_rules",
+ "get_kyc_rules_with_account",
params,
rs);
}
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_get_kyc_rules2 (
+TALER_EXCHANGEDB_get_kyc_rules (
struct TALER_EXCHANGEDB_PostgresContext *pg,
const struct TALER_NormalizedPaytoHashP *h_payto,
json_t **jrules)
@@ -107,7 +107,7 @@ TALER_TALER_EXCHANGEDB_get_kyc_rules2 (
*jrules = NULL;
PREPARE (pg,
- "get_kyc_rules2",
+ "get_kyc_rules",
"SELECT"
" jnew_rules::TEXT"
" FROM legitimization_outcomes"
@@ -118,7 +118,7 @@ TALER_TALER_EXCHANGEDB_get_kyc_rules2 (
" LIMIT 1;");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "get_kyc_rules2",
+ "get_kyc_rules",
params,
rs);
}
diff --git a/src/exchangedb/get_kyc_status_by_token.c b/src/exchangedb/get_kyc_status_by_token.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_kyc_status_by_token.c
+ * @brief Implementation of the get_kyc_status_by_token function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_kyc_status_by_token.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_kyc_status_by_token (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AccountAccessTokenP *access_token,
+ uint64_t *row,
+ json_t **jmeasures)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (access_token),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "legitimization_measure_serial_id",
+ row),
+ TALER_PQ_result_spec_json (
+ "jmeasures",
+ jmeasures),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_kyc_status_by_token",
+ "SELECT"
+ " legitimization_measure_serial_id"
+ ",jmeasures::TEXT"
+ " FROM legitimization_measures"
+ " WHERE access_token=$1"
+ " AND NOT is_finished"
+ " ORDER BY display_priority DESC"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_kyc_status_by_token",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_legitimization_process_by_account.c b/src/exchangedb/get_legitimization_process_by_account.c
@@ -0,0 +1,90 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 exchangedb/get_legitimization_process_by_account.c
+ * @brief Implementation of the get_legitimization_process_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_legitimization_process_by_account.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_legitimization_process_by_account (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *provider_name,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ uint64_t *process_row,
+ struct GNUNET_TIME_Absolute *expiration,
+ char **provider_account_id,
+ char **provider_legitimization_id,
+ bool *is_wallet)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_string (provider_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "legitimization_process_serial_id",
+ process_row),
+ GNUNET_PQ_result_spec_absolute_time (
+ "expiration_time",
+ expiration),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string (
+ "provider_user_id",
+ provider_account_id),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string (
+ "provider_legitimization_id",
+ provider_legitimization_id),
+ NULL),
+ GNUNET_PQ_result_spec_bool (
+ "is_wallet",
+ is_wallet),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *provider_account_id = NULL;
+ *provider_legitimization_id = NULL;
+ PREPARE (pg,
+ "get_legitimization_process_by_account",
+ "SELECT "
+ " lp.legitimization_process_serial_id"
+ ",lp.expiration_time"
+ ",lp.provider_user_id"
+ ",lp.provider_legitimization_id"
+ ",kt.is_wallet"
+ " FROM legitimization_processes lp"
+ " JOIN kyc_targets kt"
+ " ON (lp.h_payto = kt.h_normalized_payto)"
+ " WHERE h_payto=$1"
+ " AND provider_name=$2"
+ " AND NOT finished"
+ /* Note: there *should* only be one unfinished
+ match, so this is just to be safe(r): */
+ " ORDER BY lp.expiration_time DESC"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_legitimization_process_by_account",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_legitimization_requirement_by_row.c b/src/exchangedb/get_legitimization_requirement_by_row.c
@@ -0,0 +1,109 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_legitimization_requirement_by_row.c
+ * @brief Implementation of the get_legitimization_requirement_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_legitimization_requirement_by_row.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_legitimization_requirement_by_row (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const union TALER_AccountPublicKeyP *account_pub,
+ enum GNUNET_GenericReturnValue *is_wallet,
+ struct TALER_AccountAccessTokenP *access_token,
+ uint64_t *rule_gen,
+ json_t **jrules,
+ bool *aml_review,
+ bool *kyc_required)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (account_pub),
+ GNUNET_PQ_query_param_end
+ };
+ bool bis_wallet;
+ bool bis_wallet_unknown;
+ bool not_found;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("access_token",
+ access_token),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ /* can be NULL due to LEFT JOIN */
+ TALER_PQ_result_spec_json ("jrules",
+ jrules),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ /* can be NULL due to LEFT JOIN */
+ GNUNET_PQ_result_spec_bool ("is_wallet",
+ &bis_wallet),
+ &bis_wallet_unknown),
+ GNUNET_PQ_result_spec_allow_null (
+ /* can be NULL due to LEFT JOIN */
+ GNUNET_PQ_result_spec_bool ("aml_review",
+ aml_review),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("rule_gen",
+ rule_gen),
+ NULL),
+ GNUNET_PQ_result_spec_bool ("kyc_required",
+ kyc_required),
+ GNUNET_PQ_result_spec_bool ("not_found",
+ ¬_found),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ *jrules = NULL;
+ *aml_review = false;
+ *is_wallet = GNUNET_SYSERR;
+ *rule_gen = 0;
+ memset (access_token,
+ 0,
+ sizeof (*access_token));
+ PREPARE (pg,
+ "get_legitimization_requirement_by_row",
+ "SELECT "
+ " out_access_token AS access_token"
+ ",out_jrules::TEXT AS jrules"
+ ",out_is_wallet AS is_wallet"
+ ",out_not_found AS not_found"
+ ",out_aml_review AS aml_review"
+ ",out_kyc_required AS kyc_required"
+ ",out_rule_gen AS rule_gen"
+ " FROM exchange_do_lookup_kyc_requirement_by_row"
+ " ($1, $2);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_legitimization_requirement_by_row",
+ params,
+ rs);
+ if (qs <= 0)
+ return qs;
+ if (! bis_wallet_unknown)
+ *is_wallet = (bis_wallet) ? GNUNET_YES : GNUNET_NO;
+ if (not_found)
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ return qs;
+}
diff --git a/src/exchangedb/lookup_kyc_requirement_by_row.sql b/src/exchangedb/get_legitimization_requirement_by_row.sql
diff --git a/src/exchangedb/get_old_coin_by_h_blind.c b/src/exchangedb/get_old_coin_by_h_blind.c
@@ -45,7 +45,7 @@ TALER_EXCHANGEDB_get_old_coin_by_h_blind (
/* Used in #postgres_get_old_coin_by_h_blind() */
PREPARE (pg,
- "old_coin_by_h_blind",
+ "get_old_coin_by_h_blind",
"SELECT"
" okc.coin_pub AS old_coin_pub"
",refresh_id"
@@ -54,7 +54,7 @@ TALER_EXCHANGEDB_get_old_coin_by_h_blind (
" WHERE $1=ANY(h_blind_evs)"
" LIMIT 1;");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "old_coin_by_h_blind",
+ "get_old_coin_by_h_blind",
params,
rs);
}
diff --git a/src/exchangedb/get_pending_kyc_requirement_process.c b/src/exchangedb/get_pending_kyc_requirement_process.c
@@ -1,62 +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 exchangedb/get_pending_kyc_requirement_process.c
- * @brief Implementation of the get_pending_kyc_requirement_process function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_pending_kyc_requirement_process.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_pending_kyc_requirement_process (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_name,
- char **redirect_url)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (provider_name),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("redirect_url",
- redirect_url),
- NULL),
- GNUNET_PQ_result_spec_end
- };
-
- *redirect_url = NULL;
- PREPARE (pg,
- "get_pending_kyc_requirement_process",
- "SELECT"
- " redirect_url"
- " FROM legitimization_processes"
- " WHERE provider_name=$1"
- " AND h_payto=$2"
- " AND NOT finished"
- " ORDER BY start_time DESC"
- " LIMIT 1");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "get_pending_kyc_requirement_process",
- params,
- rs);
-}
diff --git a/src/exchangedb/get_pending_legitimization.c b/src/exchangedb/get_pending_legitimization.c
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024, 2025 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_pending_legitimization.c
+ * @brief Implementation of the get_pending_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_pending_legitimization.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_pending_legitimization (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t legitimization_measure_serial_id,
+ struct TALER_AccountAccessTokenP *access_token,
+ struct TALER_NormalizedPaytoHashP *h_payto,
+ json_t **jmeasures,
+ bool *is_finished,
+ bool *is_wallet)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&legitimization_measure_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_json (
+ "jmeasures",
+ jmeasures),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_normalized_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "access_token",
+ access_token),
+ GNUNET_PQ_result_spec_bool (
+ "is_finished",
+ is_finished),
+ GNUNET_PQ_result_spec_bool (
+ "is_wallet",
+ is_wallet),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_pending_legitimization",
+ "SELECT "
+ " lm.jmeasures::TEXT"
+ ",kt.h_normalized_payto"
+ ",kt.is_wallet"
+ ",lm.access_token"
+ ",lm.is_finished"
+ " FROM legitimization_measures lm"
+ " JOIN kyc_targets kt"
+ " USING (access_token)"
+ " WHERE lm.legitimization_measure_serial_id=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_pending_legitimization",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_pending_legitimization_process.c b/src/exchangedb/get_pending_legitimization_process.c
@@ -0,0 +1,62 @@
+/*
+ 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 exchangedb/get_pending_legitimization_process.c
+ * @brief Implementation of the get_pending_legitimization_process function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_pending_legitimization_process.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_pending_legitimization_process (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_name,
+ char **redirect_url)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (provider_name),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("redirect_url",
+ redirect_url),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *redirect_url = NULL;
+ PREPARE (pg,
+ "get_pending_legitimization_process",
+ "SELECT"
+ " redirect_url"
+ " FROM legitimization_processes"
+ " WHERE provider_name=$1"
+ " AND h_payto=$2"
+ " AND NOT finished"
+ " ORDER BY start_time DESC"
+ " LIMIT 1");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_pending_legitimization_process",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_pending_profit_drain.c b/src/exchangedb/get_pending_profit_drain.c
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_pending_profit_drain.c
+ * @brief Implementation of the get_pending_profit_drain function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_pending_profit_drain.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_pending_profit_drain (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t *serial,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ char **account_section,
+ struct TALER_FullPayto *payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
+ serial),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ wtid),
+ GNUNET_PQ_result_spec_string ("account_section",
+ account_section),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri->full_payto),
+ GNUNET_PQ_result_spec_timestamp ("trigger_date",
+ request_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ amount),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_profit_drains_get_pending() */
+ PREPARE (pg,
+ "get_pending_profit_drain",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE NOT executed"
+ " ORDER BY trigger_date ASC"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_pending_profit_drain",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_profit_drain.c b/src/exchangedb/get_profit_drain.c
@@ -0,0 +1,72 @@
+/*
+ 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 exchangedb/get_profit_drain.c
+ * @brief Implementation of the get_profit_drain function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_profit_drain.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_profit_drain (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t *serial,
+ char **account_section,
+ struct TALER_FullPayto *payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
+ serial),
+ GNUNET_PQ_result_spec_string ("account_section",
+ account_section),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri->full_payto),
+ GNUNET_PQ_result_spec_timestamp ("trigger_date",
+ request_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ amount),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_profit_drain",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE wtid=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_profit_drain",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_purse.c b/src/exchangedb/get_purse.c
@@ -0,0 +1,90 @@
+/*
+ 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 get_purse.c
+ * @brief Implementation of the get_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_purse.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_purse (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_creation,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_Amount *amount,
+ struct TALER_Amount *deposited,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ bool *purse_deleted,
+ bool *purse_refunded)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ purse_expiration),
+ GNUNET_PQ_result_spec_timestamp ("purse_creation",
+ purse_creation),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ deposited),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ h_contract_terms),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ merge_timestamp),
+ NULL),
+ GNUNET_PQ_result_spec_bool ("purse_deleted",
+ purse_deleted),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_bool ("purse_refunded",
+ purse_refunded),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_purse",
+ "SELECT "
+ " pr.merge_pub"
+ ",pr.purse_creation"
+ ",pr.purse_expiration"
+ ",pr.h_contract_terms"
+ ",pr.amount_with_fee"
+ ",pr.balance"
+ ",pm.merge_timestamp"
+ ",pd.purse_sig IS NOT NULL AS purse_deleted"
+ ",pc.refunded AS purse_refunded"
+ " FROM purse_requests pr"
+ " LEFT JOIN purse_merges pm ON (pm.purse_pub = pr.purse_pub)"
+ " LEFT JOIN purse_decision pc ON (pc.purse_pub = pr.purse_pub)"
+ " LEFT JOIN purse_deletion pd ON (pd.purse_pub = pr.purse_pub)"
+ " WHERE pr.purse_pub=$1;");
+ *merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
+ *purse_refunded = false;
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_purse",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_purse_by_merge_pub.c b/src/exchangedb/get_purse_by_merge_pub.c
@@ -0,0 +1,75 @@
+/*
+ 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 exchangedb/get_purse_by_merge_pub.c
+ * @brief Implementation of the get_purse_by_merge_pub function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_purse_by_merge_pub.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_purse_by_merge_pub (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t *age_limit,
+ struct TALER_Amount *target_amount,
+ struct TALER_Amount *balance,
+ struct TALER_PurseContractSignatureP *purse_sig)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (merge_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ purse_pub),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ purse_expiration),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ h_contract_terms),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ age_limit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ target_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ balance),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
+ purse_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_purse_by_merge_pub",
+ "SELECT "
+ " purse_pub"
+ ",purse_expiration"
+ ",h_contract_terms"
+ ",age_limit"
+ ",amount_with_fee"
+ ",balance"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE merge_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_purse_by_merge_pub",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_purse_deposit.c b/src/exchangedb/get_purse_deposit.c
@@ -57,7 +57,7 @@ TALER_EXCHANGEDB_get_purse_deposit (
*partner_url = NULL;
PREPARE (pg,
- "select_purse_deposit_by_coin_pub",
+ "get_purse_deposit",
"SELECT "
" coin_sig"
",amount_with_fee"
@@ -74,7 +74,7 @@ TALER_EXCHANGEDB_get_purse_deposit (
" WHERE purse_pub=$1"
" AND coin_pub=$2;");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_deposit_by_coin_pub",
+ "get_purse_deposit",
params,
rs);
}
diff --git a/src/exchangedb/get_purse_merge.c b/src/exchangedb/get_purse_merge.c
@@ -0,0 +1,76 @@
+/*
+ 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 exchangedb/get_purse_merge.c
+ * @brief Implementation of the get_purse_merge function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_purse_merge.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_purse_merge (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseMergeSignatureP *merge_sig,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ char **partner_url,
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *refunded)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
+ merge_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ reserve_pub),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ merge_timestamp),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ partner_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_bool ("refunded",
+ refunded),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *partner_url = NULL;
+ *refunded = false;
+ PREPARE (pg,
+ "get_purse_merge",
+ "SELECT "
+ " pm.reserve_pub"
+ ",pm.merge_sig"
+ ",pm.merge_timestamp"
+ ",pr.partner_base_url"
+ ",pd.refunded"
+ " FROM purse_merges pm"
+ " LEFT JOIN purse_decision pd USING (purse_pub)"
+ " LEFT JOIN partners pr USING (partner_serial_id)"
+ " WHERE pm.purse_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_purse_merge",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_reserve.c b/src/exchangedb/get_reserve.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_reserve.c
+ * @brief Implementation of the get_reserve function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_reserve.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct TALER_EXCHANGEDB_Reserve *reserve)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ &reserve->balance),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &reserve->expiry),
+ GNUNET_PQ_result_spec_timestamp ("gc_date",
+ &reserve->gc),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_reserves_get() */
+ PREPARE (pg,
+ "get_reserve",
+ "SELECT"
+ " current_balance"
+ ",expiration_date"
+ ",gc_date"
+ " FROM reserves"
+ " WHERE reserve_pub=$1"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_reserve",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_reserve_by_h_planchets.c b/src/exchangedb/get_reserve_by_h_planchets.c
@@ -44,7 +44,7 @@ TALER_EXCHANGEDB_get_reserve_by_h_planchets (
};
/* Used in #postgres_get_reserve_by_h_planchets() */
PREPARE (pg,
- "reserve_by_h_planchets",
+ "get_reserve_by_h_planchets",
"SELECT"
" reserve_pub"
",withdraw_id"
@@ -52,7 +52,7 @@ TALER_EXCHANGEDB_get_reserve_by_h_planchets (
" WHERE planchets_h=$1"
" LIMIT 1;");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserve_by_h_planchets",
+ "get_reserve_by_h_planchets",
params,
rs);
}
diff --git a/src/exchangedb/get_reserve_close_info.c b/src/exchangedb/get_reserve_close_info.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 get_reserve_close_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_reserve_close_info.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve_close_info (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance,
+ struct TALER_FullPayto *payto_uri)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ balance),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri->full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_reserve_close_info",
+ "SELECT "
+ " r.current_balance"
+ ",wt.payto_uri"
+ " FROM reserves r"
+ " LEFT JOIN reserves_in ri"
+ " USING (reserve_pub)"
+ " LEFT JOIN wire_targets wt"
+ " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE r.reserve_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_reserve_close_info",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_reserve_close_request_info.c b/src/exchangedb/get_reserve_close_request_info.c
@@ -0,0 +1,73 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2026 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 get_reserve_close_request_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_reserve_close_request_info.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve_close_request_info (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t rowid,
+ struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *close_balance,
+ struct TALER_Amount *close_fee,
+ struct TALER_FullPayto *payto_uri)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ reserve_sig),
+ GNUNET_PQ_result_spec_timestamp ("close_timestamp",
+ request_timestamp),
+ TALER_PQ_result_spec_amount ("close",
+ pg->currency,
+ close_balance),
+ TALER_PQ_result_spec_amount ("close_fee",
+ pg->currency,
+ close_fee),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri->full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_reserve_close_request_info",
+ "SELECT "
+ " cr.reserve_sig"
+ " ,cr.close_timestamp"
+ " ,cr.close"
+ " ,cr.close_fee"
+ " ,cr.payto_uri"
+ " FROM close_requests cr"
+ " WHERE cr.reserve_pub=$1"
+ " AND cr.row_id=$2;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_reserve_close_request_info",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_reserve_history.c b/src/exchangedb/get_reserve_history.c
@@ -599,31 +599,31 @@ handle_history_entry (void *cls,
} work[] = {
/** #TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE */
{ "reserves_in",
- "reserves_in_get_transactions",
+ "get_reserve_history_reserves_in_get_transactions",
add_bank_to_exchange },
/** #TALER_EXCHANGEDB_RO_WITHDRAW_COINS */
{ "withdraw",
- "get_withdraw_details",
+ "get_reserve_history_withdraw_details",
&add_withdraw },
/** #TALER_EXCHANGEDB_RO_RECOUP_COIN */
{ "recoup",
- "recoup_by_reserve",
+ "get_reserve_history_recoup_by_reserve",
&add_recoup },
/** #TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK */
{ "reserves_close",
- "close_by_reserve",
+ "get_reserve_history_close_by_reserve",
&add_exchange_to_bank },
/** #TALER_EXCHANGEDB_RO_PURSE_MERGE */
{ "purse_decision",
- "merge_by_reserve",
+ "get_reserve_history_merge_by_reserve",
&add_p2p_merge },
/** #TALER_EXCHANGEDB_RO_OPEN_REQUEST */
{ "reserves_open_requests",
- "open_request_by_reserve",
+ "get_reserve_history_open_request_by_reserve",
&add_open_requests },
/** #TALER_EXCHANGEDB_RO_CLOSE_REQUEST */
{ "close_requests",
- "close_request_by_reserve",
+ "get_reserve_history_close_request_by_reserve",
&add_close_requests },
/* List terminator */
{ NULL, NULL, NULL }
@@ -747,7 +747,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" AND reserve_history_serial_id > $2"
" ORDER BY reserve_history_serial_id DESC;");
PREPARE (pg,
- "reserves_in_get_transactions",
+ "get_reserve_history_reserves_in_get_transactions",
"SELECT"
" ri.wire_reference"
",ri.credit"
@@ -759,7 +759,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" WHERE ri.reserve_pub=$1"
" AND ri.reserve_in_serial_id=$2;");
PREPARE (pg,
- "get_withdraw_details",
+ "get_reserve_history_withdraw_details",
"SELECT"
" planchets_h"
",amount_with_fee"
@@ -780,7 +780,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" WHERE withdraw_id=$2"
" AND reserve_pub=$1;");
PREPARE (pg,
- "recoup_by_reserve",
+ "get_reserve_history_recoup_by_reserve",
"SELECT"
" rec.coin_pub"
",rec.coin_sig"
@@ -801,7 +801,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" WHERE rec.recoup_uuid=$2"
" AND res.reserve_pub=$1;");
PREPARE (pg,
- "close_by_reserve",
+ "get_reserve_history_close_by_reserve",
"SELECT"
" rc.amount"
",rc.closing_fee"
@@ -814,7 +814,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" WHERE reserve_pub=$1"
" AND close_uuid=$2;");
PREPARE (pg,
- "merge_by_reserve",
+ "get_reserve_history_merge_by_reserve",
"SELECT"
" pr.amount_with_fee"
",pr.balance"
@@ -840,7 +840,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" AND COALESCE(pm.partner_serial_id,0)=0" /* must be local! */
" AND NOT pdes.refunded;");
PREPARE (pg,
- "open_request_by_reserve",
+ "get_reserve_history_open_request_by_reserve",
"SELECT"
" reserve_payment AS open_fee"
",request_timestamp"
@@ -851,7 +851,7 @@ TALER_EXCHANGEDB_get_reserve_history (
" WHERE reserve_pub=$1"
" AND open_request_uuid=$2;");
PREPARE (pg,
- "close_request_by_reserve",
+ "get_reserve_history_close_request_by_reserve",
"SELECT"
" close_timestamp"
",payto_uri"
@@ -873,8 +873,8 @@ TALER_EXCHANGEDB_get_reserve_history (
};
if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_committed (pg,
- "get-reserve-transactions")
+ TALER_EXCHANGEDB_start_read_committed (pg,
+ "get-reserve-transactions")
)
{
GNUNET_break (0);
diff --git a/src/exchangedb/get_reserve_origin.c b/src/exchangedb/get_reserve_origin.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 exchangedb/get_reserve_origin.c
+ * @brief Implementation of the get_reserve_origin function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_reserve_origin.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve_origin (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_FullPaytoHashP *h_payto,
+ struct TALER_FullPayto *payto_uri)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_source_h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_string (
+ "payto_uri",
+ &payto_uri->full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_reserve_origin",
+ "SELECT"
+ " rt.wire_source_h_payto"
+ ",wt.payto_uri"
+ " FROM reserves_in rt"
+ " JOIN wire_targets wt"
+ " ON (rt.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE rt.reserve_pub=$1");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_reserve_origin",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_rules_by_access_token.c b/src/exchangedb/get_rules_by_access_token.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_rules_by_access_token.c
+ * @brief Implementation of the get_rules_by_access_token function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_rules_by_access_token.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_rules_by_access_token (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ json_t **jnew_rules,
+ uint64_t *rowid)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json (
+ "jnew_rules",
+ jnew_rules),
+ NULL),
+ GNUNET_PQ_result_spec_uint64 (
+ "row_id",
+ rowid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *jnew_rules = NULL;
+ PREPARE (pg,
+ "get_rules_by_access_token",
+ "SELECT"
+ " jnew_rules::TEXT"
+ ",outcome_serial_id AS row_id"
+ " FROM legitimization_outcomes"
+ " WHERE h_payto=$1"
+ " AND is_active"
+ " ORDER BY expiration_time DESC,"
+ " outcome_serial_id DESC"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_rules_by_access_token",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_serial_by_table.c b/src/exchangedb/get_serial_by_table.c
@@ -0,0 +1,441 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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 get_serial_by_table.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_serial_by_table.h"
+#include "helper.h"
+
+
+/**
+ * Assign statement to @a n and PREPARE
+ * @a sql under name @a n.
+ */
+#define XPREPARE(n,sql) \
+ statement = n; \
+ PREPARE (pg, n, sql);
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_serial_by_table (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ enum TALER_EXCHANGEDB_ReplicatedTable
+ table,
+ uint64_t *serial)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ serial),
+ GNUNET_PQ_result_spec_end
+ };
+ const char *statement = NULL;
+
+ switch (table)
+ {
+ case TALER_EXCHANGEDB_RT_DENOMINATIONS:
+ XPREPARE ("select_serial_by_table_denominations",
+ "SELECT"
+ " denominations_serial AS serial"
+ " FROM denominations"
+ " ORDER BY denominations_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
+ XPREPARE ("select_serial_by_table_denomination_revocations",
+ "SELECT"
+ " denom_revocations_serial_id AS serial"
+ " FROM denomination_revocations"
+ " ORDER BY denom_revocations_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
+ XPREPARE ("select_serial_by_table_wire_targets",
+ "SELECT"
+ " wire_target_serial_id AS serial"
+ " FROM wire_targets"
+ " ORDER BY wire_target_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_TARGETS:
+ XPREPARE ("select_serial_by_table_kyc_targets",
+ "SELECT"
+ " kyc_target_serial_id AS serial"
+ " FROM kyc_targets"
+ " ORDER BY kyc_target_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES:
+ XPREPARE ("select_serial_by_table_reserves",
+ "SELECT"
+ " reserve_uuid AS serial"
+ " FROM reserves"
+ " ORDER BY reserve_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_IN:
+ XPREPARE ("select_serial_by_table_reserves_in",
+ "SELECT"
+ " reserve_in_serial_id AS serial"
+ " FROM reserves_in"
+ " ORDER BY reserve_in_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
+ XPREPARE ("select_serial_by_table_kycauths_in",
+ "SELECT"
+ " kycauth_in_serial_id AS serial"
+ " FROM kycauths_in"
+ " ORDER BY kycauth_in_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
+ XPREPARE ("select_serial_by_table_reserves_close",
+ "SELECT"
+ " close_uuid AS serial"
+ " FROM reserves_close"
+ " ORDER BY close_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
+ XPREPARE ("select_serial_by_table_reserves_open_requests",
+ "SELECT"
+ " open_request_uuid AS serial"
+ " FROM reserves_open_requests"
+ " ORDER BY open_request_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
+ XPREPARE ("select_serial_by_table_reserves_open_deposits",
+ "SELECT"
+ " reserve_open_deposit_uuid AS serial"
+ " FROM reserves_open_deposits"
+ " ORDER BY reserve_open_deposit_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITORS:
+ XPREPARE ("select_serial_by_table_auditors",
+ "SELECT"
+ " auditor_uuid AS serial"
+ " FROM auditors"
+ " ORDER BY auditor_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
+ XPREPARE ("select_serial_by_table_auditor_denom_sigs",
+ "SELECT"
+ " auditor_denom_serial AS serial"
+ " FROM auditor_denom_sigs"
+ " ORDER BY auditor_denom_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
+ XPREPARE ("select_serial_by_table_exchange_sign_keys",
+ "SELECT"
+ " esk_serial AS serial"
+ " FROM exchange_sign_keys"
+ " ORDER BY esk_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
+ XPREPARE ("select_serial_by_table_signkey_revocations",
+ "SELECT"
+ " signkey_revocations_serial_id AS serial"
+ " FROM signkey_revocations"
+ " ORDER BY signkey_revocations_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_KNOWN_COINS:
+ XPREPARE ("select_serial_by_table_known_coins",
+ "SELECT"
+ " known_coin_id AS serial"
+ " FROM known_coins"
+ " ORDER BY known_coin_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH:
+ XPREPARE ("select_serial_by_table_refresh",
+ "SELECT"
+ " refresh_id AS serial"
+ " FROM refresh"
+ " ORDER BY refresh_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
+ XPREPARE ("select_serial_by_table_batch_deposits",
+ "SELECT"
+ " batch_deposit_serial_id AS serial"
+ " FROM batch_deposits"
+ " ORDER BY batch_deposit_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
+ XPREPARE ("select_serial_by_table_coin_deposits",
+ "SELECT"
+ " coin_deposit_serial_id AS serial"
+ " FROM coin_deposits"
+ " ORDER BY coin_deposit_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_REFUNDS:
+ XPREPARE ("select_serial_by_table_refunds",
+ "SELECT"
+ " refund_serial_id AS serial"
+ " FROM refunds"
+ " ORDER BY refund_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_OUT:
+ XPREPARE ("select_serial_by_table_wire_out",
+ "SELECT"
+ " wireout_uuid AS serial"
+ " FROM wire_out"
+ " ORDER BY wireout_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
+ XPREPARE ("select_serial_by_table_aggregation_tracking",
+ "SELECT"
+ " aggregation_serial_id AS serial"
+ " FROM aggregation_tracking"
+ " ORDER BY aggregation_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_FEE:
+ XPREPARE ("select_serial_by_table_wire_fee",
+ "SELECT"
+ " wire_fee_serial AS serial"
+ " FROM wire_fee"
+ " ORDER BY wire_fee_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
+ XPREPARE ("select_serial_by_table_global_fee",
+ "SELECT"
+ " global_fee_serial AS serial"
+ " FROM global_fee"
+ " ORDER BY global_fee_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP:
+ XPREPARE ("select_serial_by_table_recoup",
+ "SELECT"
+ " recoup_uuid AS serial"
+ " FROM recoup"
+ " ORDER BY recoup_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
+ XPREPARE ("select_serial_by_table_recoup_refresh",
+ "SELECT"
+ " recoup_refresh_uuid AS serial"
+ " FROM recoup_refresh"
+ " ORDER BY recoup_refresh_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
+ XPREPARE ("select_serial_by_table_purse_requests",
+ "SELECT"
+ " purse_requests_serial_id AS serial"
+ " FROM purse_requests"
+ " ORDER BY purse_requests_serial_id DESC"
+ " LIMIT 1;")
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DECISION:
+ XPREPARE ("select_serial_by_table_purse_decision",
+ "SELECT"
+ " purse_decision_serial_id AS serial"
+ " FROM purse_decision"
+ " ORDER BY purse_decision_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_MERGES:
+ XPREPARE ("select_serial_by_table_purse_merges",
+ "SELECT"
+ " purse_merge_request_serial_id AS serial"
+ " FROM purse_merges"
+ " ORDER BY purse_merge_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
+ XPREPARE ("select_serial_by_table_purse_deposits",
+ "SELECT"
+ " purse_deposit_serial_id AS serial"
+ " FROM purse_deposits"
+ " ORDER BY purse_deposit_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
+ XPREPARE ("select_serial_by_table_account_merges",
+ "SELECT"
+ " account_merge_request_serial_id AS serial"
+ " FROM account_merges"
+ " ORDER BY account_merge_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
+ XPREPARE ("select_serial_by_table_history_requests",
+ "SELECT"
+ " history_request_serial_id AS serial"
+ " FROM history_requests"
+ " ORDER BY history_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
+ XPREPARE ("select_serial_by_table_close_requests",
+ "SELECT"
+ " close_request_serial_id AS serial"
+ " FROM close_requests"
+ " ORDER BY close_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT:
+ XPREPARE ("select_serial_by_table_wads_out",
+ "SELECT"
+ " wad_out_serial_id AS serial"
+ " FROM wads_out"
+ " ORDER BY wad_out_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
+ XPREPARE ("select_serial_by_table_wads_out_entries",
+ "SELECT"
+ " wad_out_entry_serial_id AS serial"
+ " FROM wad_out_entries"
+ " ORDER BY wad_out_entry_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN:
+ XPREPARE ("select_serial_by_table_wads_in",
+ "SELECT"
+ " wad_in_serial_id AS serial"
+ " FROM wads_in"
+ " ORDER BY wad_in_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
+ XPREPARE ("select_serial_by_table_wads_in_entries",
+ "SELECT"
+ " wad_in_entry_serial_id AS serial"
+ " FROM wad_in_entries"
+ " ORDER BY wad_in_entry_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
+ XPREPARE ("select_serial_by_table_profit_drains",
+ "SELECT"
+ " profit_drain_serial_id AS serial"
+ " FROM profit_drains"
+ " ORDER BY profit_drain_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_profit_drains";
+ break;
+ case TALER_EXCHANGEDB_RT_AML_STAFF:
+ XPREPARE ("select_serial_by_table_aml_staff",
+ "SELECT"
+ " aml_staff_uuid AS serial"
+ " FROM aml_staff"
+ " ORDER BY aml_staff_uuid DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_aml_staff";
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DELETION:
+ XPREPARE ("select_serial_by_table_purse_deletion",
+ "SELECT"
+ " purse_deletion_serial_id AS serial"
+ " FROM purse_deletion"
+ " ORDER BY purse_deletion_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_purse_deletion";
+ break;
+ case TALER_EXCHANGEDB_RT_WITHDRAW:
+ XPREPARE ("select_serial_by_table_withdraw",
+ "SELECT"
+ " withdraw_id AS serial"
+ " FROM withdraw"
+ " ORDER BY withdraw_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_withdraw";
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES:
+ XPREPARE ("select_serial_by_table_legitimization_measures",
+ "SELECT"
+ " legitimization_measure_serial_id AS serial"
+ " FROM legitimization_measures"
+ " ORDER BY legitimization_measure_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES:
+ XPREPARE ("select_serial_by_table_legitimization_outcomes",
+ "SELECT"
+ " outcome_serial_id AS serial"
+ " FROM legitimization_outcomes"
+ " ORDER BY outcome_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
+ XPREPARE ("select_serial_by_table_legitimization_processes",
+ "SELECT"
+ " legitimization_process_serial_id AS serial"
+ " FROM legitimization_processes"
+ " ORDER BY legitimization_process_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
+ XPREPARE ("select_serial_by_table_kyc_attributes",
+ "SELECT"
+ " kyc_attributes_serial_id AS serial"
+ " FROM kyc_attributes"
+ " ORDER BY kyc_attributes_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_kyc_attributes";
+ break;
+ case TALER_EXCHANGEDB_RT_AML_HISTORY:
+ XPREPARE ("select_serial_by_table_aml_history",
+ "SELECT"
+ " aml_history_serial_id AS serial"
+ " FROM aml_history"
+ " ORDER BY aml_history_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_aml_history";
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_EVENTS:
+ XPREPARE ("select_serial_by_table_kyc_events",
+ "SELECT"
+ " kyc_event_serial_id AS serial"
+ " FROM kyc_events"
+ " ORDER BY kyc_event_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ }
+ if (NULL == statement)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ statement,
+ params,
+ rs);
+}
+
+
+#undef XPREPARE
diff --git a/src/exchangedb/get_signkey.c b/src/exchangedb/get_signkey.c
@@ -0,0 +1,60 @@
+/*
+ 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 exchangedb/get_signkey.c
+ * @brief Implementation of the get_signkey function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_signkey.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_signkey (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_EXCHANGEDB_SignkeyMetaData *meta)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &meta->start),
+ GNUNET_PQ_result_spec_timestamp ("expire_sign",
+ &meta->expire_sign),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &meta->expire_legal),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ PREPARE (pg,
+ "get_signkey",
+ "SELECT"
+ " valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ " FROM exchange_sign_keys"
+ " WHERE exchange_pub=$1");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_signkey",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_signkey_revocation.c b/src/exchangedb/get_signkey_revocation.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 exchangedb/get_signkey_revocation.c
+ * @brief Implementation of the get_signkey_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_signkey_revocation.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_signkey_revocation (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_signkey_revocation",
+ "SELECT "
+ " master_sig"
+ " FROM signkey_revocations"
+ " WHERE esk_serial="
+ " (SELECT esk_serial"
+ " FROM exchange_sign_keys"
+ " WHERE exchange_pub=$1);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_signkey_revocation",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/get_transfer_by_deposit.c b/src/exchangedb/get_transfer_by_deposit.c
@@ -0,0 +1,220 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_transfer_by_deposit.c
+ * @brief Implementation of the get_transfer_by_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_transfer_by_deposit.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_transfer_by_deposit (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ bool *pending,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp *exec_time,
+ struct TALER_Amount *amount_with_fee,
+ struct TALER_Amount *deposit_fee,
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ union TALER_AccountPublicKeyP *account_pub)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_FullPayto payto_uri;
+ struct TALER_WireSaltP wire_salt;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ wtid),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &wire_salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri.full_payto),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ exec_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ deposit_fee),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("target_pub",
+ account_pub),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ memset (kyc,
+ 0,
+ sizeof (*kyc));
+ /* check if the aggregation record exists and get it */
+ PREPARE (pg,
+ "get_transfer_by_deposit_wtid",
+ "SELECT"
+ " atr.wtid_raw"
+ ",wire_out.execution_date"
+ ",cdep.amount_with_fee"
+ ",bdep.wire_salt"
+ ",wt.payto_uri"
+ ",kt.target_pub"
+ ",denom.fee_deposit"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ /* kyc_targets might not match; then target_pub will be NULL */
+ " LEFT JOIN kyc_targets kt"
+ " USING (h_normalized_payto)"
+ " JOIN aggregation_tracking atr"
+ " ON (cdep.batch_deposit_serial_id = atr.batch_deposit_serial_id)"
+ " JOIN known_coins kc"
+ " ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " JOIN wire_out"
+ " USING (wtid_raw)"
+ " WHERE cdep.coin_pub=$1"
+ " AND bdep.merchant_pub=$3"
+ " AND bdep.h_contract_terms=$2");
+ /* NOTE: above query might be more efficient if we computed the shard
+ from the merchant_pub and included that in the query */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_transfer_by_deposit_wtid",
+ params,
+ rs);
+ if (0 > qs)
+ return qs;
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ struct TALER_MerchantWireHashP wh;
+
+ TALER_merchant_wire_signature_hash (payto_uri,
+ &wire_salt,
+ &wh);
+ if (0 ==
+ GNUNET_memcmp (&wh,
+ h_wire))
+ {
+ *pending = false;
+ kyc->ok = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return qs;
+ }
+ qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ GNUNET_PQ_cleanup_result (rs);
+ }
+ *pending = true;
+ memset (wtid,
+ 0,
+ sizeof (*wtid));
+ GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "lookup_deposit_wtid returned 0 matching rows\n");
+ {
+ /* Check if transaction exists in deposits, so that we just
+ do not have a WTID yet. In that case, return without wtid
+ (by setting 'pending' true). */
+ struct GNUNET_PQ_ResultSpec rs2[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &wire_salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri.full_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ deposit_fee),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ exec_time),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("legitimization_requirement_serial_id",
+ &kyc->requirement_row),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("target_pub",
+ account_pub),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_transfer_by_deposit_without_wtid",
+ "SELECT"
+ " bdep.wire_salt"
+ ",wt.payto_uri"
+ ",cdep.amount_with_fee"
+ ",denom.fee_deposit"
+ ",bdep.wire_deadline"
+ ",agt.legitimization_requirement_serial_id"
+ ",kt.target_pub"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ /* kyc_targets might not match; then target_pub will be NULL */
+ " LEFT JOIN kyc_targets kt"
+ " USING (h_normalized_payto)"
+ " JOIN known_coins kc"
+ " ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " LEFT JOIN aggregation_transient agt "
+ " ON ( (bdep.wire_target_h_payto = agt.wire_target_h_payto) AND"
+ " (bdep.merchant_pub = agt.merchant_pub) )"
+ " WHERE cdep.coin_pub=$1"
+ " AND bdep.merchant_pub=$3"
+ " AND bdep.h_contract_terms=$2"
+ " LIMIT 1;");
+ /* NOTE: above query might be more efficient if we computed the shard
+ from the merchant_pub and included that in the query */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_transfer_by_deposit_without_wtid",
+ params,
+ rs2);
+ if (0 > qs)
+ return qs;
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ struct TALER_MerchantWireHashP wh;
+
+ TALER_merchant_wire_signature_hash (payto_uri,
+ &wire_salt,
+ &wh);
+ if (0 !=
+ GNUNET_memcmp (&wh,
+ h_wire))
+ {
+ GNUNET_PQ_cleanup_result (rs2);
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ GNUNET_PQ_cleanup_result (rs2);
+ if (0 == kyc->requirement_row)
+ kyc->ok = true; /* technically: unknown */
+ }
+ return qs;
+ }
+}
diff --git a/src/exchangedb/get_unfinished_close_requests.c b/src/exchangedb/get_unfinished_close_requests.c
@@ -1,162 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 get_unfinished_close_requests.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_unfinished_close_requests.h"
-#include "helper.h"
-
-
-/**
- * Closure for #reserve_close_cb().
- */
-struct CloseReserveContext
-{
- /**
- * Function to call for each to be closed reserve.
- */
- TALER_EXCHANGEDB_ReserveExpiredCallback rec;
-
- /**
- * Closure to give to @e rec.
- */
- void *rec_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CloseReserveContext *erc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = erc->pg;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_TIME_Timestamp exp_date;
- struct TALER_FullPayto account_details;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount remaining_balance;
- uint64_t close_request_row;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &exp_date),
- GNUNET_PQ_result_spec_string ("account_details",
- &account_details.full_payto),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("close",
- &remaining_balance),
- GNUNET_PQ_result_spec_uint64 ("close_request_serial_id",
- &close_request_row),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ret = GNUNET_SYSERR;
- break;
- }
- ret = erc->rec (erc->rec_cls,
- &reserve_pub,
- &remaining_balance,
- account_details,
- exp_date,
- close_request_row);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
- erc->status = ret;
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_unfinished_close_requests (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- TALER_EXCHANGEDB_ReserveExpiredCallback rec,
- void *rec_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct CloseReserveContext ectx = {
- .rec = rec,
- .rec_cls = rec_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "get_unfinished_close_requests",
- "UPDATE close_requests AS rc"
- " SET done=TRUE"
- " WHERE NOT done"
- " RETURNING"
- " reserve_pub"
- " ,close_request_serial_id"
- " ,close_timestamp AS expiration_date"
- " ,close"
- " ,(SELECT payto_uri"
- " FROM reserves_in ri"
- " JOIN wire_targets wt"
- " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE ri.reserve_pub=rc.reserve_pub)"
- " AS account_details;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_unfinished_close_requests",
- params,
- &reserve_cb,
- &ectx);
- switch (ectx.status)
- {
- case GNUNET_SYSERR:
- return GNUNET_DB_STATUS_HARD_ERROR;
- case GNUNET_NO:
- return GNUNET_DB_STATUS_SOFT_ERROR;
- case GNUNET_OK:
- break;
- }
- return qs;
-}
diff --git a/src/exchangedb/get_wire_accounts.c b/src/exchangedb/get_wire_accounts.c
@@ -1,180 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/get_wire_accounts.c
- * @brief Implementation of the get_wire_accounts function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_wire_accounts.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_wire_accounts_cb().
- */
-struct GetWireAccountsContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_WireAccountCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Flag set to #GNUNET_OK as long as everything is fine.
- */
- enum GNUNET_GenericReturnValue status;
-
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_wire_accounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetWireAccountsContext *ctx = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_FullPayto payto_uri;
- char *conversion_url = NULL;
- char *open_banking_gateway = NULL;
- char *prepared_transfer_url = NULL;
- json_t *debit_restrictions = NULL;
- json_t *credit_restrictions = NULL;
- struct TALER_MasterSignatureP master_sig;
- char *bank_label = NULL;
- int64_t priority;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri.full_payto),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("conversion_url",
- &conversion_url),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("open_banking_gateway",
- &open_banking_gateway),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- /* FIXME: rename in database migration */
- GNUNET_PQ_result_spec_string ("wire_transfer_gateway",
- &prepared_transfer_url),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("bank_label",
- &bank_label),
- NULL),
- GNUNET_PQ_result_spec_int64 ("priority",
- &priority),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json ("debit_restrictions",
- &debit_restrictions),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json ("credit_restrictions",
- &credit_restrictions),
- NULL),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- if (NULL == debit_restrictions)
- {
- debit_restrictions = json_array ();
- GNUNET_assert (NULL != debit_restrictions);
- }
- if (NULL == credit_restrictions)
- {
- credit_restrictions = json_array ();
- GNUNET_assert (NULL != credit_restrictions);
- }
- ctx->cb (ctx->cb_cls,
- payto_uri,
- conversion_url,
- open_banking_gateway,
- prepared_transfer_url,
- debit_restrictions,
- credit_restrictions,
- &master_sig,
- bank_label,
- priority);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_wire_accounts (struct TALER_EXCHANGEDB_PostgresContext *pg,
- TALER_EXCHANGEDB_WireAccountCallback cb,
- void *cb_cls)
-{
- struct GetWireAccountsContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "get_wire_accounts",
- "SELECT"
- " payto_uri"
- ",conversion_url"
- ",open_banking_gateway"
- ",wire_transfer_gateway"
- ",debit_restrictions::TEXT"
- ",credit_restrictions::TEXT"
- ",master_sig"
- ",bank_label"
- ",priority"
- " FROM wire_accounts"
- " WHERE is_active");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_wire_accounts",
- params,
- &get_wire_accounts_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/get_wire_fee_by_time.c b/src/exchangedb/get_wire_fee_by_time.c
@@ -0,0 +1,152 @@
+/*
+ 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 exchangedb/get_wire_fee_by_time.c
+ * @brief Implementation of the get_wire_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_wire_fee_by_time.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #wire_fee_by_time_helper()
+ */
+struct WireFeeLookupContext
+{
+
+ /**
+ * Set to the wire fees. Set to invalid if fees conflict over
+ * the given time period.
+ */
+ struct TALER_WireFeeSet *fees;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+};
+
+
+/**
+ * Helper function for #TALER_EXCHANGEDB_get_wire_fee_by_time().
+ * Calls the callback with the wire fee structure.
+ *
+ * @param cls a `struct WireFeeLookupContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+wire_fee_by_time_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireFeeLookupContext *wlc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = wlc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_WireFeeSet fs;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &fs.wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &fs.closing),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_WireFeeSet));
+ return;
+ }
+ if (0 == i)
+ {
+ *wlc->fees = fs;
+ continue;
+ }
+ if (0 !=
+ TALER_wire_fee_set_cmp (&fs,
+ wlc->fees))
+ {
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_WireFeeSet));
+ return;
+ }
+ }
+}
+
+
+/**
+ * Lookup information about known wire fees. Finds all applicable
+ * fees in the given range. If they are identical, returns the
+ * respective @a fees. If any of the fees
+ * differ between @a start_time and @a end_time, the transaction
+ * succeeds BUT returns an invalid amount for both fees.
+ *
+ * @param pg the database context
+ * @param wire_method the wire method to lookup fees for
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees wire fees for that time period; if
+ * different fees exists within this time
+ * period, an 'invalid' amount is returned.
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_wire_fee_by_time (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *wire_method,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_WireFeeSet *fees)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (wire_method),
+ GNUNET_PQ_query_param_timestamp (&start_time),
+ GNUNET_PQ_query_param_timestamp (&end_time),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireFeeLookupContext wlc = {
+ .fees = fees,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "get_wire_fee_by_time",
+ "SELECT"
+ " wire_fee"
+ ",closing_fee"
+ " FROM wire_fee"
+ " WHERE wire_method=$1"
+ " AND end_date > $2"
+ " AND start_date < $3;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_wire_fee_by_time",
+ params,
+ &wire_fee_by_time_helper,
+ &wlc);
+}
diff --git a/src/exchangedb/get_wire_fees.c b/src/exchangedb/get_wire_fees.c
@@ -1,144 +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 exchangedb/get_wire_fees.c
- * @brief Implementation of the get_wire_fees function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/get_wire_fees.h"
-#include "helper.h"
-
-/**
- * Closure for #get_wire_fees_cb().
- */
-struct GetWireFeesContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_WireFeeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 GetWireFeesContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_wire_fees_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetWireFeesContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_MasterSignatureP master_sig;
- struct TALER_WireFeeSet fees;
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
- &fees.wire),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &fees.closing),
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &end_date),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- 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,
- &fees,
- start_date,
- end_date,
- &master_sig);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_get_wire_fees (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const char *wire_method,
- TALER_EXCHANGEDB_WireFeeCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (wire_method),
- GNUNET_PQ_query_param_end
- };
- struct GetWireFeesContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "get_wire_fees",
- "SELECT"
- " wire_fee"
- ",closing_fee"
- ",start_date"
- ",end_date"
- ",master_sig"
- " FROM wire_fee"
- " WHERE wire_method=$1");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_wire_fees",
- params,
- &get_wire_fees_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/get_wire_timestamp.c b/src/exchangedb/get_wire_timestamp.c
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/get_wire_timestamp.c
+ * @brief Implementation of the get_wire_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/get_wire_timestamp.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_wire_timestamp (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPayto payto_uri,
+ struct GNUNET_TIME_Timestamp *last_date)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (payto_uri.full_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("last_change",
+ last_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_wire_timestamp",
+ "SELECT"
+ " last_change"
+ " FROM wire_accounts"
+ " WHERE payto_uri=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_wire_timestamp",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/have_deposit2.c b/src/exchangedb/have_deposit2.c
@@ -1,113 +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 exchangedb/have_deposit2.c
- * @brief Implementation of the have_deposit2 function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/have_deposit2.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_have_deposit2 (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant,
- struct GNUNET_TIME_Timestamp refund_deadline,
- struct TALER_Amount *deposit_fee,
- struct GNUNET_TIME_Timestamp *exchange_timestamp)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (merchant),
- GNUNET_PQ_query_param_end
- };
- struct TALER_EXCHANGEDB_Deposit deposit2;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit2.amount_with_fee),
- GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
- &deposit2.timestamp),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- exchange_timestamp),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &deposit2.refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &deposit2.wire_deadline),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- deposit_fee),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &deposit2.wire_salt),
- GNUNET_PQ_result_spec_string ("receiver_wire_account",
- &deposit2.receiver_wire_account.full_payto),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_MerchantWireHashP h_wire2;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Getting deposits for coin %s\n",
- TALER_B2S (coin_pub));
- PREPARE (pg,
- "get_deposit",
- "SELECT"
- " cdep.amount_with_fee"
- ",denominations.fee_deposit"
- ",bdep.wallet_timestamp"
- ",bdep.exchange_timestamp"
- ",bdep.refund_deadline"
- ",bdep.wire_deadline"
- ",bdep.h_contract_terms"
- ",bdep.wire_salt"
- ",wt.payto_uri AS receiver_wire_account"
- " FROM coin_deposits cdep"
- " JOIN batch_deposits bdep USING (batch_deposit_serial_id)"
- " JOIN known_coins kc ON (kc.coin_pub = cdep.coin_pub)"
- " JOIN denominations USING (denominations_serial)"
- " JOIN wire_targets wt USING (wire_target_h_payto)"
- " WHERE cdep.coin_pub=$1"
- " AND bdep.merchant_pub=$3"
- " AND bdep.h_contract_terms=$2;");
- /* Note: query might be made more efficient if we computed the 'shard'
- from merchant_pub and included that as a constraint on bdep! */
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_deposit",
- params,
- rs);
- if (0 >= qs)
- return qs;
- TALER_merchant_wire_signature_hash (deposit2.receiver_wire_account,
- &deposit2.wire_salt,
- &h_wire2);
- GNUNET_free (deposit2.receiver_wire_account.full_payto);
- /* Now we check that the other information in @a deposit
- also matches, and if not report inconsistencies. */
- if ( (GNUNET_TIME_timestamp_cmp (refund_deadline,
- !=,
- deposit2.refund_deadline)) ||
- (0 != GNUNET_memcmp (h_wire,
- &h_wire2) ) )
- {
- /* Inconsistencies detected! Does not match! */
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
diff --git a/src/exchangedb/insert_active_legitimization_measure.c b/src/exchangedb/insert_active_legitimization_measure.c
@@ -45,14 +45,14 @@ TALER_EXCHANGEDB_insert_active_legitimization_measure (
};
PREPARE (pg,
- "do_insert_active_legitimization_measure",
+ "insert_active_legitimization_measure",
"SELECT"
" out_legitimization_measure_serial_id"
" FROM exchange_do_insert_active_legitimization_measure"
"($1, $2, $3::TEXT::JSONB);");
return GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "do_insert_active_legitimization_measure",
+ "insert_active_legitimization_measure",
params,
rs);
}
diff --git a/src/exchangedb/insert_aggregation_transient.c b/src/exchangedb/insert_aggregation_transient.c
@@ -0,0 +1,61 @@
+/*
+ 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 exchangedb/insert_aggregation_transient.c
+ * @brief Implementation of the insert_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_aggregation_transient.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_aggregation_transient (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPaytoHashP *h_payto,
+ const char *exchange_account_section,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
+ const struct TALER_Amount *total)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ total),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_aggregation_transient",
+ "INSERT INTO aggregation_transient"
+ " (amount"
+ " ,merchant_pub"
+ " ,wire_target_h_payto"
+ " ,legitimization_requirement_serial_id"
+ " ,exchange_account_section"
+ " ,wtid_raw)"
+ " VALUES ($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_aggregation_transient",
+ params);
+}
diff --git a/src/exchangedb/insert_aml_decision.c b/src/exchangedb/insert_aml_decision.c
@@ -155,7 +155,7 @@ TALER_EXCHANGEDB_insert_aml_decision (
TALER_full_payto_hash (payto_uri,
&h_full_payto);
PREPARE (pg,
- "do_insert_aml_decision",
+ "insert_aml_decision",
"SELECT"
" out_invalid_officer"
",out_account_unknown"
@@ -169,7 +169,7 @@ TALER_EXCHANGEDB_insert_aml_decision (
"Inserting LEGI OUTCOME from AML decision with notification on %s\n",
notify_s);
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "do_insert_aml_decision",
+ "insert_aml_decision",
params,
rs);
GNUNET_PQ_cleanup_query_params_closures (params);
diff --git a/src/exchangedb/insert_aml_officer.c b/src/exchangedb/insert_aml_officer.c
@@ -50,13 +50,13 @@ TALER_EXCHANGEDB_insert_aml_officer (
};
PREPARE (pg,
- "do_insert_aml_staff",
+ "insert_aml_officer",
"SELECT"
" out_last_change"
" FROM exchange_do_insert_aml_officer"
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "do_insert_aml_staff",
+ "insert_aml_officer",
params,
rs);
}
diff --git a/src/exchangedb/insert_auditor_denom_sig.c b/src/exchangedb/insert_auditor_denom_sig.c
@@ -24,7 +24,7 @@
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_insert_auditor_denom_sig (
+TALER_EXCHANGEDB_insert_auditor_denom_sig (
struct TALER_EXCHANGEDB_PostgresContext *pg,
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_AuditorPublicKeyP *auditor_pub,
diff --git a/src/exchangedb/insert_close_request.c b/src/exchangedb/insert_close_request.c
@@ -46,7 +46,7 @@ TALER_EXCHANGEDB_insert_close_request (
};
PREPARE (pg,
- "insert_account_close",
+ "insert_close_request",
"INSERT INTO close_requests"
"(reserve_pub"
",close_timestamp"
@@ -59,6 +59,6 @@ TALER_EXCHANGEDB_insert_close_request (
"($1, $2, $3, $4, $5, $6)"
" ON CONFLICT DO NOTHING;");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_account_close",
+ "insert_close_request",
params);
}
diff --git a/src/exchangedb/insert_contract.c b/src/exchangedb/insert_contract.c
@@ -20,7 +20,7 @@
*/
#include "taler/taler_pq_lib.h"
#include "exchange-database/insert_contract.h"
-#include "exchange-database/select_contract_by_purse.h"
+#include "exchange-database/get_contract_by_purse.h"
#include "helper.h"
enum GNUNET_DB_QueryStatus
@@ -63,9 +63,9 @@ TALER_EXCHANGEDB_insert_contract (
{
struct TALER_EncryptedContract econtract2;
- qs = TALER_TALER_EXCHANGEDB_select_contract_by_purse (pg,
- purse_pub,
- &econtract2);
+ qs = TALER_EXCHANGEDB_get_contract_by_purse (pg,
+ purse_pub,
+ &econtract2);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
GNUNET_break (0);
diff --git a/src/exchangedb/insert_denomination_info.c b/src/exchangedb/insert_denomination_info.c
@@ -74,7 +74,7 @@ TALER_EXCHANGEDB_insert_denomination_info (
issue->value.currency,
&issue->fees));
PREPARE (pg,
- "denomination_insert",
+ "insert_denomination_info",
"INSERT INTO denominations "
"(denom_pub_hash"
",denom_pub"
@@ -93,6 +93,6 @@ TALER_EXCHANGEDB_insert_denomination_info (
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
" $11, $12, $13);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "denomination_insert",
+ "insert_denomination_info",
params);
}
diff --git a/src/exchangedb/insert_denomination_revocation.c b/src/exchangedb/insert_denomination_revocation.c
@@ -37,7 +37,7 @@ TALER_EXCHANGEDB_insert_denomination_revocation (
/* Used in #postgres_insert_denomination_revocation() */
PREPARE (pg,
- "denomination_revocation_insert",
+ "insert_denomination_revocation",
"INSERT INTO denomination_revocations "
"(denominations_serial"
",master_sig"
@@ -45,6 +45,6 @@ TALER_EXCHANGEDB_insert_denomination_revocation (
" FROM denominations"
" WHERE denom_pub_hash=$1;");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "denomination_revocation_insert",
+ "insert_denomination_revocation",
params);
}
diff --git a/src/exchangedb/insert_drain_profit.c b/src/exchangedb/insert_drain_profit.c
@@ -1,60 +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 exchangedb/insert_drain_profit.c
- * @brief Implementation of the insert_drain_profit function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/insert_drain_profit.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_insert_drain_profit (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const char *account_section,
- const struct TALER_FullPayto payto_uri,
- struct GNUNET_TIME_Timestamp request_timestamp,
- const struct TALER_Amount *amount,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_string (account_section),
- GNUNET_PQ_query_param_string (payto_uri.full_payto),
- GNUNET_PQ_query_param_timestamp (&request_timestamp),
- TALER_PQ_query_param_amount (pg->conn,
- amount),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "drain_profit_insert",
- "INSERT INTO profit_drains "
- "(wtid"
- ",account_section"
- ",payto_uri"
- ",trigger_date"
- ",amount"
- ",master_sig"
- ") VALUES ($1, $2, $3, $4, $5, $6);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "drain_profit_insert",
- params);
-}
diff --git a/src/exchangedb/insert_kyc_requirement_process.c b/src/exchangedb/insert_kyc_requirement_process.c
@@ -1,85 +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 exchangedb/insert_kyc_requirement_process.c
- * @brief Implementation of the insert_kyc_requirement_process function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/insert_kyc_requirement_process.h"
-#include "helper.h"
-#include <gnunet/gnunet_pq_lib.h>
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_insert_kyc_requirement_process (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- uint32_t measure_index,
- uint64_t legitimization_measure_serial_id,
- const char *provider_name,
- const char *provider_account_id,
- const char *provider_legitimization_id,
- uint64_t *process_row)
-{
- struct GNUNET_TIME_Absolute now
- = GNUNET_TIME_absolute_get ();
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_string (provider_name),
- (NULL != provider_account_id)
- ? GNUNET_PQ_query_param_string (provider_account_id)
- : GNUNET_PQ_query_param_null (),
- (NULL != provider_legitimization_id)
- ? GNUNET_PQ_query_param_string (provider_legitimization_id)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_uint64 (&legitimization_measure_serial_id),
- GNUNET_PQ_query_param_uint32 (&measure_index),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
- process_row),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "insert_kyc_requirement_process",
- "INSERT INTO legitimization_processes"
- " (h_payto"
- " ,start_time"
- " ,provider_name"
- " ,provider_user_id"
- " ,provider_legitimization_id"
- " ,legitimization_measure_serial_id"
- " ,measure_index"
- " ) VALUES "
- " ($1, $2, $3, $4, $5, $6, $7)"
- " ON CONFLICT (legitimization_measure_serial_id,measure_index)"
- " DO UPDATE"
- " SET h_payto=$1"
- " ,start_time=$2"
- " ,provider_name=$3"
- " ,provider_user_id=$4"
- " ,provider_legitimization_id=$5"
- " RETURNING legitimization_process_serial_id");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "insert_kyc_requirement_process",
- params,
- rs);
-}
diff --git a/src/exchangedb/insert_kycauth_in.c b/src/exchangedb/insert_kycauth_in.c
@@ -0,0 +1,78 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/insert_kycauth_in.c
+ * @brief Implementation of the insert_kycauth_in function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_kycauth_in.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_kycauth_in (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const union TALER_AccountPublicKeyP *account_pub,
+ const struct TALER_Amount *credit_amount,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_FullPayto debit_account_uri,
+ const char *section_name,
+ uint64_t serial_id)
+{
+ struct TALER_NormalizedPaytoHashP h_normalized_payto;
+ struct TALER_FullPaytoHashP h_full_payto;
+
+ TALER_full_payto_hash (debit_account_uri,
+ &h_full_payto);
+ TALER_full_payto_normalize_and_hash (debit_account_uri,
+ &h_normalized_payto);
+ {
+ struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = h_normalized_payto
+ };
+ char *notify_s
+ = GNUNET_PQ_get_event_notify_channel (&rep.header);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (account_pub),
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ TALER_PQ_query_param_amount (pg->conn,
+ credit_amount),
+ GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
+ GNUNET_PQ_query_param_auto_from_type (&h_normalized_payto),
+ GNUNET_PQ_query_param_string (debit_account_uri.full_payto),
+ GNUNET_PQ_query_param_string (section_name),
+ GNUNET_PQ_query_param_timestamp (&execution_date),
+ GNUNET_PQ_query_param_string (notify_s),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "insert_kycauth_in",
+ "CALL"
+ " exchange_do_kycauth_in_insert"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
+ qs = GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "insert_kycauth_in",
+ params);
+ GNUNET_free (notify_s);
+ return qs;
+ }
+}
diff --git a/src/exchangedb/kycauth_in_insert.sql b/src/exchangedb/insert_kycauth_in.sql
diff --git a/src/exchangedb/insert_legitimization_process.c b/src/exchangedb/insert_legitimization_process.c
@@ -0,0 +1,85 @@
+/*
+ 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 exchangedb/insert_legitimization_process.c
+ * @brief Implementation of the insert_legitimization_process function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_legitimization_process.h"
+#include "helper.h"
+#include <gnunet/gnunet_pq_lib.h>
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_legitimization_process (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ uint32_t measure_index,
+ uint64_t legitimization_measure_serial_id,
+ const char *provider_name,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ uint64_t *process_row)
+{
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_string (provider_name),
+ (NULL != provider_account_id)
+ ? GNUNET_PQ_query_param_string (provider_account_id)
+ : GNUNET_PQ_query_param_null (),
+ (NULL != provider_legitimization_id)
+ ? GNUNET_PQ_query_param_string (provider_legitimization_id)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_uint64 (&legitimization_measure_serial_id),
+ GNUNET_PQ_query_param_uint32 (&measure_index),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
+ process_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "insert_legitimization_process",
+ "INSERT INTO legitimization_processes"
+ " (h_payto"
+ " ,start_time"
+ " ,provider_name"
+ " ,provider_user_id"
+ " ,provider_legitimization_id"
+ " ,legitimization_measure_serial_id"
+ " ,measure_index"
+ " ) VALUES "
+ " ($1, $2, $3, $4, $5, $6, $7)"
+ " ON CONFLICT (legitimization_measure_serial_id,measure_index)"
+ " DO UPDATE"
+ " SET h_payto=$1"
+ " ,start_time=$2"
+ " ,provider_name=$3"
+ " ,provider_user_id=$4"
+ " ,provider_legitimization_id=$5"
+ " RETURNING legitimization_process_serial_id");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "insert_legitimization_process",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/insert_prewire.c b/src/exchangedb/insert_prewire.c
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/insert_prewire.c
+ * @brief Implementation of the insert_prewire function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_prewire.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_prewire (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *type,
+ const char *buf,
+ size_t buf_size)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (type),
+ GNUNET_PQ_query_param_fixed_size (buf, buf_size),
+ GNUNET_PQ_query_param_end
+ };
+
+
+ /* Used in #postgres_wire_prepare_data_insert() to store
+ wire transfer information before actually committing it with the bank */
+ PREPARE (pg,
+ "insert_prewire",
+ "INSERT INTO prewire "
+ "(wire_method"
+ ",buf"
+ ") VALUES "
+ "($1, $2);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_prewire",
+ params);
+}
diff --git a/src/exchangedb/insert_profit_drain.c b/src/exchangedb/insert_profit_drain.c
@@ -0,0 +1,60 @@
+/*
+ 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 exchangedb/insert_profit_drain.c
+ * @brief Implementation of the insert_profit_drain function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_profit_drain.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_profit_drain (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *account_section,
+ const struct TALER_FullPayto payto_uri,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_string (account_section),
+ GNUNET_PQ_query_param_string (payto_uri.full_payto),
+ GNUNET_PQ_query_param_timestamp (&request_timestamp),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_profit_drain",
+ "INSERT INTO profit_drains "
+ "(wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ ") VALUES ($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_profit_drain",
+ params);
+}
diff --git a/src/exchangedb/insert_records_by_table.c b/src/exchangedb/insert_records_by_table.c
@@ -92,7 +92,7 @@ irbt_cb_table_denominations (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_denominations",
+ "insert_records_by_table_into_table_denominations",
"INSERT INTO denominations"
"(denominations_serial"
",denom_pub_hash"
@@ -118,7 +118,7 @@ irbt_cb_table_denominations (struct TALER_EXCHANGEDB_PostgresContext *pg,
&denom_hash);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_denominations",
+ "insert_records_by_table_into_table_denominations",
params);
}
@@ -144,7 +144,7 @@ irbt_cb_table_denomination_revocations (
};
PREPARE (pg,
- "insert_into_table_denomination_revocations",
+ "insert_records_by_table_into_table_denomination_revocations",
"INSERT INTO denomination_revocations"
"(denom_revocations_serial_id"
",master_sig"
@@ -152,7 +152,7 @@ irbt_cb_table_denomination_revocations (
") VALUES "
"($1, $2, $3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_denomination_revocations",
+ "insert_records_by_table_into_table_denomination_revocations",
params);
}
@@ -185,7 +185,7 @@ irbt_cb_table_wire_targets (struct TALER_EXCHANGEDB_PostgresContext *pg,
td->details.wire_targets.full_payto_uri,
&normalized_payto_hash);
PREPARE (pg,
- "insert_into_table_wire_targets",
+ "insert_records_by_table_into_table_wire_targets",
"INSERT INTO wire_targets"
"(wire_target_serial_id"
",wire_target_h_payto"
@@ -195,7 +195,7 @@ irbt_cb_table_wire_targets (struct TALER_EXCHANGEDB_PostgresContext *pg,
"($1, $2, $3, $4);");
return GNUNET_PQ_eval_prepared_non_select (
pg->conn,
- "insert_into_table_wire_targets",
+ "insert_records_by_table_into_table_wire_targets",
params);
}
@@ -226,7 +226,7 @@ irbt_cb_table_kyc_targets (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_kyc_targets",
+ "insert_records_by_table_into_table_kyc_targets",
"INSERT INTO kyc_targets"
"(kyc_target_serial_id"
",h_normalized_payto"
@@ -236,7 +236,7 @@ irbt_cb_table_kyc_targets (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_kyc_targets",
+ "insert_records_by_table_into_table_kyc_targets",
params);
}
@@ -266,7 +266,7 @@ irbt_cb_table_legitimization_measures (
};
PREPARE (pg,
- "insert_into_table_legitimization_measures",
+ "insert_records_by_table_into_table_legitimization_measures",
"INSERT INTO legitimization_measures"
"(legitimization_measure_serial_id"
",access_token"
@@ -276,7 +276,7 @@ irbt_cb_table_legitimization_measures (
") VALUES "
"($1, $2, $3, $4::TEXT::JSONB, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_legitimization_measures",
+ "insert_records_by_table_into_table_legitimization_measures",
params);
}
@@ -310,7 +310,7 @@ irbt_cb_table_legitimization_outcomes (
};
PREPARE (pg,
- "insert_into_table_legitimization_outcomes",
+ "insert_records_by_table_into_table_legitimization_outcomes",
"INSERT INTO legitimization_outcomes"
"(outcome_serial_id"
",h_payto"
@@ -322,7 +322,7 @@ irbt_cb_table_legitimization_outcomes (
") VALUES "
"($1, $2, $3, $4, $5::TEXT::JSONB, $6, $7::TEXT::JSONB);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_legitimization_outcomes",
+ "insert_records_by_table_into_table_legitimization_outcomes",
params);
}
@@ -362,7 +362,7 @@ irbt_cb_table_legitimization_processes (
};
PREPARE (pg,
- "insert_into_table_legitimization_processes",
+ "insert_records_by_table_into_table_legitimization_processes",
"INSERT INTO legitimization_processes"
"(legitimization_process_serial_id"
",h_payto"
@@ -377,7 +377,7 @@ irbt_cb_table_legitimization_processes (
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_legitimization_processes",
+ "insert_records_by_table_into_table_legitimization_processes",
params);
}
@@ -401,7 +401,7 @@ irbt_cb_table_reserves (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_reserves",
+ "insert_records_by_table_into_table_reserves",
"INSERT INTO reserves"
"(reserve_uuid"
",reserve_pub"
@@ -410,7 +410,7 @@ irbt_cb_table_reserves (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves",
+ "insert_records_by_table_into_table_reserves",
params);
}
@@ -442,7 +442,7 @@ irbt_cb_table_reserves_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_reserves_in",
+ "insert_records_by_table_into_table_reserves_in",
"INSERT INTO reserves_in"
"(reserve_in_serial_id"
",wire_reference"
@@ -454,7 +454,7 @@ irbt_cb_table_reserves_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_in",
+ "insert_records_by_table_into_table_reserves_in",
params);
}
@@ -486,7 +486,7 @@ irbt_cb_table_kycauths_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_kycauth_in",
+ "insert_records_by_table_into_table_kycauth_in",
"INSERT INTO kycauths_in"
"(kycauth_in_serial_id"
",wire_reference"
@@ -498,7 +498,7 @@ irbt_cb_table_kycauths_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_kycauth_in",
+ "insert_records_by_table_into_table_kycauth_in",
params);
}
@@ -533,7 +533,7 @@ irbt_cb_table_reserves_open_requests (
};
PREPARE (pg,
- "insert_into_table_reserves_open_requests",
+ "insert_records_by_table_into_table_reserves_open_requests",
"INSERT INTO reserves_open_requests"
"(open_request_uuid"
",reserve_pub"
@@ -545,7 +545,7 @@ irbt_cb_table_reserves_open_requests (
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_open_requests",
+ "insert_records_by_table_into_table_reserves_open_requests",
params);
}
@@ -576,7 +576,7 @@ irbt_cb_table_reserves_open_deposits (
};
PREPARE (pg,
- "insert_into_table_reserves_open_deposits",
+ "insert_records_by_table_into_table_reserves_open_deposits",
"INSERT INTO reserves_open_deposits"
"(reserve_open_deposit_uuid"
",reserve_sig"
@@ -587,7 +587,7 @@ irbt_cb_table_reserves_open_deposits (
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_open_deposits",
+ "insert_records_by_table_into_table_reserves_open_deposits",
params);
}
@@ -622,7 +622,7 @@ irbt_cb_table_reserves_close (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_reserves_close",
+ "insert_records_by_table_into_table_reserves_close",
"INSERT INTO reserves_close"
"(close_uuid"
",execution_date"
@@ -634,7 +634,7 @@ irbt_cb_table_reserves_close (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_close",
+ "insert_records_by_table_into_table_reserves_close",
params);
}
@@ -660,7 +660,7 @@ irbt_cb_table_auditors (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_auditors",
+ "insert_records_by_table_into_table_auditors",
"INSERT INTO auditors"
"(auditor_uuid"
",auditor_pub"
@@ -671,7 +671,7 @@ irbt_cb_table_auditors (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_auditors",
+ "insert_records_by_table_into_table_auditors",
params);
}
@@ -697,7 +697,7 @@ irbt_cb_table_auditor_denom_sigs (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_auditor_denom_sigs",
+ "insert_records_by_table_into_table_auditor_denom_sigs",
"INSERT INTO auditor_denom_sigs"
"(auditor_denom_serial"
",auditor_uuid"
@@ -706,7 +706,7 @@ irbt_cb_table_auditor_denom_sigs (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_auditor_denom_sigs",
+ "insert_records_by_table_into_table_auditor_denom_sigs",
params);
}
@@ -737,7 +737,7 @@ irbt_cb_table_exchange_sign_keys (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_exchange_sign_keys",
+ "insert_records_by_table_into_table_exchange_sign_keys",
"INSERT INTO exchange_sign_keys"
"(esk_serial"
",exchange_pub"
@@ -748,7 +748,7 @@ irbt_cb_table_exchange_sign_keys (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_exchange_sign_keys",
+ "insert_records_by_table_into_table_exchange_sign_keys",
params);
}
@@ -772,7 +772,7 @@ irbt_cb_table_signkey_revocations (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_signkey_revocations",
+ "insert_records_by_table_into_table_signkey_revocations",
"INSERT INTO signkey_revocations"
"(signkey_revocations_serial_id"
",esk_serial"
@@ -780,7 +780,7 @@ irbt_cb_table_signkey_revocations (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_signkey_revocations",
+ "insert_records_by_table_into_table_signkey_revocations",
params);
}
@@ -807,7 +807,7 @@ irbt_cb_table_known_coins (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_known_coins",
+ "insert_records_by_table_into_table_known_coins",
"INSERT INTO known_coins"
"(known_coin_id"
",coin_pub"
@@ -816,7 +816,7 @@ irbt_cb_table_known_coins (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_known_coins",
+ "insert_records_by_table_into_table_known_coins",
params);
}
@@ -877,7 +877,7 @@ irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "insert_into_table_refresh",
+ "insert_records_by_table_into_table_refresh",
"INSERT INTO refresh"
"(refresh_id"
",rc"
@@ -897,7 +897,7 @@ irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13,$14,$15);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_refresh",
+ "insert_records_by_table_into_table_refresh",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
@@ -949,7 +949,7 @@ irbt_cb_table_batch_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_batch_deposits",
+ "insert_records_by_table_into_table_batch_deposits",
"INSERT INTO batch_deposits"
"(batch_deposit_serial_id"
",shard"
@@ -970,7 +970,7 @@ irbt_cb_table_batch_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
" $11, $12, $13, $14, $15);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_batch_deposits",
+ "insert_records_by_table_into_table_batch_deposits",
params);
}
@@ -1000,7 +1000,7 @@ irbt_cb_table_coin_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_coin_deposits",
+ "insert_records_by_table_into_table_coin_deposits",
"INSERT INTO coin_deposits"
"(coin_deposit_serial_id"
",batch_deposit_serial_id"
@@ -1010,7 +1010,7 @@ irbt_cb_table_coin_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_coin_deposits",
+ "insert_records_by_table_into_table_coin_deposits",
params);
}
@@ -1039,7 +1039,7 @@ irbt_cb_table_refunds (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_refunds",
+ "insert_records_by_table_into_table_refunds",
"INSERT INTO refunds"
"(refund_serial_id"
",coin_pub"
@@ -1050,7 +1050,7 @@ irbt_cb_table_refunds (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_refunds",
+ "insert_records_by_table_into_table_refunds",
params);
}
@@ -1080,7 +1080,7 @@ irbt_cb_table_wire_out (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_wire_out",
+ "insert_records_by_table_into_table_wire_out",
"INSERT INTO wire_out"
"(wireout_uuid"
",execution_date"
@@ -1091,7 +1091,7 @@ irbt_cb_table_wire_out (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wire_out",
+ "insert_records_by_table_into_table_wire_out",
params);
}
@@ -1116,7 +1116,7 @@ irbt_cb_table_aggregation_tracking (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_aggregation_tracking",
+ "insert_records_by_table_into_table_aggregation_tracking",
"INSERT INTO aggregation_tracking"
"(aggregation_serial_id"
",batch_deposit_serial_id"
@@ -1124,7 +1124,7 @@ irbt_cb_table_aggregation_tracking (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_aggregation_tracking",
+ "insert_records_by_table_into_table_aggregation_tracking",
params);
}
@@ -1155,7 +1155,7 @@ irbt_cb_table_wire_fee (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_wire_fee",
+ "insert_records_by_table_into_table_wire_fee",
"INSERT INTO wire_fee"
"(wire_fee_serial"
",wire_method"
@@ -1167,7 +1167,7 @@ irbt_cb_table_wire_fee (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wire_fee",
+ "insert_records_by_table_into_table_wire_fee",
params);
}
@@ -1210,7 +1210,7 @@ irbt_cb_table_global_fee (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_global_fee",
+ "insert_records_by_table_into_table_global_fee",
"INSERT INTO global_fee"
"(global_fee_serial"
",start_date"
@@ -1225,7 +1225,7 @@ irbt_cb_table_global_fee (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_global_fee",
+ "insert_records_by_table_into_table_global_fee",
params);
}
@@ -1255,7 +1255,7 @@ irbt_cb_table_recoup (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_recoup",
+ "insert_records_by_table_into_table_recoup",
"INSERT INTO recoup"
"(recoup_uuid"
",coin_sig"
@@ -1267,7 +1267,7 @@ irbt_cb_table_recoup (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_recoup",
+ "insert_records_by_table_into_table_recoup",
params);
}
@@ -1304,7 +1304,7 @@ irbt_cb_table_recoup_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_recoup_refresh",
+ "insert_records_by_table_into_table_recoup_refresh",
"INSERT INTO recoup_refresh"
"(recoup_refresh_uuid"
",coin_sig"
@@ -1317,7 +1317,7 @@ irbt_cb_table_recoup_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_recoup_refresh",
+ "insert_records_by_table_into_table_recoup_refresh",
params);
}
@@ -1358,7 +1358,7 @@ irbt_cb_table_purse_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_purse_requests",
+ "insert_records_by_table_into_table_purse_requests",
"INSERT INTO purse_requests"
"(purse_requests_serial_id"
",purse_pub"
@@ -1374,7 +1374,7 @@ irbt_cb_table_purse_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_requests",
+ "insert_records_by_table_into_table_purse_requests",
params);
}
@@ -1401,7 +1401,7 @@ irbt_cb_table_purse_decision (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_purse_decision",
+ "insert_records_by_table_into_table_purse_decision",
"INSERT INTO purse_decision"
"(purse_refunds_serial_id"
",purse_pub"
@@ -1410,7 +1410,7 @@ irbt_cb_table_purse_decision (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_decision",
+ "insert_records_by_table_into_table_purse_decision",
params);
}
@@ -1437,7 +1437,7 @@ irbt_cb_table_purse_merges (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_purse_merges",
+ "insert_records_by_table_into_table_purse_merges",
"INSERT INTO purse_merges"
"(purse_merge_request_serial_id"
",partner_serial_id"
@@ -1448,7 +1448,7 @@ irbt_cb_table_purse_merges (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_merges",
+ "insert_records_by_table_into_table_purse_merges",
params);
}
@@ -1478,7 +1478,7 @@ irbt_cb_table_purse_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_purse_deposits",
+ "insert_records_by_table_into_table_purse_deposits",
"INSERT INTO purse_deposits"
"(purse_deposit_serial_id"
",partner_serial_id"
@@ -1489,7 +1489,7 @@ irbt_cb_table_purse_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_deposits",
+ "insert_records_by_table_into_table_purse_deposits",
params);
}
@@ -1518,7 +1518,7 @@ irbt_cb_table_account_mergers (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_account_merges",
+ "insert_records_by_table_into_table_account_merges",
"INSERT INTO account_merges"
"(account_merge_request_serial_id"
",reserve_pub"
@@ -1528,7 +1528,7 @@ irbt_cb_table_account_mergers (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_account_merges",
+ "insert_records_by_table_into_table_account_merges",
params);
}
@@ -1558,7 +1558,7 @@ irbt_cb_table_history_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_history_requests",
+ "insert_records_by_table_into_table_history_requests",
"INSERT INTO history_requests"
"(history_request_serial_id"
",reserve_pub"
@@ -1568,7 +1568,7 @@ irbt_cb_table_history_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_history_requests",
+ "insert_records_by_table_into_table_history_requests",
params);
}
@@ -1603,7 +1603,7 @@ irbt_cb_table_close_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_close_requests",
+ "insert_records_by_table_into_table_close_requests",
"INSERT INTO close_requests"
"(close_request_serial_id"
",reserve_pub"
@@ -1615,7 +1615,7 @@ irbt_cb_table_close_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_close_requests",
+ "insert_records_by_table_into_table_close_requests",
params);
}
@@ -1642,7 +1642,7 @@ irbt_cb_table_wads_out (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_wads_out",
+ "insert_records_by_table_into_table_wads_out",
"INSERT INTO wads_out"
"(wad_out_serial_id"
",wad_id"
@@ -1652,7 +1652,7 @@ irbt_cb_table_wads_out (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_out",
+ "insert_records_by_table_into_table_wads_out",
params);
}
@@ -1698,7 +1698,7 @@ irbt_cb_table_wads_out_entries (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_wad_out_entries",
+ "insert_records_by_table_into_table_wad_out_entries",
"INSERT INTO wad_out_entries"
"(wad_out_entry_serial_id"
",wad_out_serial_id"
@@ -1715,7 +1715,7 @@ irbt_cb_table_wads_out_entries (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_out_entries",
+ "insert_records_by_table_into_table_wad_out_entries",
params);
}
@@ -1742,7 +1742,7 @@ irbt_cb_table_wads_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_wads_in",
+ "insert_records_by_table_into_table_wads_in",
"INSERT INTO wads_in"
"(wad_in_serial_id"
",wad_id"
@@ -1752,7 +1752,7 @@ irbt_cb_table_wads_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_in",
+ "insert_records_by_table_into_table_wads_in",
params);
}
@@ -1796,7 +1796,7 @@ irbt_cb_table_wads_in_entries (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_wad_in_entries",
+ "insert_records_by_table_into_table_wad_in_entries",
"INSERT INTO wad_in_entries"
"(wad_in_entry_serial_id"
",wad_in_serial_id"
@@ -1813,7 +1813,7 @@ irbt_cb_table_wads_in_entries (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_in_entries",
+ "insert_records_by_table_into_table_wad_in_entries",
params);
}
@@ -1847,7 +1847,7 @@ irbt_cb_table_profit_drains (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_profit_drains",
+ "insert_records_by_table_into_table_profit_drains",
"INSERT INTO profit_drains"
"(profit_drain_serial_id"
",wtid"
@@ -1859,7 +1859,7 @@ irbt_cb_table_profit_drains (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_profit_drains",
+ "insert_records_by_table_into_table_profit_drains",
params);
}
@@ -1892,7 +1892,7 @@ irbt_cb_table_aml_staff (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_aml_staff",
+ "insert_records_by_table_into_table_aml_staff",
"INSERT INTO aml_staff"
"(aml_staff_uuid"
",decider_pub"
@@ -1904,7 +1904,7 @@ irbt_cb_table_aml_staff (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_aml_staff",
+ "insert_records_by_table_into_table_aml_staff",
params);
}
@@ -1938,7 +1938,7 @@ irbt_cb_table_kyc_attributes (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_kyc_attributes",
+ "insert_records_by_table_into_table_kyc_attributes",
"INSERT INTO kyc_attributes"
"(kyc_attributes_serial_id"
",h_payto"
@@ -1950,7 +1950,7 @@ irbt_cb_table_kyc_attributes (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_kyc_attributes",
+ "insert_records_by_table_into_table_kyc_attributes",
params);
}
@@ -1981,7 +1981,7 @@ irbt_cb_table_aml_history (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_aml_history",
+ "insert_records_by_table_into_table_aml_history",
"INSERT INTO aml_history"
"(aml_history_serial_id"
",h_payto"
@@ -1992,7 +1992,7 @@ irbt_cb_table_aml_history (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3, $4, $5, $6);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_aml_history",
+ "insert_records_by_table_into_table_aml_history",
params);
}
@@ -2017,7 +2017,7 @@ irbt_cb_table_kyc_events (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_kyc_events",
+ "insert_records_by_table_into_table_kyc_events",
"INSERT INTO kyc_events"
"(kyc_event_serial_id"
",event_timestamp"
@@ -2025,7 +2025,7 @@ irbt_cb_table_kyc_events (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_kyc_events",
+ "insert_records_by_table_into_table_kyc_events",
params);
}
@@ -2050,7 +2050,7 @@ irbt_cb_table_purse_deletion (struct TALER_EXCHANGEDB_PostgresContext *pg,
};
PREPARE (pg,
- "insert_into_table_purse_deletion",
+ "insert_records_by_table_into_table_purse_deletion",
"INSERT INTO purse_deletion"
"(purse_deletion_serial_id"
",purse_pub"
@@ -2058,7 +2058,7 @@ irbt_cb_table_purse_deletion (struct TALER_EXCHANGEDB_PostgresContext *pg,
") VALUES "
"($1, $2, $3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_deletion",
+ "insert_records_by_table_into_table_purse_deletion",
params);
}
@@ -2126,7 +2126,7 @@ irbt_cb_table_withdraw (
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "insert_into_table_withdraw",
+ "insert_records_by_table_into_table_withdraw",
"INSERT INTO withdraw"
"(withdraw_id"
",planchets_h"
@@ -2145,7 +2145,7 @@ irbt_cb_table_withdraw (
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_withdraw",
+ "insert_records_by_table_into_table_withdraw",
params);
GNUNET_PQ_cleanup_query_params_closures (params);
return qs;
diff --git a/src/exchangedb/insert_reserve_closed.c b/src/exchangedb/insert_reserve_closed.c
@@ -21,8 +21,8 @@
#include "taler/taler_pq_lib.h"
#include "exchange-database/insert_reserve_closed.h"
#include "helper.h"
-#include "exchange-database/reserves_get.h"
-#include "exchange-database/reserves_update.h"
+#include "exchange-database/get_reserve.h"
+#include "exchange-database/update_reserve.h"
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_insert_reserve_closed (
@@ -56,7 +56,7 @@ TALER_EXCHANGEDB_insert_reserve_closed (
};
PREPARE (pg,
- "reserves_close_insert",
+ "insert_reserve_closed",
"INSERT INTO reserves_close "
"(reserve_pub"
",execution_date"
@@ -68,7 +68,7 @@ TALER_EXCHANGEDB_insert_reserve_closed (
") VALUES ($1, $2, $3, $4, $5, $6, $7);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reserves_close_insert",
+ "insert_reserve_closed",
params);
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
@@ -77,8 +77,8 @@ TALER_EXCHANGEDB_insert_reserve_closed (
/* update reserve balance */
reserve.pub = *reserve_pub;
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- (qs = TALER_EXCHANGEDB_reserves_get (pg,
- &reserve)))
+ (qs = TALER_EXCHANGEDB_get_reserve (pg,
+ &reserve)))
{
/* Existence should have been checked before we got here... */
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -104,6 +104,6 @@ TALER_EXCHANGEDB_insert_reserve_closed (
}
GNUNET_break (TALER_AAR_RESULT_ZERO == ret);
}
- return TALER_EXCHANGEDB_reserves_update (pg,
- &reserve);
+ return TALER_EXCHANGEDB_update_reserve (pg,
+ &reserve);
}
diff --git a/src/exchangedb/insert_sanction_list_hit.c b/src/exchangedb/insert_sanction_list_hit.c
@@ -70,7 +70,7 @@ TALER_EXCHANGEDB_insert_sanction_list_hit (
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "do_insert_sanction_list_hit",
+ "insert_sanction_list_hit",
"SELECT"
" out_outcome_serial_id AS outcome_serial_id"
" FROM exchange_do_insert_sanction_list_hit"
@@ -79,7 +79,7 @@ TALER_EXCHANGEDB_insert_sanction_list_hit (
"Inserting LEGI OUTCOME from sanction list hit\n");
qs = GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "do_insert_sanction_list_hit",
+ "insert_sanction_list_hit",
params,
rs);
(void) outcome_serial_id;
diff --git a/src/exchangedb/insert_signkey.c b/src/exchangedb/insert_signkey.c
@@ -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 exchangedb/insert_signkey.c
+ * @brief Implementation of the insert_signkey function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_signkey.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_signkey (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_EXCHANGEDB_SignkeyMetaData *meta,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct GNUNET_PQ_QueryParam iparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_timestamp (&meta->start),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_sign),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_signkey",
+ "INSERT INTO exchange_sign_keys "
+ "(exchange_pub"
+ ",valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_signkey",
+ iparams);
+}
diff --git a/src/exchangedb/insert_successor_measure.c b/src/exchangedb/insert_successor_measure.c
@@ -68,7 +68,7 @@ TALER_EXCHANGEDB_insert_successor_measure (
enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
- "do_insert_successor_measure",
+ "insert_successor_measure",
"SELECT"
" out_account_unknown"
",out_last_date"
@@ -77,7 +77,7 @@ TALER_EXCHANGEDB_insert_successor_measure (
"($1, $2, $3, $4, $5::TEXT::JSONB, $6);");
qs = GNUNET_PQ_eval_prepared_singleton_select (
pg->conn,
- "do_insert_successor_measure",
+ "insert_successor_measure",
params,
rs);
GNUNET_free (notify_s);
diff --git a/src/exchangedb/insert_wad_in.c b/src/exchangedb/insert_wad_in.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/insert_wad_in.c
+ * @brief Implementation of the insert_wad_in function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_wad_in.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_wad_in (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_WadIdentifierP *wad_id,
+ const char *origin_exchange_url,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_FullPayto debit_account_uri,
+ const char *section_name,
+ uint64_t serial_id)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wad_id),
+ GNUNET_PQ_query_param_string (origin_exchange_url),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ GNUNET_PQ_query_param_timestamp (&execution_date),
+ GNUNET_PQ_query_param_end
+ };
+
+ // FIXME-#7271: should we keep the account data + serial_id?
+ PREPARE (pg,
+ "insert_wad_in",
+ "INSERT INTO wads_in "
+ "(wad_id"
+ ",origin_exchange_url"
+ ",amount"
+ ",arrival_time"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wad_in",
+ params);
+}
diff --git a/src/exchangedb/insert_wire_fee.c b/src/exchangedb/insert_wire_fee.c
@@ -25,14 +25,14 @@
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_insert_wire_fee (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *type,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_WireFeeSet *fees,
- const struct TALER_MasterSignatureP *
- master_sig)
+TALER_EXCHANGEDB_insert_wire_fee (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *type,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_WireFeeSet *fees,
+ const struct TALER_MasterSignatureP *
+ master_sig)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (type),
diff --git a/src/exchangedb/insert_wire_out.c b/src/exchangedb/insert_wire_out.c
@@ -0,0 +1,63 @@
+/*
+ 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 exchangedb/insert_wire_out.c
+ * @brief Implementation of the insert_wire_out function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/insert_wire_out.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_wire_out (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_FullPaytoHashP *h_payto,
+ const char *exchange_account_section,
+ const struct TALER_Amount *amount,
+ const char *extra_wire_subject_metadata)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&date),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ NULL == extra_wire_subject_metadata
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (extra_wire_subject_metadata),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_wire_out",
+ "INSERT INTO wire_out "
+ "(execution_date"
+ ",wtid_raw"
+ ",wire_target_h_payto"
+ ",exchange_account_section"
+ ",amount"
+ ",extra_wire_subject_metadata"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wire_out",
+ params);
+}
diff --git a/src/exchangedb/iterate_account_merges_above_serial_id.c b/src/exchangedb/iterate_account_merges_above_serial_id.c
@@ -0,0 +1,188 @@
+/*
+ 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 iterate_account_merges_above_serial_id.c
+ * @brief Implementation of the iterate_account_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_account_merges_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #account_merge_serial_helper_cb().
+ */
+struct AccountMergeSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AccountMergeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AccountMergeSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+account_merge_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AccountMergeSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct TALER_Amount amount;
+ uint32_t min_age;
+ uint32_t flags32;
+ enum TALER_WalletAccountMergeFlags flags;
+ struct TALER_Amount purse_fee;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ struct TALER_ReserveSignatureP reserve_sig;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &purse_fee),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ &min_age),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ &purse_expiration),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ &merge_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("account_merge_request_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ flags = (enum TALER_WalletAccountMergeFlags) flags32;
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &reserve_pub,
+ &purse_pub,
+ &h_contract_terms,
+ purse_expiration,
+ &amount,
+ min_age,
+ flags,
+ &purse_fee,
+ merge_timestamp,
+ &reserve_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_account_merges_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AccountMergeCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AccountMergeSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_account_merges_above_serial_id",
+ "SELECT"
+ " am.account_merge_request_serial_id"
+ ",am.reserve_pub"
+ ",am.purse_pub"
+ ",pr.h_contract_terms"
+ ",pr.purse_expiration"
+ ",pr.amount_with_fee"
+ ",pr.age_limit"
+ ",pr.flags"
+ ",pr.purse_fee"
+ ",pm.merge_timestamp"
+ ",am.reserve_sig"
+ " FROM account_merges am"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " JOIN purse_merges pm USING (purse_pub)"
+ " WHERE ("
+ " (account_merge_request_serial_id>=$1)"
+ " )"
+ " ORDER BY account_merge_request_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_account_merges_above_serial_id",
+ params,
+ &account_merge_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_active_auditors.c b/src/exchangedb/iterate_active_auditors.c
@@ -103,7 +103,7 @@ TALER_EXCHANGEDB_iterate_active_auditors (struct
};
PREPARE (pg,
- "select_auditors",
+ "iterate_active_auditors",
"SELECT"
" auditor_pub"
",auditor_url"
@@ -113,7 +113,7 @@ TALER_EXCHANGEDB_iterate_active_auditors (struct
" is_active;");
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_auditors",
+ "iterate_active_auditors",
params,
&auditors_cb_helper,
&dic);
diff --git a/src/exchangedb/iterate_active_signkeys.c b/src/exchangedb/iterate_active_signkeys.c
@@ -119,7 +119,7 @@ TALER_EXCHANGEDB_iterate_active_signkeys (struct
};
PREPARE (pg,
- "select_signkeys",
+ "iterate_active_signkeys",
"SELECT"
" master_sig"
",exchange_pub"
@@ -135,7 +135,7 @@ TALER_EXCHANGEDB_iterate_active_signkeys (struct
" WHERE esk.esk_serial = skr.esk_serial);");
now = GNUNET_TIME_absolute_get ();
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_signkeys",
+ "iterate_active_signkeys",
params,
&signkeys_cb_helper,
&dic);
diff --git a/src/exchangedb/iterate_aggregation_amounts_for_kyc_check.c b/src/exchangedb/iterate_aggregation_amounts_for_kyc_check.c
@@ -0,0 +1,154 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_aggregation_amounts_for_kyc_check.c
+ * @brief Implementation of the iterate_aggregation_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aggregation_amounts_for_kyc_check.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_KYCLOGIC_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aggregation_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_aggregation_amounts_for_kyc_check",
+ "SELECT"
+ " amount"
+ ",execution_date AS date"
+ " FROM wire_out"
+ " WHERE wire_target_h_payto IN"
+ " (SELECT wire_target_h_payto"
+ " FROM wire_targets"
+ " WHERE h_normalized_payto=$1"
+ " )"
+ " AND execution_date >= $2"
+ " ORDER BY execution_date DESC");
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_aggregation_amounts_for_kyc_check",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_aggregations_above_serial_id.c b/src/exchangedb/iterate_aggregations_above_serial_id.c
@@ -0,0 +1,137 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_aggregations_above_serial_id.c
+ * @brief Implementation of the iterate_aggregations_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aggregations_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #aggregation_serial_helper_cb().
+ */
+struct AggregationSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AggregationCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AggregationSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+aggregation_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AggregationSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t tracking_rowid;
+ uint64_t batch_deposit_serial_id;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
+ &amount),
+ GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id",
+ &tracking_rowid),
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ dsc->cb (dsc->cb_cls,
+ &amount,
+ tracking_rowid,
+ batch_deposit_serial_id);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aggregations_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t min_tracking_serial_id,
+ TALER_EXCHANGEDB_AggregationCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&min_tracking_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AggregationSerialContext asc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch aggregations with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "iterate_aggregations_above_serial_id",
+ "SELECT"
+ " aggregation_serial_id"
+ ",batch_deposit_serial_id"
+ ",total_amount"
+ " FROM exchange_do_select_aggregations_above_serial($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_aggregations_above_serial_id",
+ params,
+ &aggregation_serial_helper_cb,
+ &asc);
+ if (GNUNET_OK != asc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/select_aggregations_above_serial.sql b/src/exchangedb/iterate_aggregations_above_serial_id.sql
diff --git a/src/exchangedb/iterate_all_kyc_attributes.c b/src/exchangedb/iterate_all_kyc_attributes.c
@@ -0,0 +1,168 @@
+/*
+ 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 exchangedb/iterate_all_kyc_attributes.c
+ * @brief Implementation of the iterate_all_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_all_kyc_attributes.h"
+#include "helper.h"
+
+/**
+ * Closure for #get_all_attributes_cb().
+ */
+struct GetAttributesContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_AllAttributesCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 GetAttributesContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_attributes_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetAttributesContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ struct TALER_NormalizedPaytoHashP h_payto;
+ json_t *properties = NULL;
+ size_t enc_attributes_size;
+ void *enc_attributes;
+ char *provider;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("provider_name",
+ &provider),
+ GNUNET_PQ_result_spec_uint64 ("kyc_attributes_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("jproperties",
+ &properties),
+ NULL),
+ GNUNET_PQ_result_spec_timestamp ("collection_time",
+ &collection_time),
+ GNUNET_PQ_result_spec_timestamp ("expiration_time",
+ &expiration_time),
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ &h_payto),
+ GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
+ &enc_attributes,
+ &enc_attributes_size),
+ 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,
+ rowid,
+ &h_payto,
+ provider,
+ collection_time,
+ expiration_time,
+ properties,
+ enc_attributes_size,
+ enc_attributes);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_all_kyc_attributes (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t min_row_id,
+ TALER_EXCHANGEDB_AllAttributesCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&min_row_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetAttributesContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_all_kyc_attributes",
+ "SELECT "
+ " lp.provider_name"
+ ",ka.h_payto"
+ ",ka.kyc_attributes_serial_id"
+ ",lo.jproperties::TEXT"
+ ",ka.collection_time"
+ ",ka.expiration_time"
+ ",ka.encrypted_attributes"
+ " FROM kyc_attributes ka"
+ " JOIN legitimization_processes lp"
+ " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
+ " LEFT JOIN legitimization_outcomes lo"
+ " ON (ka.h_payto = lo.h_payto)"
+ /* **IF** we joined with 'lo', the lo must be active */
+ " WHERE COALESCE(lo.is_active,TRUE)"
+ " AND kyc_attributes_serial_id > $1"
+ " ORDER BY kyc_attributes_serial_id ASC"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_all_kyc_attributes",
+ params,
+ &get_attributes_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_all_purse_decisions_above_serial_id.c b/src/exchangedb/iterate_all_purse_decisions_above_serial_id.c
@@ -0,0 +1,142 @@
+/*
+ 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 iterate_all_purse_decisions_above_serial_id.c
+ * @brief Implementation of the iterate_all_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_all_purse_decisions_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #all_purse_decision_serial_helper_cb().
+ */
+struct AllPurseDecisionSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AllPurseDecisionCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+all_purse_decision_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AllPurseDecisionSerialContext *dsc = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ bool refunded;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_bool ("refunded",
+ &refunded),
+ GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ refunded);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_all_purse_decisions_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AllPurseDecisionSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_all_purse_decisions_above_serial_id",
+ "SELECT"
+ " purse_pub"
+ ",refunded"
+ ",purse_decision_serial_id"
+ " FROM purse_decision"
+ " WHERE purse_decision_serial_id>=$1"
+ " ORDER BY purse_decision_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_all_purse_decisions_above_serial_id",
+ params,
+ &all_purse_decision_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_all_purse_deletions_above_serial_id.c b/src/exchangedb/iterate_all_purse_deletions_above_serial_id.c
@@ -0,0 +1,142 @@
+/*
+ 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 exchangedb/iterate_all_purse_deletions_above_serial_id.c
+ * @brief Implementation of the iterate_all_purse_deletions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_all_purse_deletions_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #all_purse_deletion_serial_helper_cb().
+ */
+struct AllPurseDeletionSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AllPurseDeletionsCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+all_purse_deletion_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AllPurseDeletionSerialContext *dsc = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseContractSignatureP purse_sig;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
+ &purse_sig),
+ GNUNET_PQ_result_spec_uint64 ("purse_deletion_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ &purse_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_all_purse_deletions_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AllPurseDeletionsCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AllPurseDeletionSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_all_purse_deletions_above_serial_id",
+ "SELECT"
+ " purse_pub"
+ ",purse_sig"
+ ",purse_deletion_serial_id"
+ " FROM purse_deletion"
+ " WHERE purse_deletion_serial_id>=$1"
+ " ORDER BY purse_deletion_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_all_purse_deletions_above_serial_id",
+ params,
+ &all_purse_deletion_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_aml_attributes.c b/src/exchangedb/iterate_aml_attributes.c
@@ -0,0 +1,189 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_aml_attributes.c
+ * @brief Implementation of the iterate_aml_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aml_attributes.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct AmlAttributeResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlAttributeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_aml_attributes().
+ *
+ * @param cls closure of type `struct AmlAttributeResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_attributes (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AmlAttributeResultContext *ctx = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp collection_time;
+ char *officer_name = NULL;
+ bool by_aml_officer;
+ size_t enc_attributes_size;
+ void *enc_attributes;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("kyc_attributes_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("collection_time",
+ &collection_time),
+ GNUNET_PQ_result_spec_bool ("by_aml_officer",
+ &by_aml_officer),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("decider_name",
+ &officer_name),
+ NULL),
+ GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
+ &enc_attributes,
+ &enc_attributes_size),
+ 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,
+ rowid,
+ collection_time,
+ by_aml_officer,
+ officer_name,
+ enc_attributes_size,
+ enc_attributes);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_attributes (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlAttributeCallback cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct AmlAttributeResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ const char *stmt = (limit > 0)
+ ? "iterate_aml_attributes_inc"
+ : "iterate_aml_attributes_dec";
+
+ PREPARE (pg,
+ "iterate_aml_attributes_inc",
+ "SELECT"
+ " ka.kyc_attributes_serial_id"
+ ",ka.collection_time"
+ ",ka.by_aml_officer"
+ ",astaff.decider_name"
+ ",ka.encrypted_attributes"
+ " FROM kyc_attributes ka"
+ " LEFT JOIN legitimization_processes lp"
+ " ON (ka.by_aml_officer AND"
+ " (ka.legitimization_serial = lp.legitimization_process_serial_id))"
+ " LEFT JOIN aml_staff astaff"
+ " ON (ka.by_aml_officer AND"
+ " (DECODE(lp.provider_user_id, 'base64') = astaff.decider_pub))"
+ " WHERE ka.h_payto=$1"
+ " AND ka.kyc_attributes_serial_id > $2"
+ " ORDER BY ka.kyc_attributes_serial_id ASC"
+ " LIMIT $3");
+ PREPARE (pg,
+ "iterate_aml_attributes_dec",
+ "SELECT"
+ " ka.kyc_attributes_serial_id"
+ ",ka.collection_time"
+ ",ka.by_aml_officer"
+ ",astaff.decider_name"
+ ",ka.encrypted_attributes"
+ " FROM kyc_attributes ka"
+ " LEFT JOIN legitimization_processes lp"
+ " ON (ka.by_aml_officer AND"
+ " (ka.legitimization_serial = lp.legitimization_process_serial_id))"
+ " LEFT JOIN aml_staff astaff"
+ " ON (ka.by_aml_officer AND"
+ " (DECODE(lp.provider_user_id, 'base64') = astaff.decider_pub))"
+ " WHERE ka.h_payto=$1"
+ " AND ka.kyc_attributes_serial_id < $2"
+ " ORDER BY ka.kyc_attributes_serial_id DESC"
+ " LIMIT $3");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ stmt,
+ params,
+ &handle_aml_attributes,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_aml_decisions.c b/src/exchangedb/iterate_aml_decisions.c
@@ -0,0 +1,248 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_aml_decisions.c
+ * @brief Implementation of the iterate_aml_decisions function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aml_decisions.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct AmlProcessResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlDecisionCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_aml_decisions().
+ *
+ * @param cls closure of type `struct AmlProcessResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AmlProcessResultContext *ctx = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_NormalizedPaytoHashP h_payto;
+ uint64_t rowid;
+ char *justification = NULL;
+ struct GNUNET_TIME_Timestamp decision_time;
+ struct GNUNET_TIME_Absolute expiration_time;
+ json_t *jproperties = NULL;
+ bool is_wallet;
+ bool to_investigate;
+ bool is_active;
+ json_t *account_rules;
+ struct TALER_FullPayto payto;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("outcome_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ &h_payto),
+ GNUNET_PQ_result_spec_bool ("is_wallet",
+ &is_wallet),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("justification",
+ &justification),
+ NULL),
+ GNUNET_PQ_result_spec_timestamp ("decision_time",
+ &decision_time),
+ GNUNET_PQ_result_spec_absolute_time ("expiration_time",
+ &expiration_time),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("jproperties",
+ &jproperties),
+ NULL),
+ TALER_PQ_result_spec_json ("jnew_rules",
+ &account_rules),
+ GNUNET_PQ_result_spec_bool ("to_investigate",
+ &to_investigate),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ &is_active),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto.full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (GNUNET_TIME_absolute_is_past (expiration_time))
+ is_active = false;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning AML decisions for `%s' (%s)\n",
+ TALER_B2S (&h_payto),
+ is_wallet
+ ? "wallet"
+ : "account");
+ ctx->cb (ctx->cb_cls,
+ rowid,
+ justification,
+ &h_payto,
+ decision_time,
+ expiration_time,
+ jproperties,
+ to_investigate,
+ is_active,
+ is_wallet,
+ payto,
+ account_rules);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_decisions (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ enum TALER_EXCHANGE_YesNoAll investigation_only,
+ enum TALER_EXCHANGE_YesNoAll active_only,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlDecisionCallback cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_bool (NULL == h_payto),
+ NULL == h_payto
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
+ investigation_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
+ investigation_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
+ active_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
+ active_only)),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct AmlProcessResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ const char *stmt = (limit > 0)
+ ? "iterate_aml_decisions_inc"
+ : "iterate_aml_decisions_dec";
+
+ PREPARE (pg,
+ "iterate_aml_decisions_inc",
+ "SELECT"
+ " lo.outcome_serial_id"
+ ",lo.h_payto"
+ ",ah.justification"
+ ",lo.decision_time"
+ ",lo.expiration_time"
+ ",lo.jproperties::TEXT"
+ ",lo.to_investigate"
+ ",lo.is_active"
+ ",lo.jnew_rules::TEXT"
+ ",kt.is_wallet"
+ ",wt.payto_uri"
+ " FROM legitimization_outcomes lo"
+ " JOIN kyc_targets kt"
+ " ON (lo.h_payto = kt.h_normalized_payto)"
+ " JOIN wire_targets wt"
+ " ON (lo.h_payto = wt.h_normalized_payto)"
+ " LEFT JOIN aml_history ah"
+ " USING (outcome_serial_id)"
+ " WHERE (outcome_serial_id > $7)"
+ " AND ($1 OR (lo.h_payto = $2))"
+ " AND ($3 OR (lo.to_investigate = $4))"
+ " AND ($5 OR (lo.is_active = $6))"
+ " ORDER BY lo.outcome_serial_id ASC"
+ " LIMIT $8");
+ PREPARE (pg,
+ "iterate_aml_decisions_dec",
+ "SELECT"
+ " lo.outcome_serial_id"
+ ",lo.h_payto"
+ ",ah.justification"
+ ",lo.decision_time"
+ ",lo.expiration_time"
+ ",lo.jproperties::TEXT"
+ ",lo.to_investigate"
+ ",lo.is_active"
+ ",lo.jnew_rules::TEXT"
+ ",kt.is_wallet"
+ ",wt.payto_uri"
+ " FROM legitimization_outcomes lo"
+ " JOIN kyc_targets kt"
+ " ON (lo.h_payto = kt.h_normalized_payto)"
+ " JOIN wire_targets wt"
+ " ON (lo.h_payto = wt.h_normalized_payto)"
+ " LEFT JOIN aml_history ah"
+ " USING (outcome_serial_id)"
+ " WHERE lo.outcome_serial_id < $7"
+ " AND ($1 OR (lo.h_payto = $2))"
+ " AND ($3 OR (lo.to_investigate = $4))"
+ " AND ($5 OR (lo.is_active = $6))"
+ " ORDER BY lo.outcome_serial_id DESC"
+ " LIMIT $8");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ stmt,
+ params,
+ &handle_aml_result,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_aml_history.c b/src/exchangedb/iterate_aml_history.c
@@ -0,0 +1,200 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_aml_history.c
+ * @brief Implementation of the iterate_aml_history function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aml_history.h"
+#include "helper.h"
+
+
+/**
+ * Closure for callbacks called from #TALER_EXCHANGEDB_iterate_aml_history()
+ */
+struct AmlHistoryContext
+{
+
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlHistoryCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to 'true' if the transaction failed.
+ */
+ bool failed;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AmlHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_entry (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AmlHistoryContext *ahc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t outcome_serial_id;
+ struct GNUNET_TIME_Timestamp decision_time;
+ char *justification;
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+ json_t *jproperties = NULL;
+ json_t *jnew_rules = NULL;
+ bool to_investigate;
+ bool is_active;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("outcome_serial_id",
+ &outcome_serial_id),
+ GNUNET_PQ_result_spec_timestamp ("decision_time",
+ &decision_time),
+ GNUNET_PQ_result_spec_string ("justification",
+ &justification),
+ GNUNET_PQ_result_spec_auto_from_type ("decider_pub",
+ &decider_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("jproperties",
+ &jproperties),
+ NULL),
+ TALER_PQ_result_spec_json ("jnew_rules",
+ &jnew_rules),
+ GNUNET_PQ_result_spec_bool ("to_investigate",
+ &to_investigate),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ &is_active),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ahc->failed = true;
+ return;
+ }
+ ahc->cb (ahc->cb_cls,
+ outcome_serial_id,
+ decision_time,
+ justification,
+ &decider_pub,
+ jproperties,
+ jnew_rules,
+ to_investigate,
+ is_active);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_history (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlHistoryCallback cb,
+ void *cb_cls)
+{
+ struct AmlHistoryContext ahc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls
+ };
+ uint64_t ulimit = (limit < 0) ? (-limit) : limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_aml_history_desc",
+ "SELECT"
+ " lo.decision_time"
+ ",lo.outcome_serial_id"
+ ",ah.justification"
+ ",ah.decider_pub"
+ ",lo.jproperties::TEXT"
+ ",lo.jnew_rules::TEXT"
+ ",lo.to_investigate"
+ ",lo.is_active"
+ " FROM aml_history ah"
+ " JOIN legitimization_outcomes lo"
+ " USING (outcome_serial_id)"
+ " WHERE ah.h_payto=$1"
+ " AND lo.outcome_serial_id < $2"
+ " ORDER BY outcome_serial_id DESC"
+ " LIMIT $3;");
+ PREPARE (pg,
+ "iterate_aml_history_asc",
+ "SELECT"
+ " lo.decision_time"
+ ",lo.outcome_serial_id"
+ ",ah.justification"
+ ",ah.decider_pub"
+ ",lo.jproperties::TEXT"
+ ",lo.jnew_rules::TEXT"
+ ",lo.to_investigate"
+ ",lo.is_active"
+ " FROM aml_history ah"
+ " JOIN legitimization_outcomes lo"
+ " USING (outcome_serial_id)"
+ " WHERE ah.h_payto=$1"
+ " AND lo.outcome_serial_id > $2"
+ " ORDER BY outcome_serial_id ASC"
+ " LIMIT $3;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit < 0)
+ ? "iterate_aml_history_desc"
+ : "iterate_aml_history_asc",
+ params,
+ &handle_aml_entry,
+ &ahc);
+ if (qs <= 0)
+ return qs;
+ if (ahc.failed)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/iterate_aml_measures.c b/src/exchangedb/iterate_aml_measures.c
@@ -0,0 +1,185 @@
+/*
+ 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 exchangedb/iterate_aml_measures.c
+ * @brief Implementation of the iterate_aml_measures function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aml_measures.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct LegiMeasureResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_LegitimizationMeasureCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_aml_measures().
+ *
+ * @param cls closure of type `struct LegiMeasureResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LegiMeasureResultContext *ctx = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_NormalizedPaytoHashP h_payto;
+ uint64_t rowid;
+ struct GNUNET_TIME_Absolute start_time;
+ json_t *jmeasures;
+ bool is_finished;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("legitimization_measure_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("h_normalized_payto",
+ &h_payto),
+ GNUNET_PQ_result_spec_absolute_time ("start_time",
+ &start_time),
+ TALER_PQ_result_spec_json ("jmeasures",
+ &jmeasures),
+ GNUNET_PQ_result_spec_bool ("is_finished",
+ &is_finished),
+ 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,
+ &h_payto,
+ start_time,
+ jmeasures,
+ is_finished,
+ rowid);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_measures (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ enum TALER_EXCHANGE_YesNoAll active_only,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_LegitimizationMeasureCallback cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_bool (NULL == h_payto),
+ NULL == h_payto
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
+ active_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_NO ==
+ active_only)),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_end
+ };
+ struct LegiMeasureResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ const char *stmt = (limit > 0)
+ ? "iterate_aml_measures_inc"
+ : "iterate_aml_measures_dec";
+
+ PREPARE (pg,
+ "iterate_aml_measures_inc",
+ "SELECT"
+ " lm.legitimization_measure_serial_id"
+ ",kt.h_normalized_payto"
+ ",lm.jmeasures::TEXT"
+ ",lm.start_time"
+ ",lm.is_finished"
+ " FROM kyc_targets kt"
+ " JOIN legitimization_measures lm"
+ " USING (access_token)"
+ " WHERE (legitimization_measure_serial_id > $5)"
+ " AND ($1 OR (kt.h_normalized_payto = $2))"
+ " AND ($3 OR (lm.is_finished = $4))"
+ " ORDER BY lm.legitimization_measure_serial_id ASC"
+ " LIMIT $6");
+ PREPARE (pg,
+ "iterate_aml_measures_dec",
+ "SELECT"
+ " lm.legitimization_measure_serial_id"
+ ",kt.h_normalized_payto"
+ ",lm.jmeasures::TEXT"
+ ",lm.start_time"
+ ",lm.is_finished"
+ " FROM kyc_targets kt"
+ " JOIN legitimization_measures lm"
+ " USING (access_token)"
+ " WHERE (legitimization_measure_serial_id < $5)"
+ " AND ($1 OR (kt.h_normalized_payto = $2))"
+ " AND ($3 OR (lm.is_finished = $4))"
+ " ORDER BY lm.legitimization_measure_serial_id DESC"
+ " LIMIT $6");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ stmt,
+ params,
+ &handle_aml_result,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_aml_statistics.c b/src/exchangedb/iterate_aml_statistics.c
@@ -0,0 +1,142 @@
+/*
+ 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 exchangedb/iterate_aml_statistics.c
+ * @brief Implementation of the iterate_aml_statistics function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_aml_statistics.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_statistics_cb().
+ */
+struct GetStatisticsContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_AmlStatisticsCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 GetStatisticsContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_statistics_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetStatisticsContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t val;
+ char *name;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("name",
+ &name),
+ GNUNET_PQ_result_spec_uint64 ("value",
+ &val),
+ 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,
+ name,
+ val);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_statistics (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ size_t num_names,
+ const char *names[static num_names],
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ TALER_EXCHANGEDB_AmlStatisticsCallback cb,
+ void *cb_cls)
+{
+ struct GetStatisticsContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (num_names,
+ names,
+ pg->conn),
+ GNUNET_PQ_query_param_timestamp (&start_date),
+ GNUNET_PQ_query_param_timestamp (&end_date),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_aml_statistics",
+ "SELECT "
+ " event_type AS name"
+ ",COUNT(*) AS value"
+ " FROM kyc_events"
+ " WHERE event_type = ANY ($1)"
+ " AND event_timestamp >= $2"
+ " AND event_timestamp < $3"
+ " GROUP BY event_type;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_aml_statistics",
+ params,
+ &get_statistics_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_auditor_denominations.c b/src/exchangedb/iterate_auditor_denominations.c
@@ -100,7 +100,7 @@ TALER_EXCHANGEDB_iterate_auditor_denominations (
};
/* Used in #postgres_iterate_auditor_denominations() */
PREPARE (pg,
- "select_auditor_denoms",
+ "iterate_auditor_denominations",
"SELECT"
" auditors.auditor_pub"
",denominations.denom_pub_hash"
@@ -110,7 +110,7 @@ TALER_EXCHANGEDB_iterate_auditor_denominations (
" JOIN denominations USING (denominations_serial)"
" WHERE auditors.is_active;");
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_auditor_denoms",
+ "iterate_auditor_denominations",
params,
&auditor_denoms_cb_helper,
&dic);
diff --git a/src/exchangedb/iterate_batch_deposits_missing_wire.c b/src/exchangedb/iterate_batch_deposits_missing_wire.c
@@ -0,0 +1,140 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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 exchangedb/iterate_batch_deposits_missing_wire.c
+ * @brief Implementation of the iterate_batch_deposits_missing_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_batch_deposits_missing_wire.h"
+#include "helper.h"
+
+/**
+ * Closure for #missing_wire_cb().
+ */
+struct MissingWireContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_WireMissingCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+missing_wire_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct MissingWireContext *mwc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = mwc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t batch_deposit_serial_id;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct TALER_FullPaytoHashP wire_target_h_payto;
+ struct TALER_Amount total_amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
+ &wire_target_h_payto),
+ GNUNET_PQ_result_spec_timestamp ("deadline",
+ &deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
+ &total_amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ mwc->status = GNUNET_SYSERR;
+ return;
+ }
+ mwc->cb (mwc->cb_cls,
+ batch_deposit_serial_id,
+ &total_amount,
+ &wire_target_h_payto,
+ deadline);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_batch_deposits_missing_wire (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t min_batch_deposit_serial_id,
+ TALER_EXCHANGEDB_WireMissingCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&min_batch_deposit_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct MissingWireContext mwc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_batch_deposits_missing_wire",
+ "SELECT"
+ " batch_deposit_serial_id"
+ ",wire_target_h_payto"
+ ",deadline"
+ ",total_amount"
+ " FROM exchange_do_select_deposits_missing_wire"
+ " ($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_batch_deposits_missing_wire",
+ params,
+ &missing_wire_cb,
+ &mwc);
+ if (GNUNET_OK != mwc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/select_batch_deposits_missing_wire.sql b/src/exchangedb/iterate_batch_deposits_missing_wire.sql
diff --git a/src/exchangedb/iterate_coin_deposits_above_serial_id.c b/src/exchangedb/iterate_coin_deposits_above_serial_id.c
@@ -0,0 +1,200 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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 exchangedb/iterate_coin_deposits_above_serial_id.c
+ * @brief Implementation of the iterate_coin_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_coin_deposits_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #deposit_serial_helper_cb().
+ */
+struct CoinDepositSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_DepositCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinDepositSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+coin_deposit_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinDepositSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_Deposit deposit;
+ struct GNUNET_TIME_Timestamp exchange_timestamp;
+ struct TALER_DenominationPublicKey denom_pub;
+ bool done;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit.amount_with_fee),
+ GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
+ &deposit.timestamp),
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ &exchange_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &deposit.merchant_pub),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &deposit.coin.coin_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &deposit.coin.h_age_commitment),
+ &deposit.coin.no_age_commitment),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("wallet_data_hash",
+ &deposit.wallet_data_hash),
+ &deposit.no_wallet_data_hash),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit.csig),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &deposit.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &deposit.wire_deadline),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &deposit.h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &deposit.wire_salt),
+ GNUNET_PQ_result_spec_string ("receiver_wire_account",
+ &deposit.receiver_wire_account.full_payto),
+ GNUNET_PQ_result_spec_bool ("done",
+ &done),
+ GNUNET_PQ_result_spec_uint64 ("coin_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ memset (&deposit,
+ 0,
+ sizeof (deposit));
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ exchange_timestamp,
+ &deposit,
+ &denom_pub,
+ done);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_coin_deposits_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_DepositCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct CoinDepositSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch deposits with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "iterate_coin_deposits_above_serial_id",
+ "SELECT"
+ " cdep.amount_with_fee"
+ ",bdep.wallet_timestamp"
+ ",bdep.exchange_timestamp"
+ ",bdep.merchant_pub"
+ ",bdep.wallet_data_hash"
+ ",denom.denom_pub"
+ ",kc.coin_pub"
+ ",kc.age_commitment_hash"
+ ",cdep.coin_sig"
+ ",bdep.refund_deadline"
+ ",bdep.wire_deadline"
+ ",bdep.h_contract_terms"
+ ",bdep.wire_salt"
+ ",wt.payto_uri AS receiver_wire_account"
+ ",bdep.done"
+ ",cdep.coin_deposit_serial_id"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE (coin_deposit_serial_id>=$1)"
+ " ORDER BY coin_deposit_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_coin_deposits_above_serial_id",
+ params,
+ &coin_deposit_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_denomination_info.c b/src/exchangedb/iterate_denomination_info.c
@@ -160,7 +160,7 @@ TALER_EXCHANGEDB_iterate_denomination_info (struct
};
PREPARE (pg,
- "denomination_iterate",
+ "iterate_denomination_info",
"SELECT"
" denominations_serial"
",master_sig"
@@ -178,7 +178,7 @@ TALER_EXCHANGEDB_iterate_denomination_info (struct
",age_mask"
" FROM denominations;");
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "denomination_iterate",
+ "iterate_denomination_info",
params,
&domination_cb_helper,
&dic);
diff --git a/src/exchangedb/iterate_denominations.c b/src/exchangedb/iterate_denominations.c
@@ -146,7 +146,7 @@ TALER_EXCHANGEDB_iterate_denominations (struct
};
PREPARE (pg,
- "select_denominations",
+ "iterate_denominations",
"SELECT"
" denominations_serial"
",denominations.master_sig"
@@ -168,7 +168,7 @@ TALER_EXCHANGEDB_iterate_denominations (struct
" denomination_revocations USING (denominations_serial)"
" WHERE expire_deposit > $1;");
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_denominations",
+ "iterate_denominations",
params,
&dominations_cb_helper,
&dic);
diff --git a/src/exchangedb/iterate_deposit_amounts_for_kyc_check.c b/src/exchangedb/iterate_deposit_amounts_for_kyc_check.c
@@ -0,0 +1,153 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_deposit_amounts_for_kyc_check.c
+ * @brief Implementation of the iterate_deposit_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_deposit_amounts_for_kyc_check.h"
+#include "helper.h"
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_KYCLOGIC_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_deposit_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_deposit_amounts_for_kyc_check",
+ "SELECT"
+ " cd.amount_with_fee AS amount"
+ ",bd.exchange_timestamp AS date"
+ " FROM batch_deposits bd"
+ " JOIN coin_deposits cd"
+ " USING (batch_deposit_serial_id)"
+ " WHERE wire_target_h_payto IN ("
+ " SELECT wire_target_h_payto"
+ " FROM wire_targets"
+ " WHERE h_normalized_payto=$1"
+ " )"
+ " AND bd.exchange_timestamp >= $2"
+ " ORDER BY bd.exchange_timestamp DESC");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_deposit_amounts_for_kyc_check",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_exchange_credit_transfers.c b/src/exchangedb/iterate_exchange_credit_transfers.c
@@ -0,0 +1,180 @@
+/*
+ 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 exchangedb/iterate_exchange_credit_transfers.c
+ * @brief Implementation of the iterate_exchange_credit_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_exchange_credit_transfers.h"
+#include "helper.h"
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct SelectTransferContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlTransferCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_exchange_debit_transfers().
+ *
+ * @param cls closure of type `struct SelectTransferContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_transfer_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SelectTransferContext *stc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ char *payto_uri;
+ uint64_t rowid;
+ struct GNUNET_TIME_Absolute execution_time;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_absolute_time ("execution_time",
+ &execution_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ stc->status = GNUNET_SYSERR;
+ return;
+ }
+ stc->cb (stc->cb_cls,
+ rowid,
+ payto_uri,
+ execution_time,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_exchange_credit_transfers (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ void *cb_cls)
+{
+ struct SelectTransferContext stc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ TALER_PQ_query_param_amount (pg->conn,
+ threshold),
+ NULL != h_payto
+ ? GNUNET_PQ_query_param_auto_from_type (h_payto)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_exchange_credit_transfers_inc",
+ "SELECT"
+ " ri.reserve_in_serial_id AS serial_id"
+ ",wt.payto_uri"
+ ",ri.execution_date AS execution_time"
+ ",ri.credit AS amount"
+ " FROM reserves_in ri"
+ " LEFT JOIN wire_targets wt"
+ " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE (ri.reserve_in_serial_id > $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (ri.credit).val > ($3::taler_amount).val)"
+ " OR ( ( (ri.credit).val >= ($3::taler_amount).val)"
+ " AND ( (ri.credit).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY ri.reserve_in_serial_id ASC"
+ " LIMIT $2");
+ PREPARE (pg,
+ "iterate_exchange_credit_transfers_dec",
+ "SELECT"
+ " ri.reserve_in_serial_id AS serial_id"
+ ",wt.payto_uri"
+ ",ri.execution_date AS execution_time"
+ ",ri.credit AS amount"
+ " FROM reserves_in ri"
+ " LEFT JOIN wire_targets wt"
+ " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE (ri.reserve_in_serial_id < $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (ri.credit).val > ($3::taler_amount).val)"
+ " OR ( ( (ri.credit).val >= ($3::taler_amount).val)"
+ " AND ( (ri.credit).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY ri.reserve_in_serial_id DESC"
+ " LIMIT $2");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_exchange_credit_transfers_inc"
+ : "iterate_exchange_credit_transfers_dec",
+ params,
+ &handle_transfer_result,
+ &stc);
+ if (GNUNET_OK != stc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_exchange_debit_transfers.c b/src/exchangedb/iterate_exchange_debit_transfers.c
@@ -0,0 +1,181 @@
+/*
+ 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 exchangedb/iterate_exchange_debit_transfers.c
+ * @brief Implementation of the iterate_exchange_debit_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_exchange_debit_transfers.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct SelectTransferContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlTransferCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_exchange_debit_transfers().
+ *
+ * @param cls closure of type `struct SelectTransferContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_transfer_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SelectTransferContext *stc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ char *payto_uri;
+ uint64_t rowid;
+ struct GNUNET_TIME_Absolute execution_time;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_absolute_time ("execution_time",
+ &execution_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ stc->status = GNUNET_SYSERR;
+ return;
+ }
+ stc->cb (stc->cb_cls,
+ rowid,
+ payto_uri,
+ execution_time,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_exchange_debit_transfers (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ void *cb_cls)
+{
+ struct SelectTransferContext stc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ TALER_PQ_query_param_amount (pg->conn,
+ threshold),
+ NULL != h_payto
+ ? GNUNET_PQ_query_param_auto_from_type (h_payto)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_exchange_debit_transfers_inc",
+ "SELECT"
+ " wo.wireout_uuid AS serial_id"
+ ",wt.payto_uri"
+ ",wo.execution_date AS execution_time"
+ ",wo.amount"
+ " FROM wire_out wo"
+ " LEFT JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " WHERE (wo.wireout_uuid > $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (wo.amount).val > ($3::taler_amount).val)"
+ " OR ( ( (wo.amount).val >= ($3::taler_amount).val)"
+ " AND ( (wo.amount).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY wo.wireout_uuid ASC"
+ " LIMIT $2");
+ PREPARE (pg,
+ "iterate_exchange_debit_transfers_dec",
+ "SELECT"
+ " wo.wireout_uuid AS serial_id"
+ ",wt.payto_uri"
+ ",wo.execution_date AS execution_time"
+ ",wo.amount"
+ " FROM wire_out wo"
+ " LEFT JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " WHERE (wo.wireout_uuid < $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (wo.amount).val > ($3::taler_amount).val)"
+ " OR ( ( (wo.amount).val >= ($3::taler_amount).val)"
+ " AND ( (wo.amount).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY wo.wireout_uuid DESC"
+ " LIMIT $2");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_exchange_debit_transfers_inc"
+ : "iterate_exchange_debit_transfers_dec",
+ params,
+ &handle_transfer_cb,
+ &stc);
+ if (GNUNET_OK != stc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_exchange_kycauth_transfers.c b/src/exchangedb/iterate_exchange_kycauth_transfers.c
@@ -0,0 +1,180 @@
+/*
+ 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 exchangedb/iterate_exchange_kycauth_transfers.c
+ * @brief Implementation of the iterate_exchange_kycauth_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_exchange_kycauth_transfers.h"
+#include "helper.h"
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct SelectTransferContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlTransferCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_exchange_debit_transfers().
+ *
+ * @param cls closure of type `struct SelectTransferContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_transfer_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SelectTransferContext *stc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ char *payto_uri;
+ uint64_t rowid;
+ struct GNUNET_TIME_Absolute execution_time;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_absolute_time ("execution_time",
+ &execution_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ stc->status = GNUNET_SYSERR;
+ return;
+ }
+ stc->cb (stc->cb_cls,
+ rowid,
+ payto_uri,
+ execution_time,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_exchange_kycauth_transfers (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ void *cb_cls)
+{
+ struct SelectTransferContext stc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ TALER_PQ_query_param_amount (pg->conn,
+ threshold),
+ NULL != h_payto
+ ? GNUNET_PQ_query_param_auto_from_type (h_payto)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_exchange_kycauth_transfers_inc",
+ "SELECT"
+ " ki.kycauth_in_serial_id AS serial_id"
+ ",wt.payto_uri"
+ ",ki.execution_date AS execution_time"
+ ",ki.credit AS amount"
+ " FROM kycauths_in ki"
+ " LEFT JOIN wire_targets wt"
+ " ON (ki.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE (ki.kycauth_in_serial_id > $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (ki.credit).val > ($3::taler_amount).val)"
+ " OR ( ( (ki.credit).val >= ($3::taler_amount).val)"
+ " AND ( (ki.credit).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY ki.kycauth_in_serial_id ASC"
+ " LIMIT $2");
+ PREPARE (pg,
+ "iterate_exchange_kycauth_transfers_dec",
+ "SELECT"
+ " ki.kycauth_in_serial_id AS serial_id"
+ ",wt.payto_uri"
+ ",ki.execution_date AS execution_time"
+ ",ki.credit AS amount"
+ " FROM kycauths_in ki"
+ " LEFT JOIN wire_targets wt"
+ " ON (ki.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE (ki.kycauth_in_serial_id < $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (ki.credit).val > ($3::taler_amount).val)"
+ " OR ( ( (ki.credit).val >= ($3::taler_amount).val)"
+ " AND ( (ki.credit).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY ki.kycauth_in_serial_id DESC"
+ " LIMIT $2");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_exchange_kycauth_transfers_inc"
+ : "iterate_exchange_kycauth_transfers_dec",
+ params,
+ &handle_transfer_result,
+ &stc);
+ if (GNUNET_OK != stc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_expired_reserves.c b/src/exchangedb/iterate_expired_reserves.c
@@ -0,0 +1,169 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 iterate_expired_reserves.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_expired_reserves.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #reserve_expired_cb().
+ */
+struct ExpiredReserveContext
+{
+ /**
+ * Function to call for each expired reserve.
+ */
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec;
+
+ /**
+ * Closure to give to @e rec.
+ */
+ void *rec_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_expired_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ExpiredReserveContext *erc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = erc->pg;
+ enum GNUNET_GenericReturnValue ret = GNUNET_OK;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp exp_date;
+ struct TALER_FullPayto account_details;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount remaining_balance;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &exp_date),
+ GNUNET_PQ_result_spec_string ("account_details",
+ &account_details.full_payto),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ &remaining_balance),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ ret = erc->rec (erc->rec_cls,
+ &reserve_pub,
+ &remaining_balance,
+ account_details,
+ exp_date,
+ 0);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+ erc->status = ret;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_expired_reserves (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct GNUNET_TIME_Timestamp now,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct ExpiredReserveContext ectx = {
+ .rec = rec,
+ .rec_cls = rec_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_expired_reserves",
+ "WITH ed AS MATERIALIZED ( "
+ " SELECT expiration_date"
+ " ,wire_source_h_payto"
+ " ,current_balance"
+ " ,r.reserve_pub"
+ " FROM reserves r"
+ " JOIN reserves_in"
+ " USING (reserve_pub)"
+ " WHERE expiration_date <= $1 "
+ " AND ((current_balance).val != 0 OR (current_balance).frac != 0) "
+ " ORDER BY expiration_date ASC "
+ " LIMIT 1 "
+ ") "
+ "SELECT"
+ " wt.payto_uri AS account_details"
+ " ,ed.expiration_date"
+ " ,ed.reserve_pub"
+ " ,ed.current_balance"
+ " FROM wire_targets wt"
+ " JOIN ed"
+ " ON (ed.wire_source_h_payto=wt.wire_target_h_payto);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_expired_reserves",
+ params,
+ &reserve_expired_cb,
+ &ectx);
+ switch (ectx.status)
+ {
+ case GNUNET_SYSERR:
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_NO:
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ case GNUNET_OK:
+ break;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/iterate_global_fees.c b/src/exchangedb/iterate_global_fees.c
@@ -0,0 +1,168 @@
+/*
+ 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 exchangedb/iterate_global_fees.c
+ * @brief Implementation of the iterate_global_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_dbevents.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_global_fees.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #global_fees_cb().
+ */
+struct GlobalFeeContext
+{
+ /**
+ * Function to call for each global fee block.
+ */
+ TALER_EXCHANGEDB_GlobalFeeCallback cb;
+
+ /**
+ * Closure to give to @e rec.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+global_fees_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GlobalFeeContext *gctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = gctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_GlobalFeeSet fees;
+ struct GNUNET_TIME_Relative purse_timeout;
+ struct GNUNET_TIME_Relative history_expiration;
+ uint32_t purse_account_limit;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
+ &fees.history),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
+ &fees.account),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &fees.purse),
+ GNUNET_PQ_result_spec_relative_time ("purse_timeout",
+ &purse_timeout),
+ GNUNET_PQ_result_spec_relative_time ("history_expiration",
+ &history_expiration),
+ GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
+ &purse_account_limit),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ gctx->status = GNUNET_SYSERR;
+ break;
+ }
+ gctx->cb (gctx->cb_cls,
+ &fees,
+ purse_timeout,
+ history_expiration,
+ purse_account_limit,
+ start_date,
+ end_date,
+ &master_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_global_fees (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ TALER_EXCHANGEDB_GlobalFeeCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_TIME_Timestamp date
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_subtract (
+ GNUNET_TIME_absolute_get (),
+ GNUNET_TIME_UNIT_YEARS));
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&date),
+ GNUNET_PQ_query_param_end
+ };
+ struct GlobalFeeContext gctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_global_fees",
+ "SELECT "
+ " start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ " FROM global_fee"
+ " WHERE start_date >= $1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_global_fees",
+ params,
+ &global_fees_cb,
+ &gctx);
+ if (GNUNET_OK != gctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_kyc_accounts.c b/src/exchangedb/iterate_kyc_accounts.c
@@ -0,0 +1,238 @@
+/*
+ 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 exchangedb/iterate_kyc_accounts.c
+ * @brief Implementation of the iterate_kyc_accounts function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_kyc_accounts.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct KycAccountResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlAccountListCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_kyc_accounts().
+ *
+ * @param cls closure of type `struct KycAccountResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_kyc_account_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAccountResultContext *ctx = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_NormalizedPaytoHashP h_payto;
+ char *comments = NULL;
+ struct GNUNET_TIME_Timestamp open_time
+ = GNUNET_TIME_UNIT_FOREVER_TS;
+ struct GNUNET_TIME_Timestamp close_time
+ = GNUNET_TIME_UNIT_FOREVER_TS;
+ bool to_investigate;
+ bool high_risk;
+ struct TALER_FullPayto payto;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("kyc_target_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ &h_payto),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("comments",
+ &comments),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("open_time",
+ &open_time),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("close_time",
+ &close_time),
+ NULL),
+ GNUNET_PQ_result_spec_bool ("to_investigate",
+ &to_investigate),
+ GNUNET_PQ_result_spec_bool ("high_risk",
+ &high_risk),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto.full_payto),
+ 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,
+ rowid,
+ &h_payto,
+ open_time,
+ close_time,
+ comments,
+ high_risk,
+ to_investigate,
+ payto);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_accounts (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ enum TALER_EXCHANGE_YesNoAll investigation_only,
+ enum TALER_EXCHANGE_YesNoAll open_only,
+ enum TALER_EXCHANGE_YesNoAll high_risk_only,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlAccountListCallback cb,
+ void *cb_cls)
+{
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
+ investigation_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
+ investigation_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
+ open_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
+ open_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
+ high_risk_only)),
+ GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
+ high_risk_only)),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAccountResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ const char *stmt = (limit > 0)
+ ? "iterate_kyc_accounts_inc"
+ : "iterate_kyc_accounts_dec";
+
+ PREPARE (pg,
+ "iterate_kyc_accounts_inc",
+ "SELECT"
+ " kt.kyc_target_serial_id"
+ ",kt.h_normalized_payto AS h_payto"
+ ",kt.open_time"
+ ",kt.close_time"
+ ",lo.jproperties ->> 'FILE_NOTE' AS comments"
+ ",COALESCE(lo.to_investigate,FALSE) AS to_investigate"
+ ",COALESCE((lo.jproperties ->> 'HIGH_RISK_CUSTOMER')::bool,FALSE) AS high_risk"
+ ",wt.payto_uri"
+ " FROM kyc_targets kt"
+ " LEFT JOIN legitimization_outcomes lo"
+ " ON (lo.h_payto = kt.h_normalized_payto)"
+ " LEFT JOIN LATERAL ("
+ " SELECT payto_uri"
+ " FROM wire_targets"
+ " WHERE h_normalized_payto = kt.h_normalized_payto"
+ " ORDER BY wire_target_serial_id DESC"
+ " LIMIT 1"
+ " ) wt ON true"
+ " WHERE (kyc_target_serial_id > $1)"
+ // select most recent outcomes only
+ " AND COALESCE (lo.is_active, TRUE)"
+ " AND ($3 OR (COALESCE(lo.to_investigate,FALSE) = $4))"
+ // Account is open if we had an AML outcome
+ " AND ($5 OR ((lo.outcome_serial_id IS NULL) = $6))"
+ " AND ($7 OR ((COALESCE((lo.jproperties ->>'HIGH_RISK_CUSTOMER')::bool,FALSE) = $8)))"
+ " ORDER BY kt.kyc_target_serial_id ASC"
+ " LIMIT $2");
+ PREPARE (pg,
+ "iterate_kyc_accounts_dec",
+ "SELECT"
+ " kt.kyc_target_serial_id"
+ ",kt.h_normalized_payto AS h_payto"
+ ",kt.open_time"
+ ",kt.close_time"
+ ",lo.jproperties ->> 'FILE_NOTE' AS comments"
+ ",COALESCE(lo.to_investigate,FALSE) AS to_investigate"
+ ",COALESCE((lo.jproperties ->> 'HIGH_RISK_CUSTOMER')::bool,FALSE) AS high_risk"
+ ",wt.payto_uri"
+ " FROM kyc_targets kt"
+ " LEFT JOIN legitimization_outcomes lo"
+ " ON (lo.h_payto = kt.h_normalized_payto)"
+ " LEFT JOIN LATERAL ("
+ " SELECT payto_uri"
+ " FROM wire_targets"
+ " WHERE h_normalized_payto = kt.h_normalized_payto"
+ " ORDER BY wire_target_serial_id DESC"
+ " LIMIT 1"
+ " ) wt ON true"
+ " WHERE (kyc_target_serial_id < $1)"
+ // select most recent outcomes only
+ " AND COALESCE (lo.is_active, TRUE)"
+ " AND ($3 OR (COALESCE(lo.to_investigate,FALSE) = $4))"
+ // Account is open if we had an AML outcome
+ " AND ($5 OR ((lo.outcome_serial_id IS NULL) = $6))"
+ " AND ($7 OR ((COALESCE((lo.jproperties ->>'HIGH_RISK_CUSTOMER')::bool,FALSE) = $8)))"
+ " ORDER BY kt.kyc_target_serial_id DESC"
+ " LIMIT $2");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ stmt,
+ params,
+ &handle_kyc_account_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_kyc_attributes.c b/src/exchangedb/iterate_kyc_attributes.c
@@ -0,0 +1,154 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_kyc_attributes.c
+ * @brief Implementation of the iterate_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_kyc_attributes.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_attributes_cb().
+ */
+struct GetAttributesContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_AttributeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Key of our query.
+ */
+ const struct TALER_NormalizedPaytoHashP *h_payto;
+
+ /**
+ * 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 GetAttributesContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_attributes_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetAttributesContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ size_t enc_attributes_size;
+ void *enc_attributes;
+ char *provider;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("provider_name",
+ &provider),
+ GNUNET_PQ_result_spec_timestamp ("collection_time",
+ &collection_time),
+ GNUNET_PQ_result_spec_timestamp ("expiration_time",
+ &expiration_time),
+ GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
+ &enc_attributes,
+ &enc_attributes_size),
+ 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,
+ ctx->h_payto,
+ provider,
+ collection_time,
+ expiration_time,
+ enc_attributes_size,
+ enc_attributes);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_attributes (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetAttributesContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .h_payto = h_payto,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_kyc_attributes",
+ "SELECT "
+ " lp.provider_name"
+ ",ka.collection_time"
+ ",ka.expiration_time"
+ ",ka.encrypted_attributes"
+ " FROM kyc_attributes ka"
+ " JOIN legitimization_processes lp"
+ " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
+ " WHERE ka.h_payto=$1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_kyc_attributes",
+ params,
+ &get_attributes_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_kyc_history.c b/src/exchangedb/iterate_kyc_history.c
@@ -0,0 +1,192 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_kyc_history.c
+ * @brief Implementation of the iterate_kyc_history function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_kyc_history.h"
+#include "helper.h"
+
+/**
+ * Closure for callbacks called from #TALER_EXCHANGEDB_iterate_kyc_history()
+ */
+struct KycHistoryContext
+{
+
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_KycHistoryCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to 'true' if the transaction failed.
+ */
+ bool failed;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct KycHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_kyc_entry (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycHistoryContext *khc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ char *provider_name = NULL;
+ bool finished;
+ uint32_t error_code;
+ char *error_message = NULL;
+ char *provider_user_id = NULL;
+ char *provider_legitimization_id = NULL;
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Absolute expiration_time
+ = GNUNET_TIME_UNIT_ZERO_ABS;
+ void *encrypted_attributes;
+ size_t encrypted_attributes_len;
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("provider_name",
+ &provider_name),
+ NULL),
+ GNUNET_PQ_result_spec_bool ("finished",
+ &finished),
+ GNUNET_PQ_result_spec_uint32 ("error_code",
+ &error_code),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("error_message",
+ &error_message),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("provider_user_id",
+ &provider_user_id),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("provider_legitimization_id",
+ &provider_legitimization_id),
+ NULL),
+ GNUNET_PQ_result_spec_timestamp ("collection_time",
+ &collection_time),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_absolute_time ("expiration_time",
+ &expiration_time),
+ NULL),
+ GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
+ &encrypted_attributes,
+ &encrypted_attributes_len),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ khc->failed = true;
+ return;
+ }
+ khc->cb (khc->cb_cls,
+ provider_name,
+ finished,
+ (enum TALER_ErrorCode) error_code,
+ error_message,
+ provider_user_id,
+ provider_legitimization_id,
+ collection_time,
+ expiration_time,
+ encrypted_attributes_len,
+ encrypted_attributes);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_history (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_KycHistoryCallback cb,
+ void *cb_cls)
+{
+ struct KycHistoryContext khc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_kyc_history",
+ "SELECT"
+ " lp.provider_name"
+ ",lp.finished"
+ ",lp.error_code"
+ ",lp.error_message"
+ ",lp.provider_user_id"
+ ",lp.provider_legitimization_id"
+ ",ka.collection_time"
+ ",ka.expiration_time"
+ ",ka.encrypted_attributes"
+ " FROM kyc_attributes ka"
+ " JOIN legitimization_processes lp"
+ " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
+ " WHERE ka.h_payto=$1"
+ " ORDER BY ka.collection_time DESC;");
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_kyc_history",
+ params,
+ &handle_kyc_entry,
+ &khc);
+ if (qs <= 0)
+ return qs;
+ if (khc.failed)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/iterate_kyc_reference.c b/src/exchangedb/iterate_kyc_reference.c
@@ -1,126 +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 iterate_kyc_reference.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/iterate_kyc_reference.h"
-#include "helper.h"
-
-
-/**
- * Closure for #iterate_kyc_reference_cb()
- */
-struct IteratorContext
-{
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_LegitimizationProcessCallback cb;
-
- /**
- * Closure to pass to @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-};
-
-
-/**
- * Helper function for #TALER_EXCHANGEDB_iterate_kyc_reference().
- * Calls the callback with each denomination key.
- *
- * @param cls a `struct IteratorContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-iterate_kyc_reference_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct IteratorContext *ic = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- char *kyc_provider_name_name;
- char *provider_user_id;
- char *legitimization_id;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("provider_name",
- &kyc_provider_name_name),
- GNUNET_PQ_result_spec_string ("provider_user_id",
- &provider_user_id),
- GNUNET_PQ_result_spec_string ("provider_legitimization_id",
- &legitimization_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
- ic->cb (ic->cb_cls,
- kyc_provider_name_name,
- provider_user_id,
- legitimization_id);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_iterate_kyc_reference (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_LegitimizationProcessCallback lpc,
- void *lpc_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct IteratorContext ic = {
- .cb = lpc,
- .cb_cls = lpc_cls,
- .pg = pg
- };
-
- PREPARE (pg,
- "iterate_kyc_reference",
- "SELECT "
- " provider_name"
- ",provider_user_id"
- ",provider_legitimization_id"
- " FROM legitimization_processes"
- " WHERE h_payto=$1;");
- return GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "iterate_kyc_reference",
- params,
- &iterate_kyc_reference_cb,
- &ic);
-}
diff --git a/src/exchangedb/iterate_kyc_references.c b/src/exchangedb/iterate_kyc_references.c
@@ -0,0 +1,126 @@
+/*
+ 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 iterate_kyc_references.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_kyc_references.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #iterate_kyc_reference_cb()
+ */
+struct IteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_LegitimizationProcessCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+};
+
+
+/**
+ * Helper function for #TALER_EXCHANGEDB_iterate_kyc_references().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct IteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+iterate_kyc_reference_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct IteratorContext *ic = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ char *kyc_provider_name_name;
+ char *provider_user_id;
+ char *legitimization_id;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("provider_name",
+ &kyc_provider_name_name),
+ GNUNET_PQ_result_spec_string ("provider_user_id",
+ &provider_user_id),
+ GNUNET_PQ_result_spec_string ("provider_legitimization_id",
+ &legitimization_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ic->cb (ic->cb_cls,
+ kyc_provider_name_name,
+ provider_user_id,
+ legitimization_id);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_references (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_LegitimizationProcessCallback lpc,
+ void *lpc_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct IteratorContext ic = {
+ .cb = lpc,
+ .cb_cls = lpc_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "iterate_kyc_references",
+ "SELECT "
+ " provider_name"
+ ",provider_user_id"
+ ",provider_legitimization_id"
+ " FROM legitimization_processes"
+ " WHERE h_payto=$1;");
+ return GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_kyc_references",
+ params,
+ &iterate_kyc_reference_cb,
+ &ic);
+}
diff --git a/src/exchangedb/iterate_merge_amounts_for_kyc_check.c b/src/exchangedb/iterate_merge_amounts_for_kyc_check.c
@@ -0,0 +1,152 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_merge_amounts_for_kyc_check.c
+ * @brief Implementation of the iterate_merge_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_merge_amounts_for_kyc_check.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_KYCLOGIC_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_merge_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_merge_amounts_for_kyc_check",
+ "SELECT"
+ " amount_with_fee AS amount"
+ ",merge_timestamp AS date"
+ " FROM account_merges"
+ " JOIN purse_merges USING (purse_pub)"
+ " JOIN purse_requests USING (purse_pub)"
+ " JOIN purse_decision USING (purse_pub)"
+ " WHERE wallet_h_payto=$1"
+ " AND merge_timestamp >= $2"
+ " AND NOT refunded"
+ " ORDER BY merge_timestamp DESC");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_merge_amounts_for_kyc_check",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_prewires.c b/src/exchangedb/iterate_prewires.c
@@ -0,0 +1,138 @@
+/*
+ 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 exchangedb/iterate_prewires.c
+ * @brief Implementation of the iterate_prewires function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_prewires.h"
+#include "helper.h"
+
+/**
+ * Closure for #prewire_cb().
+ */
+struct PrewireContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_WirePreparationIterator cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * #GNUNET_OK if everything went fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+prewire_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PrewireContext *pc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t prewire_uuid;
+ char *wire_method;
+ void *buf = NULL;
+ size_t buf_size;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("prewire_uuid",
+ &prewire_uuid),
+ GNUNET_PQ_result_spec_string ("wire_method",
+ &wire_method),
+ GNUNET_PQ_result_spec_variable_size ("buf",
+ &buf,
+ &buf_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ pc->status = GNUNET_SYSERR;
+ return;
+ }
+ pc->cb (pc->cb_cls,
+ prewire_uuid,
+ wire_method,
+ buf,
+ buf_size);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_prewires (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t start_row,
+ uint64_t limit,
+ TALER_EXCHANGEDB_WirePreparationIterator
+ cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&start_row),
+ GNUNET_PQ_query_param_uint64 (&limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct PrewireContext pc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_prewires",
+ "SELECT"
+ " prewire_uuid"
+ ",wire_method"
+ ",buf"
+ " FROM prewire"
+ " WHERE prewire_uuid >= $1"
+ " AND finished=FALSE"
+ " AND failed=FALSE"
+ " ORDER BY prewire_uuid ASC"
+ " LIMIT $2;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_prewires",
+ params,
+ &prewire_cb,
+ &pc);
+ if (GNUNET_OK != pc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_purse_decisions_above_serial_id.c b/src/exchangedb/iterate_purse_decisions_above_serial_id.c
@@ -0,0 +1,158 @@
+/*
+ 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 exchangedb/iterate_purse_decisions_above_serial_id.c
+ * @brief Implementation of the iterate_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_purse_decisions_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #purse_decision_serial_helper_cb().
+ */
+struct PurseDecisionSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseDecisionCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_decision_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseDecisionSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ bool no_reserve = true;
+ uint64_t rowid;
+ struct TALER_Amount val;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ &no_reserve),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &val),
+ GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ no_reserve ? NULL : &reserve_pub,
+ &val);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_decisions_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ bool refunded,
+ TALER_EXCHANGEDB_PurseDecisionCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_bool (refunded),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseDecisionSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_decisions_above_serial_id",
+ "SELECT"
+ " pd.purse_pub"
+ ",pm.reserve_pub"
+ ",pd.purse_decision_serial_id"
+ ",pr.amount_with_fee"
+ " FROM purse_decision pd"
+ " JOIN purse_requests pr ON (pd.purse_pub = pr.purse_pub)"
+ " LEFT JOIN purse_merges pm ON (pm.purse_pub = pd.purse_pub)"
+ " WHERE ("
+ " (purse_decision_serial_id>=$1) AND "
+ " (refunded=$2)"
+ " )"
+ " ORDER BY purse_decision_serial_id ASC;");
+
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_purse_decisions_above_serial_id",
+ params,
+ &purse_decision_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_purse_deposits_above_serial_id.c b/src/exchangedb/iterate_purse_deposits_above_serial_id.c
@@ -0,0 +1,198 @@
+/*
+ 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 iterate_purse_deposits_above_serial_id.c
+ * @brief Implementation of the iterate_purse_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_purse_deposits_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #purse_deposit_serial_helper_cb().
+ */
+struct PurseDepositSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseDepositCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_deposit_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseDepositSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_PurseDeposit deposit = {
+ .exchange_base_url = NULL
+ };
+ struct TALER_DenominationPublicKey denom_pub;
+ uint64_t rowid;
+ uint32_t flags32;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ bool not_merged = false;
+ struct TALER_Amount purse_balance;
+ struct TALER_Amount purse_total;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit.amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &purse_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total",
+ &purse_total),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &deposit.deposit_fee),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ &deposit.exchange_base_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ ¬_merged),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &deposit.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit.coin_sig),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &deposit.coin_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &deposit.h_age_commitment),
+ &deposit.no_age_commitment),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ memset (&deposit,
+ 0,
+ sizeof (deposit));
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &deposit,
+ not_merged ? NULL : &reserve_pub,
+ (enum TALER_WalletAccountMergeFlags) flags32,
+ &purse_balance,
+ &purse_total,
+ &denom_pub);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_deposits_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseDepositCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseDepositSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_deposits_above_serial_id",
+ "SELECT"
+ " pd.amount_with_fee"
+ ",pr.amount_with_fee AS total"
+ ",pr.balance"
+ ",pr.flags"
+ ",pd.purse_pub"
+ ",pd.coin_sig"
+ ",partner_base_url"
+ ",denom.denom_pub"
+ ",denom.fee_deposit"
+ ",pm.reserve_pub"
+ ",kc.coin_pub"
+ ",kc.age_commitment_hash"
+ ",pd.purse_deposit_serial_id"
+ " FROM purse_deposits pd"
+ " LEFT JOIN partners USING (partner_serial_id)"
+ " LEFT JOIN purse_merges pm USING (purse_pub)"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " JOIN known_coins kc USING (coin_pub)"
+ " JOIN denominations denom USING (denominations_serial)"
+ " WHERE ("
+ " (purse_deposit_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_deposit_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_purse_deposits_above_serial_id",
+ params,
+ &purse_deposit_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_purse_deposits_by_purse.c b/src/exchangedb/iterate_purse_deposits_by_purse.c
@@ -0,0 +1,149 @@
+/*
+ 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 exchangedb/iterate_purse_deposits_by_purse.c
+ * @brief Implementation of the iterate_purse_deposits_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_purse_deposits_by_purse.h"
+#include "helper.h"
+
+/**
+ * Closure for #purse_refund_coin_helper_cb().
+ */
+struct PurseRefundCoinContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseRefundCoinCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundCoinContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_refund_coin_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseRefundCoinContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount amount_with_fee;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_DenominationPublicKey denom_pub;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &amount_with_fee,
+ &coin_pub,
+ &denom_pub);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_deposits_by_purse (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ TALER_EXCHANGEDB_PurseRefundCoinCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseRefundCoinContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_deposits_by_purse",
+ "SELECT"
+ " pd.purse_deposit_serial_id"
+ ",pd.amount_with_fee"
+ ",pd.coin_pub"
+ ",denom.denom_pub"
+ " FROM purse_deposits pd"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE purse_pub=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_purse_deposits_by_purse",
+ params,
+ &purse_refund_coin_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_purse_merges_above_serial_id.c b/src/exchangedb/iterate_purse_merges_above_serial_id.c
@@ -0,0 +1,186 @@
+/*
+ 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 iterate_purse_merges_above_serial_id.c
+ * @brief Implementation of the iterate_purse_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_purse_merges_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #purse_deposit_serial_helper_cb().
+ */
+struct PurseMergeSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseMergeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseMergeSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_merges_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseMergeSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ char *partner_base_url = NULL;
+ struct TALER_Amount amount;
+ struct TALER_Amount balance;
+ uint32_t flags32;
+ enum TALER_WalletAccountMergeFlags flags;
+ struct TALER_PurseMergePublicKeyP merge_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseMergeSignatureP merge_sig;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &balance),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ &partner_base_url),
+ NULL),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ &merge_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
+ &merge_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
+ &merge_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_merge_request_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ flags = (enum TALER_WalletAccountMergeFlags) flags32;
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ partner_base_url,
+ &amount,
+ &balance,
+ flags,
+ &merge_pub,
+ &reserve_pub,
+ &merge_sig,
+ &purse_pub,
+ merge_timestamp);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_merges_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseMergeCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseMergeSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_merges_above_serial_id",
+ "SELECT"
+ " pm.purse_merge_request_serial_id"
+ ",partner_base_url"
+ ",pr.amount_with_fee"
+ ",pr.balance"
+ ",pr.flags"
+ ",pr.merge_pub"
+ ",pm.reserve_pub"
+ ",pm.merge_sig"
+ ",pm.purse_pub"
+ ",pm.merge_timestamp"
+ " FROM purse_merges pm"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " LEFT JOIN partners USING (partner_serial_id)"
+ " WHERE ("
+ " (purse_merge_request_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_merge_request_serial_id ASC;");
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_purse_merges_above_serial_id",
+ params,
+ &purse_merges_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_purse_requests_above_serial_id.c b/src/exchangedb/iterate_purse_requests_above_serial_id.c
@@ -0,0 +1,174 @@
+/*
+ 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 iterate_purse_requests_above_serial_id.c
+ * @brief Implementation of the iterate_purse_requests_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_purse_requests_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #purse_deposit_serial_helper_cb().
+ */
+struct PurseRequestsSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseRequestCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRequestsSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_requests_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseRequestsSerialContext *dsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_Amount target_amount;
+ uint32_t age_limit;
+ struct TALER_PurseMergePublicKeyP merge_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_PurseContractSignatureP purse_sig;
+ struct GNUNET_TIME_Timestamp purse_creation;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &target_amount),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ &age_limit),
+ GNUNET_PQ_result_spec_timestamp ("purse_creation",
+ &purse_creation),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ &purse_expiration),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
+ &purse_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
+ &merge_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_requests_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ &merge_pub,
+ purse_creation,
+ purse_expiration,
+ &h_contract_terms,
+ age_limit,
+ &target_amount,
+ &purse_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_requests_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseRequestCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseRequestsSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_purse_requests_above_serial_id",
+ "SELECT"
+ " purse_requests_serial_id"
+ ",purse_pub"
+ ",amount_with_fee"
+ ",age_limit"
+ ",h_contract_terms"
+ ",purse_creation"
+ ",purse_expiration"
+ ",merge_pub"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE ("
+ " (purse_requests_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_requests_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_purse_requests_above_serial_id",
+ params,
+ &purse_requests_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_records_by_table.c b/src/exchangedb/iterate_records_by_table.c
@@ -0,0 +1,3607 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2020-2025 Taler Systems SA
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/**
+ * @file exchangedb/iterate_records_by_table.c
+ * @brief implementation of lookup_records_by_table
+ * @author Christian Grothoff
+ * @author Özgür Kesim
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_dbevents.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_records_by_table.h"
+#include "helper.h"
+#include <gnunet/gnunet_pq_lib.h>
+
+
+/**
+ * Closure for callbacks used by #postgres_lookup_records_by_table.
+ */
+struct LookupRecordsByTableContext
+{
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_ReplicationCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Set to true on errors.
+ */
+ bool error;
+};
+
+
+/**
+ * Function called with denominations table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_denominations (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_DENOMINATIONS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint32 (
+ "denom_type",
+ &td.details.denominations.denom_type),
+ GNUNET_PQ_result_spec_uint32 (
+ "age_mask",
+ &td.details.denominations.age_mask),
+ TALER_PQ_result_spec_denom_pub (
+ "denom_pub",
+ &td.details.denominations.denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.denominations.master_sig),
+ GNUNET_PQ_result_spec_timestamp (
+ "valid_from",
+ &td.details.denominations.valid_from),
+ GNUNET_PQ_result_spec_timestamp (
+ "expire_withdraw",
+ &td.details.denominations.
+ expire_withdraw),
+ GNUNET_PQ_result_spec_timestamp (
+ "expire_deposit",
+ &td.details.denominations.
+ expire_deposit),
+ GNUNET_PQ_result_spec_timestamp (
+ "expire_legal",
+ &td.details.denominations.expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "coin",
+ &td.details.denominations.coin),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "fee_withdraw",
+ &td.details.denominations.fees.withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "fee_deposit",
+ &td.details.denominations.fees.deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "fee_refresh",
+ &td.details.denominations.fees.refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "fee_refund",
+ &td.details.denominations.fees.refund),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with denomination_revocations table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_denomination_revocations (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "denominations_serial",
+ &td.details.denomination_revocations.denominations_serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.denomination_revocations.master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wire_targets table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wire_targets (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WIRE_TARGETS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_string (
+ "payto_uri",
+ &td.details.wire_targets.full_payto_uri.full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wire_targets table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_kyc_targets (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_KYC_TARGETS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_normalized_payto",
+ &td.details.kyc_targets.h_normalized_payto),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "access_token",
+ &td.details.kyc_targets.access_token),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "target_pub",
+ &td.details.kyc_targets.target_pub),
+ &td.details.kyc_targets.no_account),
+ GNUNET_PQ_result_spec_bool (
+ "is_wallet",
+ &td.details.kyc_targets.is_wallet),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with reserves table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &td.details.reserves.reserve_pub),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &td.details.reserves.expiration_date),
+ GNUNET_PQ_result_spec_timestamp ("gc_date",
+ &td.details.reserves.gc_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with reserves_in table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves_in (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES_IN
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.reserves_in.reserve_pub),
+ GNUNET_PQ_result_spec_uint64 (
+ "wire_reference",
+ &td.details.reserves_in.wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "credit",
+ &td.details.reserves_in.credit),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_source_h_payto",
+ &td.details.reserves_in.sender_account_h_payto),
+ GNUNET_PQ_result_spec_string (
+ "exchange_account_section",
+ &td.details.reserves_in.exchange_account_section),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_date",
+ &td.details.reserves_in.execution_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with kycauth_in table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_kycauth_in (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_KYCAUTHS_IN
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "account_pub",
+ &td.details.kycauth_in.account_pub),
+ GNUNET_PQ_result_spec_uint64 (
+ "wire_reference",
+ &td.details.kycauth_in.wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "credit",
+ &td.details.kycauth_in.credit),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_source_h_payto",
+ &td.details.kycauth_in.sender_account_h_payto),
+ GNUNET_PQ_result_spec_string (
+ "exchange_account_section",
+ &td.details.kycauth_in.exchange_account_section),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_date",
+ &td.details.kycauth_in.execution_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with reserves_close table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves_close (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES_CLOSE
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.reserves_close.reserve_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_date",
+ &td.details.reserves_close.execution_date),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wtid",
+ &td.details.reserves_close.wtid),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_target_h_payto",
+ &td.details.reserves_close.sender_account_h_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.reserves_close.amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "closing_fee",
+ &td.details.reserves_close.closing_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with reserves_open_requests table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves_open_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.reserves_open_requests.reserve_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "request_timestamp",
+ &td.details.reserves_open_requests.request_timestamp),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_date",
+ &td.details.reserves_open_requests.expiration_date),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.reserves_open_requests.reserve_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "reserve_payment",
+ &td.details.reserves_open_requests.reserve_payment),
+ GNUNET_PQ_result_spec_uint32 (
+ "requested_purse_limit",
+ &td.details.reserves_open_requests.requested_purse_limit),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with reserves_open_deposits table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves_open_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.reserves_open_deposits.reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.reserves_open_deposits.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.reserves_open_deposits.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_sig",
+ &td.details.reserves_open_deposits.coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "contribution",
+ &td.details.reserves_open_deposits.contribution),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with auditors table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_auditors (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AUDITORS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
+ &td.details.auditors.auditor_pub),
+ GNUNET_PQ_result_spec_string ("auditor_url",
+ &td.details.auditors.auditor_url),
+ GNUNET_PQ_result_spec_string ("auditor_name",
+ &td.details.auditors.auditor_name),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ &td.details.auditors.is_active),
+ GNUNET_PQ_result_spec_timestamp ("last_change",
+ &td.details.auditors.last_change),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with auditor_denom_sigs table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_auditor_denom_sigs (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "auditor_uuid",
+ &td.details.auditor_denom_sigs.auditor_uuid),
+ GNUNET_PQ_result_spec_uint64 (
+ "denominations_serial",
+ &td.details.auditor_denom_sigs.denominations_serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "auditor_sig",
+ &td.details.auditor_denom_sigs.auditor_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with exchange_sign_keys table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_exchange_sign_keys (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
+ &td.details.exchange_sign_keys.
+ exchange_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &td.details.exchange_sign_keys.
+ master_sig),
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &td.details.exchange_sign_keys.meta.
+ start),
+ GNUNET_PQ_result_spec_timestamp ("expire_sign",
+ &td.details.exchange_sign_keys.meta.
+ expire_sign),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &td.details.exchange_sign_keys.meta.
+ expire_legal),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with signkey_revocations table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_signkey_revocations (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 ("esk_serial",
+ &td.details.signkey_revocations.esk_serial),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &td.details.signkey_revocations.
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with known_coins table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_known_coins (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_KNOWN_COINS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.known_coins.coin_pub),
+ TALER_PQ_result_spec_denom_sig (
+ "denom_sig",
+ &td.details.known_coins.denom_sig),
+ GNUNET_PQ_result_spec_uint64 (
+ "denominations_serial",
+ &td.details.known_coins.denominations_serial),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with refresh table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_refresh (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_REFRESH
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ bool no_cs_r_values;
+ bool no_cs_r_choices;
+ size_t num_denom_sigs;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "rc",
+ &td.details.refresh.rc),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "execution_date",
+ &td.details.refresh.execution_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.refresh.amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "old_coin_pub",
+ &td.details.refresh.old_coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "old_coin_sig",
+ &td.details.refresh.old_coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "refresh_seed",
+ &td.details.refresh.refresh_seed),
+ GNUNET_PQ_result_spec_uint32 (
+ "noreveal_index",
+ &td.details.refresh.noreveal_index),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "planchets_h",
+ &td.details.refresh.planchets_h),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "selected_h",
+ &td.details.refresh.selected_h),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "blinding_seed",
+ &td.details.refresh.blinding_seed),
+ &td.details.refresh.no_blinding_seed),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_array_cs_r_pub (
+ pg->conn,
+ "cs_r_values",
+ &td.details.refresh.num_cs_r_values,
+ &td.details.refresh.cs_r_values),
+ &no_cs_r_values),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 (
+ "cs_r_choices",
+ &td.details.refresh.cs_r_choices),
+ &no_cs_r_choices),
+ GNUNET_PQ_result_spec_array_uint64 (
+ pg->conn,
+ "denom_serials",
+ &td.details.refresh.num_coins,
+ &td.details.refresh.denom_serials),
+ TALER_PQ_result_spec_array_blinded_denom_sig (
+ pg->conn,
+ "denom_sigs",
+ &num_denom_sigs,
+ &td.details.refresh.denom_sigs),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with batch deposits table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_batch_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_BATCH_DEPOSITS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "shard",
+ &td.details.batch_deposits.shard),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "merchant_pub",
+ &td.details.batch_deposits.merchant_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "wallet_timestamp",
+ &td.details.batch_deposits.wallet_timestamp),
+ GNUNET_PQ_result_spec_timestamp (
+ "exchange_timestamp",
+ &td.details.batch_deposits.exchange_timestamp),
+ GNUNET_PQ_result_spec_timestamp (
+ "refund_deadline",
+ &td.details.batch_deposits.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp (
+ "wire_deadline",
+ &td.details.batch_deposits.wire_deadline),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_contract_terms",
+ &td.details.batch_deposits.h_contract_terms),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wallet_data_hash",
+ &td.details.batch_deposits.wallet_data_hash),
+ &td.details.batch_deposits.no_wallet_data_hash),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_salt",
+ &td.details.batch_deposits.wire_salt),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_target_h_payto",
+ &td.details.batch_deposits.wire_target_h_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "total_amount",
+ &td.details.batch_deposits.total_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "total_without_fee",
+ &td.details.batch_deposits.total_without_fee),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "merchant_sig",
+ &td.details.batch_deposits.merchant_sig),
+ GNUNET_PQ_result_spec_bool (
+ "done",
+ &td.details.batch_deposits.done),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with coin deposits table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_coin_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_COIN_DEPOSITS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "batch_deposit_serial_id",
+ &td.details.coin_deposits.batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.coin_deposits.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_sig",
+ &td.details.coin_deposits.coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.coin_deposits.amount_with_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with refunds table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_refunds (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_REFUNDS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.refunds.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "merchant_sig",
+ &td.details.refunds.merchant_sig),
+ GNUNET_PQ_result_spec_uint64 (
+ "rtransaction_id",
+ &td.details.refunds.rtransaction_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.refunds.amount_with_fee),
+ GNUNET_PQ_result_spec_uint64 (
+ "batch_deposit_serial_id",
+ &td.details.refunds.batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wire_out table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wire_out (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WIRE_OUT
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_date",
+ &td.details.wire_out.execution_date),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wtid_raw",
+ &td.details.wire_out.wtid_raw),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_target_h_payto",
+ &td.details.wire_out.wire_target_h_payto),
+ GNUNET_PQ_result_spec_string (
+ "exchange_account_section",
+ &td.details.wire_out.exchange_account_section),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.wire_out.amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with aggregation_tracking table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_aggregation_tracking (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "batch_deposit_serial_id",
+ &td.details.aggregation_tracking.batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wtid_raw",
+ &td.details.aggregation_tracking.wtid_raw),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wire_fee table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wire_fee (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WIRE_FEE
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_string ("wire_method",
+ &td.details.wire_fee.wire_method),
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &td.details.wire_fee.start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &td.details.wire_fee.end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &td.details.wire_fee.fees.wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &td.details.wire_fee.fees.closing),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &td.details.wire_fee.master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wire_fee table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_global_fee (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_GLOBAL_FEE
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_timestamp (
+ "start_date",
+ &td.details.global_fee.start_date),
+ GNUNET_PQ_result_spec_timestamp (
+ "end_date",
+ &td.details.global_fee.end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "history_fee",
+ &td.details.global_fee.fees.history),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "account_fee",
+ &td.details.global_fee.fees.account),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "purse_fee",
+ &td.details.global_fee.fees.purse),
+ GNUNET_PQ_result_spec_relative_time (
+ "purse_timeout",
+ &td.details.global_fee.purse_timeout),
+ GNUNET_PQ_result_spec_relative_time (
+ "history_expiration",
+ &td.details.global_fee.history_expiration),
+ GNUNET_PQ_result_spec_uint32 (
+ "purse_account_limit",
+ &td.details.global_fee.purse_account_limit),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.global_fee.master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with recoup table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_recoup (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RECOUP
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &td.details.recoup.coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &td.details.recoup.coin_blind),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &td.details.recoup.amount),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &td.details.recoup.timestamp),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.recoup.coin_pub),
+ GNUNET_PQ_result_spec_uint64 ("withdraw_serial_id",
+ &td.details.recoup.withdraw_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with recoup_refresh table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_recoup_refresh (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RECOUP_REFRESH
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_sig",
+ &td.details.recoup_refresh.coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_blind",
+ &td.details.recoup_refresh.coin_blind),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.recoup_refresh.amount),
+ GNUNET_PQ_result_spec_timestamp (
+ "recoup_timestamp",
+ &td.details.recoup_refresh.recoup_timestamp),
+ GNUNET_PQ_result_spec_uint64 (
+ "known_coin_id",
+ &td.details.recoup_refresh.known_coin_id),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.recoup_refresh.coin_pub),
+ GNUNET_PQ_result_spec_uint64 (
+ "refresh_id",
+ &td.details.recoup_refresh.refresh_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with purse_requests table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_purse_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PURSE_REQUESTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "purse_requests_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.purse_requests.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "merge_pub",
+ &td.details.purse_requests.merge_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "purse_creation",
+ &td.details.purse_requests.purse_creation),
+ GNUNET_PQ_result_spec_timestamp (
+ "purse_expiration",
+ &td.details.purse_requests.purse_expiration),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_contract_terms",
+ &td.details.purse_requests.h_contract_terms),
+ GNUNET_PQ_result_spec_uint32 (
+ "age_limit",
+ &td.details.purse_requests.age_limit),
+ GNUNET_PQ_result_spec_uint32 (
+ "flags",
+ &td.details.purse_requests.flags),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.purse_requests.amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "purse_fee",
+ &td.details.purse_requests.purse_fee),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_sig",
+ &td.details.purse_requests.purse_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with purse_decision table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_purse_decision (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PURSE_DECISION
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "purse_decision_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.purse_decision.purse_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "action_timestamp",
+ &td.details.purse_decision.action_timestamp),
+ GNUNET_PQ_result_spec_bool (
+ "refunded",
+ &td.details.purse_decision.refunded),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with purse_merges table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_purse_merges (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PURSE_MERGES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "purse_merge_request_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "partner_serial_id",
+ &td.details.purse_merges.partner_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.purse_merges.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.purse_merges.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "merge_sig",
+ &td.details.purse_merges.merge_sig),
+ GNUNET_PQ_result_spec_timestamp (
+ "merge_timestamp",
+ &td.details.purse_merges.merge_timestamp),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with purse_deposits table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_purse_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PURSE_DEPOSITS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "purse_deposit_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "partner_serial_id",
+ &td.details.purse_deposits.partner_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.purse_deposits.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.purse_deposits.coin_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.purse_deposits.amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_sig",
+ &td.details.purse_deposits.coin_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with account_merges table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_account_merges (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_ACCOUNT_MERGES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "account_merge_request_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.account_merges.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.account_merges.reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.account_merges.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wallet_h_payto",
+ &td.details.account_merges.wallet_h_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with history_requests table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_history_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_HISTORY_REQUESTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "history_request_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.history_requests.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.history_requests.reserve_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "history_fee",
+ &td.details.history_requests.history_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with close_requests table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_close_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_CLOSE_REQUESTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "close_request_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.close_requests.reserve_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "close_timestamp",
+ &td.details.close_requests.close_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.close_requests.reserve_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "close",
+ &td.details.close_requests.close),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "close_fee",
+ &td.details.close_requests.close_fee),
+ GNUNET_PQ_result_spec_string (
+ "payto_uri",
+ &td.details.close_requests.payto_uri.full_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wads_out table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wads_out (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WADS_OUT
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "wad_out_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wad_id",
+ &td.details.wads_out.wad_id),
+ GNUNET_PQ_result_spec_uint64 (
+ "partner_serial_id",
+ &td.details.wads_out.partner_serial_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.wads_out.amount),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_time",
+ &td.details.wads_out.execution_time),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wads_out_entries table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wads_out_entries (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "wad_out_entry_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.wads_out_entries.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.wads_out_entries.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_contract",
+ &td.details.wads_out_entries.h_contract),
+ GNUNET_PQ_result_spec_timestamp (
+ "purse_expiration",
+ &td.details.wads_out_entries.purse_expiration),
+ GNUNET_PQ_result_spec_timestamp (
+ "merge_timestamp",
+ &td.details.wads_out_entries.merge_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.wads_out_entries.amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "wad_fee",
+ &td.details.wads_out_entries.wad_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "deposit_fees",
+ &td.details.wads_out_entries.deposit_fees),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.wads_out_entries.reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_sig",
+ &td.details.wads_out_entries.purse_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wads_in table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wads_in (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WADS_IN
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "wad_in_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wad_id",
+ &td.details.wads_in.wad_id),
+ GNUNET_PQ_result_spec_string (
+ "origin_exchange_url",
+ &td.details.wads_in.origin_exchange_url),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.wads_in.amount),
+ GNUNET_PQ_result_spec_timestamp (
+ "arrival_time",
+ &td.details.wads_in.arrival_time),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with wads_in_entries table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_wads_in_entries (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "wad_in_entry_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.wads_in_entries.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.wads_in_entries.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_contract",
+ &td.details.wads_in_entries.h_contract),
+ GNUNET_PQ_result_spec_timestamp (
+ "purse_expiration",
+ &td.details.wads_in_entries.purse_expiration),
+ GNUNET_PQ_result_spec_timestamp (
+ "merge_timestamp",
+ &td.details.wads_in_entries.merge_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.wads_in_entries.amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "wad_fee",
+ &td.details.wads_in_entries.wad_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "deposit_fees",
+ &td.details.wads_in_entries.deposit_fees),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.wads_in_entries.reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_sig",
+ &td.details.wads_in_entries.purse_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with profit_drains table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_profit_drains (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PROFIT_DRAINS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "profit_drain_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wtid",
+ &td.details.profit_drains.wtid),
+ GNUNET_PQ_result_spec_string (
+ "account_section",
+ &td.details.profit_drains.account_section),
+ GNUNET_PQ_result_spec_string (
+ "payto_uri",
+ &td.details.profit_drains.payto_uri.full_payto),
+ GNUNET_PQ_result_spec_timestamp (
+ "trigger_date",
+ &td.details.profit_drains.trigger_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.profit_drains.amount),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.profit_drains.master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with aml_staff table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_aml_staff (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AML_STAFF
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "aml_staff_uuid",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "decider_pub",
+ &td.details.aml_staff.decider_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.aml_staff.master_sig),
+ GNUNET_PQ_result_spec_string (
+ "decider_name",
+ &td.details.aml_staff.decider_name),
+ GNUNET_PQ_result_spec_bool (
+ "is_active",
+ &td.details.aml_staff.is_active),
+ GNUNET_PQ_result_spec_bool (
+ "read_only",
+ &td.details.aml_staff.read_only),
+ GNUNET_PQ_result_spec_timestamp (
+ "last_change",
+ &td.details.aml_staff.last_change),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with purse_deletion table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_purse_deletion (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PURSE_DELETION
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "purse_deletion_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_sig",
+ &td.details.purse_deletion.purse_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.purse_deletion.purse_pub),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with withdraw table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_withdraw (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_WITHDRAW
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ bool no_max_age;
+ bool no_noreveal_index;
+ bool no_selected_h;
+ bool no_cs_r_values;
+ bool no_cs_r_choices;
+ size_t num_sigs;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "withdraw_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "planchets_h",
+ &td.details.withdraw.planchets_h),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_date",
+ &td.details.withdraw.execution_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.withdraw.amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.withdraw.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.withdraw.reserve_sig),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint16 (
+ "max_age",
+ &td.details.withdraw.max_age),
+ &no_max_age),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint16 (
+ "noreveal_index",
+ &td.details.withdraw.noreveal_index),
+ &no_noreveal_index),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "selected_h",
+ &td.details.withdraw.selected_h),
+ &no_selected_h),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "blinding_seed",
+ &td.details.withdraw.blinding_seed),
+ &td.details.withdraw.no_blinding_seed),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_array_cs_r_pub (
+ pg->conn,
+ "cs_r_values",
+ &td.details.withdraw.num_cs_r_values,
+ &td.details.withdraw.cs_r_values),
+ &no_cs_r_values),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 (
+ "cs_r_choices",
+ &td.details.withdraw.cs_r_choices),
+ &no_cs_r_choices),
+ GNUNET_PQ_result_spec_array_uint64 (
+ pg->conn,
+ "denom_serials",
+ &td.details.withdraw.num_coins,
+ &td.details.withdraw.denom_serials),
+ TALER_PQ_result_spec_array_blinded_denom_sig (
+ pg->conn,
+ "denom_sigs",
+ &num_sigs,
+ &td.details.withdraw.denom_sigs),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ if (num_sigs != td.details.withdraw.num_coins)
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ if (no_max_age != no_noreveal_index)
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ if (no_max_age != no_selected_h)
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ if (no_cs_r_values != no_cs_r_choices)
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ if (no_cs_r_values != td.details.withdraw.no_blinding_seed)
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ td.details.withdraw.age_proof_required = ! no_max_age;
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with legitimization_measures table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_legitimization_measures (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "access_token",
+ &td.details.legitimization_measures.target_token),
+ GNUNET_PQ_result_spec_timestamp (
+ "start_time",
+ &td.details.legitimization_measures.start_time),
+ TALER_PQ_result_spec_json (
+ "jmeasures",
+ &td.details.legitimization_measures.measures),
+ GNUNET_PQ_result_spec_uint32 (
+ "display_priority",
+ &td.details.legitimization_measures.display_priority),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with legitimization_outcomes table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_legitimization_outcomes (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.legitimization_outcomes.h_payto),
+ GNUNET_PQ_result_spec_timestamp (
+ "decision_time",
+ &td.details.legitimization_outcomes.decision_time),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_time",
+ &td.details.legitimization_outcomes.expiration_time),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json (
+ "jproperties",
+ &td.details.legitimization_outcomes.properties),
+ NULL),
+ GNUNET_PQ_result_spec_bool (
+ "to_investigate_id",
+ &td.details.legitimization_outcomes.to_investigate),
+ TALER_PQ_result_spec_json (
+ "jnew_rules",
+ &td.details.legitimization_outcomes.new_rules),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with legitimization_processes table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_legitimization_processes (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.legitimization_processes.h_payto),
+ GNUNET_PQ_result_spec_timestamp (
+ "start_time",
+ &td.details.legitimization_processes.start_time),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_time",
+ &td.details.legitimization_processes.expiration_time),
+ GNUNET_PQ_result_spec_uint64 (
+ "legitimization_measure_serial_id",
+ &td.details.legitimization_processes.legitimization_measure_serial_id),
+ GNUNET_PQ_result_spec_uint32 (
+ "measure_index",
+ &td.details.legitimization_processes.measure_index),
+ GNUNET_PQ_result_spec_string (
+ "provider_name",
+ &td.details.legitimization_processes.provider_name),
+ GNUNET_PQ_result_spec_string (
+ "provider_user_id",
+ &td.details.legitimization_processes.provider_user_id),
+ GNUNET_PQ_result_spec_string (
+ "provider_legitimization_id",
+ &td.details.legitimization_processes.provider_legitimization_id),
+ GNUNET_PQ_result_spec_string (
+ "redirect_url",
+ &td.details.legitimization_processes.redirect_url),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with kyc_attributes table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_kyc_attributes (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "kyc_attributes_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.kyc_attributes.h_payto),
+ GNUNET_PQ_result_spec_uint64 (
+ "legitimization_serial",
+ &td.details.kyc_attributes.legitimization_serial),
+ GNUNET_PQ_result_spec_timestamp (
+ "collection_time",
+ &td.details.kyc_attributes.collection_time),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_time",
+ &td.details.kyc_attributes.expiration_time),
+ GNUNET_PQ_result_spec_uint64 (
+ "trigger_outcome_serial",
+ &td.details.kyc_attributes.trigger_outcome_serial),
+ GNUNET_PQ_result_spec_variable_size (
+ "encrypted_attributes",
+ &td.details.kyc_attributes.encrypted_attributes,
+ &td.details.kyc_attributes.encrypted_attributes_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with aml_history table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_aml_history (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AML_HISTORY
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "aml_history_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.aml_history.h_payto),
+ GNUNET_PQ_result_spec_uint64 (
+ "outcome_serial_id",
+ &td.details.aml_history.outcome_serial_id),
+ GNUNET_PQ_result_spec_string (
+ "justification",
+ &td.details.aml_history.justification),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "decider_pub",
+ &td.details.aml_history.decider_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "decider_sig",
+ &td.details.aml_history.decider_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with kyc_events table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_kyc_events (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_KYC_EVENTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "kyc_event_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_timestamp (
+ "event_timestamp",
+ &td.details.kyc_events.event_timestamp),
+ GNUNET_PQ_result_spec_string (
+ "event_type",
+ &td.details.kyc_events.event_type),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Assign statement to @a n and PREPARE
+ * @a sql under name @a n.
+ */
+#define XPREPARE(n,sql) \
+ statement = n; \
+ PREPARE (pg, n, sql);
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_records_by_table (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t serial,
+ TALER_EXCHANGEDB_ReplicationCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial),
+ GNUNET_PQ_query_param_end
+ };
+ struct LookupRecordsByTableContext ctx = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls
+ };
+ GNUNET_PQ_PostgresResultHandler rh = NULL;
+ const char *statement = NULL;
+ enum GNUNET_DB_QueryStatus qs;
+
+ switch (table)
+ {
+ case TALER_EXCHANGEDB_RT_DENOMINATIONS:
+ XPREPARE ("select_above_serial_by_table_denominations",
+ "SELECT"
+ " denominations_serial AS serial"
+ ",denom_type"
+ ",denom_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin"
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ " FROM denominations"
+ " WHERE denominations_serial > $1"
+ " ORDER BY denominations_serial ASC;");
+ rh = &lrbt_cb_table_denominations;
+ break;
+ case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
+ XPREPARE ("select_above_serial_by_table_denomination_revocations",
+ "SELECT"
+ " denom_revocations_serial_id AS serial"
+ ",master_sig"
+ ",denominations_serial"
+ " FROM denomination_revocations"
+ " WHERE denom_revocations_serial_id > $1"
+ " ORDER BY denom_revocations_serial_id ASC;");
+ rh = &lrbt_cb_table_denomination_revocations;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
+ XPREPARE ("select_above_serial_by_table_wire_targets",
+ "SELECT"
+ " wire_target_serial_id AS serial"
+ ",payto_uri"
+ " FROM wire_targets"
+ " WHERE wire_target_serial_id > $1"
+ " ORDER BY wire_target_serial_id ASC;");
+ rh = &lrbt_cb_table_wire_targets;
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_TARGETS:
+ XPREPARE ("select_above_serial_by_table_kyc_targets",
+ "SELECT"
+ " kyc_target_serial_id AS serial"
+ ",h_normalized_payto"
+ ",access_token"
+ ",target_pub"
+ ",is_wallet"
+ " FROM kyc_targets"
+ " WHERE kyc_target_serial_id > $1"
+ " ORDER BY kyc_target_serial_id ASC;");
+ rh = &lrbt_cb_table_kyc_targets;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES:
+ XPREPARE ("select_above_serial_by_table_reserves",
+ "SELECT"
+ " reserve_uuid AS serial"
+ ",reserve_pub"
+ ",expiration_date"
+ ",gc_date"
+ " FROM reserves"
+ " WHERE reserve_uuid > $1"
+ " ORDER BY reserve_uuid ASC;");
+ rh = &lrbt_cb_table_reserves;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_IN:
+ XPREPARE ("select_above_serial_by_table_reserves_in",
+ "SELECT"
+ " reserve_in_serial_id AS serial"
+ ",reserve_pub"
+ ",wire_reference"
+ ",credit"
+ ",wire_source_h_payto"
+ ",exchange_account_section"
+ ",execution_date"
+ " FROM reserves_in"
+ " WHERE reserve_in_serial_id > $1"
+ " ORDER BY reserve_in_serial_id ASC;");
+ rh = &lrbt_cb_table_reserves_in;
+ break;
+ case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
+ XPREPARE ("select_above_serial_by_table_kycauth_in",
+ "SELECT"
+ " kycauth_in_serial_id AS serial"
+ ",account_pub"
+ ",wire_reference"
+ ",credit"
+ ",wire_source_h_payto"
+ ",exchange_account_section"
+ ",execution_date"
+ " FROM kycauths_in"
+ " WHERE kycauth_in_serial_id > $1"
+ " ORDER BY kycauth_in_serial_id ASC;");
+ rh = &lrbt_cb_table_kycauth_in;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
+ XPREPARE ("select_above_serial_by_table_reserves_close",
+ "SELECT"
+ " close_uuid AS serial"
+ ",reserve_pub"
+ ",execution_date"
+ ",wtid"
+ ",wire_target_h_payto"
+ ",amount"
+ ",closing_fee"
+ " FROM reserves_close"
+ " WHERE close_uuid > $1"
+ " ORDER BY close_uuid ASC;");
+ rh = &lrbt_cb_table_reserves_close;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_reserves_open_requests",
+ "SELECT"
+ " open_request_uuid AS serial"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",expiration_date"
+ ",reserve_sig"
+ ",reserve_payment"
+ ",requested_purse_limit"
+ " FROM reserves_open_requests"
+ " WHERE open_request_uuid > $1"
+ " ORDER BY open_request_uuid ASC;");
+ rh = &lrbt_cb_table_reserves_open_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_reserves_open_deposits",
+ "SELECT"
+ " reserves_open_deposit_uuid AS serial"
+ ",reserve_sig"
+ ",reserve_pub"
+ ",coin_pub"
+ ",coin_sig"
+ ",contribution"
+ " FROM reserves_open_deposits"
+ " WHERE reserves_open_deposit_uuid > $1"
+ " ORDER BY reserves_open_deposit_uuid ASC;");
+ rh = &lrbt_cb_table_reserves_open_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITORS:
+ XPREPARE ("select_above_serial_by_table_auditors",
+ "SELECT"
+ " auditor_uuid AS serial"
+ ",auditor_pub"
+ ",auditor_name"
+ ",auditor_url"
+ ",is_active"
+ ",last_change"
+ " FROM auditors"
+ " WHERE auditor_uuid > $1"
+ " ORDER BY auditor_uuid ASC;");
+ rh = &lrbt_cb_table_auditors;
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
+ XPREPARE ("select_above_serial_by_table_auditor_denom_sigs",
+ "SELECT"
+ " auditor_denom_serial AS serial"
+ ",auditor_uuid"
+ ",denominations_serial"
+ ",auditor_sig"
+ " FROM auditor_denom_sigs"
+ " WHERE auditor_denom_serial > $1"
+ " ORDER BY auditor_denom_serial ASC;");
+ rh = &lrbt_cb_table_auditor_denom_sigs;
+ break;
+ case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
+ XPREPARE ("select_above_serial_by_table_exchange_sign_keys",
+ "SELECT"
+ " esk_serial AS serial"
+ ",exchange_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ " FROM exchange_sign_keys"
+ " WHERE esk_serial > $1"
+ " ORDER BY esk_serial ASC;");
+ rh = &lrbt_cb_table_exchange_sign_keys;
+ break;
+ case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
+ XPREPARE ("select_above_serial_by_table_signkey_revocations",
+ "SELECT"
+ " signkey_revocations_serial_id AS serial"
+ ",esk_serial"
+ ",master_sig"
+ " FROM signkey_revocations"
+ " WHERE signkey_revocations_serial_id > $1"
+ " ORDER BY signkey_revocations_serial_id ASC;");
+ rh = &lrbt_cb_table_signkey_revocations;
+ break;
+ case TALER_EXCHANGEDB_RT_KNOWN_COINS:
+ XPREPARE ("select_above_serial_by_table_known_coins",
+ "SELECT"
+ " known_coin_id AS serial"
+ ",coin_pub"
+ ",denom_sig"
+ ",denominations_serial"
+ " FROM known_coins"
+ " WHERE known_coin_id > $1"
+ " ORDER BY known_coin_id ASC;");
+ rh = &lrbt_cb_table_known_coins;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH:
+ XPREPARE ("select_above_serial_by_table_refresh",
+ "SELECT"
+ " refresh_id AS serial"
+ ",rc"
+ ",execution_date"
+ ",amount_with_fee"
+ ",old_coin_pub"
+ ",old_coin_sig"
+ ",refresh_seed"
+ ",noreveal_index"
+ ",planchets_h"
+ ",selected_h"
+ ",blinding_seed"
+ ",cs_r_values"
+ ",cs_r_choices"
+ ",denom_serials"
+ ",denom_sigs"
+ " FROM refresh"
+ " WHERE refresh_id > $1"
+ " ORDER BY refresh_id ASC;");
+ rh = &lrbt_cb_table_refresh;
+ break;
+ case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_batch_deposits",
+ "SELECT"
+ " batch_deposit_serial_id AS serial"
+ ",shard"
+ ",merchant_pub"
+ ",wallet_timestamp"
+ ",exchange_timestamp"
+ ",refund_deadline"
+ ",wire_deadline"
+ ",h_contract_terms"
+ ",wallet_data_hash"
+ ",wire_salt"
+ ",wire_target_h_payto"
+ ",total_amount"
+ ",total_without_fee"
+ ",merchant_sig"
+ ",done"
+ " FROM batch_deposits"
+ " WHERE batch_deposit_serial_id > $1"
+ " ORDER BY batch_deposit_serial_id ASC;");
+ rh = &lrbt_cb_table_batch_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_coin_deposits",
+ "SELECT"
+ " coin_deposit_serial_id AS serial"
+ ",batch_deposit_serial_id"
+ ",coin_pub"
+ ",coin_sig"
+ ",amount_with_fee"
+ " FROM coin_deposits"
+ " WHERE coin_deposit_serial_id > $1"
+ " ORDER BY coin_deposit_serial_id ASC;");
+ rh = &lrbt_cb_table_coin_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_REFUNDS:
+ XPREPARE ("select_above_serial_by_table_refunds",
+ "SELECT"
+ " refund_serial_id AS serial"
+ ",coin_pub"
+ ",merchant_sig"
+ ",rtransaction_id"
+ ",amount_with_fee"
+ ",batch_deposit_serial_id"
+ " FROM refunds"
+ " WHERE refund_serial_id > $1"
+ " ORDER BY refund_serial_id ASC;");
+ rh = &lrbt_cb_table_refunds;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_OUT:
+ XPREPARE ("select_above_serial_by_table_wire_out",
+ "SELECT"
+ " wireout_uuid AS serial"
+ ",execution_date"
+ ",wtid_raw"
+ ",wire_target_h_payto"
+ ",exchange_account_section"
+ ",amount"
+ " FROM wire_out"
+ " WHERE wireout_uuid > $1"
+ " ORDER BY wireout_uuid ASC;");
+ rh = &lrbt_cb_table_wire_out;
+ break;
+ case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
+ XPREPARE ("select_above_serial_by_table_aggregation_tracking",
+ "SELECT"
+ " aggregation_serial_id AS serial"
+ ",batch_deposit_serial_id"
+ ",wtid_raw"
+ " FROM aggregation_tracking"
+ " WHERE aggregation_serial_id > $1"
+ " ORDER BY aggregation_serial_id ASC;");
+ rh = &lrbt_cb_table_aggregation_tracking;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_FEE:
+ XPREPARE ("select_above_serial_by_table_wire_fee",
+ "SELECT"
+ " wire_fee_serial AS serial"
+ ",wire_method"
+ ",start_date"
+ ",end_date"
+ ",wire_fee"
+ ",closing_fee"
+ ",master_sig"
+ " FROM wire_fee"
+ " WHERE wire_fee_serial > $1"
+ " ORDER BY wire_fee_serial ASC;");
+ rh = &lrbt_cb_table_wire_fee;
+ break;
+ case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
+ XPREPARE ("select_above_serial_by_table_global_fee",
+ "SELECT"
+ " global_fee_serial AS serial"
+ ",start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ " FROM global_fee"
+ " WHERE global_fee_serial > $1"
+ " ORDER BY global_fee_serial ASC;");
+ rh = &lrbt_cb_table_global_fee;
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP:
+ XPREPARE ("select_above_serial_by_table_recoup",
+ "SELECT"
+ " recoup_uuid AS serial"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount"
+ ",recoup_timestamp"
+ ",coin_pub"
+ ",reserve_out_serial_id"
+ " FROM recoup"
+ " WHERE recoup_uuid > $1"
+ " ORDER BY recoup_uuid ASC;");
+ rh = &lrbt_cb_table_recoup;
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
+ XPREPARE ("select_above_serial_by_table_recoup_refresh",
+ "SELECT"
+ " recoup_refresh_uuid AS serial"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount"
+ ",recoup_timestamp"
+ ",coin_pub"
+ ",known_coin_id"
+ ",refresh_id"
+ " FROM recoup_refresh"
+ " WHERE recoup_refresh_uuid > $1"
+ " ORDER BY recoup_refresh_uuid ASC;");
+ rh = &lrbt_cb_table_recoup_refresh;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_purse_requests",
+ "SELECT"
+ " purse_requests_serial_id"
+ ",purse_pub"
+ ",merge_pub"
+ ",purse_creation"
+ ",purse_expiration"
+ ",h_contract_terms"
+ ",age_limit"
+ ",flags"
+ ",amount_with_fee"
+ ",purse_fee"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE purse_requests_serial_id > $1"
+ " ORDER BY purse_requests_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DECISION:
+ XPREPARE ("select_above_serial_by_table_purse_decision",
+ "SELECT"
+ " purse_decision_serial_id"
+ ",purse_pub"
+ ",action_timestamp"
+ ",refunded"
+ " FROM purse_decision"
+ " WHERE purse_decision_serial_id > $1"
+ " ORDER BY purse_decision_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_decision;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_MERGES:
+ XPREPARE ("select_above_serial_by_table_purse_merges",
+ "SELECT"
+ " purse_merge_request_serial_id"
+ ",partner_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",merge_sig"
+ ",merge_timestamp"
+ " FROM purse_merges"
+ " WHERE purse_merge_request_serial_id > $1"
+ " ORDER BY purse_merge_request_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_merges;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_purse_deposits",
+ "SELECT"
+ " purse_deposit_serial_id"
+ ",partner_serial_id"
+ ",purse_pub"
+ ",coin_pub"
+ ",amount_with_fee"
+ ",coin_sig"
+ " FROM purse_deposits"
+ " WHERE purse_deposit_serial_id > $1"
+ " ORDER BY purse_deposit_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
+ XPREPARE ("select_above_serial_by_table_account_merges",
+ "SELECT"
+ " account_merge_request_serial_id"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",purse_pub"
+ ",wallet_h_payto"
+ " FROM account_merges"
+ " WHERE account_merge_request_serial_id > $1"
+ " ORDER BY account_merge_request_serial_id ASC;");
+ rh = &lrbt_cb_table_account_merges;
+ break;
+ case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_history_requests",
+ "SELECT"
+ " history_request_serial_id"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",reserve_sig"
+ ",history_fee"
+ " FROM history_requests"
+ " WHERE history_request_serial_id > $1"
+ " ORDER BY history_request_serial_id ASC;");
+ rh = &lrbt_cb_table_history_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_close_requests",
+ "SELECT"
+ " close_request_serial_id"
+ ",reserve_pub"
+ ",close_timestamp"
+ ",reserve_sig"
+ ",close"
+ " FROM close_requests"
+ " WHERE close_request_serial_id > $1"
+ " ORDER BY close_request_serial_id ASC;");
+ rh = &lrbt_cb_table_close_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT:
+ XPREPARE ("select_above_serial_by_table_wads_out",
+ "SELECT"
+ " wad_out_serial_id"
+ ",wad_id"
+ ",partner_serial_id"
+ ",amount"
+ ",execution_time"
+ " FROM wads_out"
+ " WHERE wad_out_serial_id > $1"
+ " ORDER BY wad_out_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_out;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
+ XPREPARE ("select_above_serial_by_table_wads_out_entries",
+ "SELECT"
+ " wad_out_entry_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",h_contract"
+ ",purse_expiration"
+ ",merge_timestamp"
+ ",amount_with_fee"
+ ",wad_fee"
+ ",deposit_fees"
+ ",reserve_sig"
+ ",purse_sig"
+ " FROM wad_out_entries"
+ " WHERE wad_out_entry_serial_id > $1"
+ " ORDER BY wad_out_entry_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_out_entries;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN:
+ XPREPARE ("select_above_serial_by_table_wads_in",
+ "SELECT"
+ " wad_in_serial_id"
+ ",wad_id"
+ ",origin_exchange_url"
+ ",amount"
+ ",arrival_time"
+ " FROM wads_in"
+ " WHERE wad_in_serial_id > $1"
+ " ORDER BY wad_in_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_in;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
+ XPREPARE ("select_above_serial_by_table_wads_in_entries",
+ "SELECT"
+ " wad_in_entry_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",h_contract"
+ ",purse_expiration"
+ ",merge_timestamp"
+ ",amount_with_fee"
+ ",wad_fee"
+ ",deposit_fees"
+ ",reserve_sig"
+ ",purse_sig"
+ " FROM wad_in_entries"
+ " WHERE wad_in_entry_serial_id > $1"
+ " ORDER BY wad_in_entry_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_in_entries;
+ break;
+ case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
+ XPREPARE ("select_above_serial_by_table_profit_drains",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE profit_drain_serial_id > $1"
+ " ORDER BY profit_drain_serial_id ASC;");
+ rh = &lrbt_cb_table_profit_drains;
+ break;
+
+ case TALER_EXCHANGEDB_RT_AML_STAFF:
+ XPREPARE ("select_above_serial_by_table_aml_staff",
+ "SELECT"
+ " aml_staff_uuid"
+ ",decider_pub"
+ ",master_sig"
+ ",decider_name"
+ ",is_active"
+ ",read_only"
+ ",last_change"
+ " FROM aml_staff"
+ " WHERE aml_staff_uuid > $1"
+ " ORDER BY aml_staff_uuid ASC;");
+ rh = &lrbt_cb_table_aml_staff;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DELETION:
+ XPREPARE ("select_above_serial_by_table_purse_deletion",
+ "SELECT"
+ " purse_deletion_serial_id"
+ ",purse_pub"
+ ",purse_sig"
+ " FROM purse_deletion"
+ " WHERE purse_deletion_serial_id > $1"
+ " ORDER BY purse_deletion_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_deletion;
+ break;
+ case TALER_EXCHANGEDB_RT_WITHDRAW:
+ XPREPARE ("select_above_serial_by_table_withdraw",
+ "SELECT"
+ " withdraw_id"
+ ",planchets_h"
+ ",execution_date"
+ ",amount_with_fee"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",max_age"
+ ",noreveal_index"
+ ",selected_h"
+ ",blinding_seed"
+ ",cs_r_values"
+ ",cs_r_choices"
+ ",denom_serials"
+ ",denom_sigs"
+ " FROM withdraw"
+ " WHERE withdraw_id > $1"
+ " ORDER BY withdraw_id ASC;");
+ rh = &lrbt_cb_table_withdraw;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES:
+ XPREPARE ("select_above_serial_by_table_legitimization_measures",
+ "SELECT"
+ " legitimization_measure_serial_id AS serial"
+ ",access_token"
+ ",start_time"
+ ",jmeasures::TEXT"
+ ",display_priority"
+ " FROM legitimization_measures"
+ " WHERE legitimization_measure_serial_id > $1"
+ " ORDER BY legitimization_measure_serial_id ASC;");
+ rh = &lrbt_cb_table_legitimization_measures;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES:
+ XPREPARE ("select_above_serial_by_table_legitimization_outcomes",
+ "SELECT"
+ " outcome_serial_id AS serial"
+ ",h_payto"
+ ",decision_time"
+ ",expiration_time"
+ ",jproperties::TEXT"
+ ",to_investigate"
+ ",jnew_rules::TEXT"
+ " FROM legitimization_outcomes"
+ " WHERE outcome_serial_id > $1"
+ " ORDER BY outcome_serial_id ASC;");
+ rh = &lrbt_cb_table_legitimization_outcomes;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
+ XPREPARE ("select_above_serial_by_table_legitimization_processes",
+ "SELECT"
+ " legitimization_process_serial_id AS serial"
+ ",h_payto"
+ ",start_time"
+ ",expiration_time"
+ ",legitimization_measure_serial_id"
+ ",measure_index"
+ ",provider_name"
+ ",provider_user_id"
+ ",provider_legitimization_id"
+ ",redirect_url"
+ " FROM legitimization_processes"
+ " WHERE legitimization_process_serial_id > $1"
+ " ORDER BY legitimization_process_serial_id ASC;");
+ rh = &lrbt_cb_table_legitimization_processes;
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
+ XPREPARE ("select_above_serial_by_table_kyc_attributes",
+ "SELECT"
+ " kyc_attributes_serial_id"
+ ",h_payto"
+ ",legitimization_serial"
+ ",collection_time"
+ ",expiration_time"
+ ",trigger_outcome_serial"
+ ",encrypted_attributes"
+ " FROM kyc_attributes"
+ " WHERE kyc_attributes_serial_id > $1"
+ " ORDER BY kyc_attributes_serial_id ASC;");
+ rh = &lrbt_cb_table_kyc_attributes;
+ break;
+ case TALER_EXCHANGEDB_RT_AML_HISTORY:
+ XPREPARE ("select_above_serial_by_table_aml_history",
+ "SELECT"
+ " aml_history_serial_id"
+ ",h_payto"
+ ",outcome_serial_id"
+ ",justification"
+ ",decider_pub"
+ ",decider_sig"
+ " FROM aml_history"
+ " WHERE aml_history_serial_id > $1"
+ " ORDER BY aml_history_serial_id ASC;");
+ rh = &lrbt_cb_table_aml_history;
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_EVENTS:
+ XPREPARE ("select_above_serial_by_table_kyc_events",
+ "SELECT"
+ " kyc_event_serial_id AS serial"
+ ",event_timestamp"
+ ",event_type"
+ " FROM kyc_events"
+ " WHERE kyc_event_serial_id > $1"
+ " ORDER BY kyc_event_serial_id ASC;");
+ rh = &lrbt_cb_table_kyc_events;
+ break;
+ }
+ if (NULL == rh)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ statement,
+ params,
+ rh,
+ &ctx);
+ if (qs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `%s'\n",
+ statement);
+ return qs;
+ }
+ if (ctx.error)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+}
+
+
+#undef XPREPARE
+
+/* end of lookup_records_by_table.c */
diff --git a/src/exchangedb/iterate_recoup_refreshes_above_serial_id.c b/src/exchangedb/iterate_recoup_refreshes_above_serial_id.c
@@ -0,0 +1,204 @@
+/*
+ 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 exchangedb/iterate_recoup_refreshes_above_serial_id.c
+ * @brief Implementation of the iterate_recoup_refreshes_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_recoup_refreshes_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #recoup_refresh_serial_helper_cb().
+ */
+struct RecoupRefreshSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RecoupRefreshCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RecoupRefreshSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+recoup_refresh_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RecoupRefreshSerialContext *psc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = psc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_CoinSpendPublicKeyP old_coin_pub;
+ struct TALER_CoinPublicInfo coin;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_DenominationHashP old_denom_pub_hash;
+ struct TALER_Amount amount;
+ struct TALER_BlindedCoinHashP h_blind_ev;
+ struct GNUNET_TIME_Timestamp timestamp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ ×tamp),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ &old_coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_denom_pub_hash",
+ &old_denom_pub_hash),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &coin_blind),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
+ &h_blind_ev),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &coin.denom_pub_hash),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &coin.h_age_commitment),
+ &coin.no_age_commitment),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &coin.denom_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ psc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = psc->cb (psc->cb_cls,
+ rowid,
+ timestamp,
+ &amount,
+ &old_coin_pub,
+ &old_denom_pub_hash,
+ &coin,
+ &denom_pub,
+ &coin_sig,
+ &coin_blind);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_recoup_refreshes_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupRefreshCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RecoupRefreshSerialContext psc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_recoup_refreshes_above_serial_id",
+ "SELECT"
+ " rr.recoup_refresh_uuid"
+ ",rr.recoup_timestamp"
+ ",rr.coin_sig"
+ ",rr.coin_blind"
+ ",rr.amount"
+ ",rrc.h_coin_ev AS h_blind_ev" // FIXME:-#9828 r.rc? r.selected_h? Old logic wanted a TALER_BlindedCoinHash, which we now need to derive (from rr.coin_blind)
+ ",new_coins.age_commitment_hash"
+ ",new_coins.coin_pub AS coin_pub"
+ ",new_denoms.denom_pub AS denom_pub"
+ ",new_denoms.denom_pub_hash"
+ ",new_coins.denom_sig AS denom_sig"
+ ",old_coins.coin_pub AS old_coin_pub"
+ ",old_denoms.denom_pub_hash AS old_denom_pub_hash"
+ " FROM recoup_refresh rr"
+ " INNER JOIN refresh_revealed_coins rrc" // FIXME-#9828: no such table anymore!
+ // but we have 'refresh_id" which is an FK into 'refresh'!
+ " USING (rrc_serial)"
+ " INNER JOIN refresh r"
+ // but we have 'refresh_id" which is an FK into 'refresh'!
+ " USING (refresh_id)"
+ " INNER JOIN known_coins old_coins"
+ " ON (r.old_coin_pub = old_coins.coin_pub)"
+ " INNER JOIN known_coins new_coins"
+ " ON (rr.coin_pub = new_coins.coin_pub)"
+ " INNER JOIN refresh_commitments rfc"
+ " ON (rrc.melt_serial_id = rfc.melt_serial_id)"
+ " INNER JOIN denominations new_denoms"
+ " ON (new_coins.denominations_serial = new_denoms.denominations_serial)"
+ " INNER JOIN denominations old_denoms"
+ " ON (old_coins.denominations_serial = old_denoms.denominations_serial)"
+ " WHERE recoup_refresh_uuid>=$1"
+ " ORDER BY recoup_refresh_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_recoup_refreshes_above_serial_id",
+ params,
+ &recoup_refresh_serial_helper_cb,
+ &psc);
+ if (GNUNET_OK != psc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_recoups_above_serial_id.c b/src/exchangedb/iterate_recoups_above_serial_id.c
@@ -0,0 +1,186 @@
+/*
+ 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 exchangedb/iterate_recoups_above_serial_id.c
+ * @brief Implementation of the iterate_recoups_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_recoups_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #recoup_serial_helper_cb().
+ */
+struct RecoupSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RecoupCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RecoupSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+recoup_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RecoupSerialContext *psc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = psc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_CoinPublicInfo coin;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
+ struct TALER_Amount amount;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct GNUNET_TIME_Timestamp timestamp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ ×tamp),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin.coin_pub),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &coin_blind),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &coin.denom_pub_hash),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &coin.h_age_commitment),
+ &coin.no_age_commitment),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &coin.denom_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ int ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ psc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = psc->cb (psc->cb_cls,
+ rowid,
+ timestamp,
+ &amount,
+ &reserve_pub,
+ &coin,
+ &denom_pub,
+ &coin_sig,
+ &coin_blind);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_recoups_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RecoupSerialContext psc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* FIXME-9828: this query joins with table/columns
+ that no longer exist... */
+ PREPARE (pg,
+ "iterate_recoups_above_serial_id",
+ "SELECT"
+ " recoup_uuid"
+ ",recoup_timestamp"
+ ",withdraw.reserve_pub"
+ ",coins.coin_pub"
+ ",coin_sig"
+ ",coin_blind"
+ ",denoms.denom_pub_hash"
+ ",coins.denom_sig"
+ ",coins.age_commitment_hash"
+ ",denoms.denom_pub"
+ ",amount"
+ " FROM recoup"
+ " JOIN known_coins coins"
+ " USING (coin_pub)"
+ " JOIN withdraw"
+ " USING (withdraw_id)"
+ " JOIN denominations denoms"
+ " ON (coins.denominations_serial = denoms.denominations_serial)"
+ " WHERE recoup_uuid>=$1"
+ " ORDER BY recoup_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_recoups_above_serial_id",
+ params,
+ &recoup_serial_helper_cb,
+ &psc);
+ if (GNUNET_OK != psc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_refreshes_above_serial_id.c b/src/exchangedb/iterate_refreshes_above_serial_id.c
@@ -0,0 +1,180 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 exchangedb/iterate_refreshes_above_serial_id.c
+ * @brief Implementation of the iterate_refreshes_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_refreshes_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #refreshs_serial_helper_cb().
+ */
+struct RefreshsSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RefreshesCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RefreshsSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+refreshs_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RefreshsSerialContext *rsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = rsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_DenominationPublicKey old_denom_pub;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct TALER_AgeCommitmentHashP h_age_commitment;
+ bool ac_isnull;
+ struct TALER_Amount amount_with_fee;
+ uint64_t rowid;
+ struct TALER_RefreshCommitmentP rc;
+ size_t num_nds;
+ uint64_t *nds;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_denom_pub ("old_denom_pub",
+ &old_denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &h_age_commitment),
+ &ac_isnull),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
+ &coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_uint64 ("refresh_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("rc",
+ &rc),
+ GNUNET_PQ_result_spec_array_uint64 (pg->conn,
+ "new_denominations_serials",
+ &num_nds,
+ &nds),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rsc->status = GNUNET_SYSERR;
+ return;
+ }
+
+ ret = rsc->cb (rsc->cb_cls,
+ rowid,
+ &old_denom_pub,
+ &coin_pub,
+ &coin_sig,
+ ac_isnull ? NULL : &h_age_commitment,
+ &amount_with_fee,
+ num_nds,
+ nds,
+ &rc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_refreshes_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefreshesCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RefreshsSerialContext rsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_refreshes_above_serial_id",
+ "SELECT"
+ " denom.denom_pub AS old_denom_pub"
+ ",r.old_coin_pub"
+ ",kc.age_commitment_hash"
+ ",r.old_coin_sig"
+ ",r.amount_with_fee"
+ ",r.refresh_id"
+ ",r.rc"
+ ",r.denom_serials AS new_denominations_serials"
+ " FROM refresh r"
+ " JOIN known_coins kc"
+ " ON (r.old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denom"
+ " ON (kc.denominations_serial = denom.denominations_serial)"
+ " WHERE refresh_id>=$1"
+ " ORDER BY refresh_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_refreshes_above_serial_id",
+ params,
+ &refreshs_serial_helper_cb,
+ &rsc);
+ if (GNUNET_OK != rsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_refunds_above_serial_id.c b/src/exchangedb/iterate_refunds_above_serial_id.c
@@ -0,0 +1,221 @@
+/*
+ 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 exchangedb/iterate_refunds_above_serial_id.c
+ * @brief Implementation of the iterate_refunds_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_refunds_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #refunds_serial_helper_cb().
+ */
+struct RefundsSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RefundCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RefundsSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+refunds_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RefundsSerialContext *rsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = rsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_Refund refund;
+ struct TALER_DenominationPublicKey denom_pub;
+ uint64_t rowid;
+ bool full_refund;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &refund.details.merchant_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
+ &refund.details.merchant_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &refund.details.h_contract_terms),
+ GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+ &refund.details.rtransaction_id),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &refund.coin.coin_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &refund.details.refund_amount),
+ GNUNET_PQ_result_spec_uint64 ("refund_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rsc->status = GNUNET_SYSERR;
+ return;
+ }
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_Amount amount_with_fee;
+ uint64_t s_f;
+ uint64_t s_v;
+ struct GNUNET_PQ_ResultSpec rs2[] = {
+ GNUNET_PQ_result_spec_uint64 ("s_v",
+ &s_v),
+ GNUNET_PQ_result_spec_uint64 ("s_f",
+ &s_f),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "iterate_refunds_above_serial_id_refund_full",
+ params,
+ rs2);
+ if (qs <= 0)
+ {
+ GNUNET_break (0);
+ rsc->status = GNUNET_SYSERR;
+ return;
+ }
+ /* normalize */
+ s_v += s_f / TALER_AMOUNT_FRAC_BASE;
+ s_f %= TALER_AMOUNT_FRAC_BASE;
+ full_refund = (s_v > amount_with_fee.value) ||
+ ( (s_v == amount_with_fee.value) &&
+ (s_f >= amount_with_fee.fraction) );
+ }
+ ret = rsc->cb (rsc->cb_cls,
+ rowid,
+ &denom_pub,
+ &refund.coin.coin_pub,
+ &refund.details.merchant_pub,
+ &refund.details.merchant_sig,
+ &refund.details.h_contract_terms,
+ refund.details.rtransaction_id,
+ full_refund,
+ &refund.details.refund_amount);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_refunds_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefundCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RefundsSerialContext rsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch refunds with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "iterate_refunds_above_serial_id_incr",
+ "SELECT"
+ " bdep.merchant_pub"
+ ",ref.merchant_sig"
+ ",bdep.h_contract_terms"
+ ",ref.rtransaction_id"
+ ",denom.denom_pub"
+ ",kc.coin_pub"
+ ",ref.amount_with_fee"
+ ",ref.refund_serial_id"
+ " FROM refunds ref"
+ " JOIN batch_deposits bdep"
+ " ON (ref.batch_deposit_serial_id=bdep.batch_deposit_serial_id)"
+ " JOIN coin_deposits cdep"
+ " ON (ref.coin_pub=cdep.coin_pub AND ref.batch_deposit_serial_id=cdep.batch_deposit_serial_id)"
+ " JOIN known_coins kc"
+ " ON (cdep.coin_pub=kc.coin_pub)"
+ " JOIN denominations denom"
+ " ON (kc.denominations_serial=denom.denominations_serial)"
+ " WHERE ref.refund_serial_id>=$1"
+ " ORDER BY ref.refund_serial_id ASC;");
+ PREPARE (pg,
+ "iterate_refunds_above_serial_id_refund_full",
+ "SELECT"
+ " CAST(SUM(CAST((ref.amount_with_fee).frac AS INT8)) AS INT8) AS s_f"
+ ",CAST(SUM((ref.amount_with_fee).val) AS INT8) AS s_v"
+ ",cdep.amount_with_fee"
+ " FROM refunds ref"
+ " JOIN coin_deposits cdep"
+ " ON (ref.coin_pub=cdep.coin_pub AND ref.batch_deposit_serial_id=cdep.batch_deposit_serial_id)"
+ " WHERE ref.refund_serial_id=$1"
+ " GROUP BY (cdep.amount_with_fee);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_refunds_above_serial_id_incr",
+ params,
+ &refunds_serial_helper_cb,
+ &rsc);
+ if (GNUNET_OK != rsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_refunds_by_coin.c b/src/exchangedb/iterate_refunds_by_coin.c
@@ -0,0 +1,139 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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 exchangedb/iterate_refunds_by_coin.c
+ * @brief Implementation of the iterate_refunds_by_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_refunds_by_coin.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_refunds_cb().
+ */
+struct SelectRefundContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_RefundCoinCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct SelectRefundContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+get_refunds_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SelectRefundContext *srctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = srctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount amount_with_fee;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ srctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (GNUNET_OK !=
+ srctx->cb (srctx->cb_cls,
+ &amount_with_fee))
+ return;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_refunds_by_coin (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract,
+ TALER_EXCHANGEDB_RefundCoinCallback cb,
+ void *cb_cls)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract),
+ GNUNET_PQ_query_param_end
+ };
+ struct SelectRefundContext srctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ const char *query = "get_refunds_by_coin_and_contract";
+
+ PREPARE (pg,
+ query,
+ "SELECT"
+ " ref.amount_with_fee"
+ " FROM refunds ref"
+ " JOIN coin_deposits cdep"
+ " USING (coin_pub,batch_deposit_serial_id)"
+ " JOIN batch_deposits bdep"
+ " ON (ref.batch_deposit_serial_id = bdep.batch_deposit_serial_id)"
+ " WHERE ref.coin_pub=$1"
+ " AND bdep.merchant_pub=$2"
+ " AND bdep.h_contract_terms=$3;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ query,
+ params,
+ &get_refunds_cb,
+ &srctx);
+ if (GNUNET_SYSERR == srctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_reserve_closed_above_serial_id.c b/src/exchangedb/iterate_reserve_closed_above_serial_id.c
@@ -0,0 +1,172 @@
+/*
+ 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 iterate_reserve_closed_above_serial_id.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_reserve_closed_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #reserve_closed_serial_helper_cb().
+ */
+struct ReserveClosedSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveClosedCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin's context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveClosedSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_closed_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveClosedSerialContext *rcsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = rcsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_FullPayto receiver_account;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount closing_fee;
+ struct GNUNET_TIME_Timestamp execution_date;
+ uint64_t close_request_row;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("close_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("receiver_account",
+ &receiver_account.full_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &closing_fee),
+ GNUNET_PQ_result_spec_uint64 ("close_request_row",
+ &close_request_row),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rcsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = rcsc->cb (rcsc->cb_cls,
+ rowid,
+ execution_date,
+ &amount_with_fee,
+ &closing_fee,
+ &reserve_pub,
+ receiver_account,
+ &wtid,
+ close_request_row);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserve_closed_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveClosedCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveClosedSerialContext rcsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (
+ pg,
+ "iterate_reserve_closed_above_serial_id",
+ "SELECT"
+ " close_uuid"
+ ",reserves.reserve_pub"
+ ",execution_date"
+ ",wtid"
+ ",wt.payto_uri AS receiver_account"
+ ",amount"
+ ",closing_fee"
+ ",close_request_row"
+ " FROM reserves_close"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN reserves"
+ " USING (reserve_pub)"
+ " WHERE close_uuid>=$1"
+ " ORDER BY close_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_reserve_closed_above_serial_id",
+ params,
+ &reserve_closed_serial_helper_cb,
+ &rcsc);
+ if (GNUNET_OK != rcsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_reserve_open_above_serial_id.c b/src/exchangedb/iterate_reserve_open_above_serial_id.c
@@ -0,0 +1,163 @@
+/*
+ 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 iterate_reserve_open_above_serial_id.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_reserve_open_above_serial_id.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #reserve_open_serial_helper_cb().
+ */
+struct ReserveOpenSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveOpenCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin's context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveOpenSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_open_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveOpenSerialContext *rcsc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = rcsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ uint32_t requested_purse_limit;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct GNUNET_TIME_Timestamp reserve_expiration;
+ struct TALER_Amount reserve_payment;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("open_request_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &reserve_sig),
+ GNUNET_PQ_result_spec_timestamp ("request_timestamp",
+ &request_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &reserve_expiration),
+ GNUNET_PQ_result_spec_uint32 ("requested_purse_limit",
+ &requested_purse_limit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_payment",
+ &reserve_payment),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rcsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = rcsc->cb (rcsc->cb_cls,
+ rowid,
+ &reserve_payment,
+ request_timestamp,
+ reserve_expiration,
+ requested_purse_limit,
+ &reserve_pub,
+ &reserve_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserve_open_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveOpenCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveOpenSerialContext rcsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (
+ pg,
+ "iterate_reserve_open_above_serial_id",
+ "SELECT"
+ " open_request_uuid"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",expiration_date"
+ ",reserve_sig"
+ ",reserve_payment"
+ ",requested_purse_limit"
+ " FROM reserves_open_requests"
+ " WHERE open_request_uuid>=$1"
+ " ORDER BY open_request_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_reserve_open_above_serial_id",
+ params,
+ &reserve_open_serial_helper_cb,
+ &rcsc);
+ if (GNUNET_OK != rcsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_reserves_in_above_serial_id.c b/src/exchangedb/iterate_reserves_in_above_serial_id.c
@@ -0,0 +1,163 @@
+/*
+ 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 exchangedb/iterate_reserves_in_above_serial_id.c
+ * @brief Implementation of the iterate_reserves_in_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_reserves_in_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #reserves_in_serial_helper_cb().
+ */
+struct ReservesInSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveInCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReservesInSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserves_in_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReservesInSerialContext *risc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = risc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount credit;
+ struct TALER_FullPayto sender_account_details;
+ struct GNUNET_TIME_Timestamp execution_date;
+ uint64_t rowid;
+ uint64_t wire_reference;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("wire_reference",
+ &wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
+ &credit),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &sender_account_details.full_payto),
+ GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ risc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = risc->cb (risc->cb_cls,
+ rowid,
+ &reserve_pub,
+ &credit,
+ sender_account_details,
+ wire_reference,
+ execution_date);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserves_in_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReservesInSerialContext risc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserves_in_above_serial_id",
+ "SELECT"
+ " reserves.reserve_pub"
+ ",wire_reference"
+ ",credit"
+ ",execution_date"
+ ",wt.payto_uri AS sender_account_details"
+ ",reserve_in_serial_id"
+ " FROM reserves_in"
+ " JOIN reserves"
+ " USING (reserve_pub)"
+ " JOIN wire_targets wt"
+ " ON (wire_source_h_payto = wire_target_h_payto)"
+ " WHERE reserve_in_serial_id>=$1"
+ " ORDER BY reserve_in_serial_id;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_reserves_in_above_serial_id",
+ params,
+ &reserves_in_serial_helper_cb,
+ &risc);
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ if (GNUNET_OK != risc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_reserves_in_above_serial_id_by_account.c b/src/exchangedb/iterate_reserves_in_above_serial_id_by_account.c
@@ -0,0 +1,166 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_reserves_in_above_serial_id_by_account.c
+ * @brief Implementation of the iterate_reserves_in_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include \
+ "exchange-database/iterate_reserves_in_above_serial_id_by_account.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #reserves_in_serial_helper_cb().
+ */
+struct ReservesInSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveInCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReservesInSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserves_in_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReservesInSerialContext *risc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = risc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount credit;
+ struct TALER_FullPayto sender_account_details;
+ struct GNUNET_TIME_Timestamp execution_date;
+ uint64_t rowid;
+ uint64_t wire_reference;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("wire_reference",
+ &wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
+ &credit),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &sender_account_details.full_payto),
+ GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ risc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = risc->cb (risc->cb_cls,
+ rowid,
+ &reserve_pub,
+ &credit,
+ sender_account_details,
+ wire_reference,
+ execution_date);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserves_in_above_serial_id_by_account (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *account_name,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_string (account_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReservesInSerialContext risc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_reserves_in_above_serial_id_by_account",
+ "SELECT"
+ " reserves.reserve_pub"
+ ",wire_reference"
+ ",credit"
+ ",execution_date"
+ ",wt.payto_uri AS sender_account_details"
+ ",reserve_in_serial_id"
+ " FROM reserves_in"
+ " JOIN reserves "
+ " USING (reserve_pub)"
+ " JOIN wire_targets wt"
+ " ON (wire_source_h_payto = wire_target_h_payto)"
+ " WHERE reserve_in_serial_id>=$1"
+ " AND exchange_account_section=$2"
+ " ORDER BY reserve_in_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_reserves_in_above_serial_id_by_account",
+ params,
+ &reserves_in_serial_helper_cb,
+ &risc);
+ if (GNUNET_OK != risc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_unfinished_close_requests.c b/src/exchangedb/iterate_unfinished_close_requests.c
@@ -0,0 +1,162 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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 iterate_unfinished_close_requests.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_unfinished_close_requests.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #reserve_close_cb().
+ */
+struct CloseReserveContext
+{
+ /**
+ * Function to call for each to be closed reserve.
+ */
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec;
+
+ /**
+ * Closure to give to @e rec.
+ */
+ void *rec_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CloseReserveContext *erc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = erc->pg;
+ enum GNUNET_GenericReturnValue ret = GNUNET_OK;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp exp_date;
+ struct TALER_FullPayto account_details;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount remaining_balance;
+ uint64_t close_request_row;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &exp_date),
+ GNUNET_PQ_result_spec_string ("account_details",
+ &account_details.full_payto),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("close",
+ &remaining_balance),
+ GNUNET_PQ_result_spec_uint64 ("close_request_serial_id",
+ &close_request_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ ret = erc->rec (erc->rec_cls,
+ &reserve_pub,
+ &remaining_balance,
+ account_details,
+ exp_date,
+ close_request_row);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+ erc->status = ret;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_unfinished_close_requests (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct CloseReserveContext ectx = {
+ .rec = rec,
+ .rec_cls = rec_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_unfinished_close_requests",
+ "UPDATE close_requests AS rc"
+ " SET done=TRUE"
+ " WHERE NOT done"
+ " RETURNING"
+ " reserve_pub"
+ " ,close_request_serial_id"
+ " ,close_timestamp AS expiration_date"
+ " ,close"
+ " ,(SELECT payto_uri"
+ " FROM reserves_in ri"
+ " JOIN wire_targets wt"
+ " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE ri.reserve_pub=rc.reserve_pub)"
+ " AS account_details;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_unfinished_close_requests",
+ params,
+ &reserve_cb,
+ &ectx);
+ switch (ectx.status)
+ {
+ case GNUNET_SYSERR:
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_NO:
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ case GNUNET_OK:
+ break;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/iterate_wallet_merges.c b/src/exchangedb/iterate_wallet_merges.c
@@ -0,0 +1,196 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2026 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_wallet_merges.c
+ * @brief Implementation of the select_wallet_merges function
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_wallet_merges.h"
+#include "helper.h"
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct SelectTransferContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlTransferCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_wallet_merges().
+ *
+ * @param cls closure of type `struct SelectTransferContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_transfer_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SelectTransferContext *stc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ char *payto_uri;
+ uint64_t rowid;
+ struct GNUNET_TIME_Absolute execution_time;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_absolute_time ("execution_time",
+ &execution_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ stc->status = GNUNET_SYSERR;
+ return;
+ }
+ stc->cb (stc->cb_cls,
+ rowid,
+ payto_uri,
+ execution_time,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wallet_merges (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ void *cb_cls)
+{
+ struct SelectTransferContext stc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ uint64_t ulimit = (limit > 0) ? limit : -limit;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&ulimit),
+ TALER_PQ_query_param_amount (pg->conn,
+ threshold),
+ NULL != h_payto
+ ? GNUNET_PQ_query_param_auto_from_type (h_payto)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wallet_merges_inc",
+ "SELECT"
+ " pd.purse_decision_serial_id AS serial_id"
+ ",wt.payto_uri"
+ ",pd.action_timestamp AS execution_time"
+ ",pr.amount_with_fee AS amount"
+ " FROM purse_decision pd"
+ " JOIN purse_requests pr"
+ " ON (pr.purse_pub = pd.purse_pub)"
+ " JOIN purse_merges pm"
+ " ON (pm.purse_pub = pd.purse_pub)"
+ " JOIN kyc_targets kt"
+ " ON (kt.target_pub = pm.reserve_pub)"
+ " JOIN wire_targets wt"
+ " ON (wt.h_normalized_payto = kt.h_normalized_payto)"
+ " WHERE kt.is_wallet"
+ " AND NOT pd.refunded"
+ " AND (pd.purse_decision_serial_id > $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (pr.amount_with_fee).val > ($3::taler_amount).val)"
+ " OR ( ( (pr.amount_with_fee).val >= ($3::taler_amount).val)"
+ " AND ( (pr.amount_with_fee).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY pd.purse_decision_serial_id ASC"
+ " LIMIT $2");
+ PREPARE (pg,
+ "iterate_wallet_merges_dec",
+ "SELECT"
+ " pd.purse_decision_serial_id AS serial_id"
+ ",wt.payto_uri"
+ ",pd.action_timestamp AS execution_time"
+ ",pr.amount_with_fee AS amount"
+ " FROM purse_decision pd"
+ " JOIN purse_requests pr"
+ " ON (pr.purse_pub = pd.purse_pub)"
+ " JOIN purse_merges pm"
+ " ON (pm.purse_pub = pd.purse_pub)"
+ " JOIN kyc_targets kt"
+ " ON (kt.target_pub = pm.reserve_pub)"
+ " JOIN wire_targets wt"
+ " ON (wt.h_normalized_payto = kt.h_normalized_payto)"
+ " WHERE kt.is_wallet"
+ " AND NOT pd.refunded"
+ " AND (pd.purse_decision_serial_id < $1)"
+ " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
+ " AND ( ( (pr.amount_with_fee).val > ($3::taler_amount).val)"
+ " OR ( ( (pr.amount_with_fee).val >= ($3::taler_amount).val)"
+ " AND ( (pr.amount_with_fee).frac >= ($3::taler_amount).frac) ) )"
+ " ORDER BY pd.purse_decision_serial_id DESC"
+ " LIMIT $2");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "iterate_wallet_merges_inc"
+ : "iterate_wallet_merges_dec",
+ params,
+ &handle_transfer_result,
+ &stc);
+ if (GNUNET_OK != stc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_wire_accounts.c b/src/exchangedb/iterate_wire_accounts.c
@@ -0,0 +1,181 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_wire_accounts.c
+ * @brief Implementation of the iterate_wire_accounts function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_wire_accounts.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_wire_accounts_cb().
+ */
+struct GetWireAccountsContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_WireAccountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_wire_accounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetWireAccountsContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_FullPayto payto_uri;
+ char *conversion_url = NULL;
+ char *open_banking_gateway = NULL;
+ char *prepared_transfer_url = NULL;
+ json_t *debit_restrictions = NULL;
+ json_t *credit_restrictions = NULL;
+ struct TALER_MasterSignatureP master_sig;
+ char *bank_label = NULL;
+ int64_t priority;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri.full_payto),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("conversion_url",
+ &conversion_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("open_banking_gateway",
+ &open_banking_gateway),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ /* FIXME: rename in database migration */
+ GNUNET_PQ_result_spec_string ("wire_transfer_gateway",
+ &prepared_transfer_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("bank_label",
+ &bank_label),
+ NULL),
+ GNUNET_PQ_result_spec_int64 ("priority",
+ &priority),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("debit_restrictions",
+ &debit_restrictions),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("credit_restrictions",
+ &credit_restrictions),
+ NULL),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (NULL == debit_restrictions)
+ {
+ debit_restrictions = json_array ();
+ GNUNET_assert (NULL != debit_restrictions);
+ }
+ if (NULL == credit_restrictions)
+ {
+ credit_restrictions = json_array ();
+ GNUNET_assert (NULL != credit_restrictions);
+ }
+ ctx->cb (ctx->cb_cls,
+ payto_uri,
+ conversion_url,
+ open_banking_gateway,
+ prepared_transfer_url,
+ debit_restrictions,
+ credit_restrictions,
+ &master_sig,
+ bank_label,
+ priority);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_accounts (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ TALER_EXCHANGEDB_WireAccountCallback cb,
+ void *cb_cls)
+{
+ struct GetWireAccountsContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_accounts",
+ "SELECT"
+ " payto_uri"
+ ",conversion_url"
+ ",open_banking_gateway"
+ ",wire_transfer_gateway"
+ ",debit_restrictions::TEXT"
+ ",credit_restrictions::TEXT"
+ ",master_sig"
+ ",bank_label"
+ ",priority"
+ " FROM wire_accounts"
+ " WHERE is_active");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_wire_accounts",
+ params,
+ &get_wire_accounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_wire_fees.c b/src/exchangedb/iterate_wire_fees.c
@@ -0,0 +1,144 @@
+/*
+ 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 exchangedb/iterate_wire_fees.c
+ * @brief Implementation of the iterate_wire_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_wire_fees.h"
+#include "helper.h"
+
+/**
+ * Closure for #get_wire_fees_cb().
+ */
+struct GetWireFeesContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_WireFeeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 GetWireFeesContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_wire_fees_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetWireFeesContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_MasterSignatureP master_sig;
+ struct TALER_WireFeeSet fees;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &fees.wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &fees.closing),
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &end_date),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ 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,
+ &fees,
+ start_date,
+ end_date,
+ &master_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_fees (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const char *wire_method,
+ TALER_EXCHANGEDB_WireFeeCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (wire_method),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetWireFeesContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_fees",
+ "SELECT"
+ " wire_fee"
+ ",closing_fee"
+ ",start_date"
+ ",end_date"
+ ",master_sig"
+ " FROM wire_fee"
+ " WHERE wire_method=$1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_wire_fees",
+ params,
+ &get_wire_fees_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_wire_outs_above_serial_id.c b/src/exchangedb/iterate_wire_outs_above_serial_id.c
@@ -0,0 +1,154 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_wire_outs_above_serial_id.c
+ * @brief Implementation of the iterate_wire_outs_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_wire_outs_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #wire_out_serial_helper_cb().
+ */
+struct WireOutSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_WireTransferOutCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ int status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireOutSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_out_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireOutSerialContext *wosc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = wosc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp date;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_FullPayto payto_uri;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &date),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri.full_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ int ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ wosc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = wosc->cb (wosc->cb_cls,
+ rowid,
+ date,
+ &wtid,
+ payto_uri,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_outs_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireOutSerialContext wosc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_outs_above_serial_id",
+ "SELECT"
+ " wo.wireout_uuid"
+ ",wo.execution_date"
+ ",wo.wtid_raw"
+ ",wt.payto_uri"
+ ",wo.amount"
+ " FROM wire_out wo"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " WHERE wireout_uuid>=$1"
+ " ORDER BY wireout_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_wire_outs_above_serial_id",
+ params,
+ &wire_out_serial_helper_cb,
+ &wosc);
+ if (GNUNET_OK != wosc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_wire_outs_above_serial_id_by_account.c b/src/exchangedb/iterate_wire_outs_above_serial_id_by_account.c
@@ -0,0 +1,157 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_wire_outs_above_serial_id_by_account.c
+ * @brief Implementation of the iterate_wire_outs_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_wire_outs_above_serial_id_by_account.h"
+#include "helper.h"
+
+/**
+ * Closure for #wire_out_serial_helper_cb().
+ */
+struct WireOutSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_WireTransferOutCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ int status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireOutSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_out_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireOutSerialContext *wosc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = wosc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp date;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_FullPayto payto_uri;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &date),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri.full_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ int ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ wosc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = wosc->cb (wosc->cb_cls,
+ rowid,
+ date,
+ &wtid,
+ payto_uri,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_outs_above_serial_id_by_account (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *account_name,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_string (account_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireOutSerialContext wosc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_outs_above_serial_id_by_account",
+ "SELECT"
+ " wo.wireout_uuid"
+ ",wo.execution_date"
+ ",wo.wtid_raw"
+ ",wt.payto_uri"
+ ",wo.amount"
+ " FROM wire_out wo"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " WHERE wo.wireout_uuid>=$1 "
+ " AND wo.exchange_account_section=$2"
+ " ORDER BY wo.wireout_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_wire_outs_above_serial_id_by_account",
+ params,
+ &wire_out_serial_helper_cb,
+ &wosc);
+ if (GNUNET_OK != wosc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_wire_transfers.c b/src/exchangedb/iterate_wire_transfers.c
@@ -0,0 +1,184 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_wire_transfers.c
+ * @brief Implementation of the iterate_wire_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_wire_transfers.h"
+#include "helper.h"
+
+/**
+ * Closure for #handle_wt_result.
+ */
+struct WireTransferResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AggregationDataCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TALER_EXCHANGEDB_iterate_wire_transfers().
+ *
+ * @param cls closure of type `struct WireTransferResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_wt_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireTransferResultContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_FullPaytoHashP h_payto;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Timestamp exec_time;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount deposit_fee;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_FullPayto payto_uri;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &h_contract_terms),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri.full_payto),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
+ &h_payto),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &merchant_pub),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &exec_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &deposit_fee),
+ 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,
+ rowid,
+ &merchant_pub,
+ payto_uri,
+ &h_payto,
+ exec_time,
+ &h_contract_terms,
+ &denom_pub,
+ &coin_pub,
+ &amount_with_fee,
+ &deposit_fee);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_transfers (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ TALER_EXCHANGEDB_AggregationDataCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireTransferResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_wire_transfers",
+ "SELECT"
+ " aggregation_serial_id"
+ ",bdep.h_contract_terms"
+ ",payto_uri"
+ ",wt.wire_target_h_payto"
+ ",kc.coin_pub"
+ ",bdep.merchant_pub"
+ ",wire_out.execution_date"
+ ",cdep.amount_with_fee"
+ ",denom.fee_deposit"
+ ",denom.denom_pub"
+ " FROM aggregation_tracking"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN coin_deposits cdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " JOIN wire_out"
+ " USING (wtid_raw)"
+ " WHERE wtid_raw=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_wire_transfers",
+ params,
+ &handle_wt_result,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_withdraw_amounts_for_kyc_check.c b/src/exchangedb/iterate_withdraw_amounts_for_kyc_check.c
@@ -0,0 +1,158 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/iterate_withdraw_amounts_for_kyc_check.c
+ * @brief Implementation of the iterate_withdraw_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_withdraw_amounts_for_kyc_check.h"
+#include "exchange-database/iterate_aggregation_amounts_for_kyc_check.h"
+#include "helper.h"
+
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_KYCLOGIC_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * 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 KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_withdraw_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_withdraw_amounts_for_kyc_check",
+ "SELECT"
+ " wd.amount_with_fee AS amount"
+ ",wd.execution_date AS date"
+ " FROM reserves_in ri"
+ " JOIN reserve_history rh"
+ " ON (rh.reserve_pub = ri.reserve_pub)"
+ " JOIN withdraw wd"
+ " ON (wd.withdraw_id = rh.serial_id)"
+ " WHERE ri.wire_source_h_payto IN ("
+ " SELECT wire_target_h_payto"
+ " FROM wire_targets"
+ " WHERE h_normalized_payto=$1"
+ " )"
+ " AND rh.table_name='withdraw'"
+ " AND wd.execution_date >= $2"
+ " ORDER BY rh.reserve_history_serial_id DESC");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_withdraw_amounts_for_kyc_check",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/iterate_withdrawals_above_serial_id.c b/src/exchangedb/iterate_withdrawals_above_serial_id.c
@@ -0,0 +1,216 @@
+/*
+ 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 exchangedb/iterate_withdrawals_above_serial_id.c
+ * @brief Implementation of the iterate_withdrawals_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ * @author Özgür Kesim
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/iterate_withdrawals_above_serial_id.h"
+#include "helper.h"
+
+/**
+ * Closure for #withdraw_serial_helper_cb().
+ */
+struct WithdrawSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_WithdrawCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct TALER_EXCHANGEDB_PostgresContext *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WithdrawSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+withdraw_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WithdrawSerialContext *rosc = cls;
+ struct TALER_EXCHANGEDB_PostgresContext *pg = rosc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_HashBlindedPlanchetsP h_planchets;
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ uint16_t max_age;
+ bool no_max_age;
+ uint16_t noreveal_index;
+ bool no_noreveal_index;
+ struct TALER_HashBlindedPlanchetsP selected_h;
+ bool no_selected_h;
+ struct TALER_BlindingMasterSeedP blinding_seed;
+ bool no_blinding_seed;
+ size_t num_denom_serials;
+ uint64_t *denom_serials = NULL;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("withdraw_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("planchets_h",
+ &h_planchets),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &reserve_sig),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint16 ("max_age",
+ &max_age),
+ &no_max_age),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint16 ("noreveal_index",
+ &noreveal_index),
+ &no_noreveal_index),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "selected_h",
+ &selected_h),
+ &no_selected_h),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "blinding_seed",
+ &blinding_seed),
+ &no_blinding_seed),
+ GNUNET_PQ_result_spec_array_uint64 (
+ pg->conn,
+ "denom_serials",
+ &num_denom_serials,
+ &denom_serials),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rosc->status = GNUNET_SYSERR;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ /* Note: here we just check that the uint8_t
+ limitations are met, other constraints are checked later */
+ if (( (! no_noreveal_index) &&
+ (UINT8_MAX <= noreveal_index)) ||
+ ( (! no_max_age) &&
+ (UINT8_MAX <= max_age)))
+ {
+ GNUNET_break (0);
+ rosc->status = GNUNET_SYSERR;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ ret = rosc->cb (rosc->cb_cls,
+ rowid,
+ num_denom_serials,
+ denom_serials,
+ no_selected_h ? NULL : &selected_h,
+ &h_planchets,
+ no_blinding_seed ? NULL : &blinding_seed,
+ ! no_max_age,
+ (uint8_t) max_age,
+ (uint8_t) noreveal_index,
+ &reserve_pub,
+ &reserve_sig,
+ execution_date,
+ &amount_with_fee);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_withdrawals_above_serial_id (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WithdrawCallback cb,
+ void *cb_cls)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct WithdrawSerialContext rosc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch deposits with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "iterate_withdrawals_above_serial_id",
+ "SELECT"
+ " withdraw_id"
+ ",planchets_h"
+ ",execution_date"
+ ",amount_with_fee"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",max_age"
+ ",noreveal_index"
+ ",selected_h"
+ ",blinding_seed"
+ ",denom_serials"
+ " FROM withdraw"
+ " WHERE withdraw_id>=$1"
+ " ORDER BY withdraw_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_withdrawals_above_serial_id",
+ params,
+ &withdraw_serial_helper_cb,
+ &rosc);
+ if (GNUNET_OK != rosc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/kyc_provider_account_lookup.c b/src/exchangedb/kyc_provider_account_lookup.c
@@ -1,66 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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 exchangedb/kyc_provider_account_lookup.c
- * @brief Implementation of the kyc_provider_account_lookup function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/kyc_provider_account_lookup.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_kyc_provider_account_lookup (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const char *provider_name,
- const char *provider_legitimization_id,
- struct TALER_NormalizedPaytoHashP *h_payto,
- bool *is_wallet,
- uint64_t *process_row)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (provider_legitimization_id),
- GNUNET_PQ_query_param_string (provider_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("h_payto",
- h_payto),
- GNUNET_PQ_result_spec_bool ("is_wallet",
- is_wallet),
- GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
- process_row),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "get_wire_target_by_legitimization_id",
- "SELECT "
- " lp.h_payto"
- ",kt.is_wallet"
- ",lp.legitimization_process_serial_id"
- " FROM legitimization_processes lp"
- " JOIN kyc_targets kt"
- " ON (lp.h_payto = kt.h_normalized_payto)"
- " WHERE provider_legitimization_id=$1"
- " AND provider_name=$2;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "get_wire_target_by_legitimization_id",
- params,
- rs);
-}
diff --git a/src/exchangedb/kycauth_in_insert.c b/src/exchangedb/kycauth_in_insert.c
@@ -1,78 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/kycauth_in_insert.c
- * @brief Implementation of the kycauth_in_insert function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/kycauth_in_insert.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_kycauth_in_insert (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const union TALER_AccountPublicKeyP *account_pub,
- const struct TALER_Amount *credit_amount,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_FullPayto debit_account_uri,
- const char *section_name,
- uint64_t serial_id)
-{
- struct TALER_NormalizedPaytoHashP h_normalized_payto;
- struct TALER_FullPaytoHashP h_full_payto;
-
- TALER_full_payto_hash (debit_account_uri,
- &h_full_payto);
- TALER_full_payto_normalize_and_hash (debit_account_uri,
- &h_normalized_payto);
- {
- struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
- .h_payto = h_normalized_payto
- };
- char *notify_s
- = GNUNET_PQ_get_event_notify_channel (&rep.header);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (account_pub),
- GNUNET_PQ_query_param_uint64 (&serial_id),
- TALER_PQ_query_param_amount (pg->conn,
- credit_amount),
- GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
- GNUNET_PQ_query_param_auto_from_type (&h_normalized_payto),
- GNUNET_PQ_query_param_string (debit_account_uri.full_payto),
- GNUNET_PQ_query_param_string (section_name),
- GNUNET_PQ_query_param_timestamp (&execution_date),
- GNUNET_PQ_query_param_string (notify_s),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "kycauth_in_insert",
- "CALL"
- " exchange_do_kycauth_in_insert"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
- qs = GNUNET_PQ_eval_prepared_non_select (
- pg->conn,
- "kycauth_in_insert",
- params);
- GNUNET_free (notify_s);
- return qs;
- }
-}
diff --git a/src/exchangedb/lookup_active_legitimization.c b/src/exchangedb/lookup_active_legitimization.c
@@ -1,62 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_pending_legitimization.c
- * @brief Implementation of the lookup_pending_legitimization function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_active_legitimization.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_active_legitimization (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t legitimization_process_serial_id,
- uint32_t *measure_index,
- json_t **jmeasures)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&legitimization_process_serial_id),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_json (
- "jmeasures",
- jmeasures),
- GNUNET_PQ_result_spec_uint32 (
- "measure_index",
- measure_index),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_active_legitimization",
- "SELECT "
- " lm.jmeasures::TEXT"
- ",lp.measure_index"
- " FROM legitimization_processes lp"
- " JOIN legitimization_measures lm"
- " USING (legitimization_measure_serial_id)"
- " WHERE lp.legitimization_process_serial_id=$1"
- " AND NOT lm.is_finished;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_active_legitimization",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_aml_file_number.c b/src/exchangedb/lookup_aml_file_number.c
@@ -1,59 +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 exchangedb/lookup_aml_file_number.c
- * @brief Implementation of the lookup_aml_file_number function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_aml_file_number.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_aml_file_number (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- uint64_t *kyc_target_row,
- bool *is_wallet)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "kyc_target_serial_id",
- kyc_target_row),
- GNUNET_PQ_result_spec_bool (
- "is_wallet",
- is_wallet),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_aml_file_number",
- "SELECT "
- " kyc_target_serial_id"
- ",is_wallet"
- " FROM kyc_targets"
- " WHERE h_normalized_payto=$1");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_aml_file_number",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_aml_history.c b/src/exchangedb/lookup_aml_history.c
@@ -1,200 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_aml_history.c
- * @brief Implementation of the lookup_aml_history function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_aml_history.h"
-#include "helper.h"
-
-
-/**
- * Closure for callbacks called from #TALER_EXCHANGEDB_lookup_aml_history()
- */
-struct AmlHistoryContext
-{
-
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlHistoryCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to 'true' if the transaction failed.
- */
- bool failed;
-
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct AmlHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_aml_entry (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AmlHistoryContext *ahc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t outcome_serial_id;
- struct GNUNET_TIME_Timestamp decision_time;
- char *justification;
- struct TALER_AmlOfficerPublicKeyP decider_pub;
- json_t *jproperties = NULL;
- json_t *jnew_rules = NULL;
- bool to_investigate;
- bool is_active;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("outcome_serial_id",
- &outcome_serial_id),
- GNUNET_PQ_result_spec_timestamp ("decision_time",
- &decision_time),
- GNUNET_PQ_result_spec_string ("justification",
- &justification),
- GNUNET_PQ_result_spec_auto_from_type ("decider_pub",
- &decider_pub),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json ("jproperties",
- &jproperties),
- NULL),
- TALER_PQ_result_spec_json ("jnew_rules",
- &jnew_rules),
- GNUNET_PQ_result_spec_bool ("to_investigate",
- &to_investigate),
- GNUNET_PQ_result_spec_bool ("is_active",
- &is_active),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ahc->failed = true;
- return;
- }
- ahc->cb (ahc->cb_cls,
- outcome_serial_id,
- decision_time,
- justification,
- &decider_pub,
- jproperties,
- jnew_rules,
- to_investigate,
- is_active);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_aml_history (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlHistoryCallback cb,
- void *cb_cls)
-{
- struct AmlHistoryContext ahc = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls
- };
- uint64_t ulimit = (limit < 0) ? (-limit) : limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "lookup_aml_history_desc",
- "SELECT"
- " lo.decision_time"
- ",lo.outcome_serial_id"
- ",ah.justification"
- ",ah.decider_pub"
- ",lo.jproperties::TEXT"
- ",lo.jnew_rules::TEXT"
- ",lo.to_investigate"
- ",lo.is_active"
- " FROM aml_history ah"
- " JOIN legitimization_outcomes lo"
- " USING (outcome_serial_id)"
- " WHERE ah.h_payto=$1"
- " AND lo.outcome_serial_id < $2"
- " ORDER BY outcome_serial_id DESC"
- " LIMIT $3;");
- PREPARE (pg,
- "lookup_aml_history_asc",
- "SELECT"
- " lo.decision_time"
- ",lo.outcome_serial_id"
- ",ah.justification"
- ",ah.decider_pub"
- ",lo.jproperties::TEXT"
- ",lo.jnew_rules::TEXT"
- ",lo.to_investigate"
- ",lo.is_active"
- " FROM aml_history ah"
- " JOIN legitimization_outcomes lo"
- " USING (outcome_serial_id)"
- " WHERE ah.h_payto=$1"
- " AND lo.outcome_serial_id > $2"
- " ORDER BY outcome_serial_id ASC"
- " LIMIT $3;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit < 0)
- ? "lookup_aml_history_desc"
- : "lookup_aml_history_asc",
- params,
- &handle_aml_entry,
- &ahc);
- if (qs <= 0)
- return qs;
- if (ahc.failed)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return qs;
-}
diff --git a/src/exchangedb/lookup_aml_officer.c b/src/exchangedb/lookup_aml_officer.c
@@ -1,68 +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 exchangedb/lookup_aml_officer.c
- * @brief Implementation of the lookup_aml_officer function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_aml_officer.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_aml_officer (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AmlOfficerPublicKeyP *decider_pub,
- struct TALER_MasterSignatureP *master_sig,
- char **decider_name,
- bool *is_active,
- bool *read_only,
- struct GNUNET_TIME_Absolute *last_change)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (decider_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_string ("decider_name",
- decider_name),
- GNUNET_PQ_result_spec_bool ("is_active",
- is_active),
- GNUNET_PQ_result_spec_bool ("read_only",
- read_only),
- GNUNET_PQ_result_spec_absolute_time ("last_change",
- last_change),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_aml_officer",
- "SELECT "
- " master_sig"
- ",decider_name"
- ",is_active"
- ",read_only"
- ",last_change"
- " FROM aml_staff"
- " WHERE decider_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_aml_officer",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_auditor_status.c b/src/exchangedb/lookup_auditor_status.c
@@ -1,57 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_auditor_status.c
- * @brief Implementation of the lookup_auditor_status function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_auditor_status.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_auditor_status (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- char **auditor_url,
- bool *enabled)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("auditor_url",
- auditor_url),
- GNUNET_PQ_result_spec_bool ("is_active",
- enabled),
- GNUNET_PQ_result_spec_end
- };
-
- /* Used in #postgres_lookup_auditor_status() */
- PREPARE (pg,
- "lookup_auditor_status",
- "SELECT"
- " auditor_url"
- ",is_active"
- " FROM auditors"
- " WHERE auditor_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_auditor_status",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_auditor_timestamp.c b/src/exchangedb/lookup_auditor_timestamp.c
@@ -1,53 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_auditor_timestamp.c
- * @brief Implementation of the lookup_auditor_timestamp function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_auditor_timestamp.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_auditor_timestamp (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- struct GNUNET_TIME_Timestamp *last_date)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("last_change",
- last_date),
- GNUNET_PQ_result_spec_end
- };
-
- /* Used in #postgres_lookup_auditor_timestamp() */
- PREPARE (pg,
- "lookup_auditor_timestamp",
- "SELECT"
- " last_change"
- " FROM auditors"
- " WHERE auditor_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_auditor_timestamp",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_completed_legitimization.c b/src/exchangedb/lookup_completed_legitimization.c
@@ -1,95 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_completed_legitimization.c
- * @brief Implementation of the lookup_pending_legitimization function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_completed_legitimization.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_completed_legitimization (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t legitimization_measure_serial_id,
- uint32_t measure_index,
- struct TALER_AccountAccessTokenP *access_token,
- struct TALER_NormalizedPaytoHashP *h_payto,
- bool *is_wallet,
- json_t **jmeasures,
- bool *is_finished,
- size_t *encrypted_attributes_len,
- void **encrypted_attributes
- )
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&legitimization_measure_serial_id),
- GNUNET_PQ_query_param_uint32 (&measure_index),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_json (
- "jmeasures",
- jmeasures),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_normalized_payto",
- h_payto),
- GNUNET_PQ_result_spec_auto_from_type (
- "access_token",
- access_token),
- GNUNET_PQ_result_spec_bool (
- "is_finished",
- is_finished),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_variable_size (
- "encrypted_attributes",
- encrypted_attributes,
- encrypted_attributes_len),
- NULL),
- GNUNET_PQ_result_spec_bool (
- "is_wallet",
- is_wallet),
- GNUNET_PQ_result_spec_end
- };
-
- *encrypted_attributes_len = 0;
- *encrypted_attributes = NULL;
- PREPARE (pg,
- "lookup_completed_legitimization",
- "SELECT "
- " lm.jmeasures::TEXT"
- ",kt.h_normalized_payto"
- ",kt.is_wallet"
- ",lm.access_token"
- ",lm.is_finished"
- ",ka.encrypted_attributes"
- " FROM legitimization_measures lm"
- " JOIN kyc_targets kt"
- " ON (lm.access_token = kt.access_token)"
- " LEFT JOIN legitimization_processes lp"
- " ON (lm.legitimization_measure_serial_id = lp.legitimization_measure_serial_id)"
- " LEFT JOIN kyc_attributes ka"
- " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
- " WHERE lm.legitimization_measure_serial_id=$1"
- " AND lp.measure_index=$2;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_completed_legitimization",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_denomination_key.c b/src/exchangedb/lookup_denomination_key.c
@@ -1,79 +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 exchangedb/lookup_denomination_key.c
- * @brief Implementation of the lookup_denomination_key function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_denomination_key.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_denomination_key (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_DenominationHashP *h_denom_pub,
- struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &meta->start),
- GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
- &meta->expire_withdraw),
- GNUNET_PQ_result_spec_timestamp ("expire_deposit",
- &meta->expire_deposit),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &meta->expire_legal),
- TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
- &meta->value),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &meta->fees.withdraw),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &meta->fees.deposit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &meta->fees.refresh),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
- &meta->fees.refund),
- GNUNET_PQ_result_spec_uint32 ("age_mask",
- &meta->age_mask.bits),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_denomination_key",
- "SELECT"
- " valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin"
- ",fee_withdraw"
- ",fee_deposit"
- ",fee_refresh"
- ",fee_refund"
- ",age_mask"
- " FROM denominations"
- " WHERE denom_pub_hash=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_denomination_key",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_global_fee_by_time.c b/src/exchangedb/lookup_global_fee_by_time.c
@@ -1,180 +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 exchangedb/lookup_global_fee_by_time.c
- * @brief Implementation of the lookup_global_fee_by_time function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_dbevents.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_global_fee_by_time.h"
-#include "helper.h"
-
-/**
- * Closure for #global_fee_by_time_helper()
- */
-struct GlobalFeeLookupContext
-{
-
- /**
- * Set to the wire fees. Set to invalid if fees conflict over
- * the given time period.
- */
- struct TALER_GlobalFeeSet *fees;
-
- /**
- * Set to timeout of unmerged purses
- */
- struct GNUNET_TIME_Relative *purse_timeout;
-
- /**
- * Set to history expiration for reserves.
- */
- struct GNUNET_TIME_Relative *history_expiration;
-
- /**
- * Set to number of free purses per account.
- */
- uint32_t *purse_account_limit;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-};
-
-
-/**
- * Helper function for #TALER_EXCHANGEDB_lookup_global_fee_by_time().
- * Calls the callback with each denomination key.
- *
- * @param cls a `struct GlobalFeeLookupContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-global_fee_by_time_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GlobalFeeLookupContext *wlc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = wlc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_GlobalFeeSet fs;
- struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative history_expiration;
- uint32_t purse_account_limit;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &fs.history),
- TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
- &fs.account),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &fs.purse),
- GNUNET_PQ_result_spec_relative_time ("purse_timeout",
- &purse_timeout),
- GNUNET_PQ_result_spec_relative_time ("history_expiration",
- &history_expiration),
- GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
- &purse_account_limit),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_GlobalFeeSet));
- return;
- }
- if (0 == i)
- {
- *wlc->fees = fs;
- *wlc->purse_timeout = purse_timeout;
- *wlc->history_expiration = history_expiration;
- *wlc->purse_account_limit = purse_account_limit;
- continue;
- }
- if ( (0 !=
- TALER_global_fee_set_cmp (&fs,
- wlc->fees)) ||
- (purse_account_limit != *wlc->purse_account_limit) ||
- (GNUNET_TIME_relative_cmp (purse_timeout,
- !=,
- *wlc->purse_timeout)) ||
- (GNUNET_TIME_relative_cmp (history_expiration,
- !=,
- *wlc->history_expiration)) )
- {
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_GlobalFeeSet));
- return;
- }
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_global_fee_by_time (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative *purse_timeout,
- struct GNUNET_TIME_Relative *history_expiration,
- uint32_t *purse_account_limit)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&start_time),
- GNUNET_PQ_query_param_timestamp (&end_time),
- GNUNET_PQ_query_param_end
- };
- struct GlobalFeeLookupContext wlc = {
- .fees = fees,
- .purse_timeout = purse_timeout,
- .history_expiration = history_expiration,
- .purse_account_limit = purse_account_limit,
- .pg = pg
- };
-
- PREPARE (pg,
- "lookup_global_fee_by_time",
- "SELECT"
- " history_fee"
- ",account_fee"
- ",purse_fee"
- ",purse_timeout"
- ",history_expiration"
- ",purse_account_limit"
- " FROM global_fee"
- " WHERE end_date > $1"
- " AND start_date < $2;");
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_global_fee_by_time",
- params,
- &global_fee_by_time_helper,
- &wlc);
-}
diff --git a/src/exchangedb/lookup_h_payto_by_access_token.c b/src/exchangedb/lookup_h_payto_by_access_token.c
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_h_payto_by_access_token.c
- * @brief Implementation of the lookup_h_payto_by_access_token function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_h_payto_by_access_token.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_h_payto_by_access_token (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AccountAccessTokenP *access_token,
- struct TALER_NormalizedPaytoHashP *h_payto,
- bool *is_wallet)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (access_token),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type (
- "h_normalized_payto",
- h_payto),
- GNUNET_PQ_result_spec_bool (
- "is_wallet",
- is_wallet),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_h_payto_by_access_token",
- "SELECT "
- " h_normalized_payto"
- " ,is_wallet"
- " FROM kyc_targets"
- " WHERE (access_token = $1);");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_h_payto_by_access_token",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_kyc_history.c b/src/exchangedb/lookup_kyc_history.c
@@ -1,192 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_kyc_history.c
- * @brief Implementation of the lookup_kyc_history function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_kyc_history.h"
-#include "helper.h"
-
-/**
- * Closure for callbacks called from #TALER_EXCHANGEDB_lookup_kyc_history()
- */
-struct KycHistoryContext
-{
-
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_KycHistoryCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to 'true' if the transaction failed.
- */
- bool failed;
-
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct KycHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_kyc_entry (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct KycHistoryContext *khc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- char *provider_name = NULL;
- bool finished;
- uint32_t error_code;
- char *error_message = NULL;
- char *provider_user_id = NULL;
- char *provider_legitimization_id = NULL;
- struct GNUNET_TIME_Timestamp collection_time;
- struct GNUNET_TIME_Absolute expiration_time
- = GNUNET_TIME_UNIT_ZERO_ABS;
- void *encrypted_attributes;
- size_t encrypted_attributes_len;
-
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("provider_name",
- &provider_name),
- NULL),
- GNUNET_PQ_result_spec_bool ("finished",
- &finished),
- GNUNET_PQ_result_spec_uint32 ("error_code",
- &error_code),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("error_message",
- &error_message),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("provider_user_id",
- &provider_user_id),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("provider_legitimization_id",
- &provider_legitimization_id),
- NULL),
- GNUNET_PQ_result_spec_timestamp ("collection_time",
- &collection_time),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_absolute_time ("expiration_time",
- &expiration_time),
- NULL),
- GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
- &encrypted_attributes,
- &encrypted_attributes_len),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- khc->failed = true;
- return;
- }
- khc->cb (khc->cb_cls,
- provider_name,
- finished,
- (enum TALER_ErrorCode) error_code,
- error_message,
- provider_user_id,
- provider_legitimization_id,
- collection_time,
- expiration_time,
- encrypted_attributes_len,
- encrypted_attributes);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_history (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_KycHistoryCallback cb,
- void *cb_cls)
-{
- struct KycHistoryContext khc = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "lookup_kyc_history",
- "SELECT"
- " lp.provider_name"
- ",lp.finished"
- ",lp.error_code"
- ",lp.error_message"
- ",lp.provider_user_id"
- ",lp.provider_legitimization_id"
- ",ka.collection_time"
- ",ka.expiration_time"
- ",ka.encrypted_attributes"
- " FROM kyc_attributes ka"
- " JOIN legitimization_processes lp"
- " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
- " WHERE ka.h_payto=$1"
- " ORDER BY ka.collection_time DESC;");
-
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "lookup_kyc_history",
- params,
- &handle_kyc_entry,
- &khc);
- if (qs <= 0)
- return qs;
- if (khc.failed)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return qs;
-}
diff --git a/src/exchangedb/lookup_kyc_process_by_account.c b/src/exchangedb/lookup_kyc_process_by_account.c
@@ -1,90 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 exchangedb/lookup_kyc_process_by_account.c
- * @brief Implementation of the lookup_kyc_process_by_account function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_kyc_process_by_account.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_process_by_account (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const char *provider_name,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- uint64_t *process_row,
- struct GNUNET_TIME_Absolute *expiration,
- char **provider_account_id,
- char **provider_legitimization_id,
- bool *is_wallet)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (provider_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "legitimization_process_serial_id",
- process_row),
- GNUNET_PQ_result_spec_absolute_time (
- "expiration_time",
- expiration),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string (
- "provider_user_id",
- provider_account_id),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string (
- "provider_legitimization_id",
- provider_legitimization_id),
- NULL),
- GNUNET_PQ_result_spec_bool (
- "is_wallet",
- is_wallet),
- GNUNET_PQ_result_spec_end
- };
-
- *provider_account_id = NULL;
- *provider_legitimization_id = NULL;
- PREPARE (pg,
- "lookup_kyc_process_by_account",
- "SELECT "
- " lp.legitimization_process_serial_id"
- ",lp.expiration_time"
- ",lp.provider_user_id"
- ",lp.provider_legitimization_id"
- ",kt.is_wallet"
- " FROM legitimization_processes lp"
- " JOIN kyc_targets kt"
- " ON (lp.h_payto = kt.h_normalized_payto)"
- " WHERE h_payto=$1"
- " AND provider_name=$2"
- " AND NOT finished"
- /* Note: there *should* only be one unfinished
- match, so this is just to be safe(r): */
- " ORDER BY lp.expiration_time DESC"
- " LIMIT 1;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_kyc_process_by_account",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_kyc_requirement_by_row.c b/src/exchangedb/lookup_kyc_requirement_by_row.c
@@ -1,109 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_kyc_requirement_by_row.c
- * @brief Implementation of the lookup_kyc_requirement_by_row function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_kyc_requirement_by_row.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_requirement_by_row (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const union TALER_AccountPublicKeyP *account_pub,
- enum GNUNET_GenericReturnValue *is_wallet,
- struct TALER_AccountAccessTokenP *access_token,
- uint64_t *rule_gen,
- json_t **jrules,
- bool *aml_review,
- bool *kyc_required)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_auto_from_type (account_pub),
- GNUNET_PQ_query_param_end
- };
- bool bis_wallet;
- bool bis_wallet_unknown;
- bool not_found;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("access_token",
- access_token),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- /* can be NULL due to LEFT JOIN */
- TALER_PQ_result_spec_json ("jrules",
- jrules),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- /* can be NULL due to LEFT JOIN */
- GNUNET_PQ_result_spec_bool ("is_wallet",
- &bis_wallet),
- &bis_wallet_unknown),
- GNUNET_PQ_result_spec_allow_null (
- /* can be NULL due to LEFT JOIN */
- GNUNET_PQ_result_spec_bool ("aml_review",
- aml_review),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 ("rule_gen",
- rule_gen),
- NULL),
- GNUNET_PQ_result_spec_bool ("kyc_required",
- kyc_required),
- GNUNET_PQ_result_spec_bool ("not_found",
- ¬_found),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- *jrules = NULL;
- *aml_review = false;
- *is_wallet = GNUNET_SYSERR;
- *rule_gen = 0;
- memset (access_token,
- 0,
- sizeof (*access_token));
- PREPARE (pg,
- "lookup_kyc_requirement_by_row",
- "SELECT "
- " out_access_token AS access_token"
- ",out_jrules::TEXT AS jrules"
- ",out_is_wallet AS is_wallet"
- ",out_not_found AS not_found"
- ",out_aml_review AS aml_review"
- ",out_kyc_required AS kyc_required"
- ",out_rule_gen AS rule_gen"
- " FROM exchange_do_lookup_kyc_requirement_by_row"
- " ($1, $2);");
- qs = GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_kyc_requirement_by_row",
- params,
- rs);
- if (qs <= 0)
- return qs;
- if (! bis_wallet_unknown)
- *is_wallet = (bis_wallet) ? GNUNET_YES : GNUNET_NO;
- if (not_found)
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- return qs;
-}
diff --git a/src/exchangedb/lookup_kyc_status_by_token.c b/src/exchangedb/lookup_kyc_status_by_token.c
@@ -1,61 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_kyc_status_by_token.c
- * @brief Implementation of the lookup_kyc_status_by_token function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_kyc_status_by_token.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_status_by_token (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AccountAccessTokenP *access_token,
- uint64_t *row,
- json_t **jmeasures)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (access_token),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "legitimization_measure_serial_id",
- row),
- TALER_PQ_result_spec_json (
- "jmeasures",
- jmeasures),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_kyc_status_by_token",
- "SELECT"
- " legitimization_measure_serial_id"
- ",jmeasures::TEXT"
- " FROM legitimization_measures"
- " WHERE access_token=$1"
- " AND NOT is_finished"
- " ORDER BY display_priority DESC"
- " LIMIT 1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_kyc_status_by_token",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_pending_legitimization.c b/src/exchangedb/lookup_pending_legitimization.c
@@ -1,76 +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 exchangedb/lookup_pending_legitimization.c
- * @brief Implementation of the lookup_pending_legitimization function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_pending_legitimization.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_pending_legitimization (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t legitimization_measure_serial_id,
- struct TALER_AccountAccessTokenP *access_token,
- struct TALER_NormalizedPaytoHashP *h_payto,
- json_t **jmeasures,
- bool *is_finished,
- bool *is_wallet)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&legitimization_measure_serial_id),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_json (
- "jmeasures",
- jmeasures),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_normalized_payto",
- h_payto),
- GNUNET_PQ_result_spec_auto_from_type (
- "access_token",
- access_token),
- GNUNET_PQ_result_spec_bool (
- "is_finished",
- is_finished),
- GNUNET_PQ_result_spec_bool (
- "is_wallet",
- is_wallet),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_pending_legitimization",
- "SELECT "
- " lm.jmeasures::TEXT"
- ",kt.h_normalized_payto"
- ",kt.is_wallet"
- ",lm.access_token"
- ",lm.is_finished"
- " FROM legitimization_measures lm"
- " JOIN kyc_targets kt"
- " USING (access_token)"
- " WHERE lm.legitimization_measure_serial_id=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_pending_legitimization",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_records_by_table.c b/src/exchangedb/lookup_records_by_table.c
@@ -1,3607 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2020-2025 Taler Systems SA
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file exchangedb/lookup_records_by_table.c
- * @brief implementation of lookup_records_by_table
- * @author Christian Grothoff
- * @author Özgür Kesim
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_dbevents.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_records_by_table.h"
-#include "helper.h"
-#include <gnunet/gnunet_pq_lib.h>
-
-
-/**
- * Closure for callbacks used by #postgres_lookup_records_by_table.
- */
-struct LookupRecordsByTableContext
-{
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_ReplicationCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Set to true on errors.
- */
- bool error;
-};
-
-
-/**
- * Function called with denominations table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_denominations (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_DENOMINATIONS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint32 (
- "denom_type",
- &td.details.denominations.denom_type),
- GNUNET_PQ_result_spec_uint32 (
- "age_mask",
- &td.details.denominations.age_mask),
- TALER_PQ_result_spec_denom_pub (
- "denom_pub",
- &td.details.denominations.denom_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "master_sig",
- &td.details.denominations.master_sig),
- GNUNET_PQ_result_spec_timestamp (
- "valid_from",
- &td.details.denominations.valid_from),
- GNUNET_PQ_result_spec_timestamp (
- "expire_withdraw",
- &td.details.denominations.
- expire_withdraw),
- GNUNET_PQ_result_spec_timestamp (
- "expire_deposit",
- &td.details.denominations.
- expire_deposit),
- GNUNET_PQ_result_spec_timestamp (
- "expire_legal",
- &td.details.denominations.expire_legal),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "coin",
- &td.details.denominations.coin),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "fee_withdraw",
- &td.details.denominations.fees.withdraw),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "fee_deposit",
- &td.details.denominations.fees.deposit),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "fee_refresh",
- &td.details.denominations.fees.refresh),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "fee_refund",
- &td.details.denominations.fees.refund),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with denomination_revocations table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_denomination_revocations (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "denominations_serial",
- &td.details.denomination_revocations.denominations_serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "master_sig",
- &td.details.denomination_revocations.master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wire_targets table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wire_targets (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WIRE_TARGETS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_string (
- "payto_uri",
- &td.details.wire_targets.full_payto_uri.full_payto),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wire_targets table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_kyc_targets (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_KYC_TARGETS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_normalized_payto",
- &td.details.kyc_targets.h_normalized_payto),
- GNUNET_PQ_result_spec_auto_from_type (
- "access_token",
- &td.details.kyc_targets.access_token),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "target_pub",
- &td.details.kyc_targets.target_pub),
- &td.details.kyc_targets.no_account),
- GNUNET_PQ_result_spec_bool (
- "is_wallet",
- &td.details.kyc_targets.is_wallet),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with reserves table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_reserves (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RESERVES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &td.details.reserves.reserve_pub),
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &td.details.reserves.expiration_date),
- GNUNET_PQ_result_spec_timestamp ("gc_date",
- &td.details.reserves.gc_date),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with reserves_in table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_reserves_in (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RESERVES_IN
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.reserves_in.reserve_pub),
- GNUNET_PQ_result_spec_uint64 (
- "wire_reference",
- &td.details.reserves_in.wire_reference),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "credit",
- &td.details.reserves_in.credit),
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_source_h_payto",
- &td.details.reserves_in.sender_account_h_payto),
- GNUNET_PQ_result_spec_string (
- "exchange_account_section",
- &td.details.reserves_in.exchange_account_section),
- GNUNET_PQ_result_spec_timestamp (
- "execution_date",
- &td.details.reserves_in.execution_date),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with kycauth_in table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_kycauth_in (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_KYCAUTHS_IN
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "account_pub",
- &td.details.kycauth_in.account_pub),
- GNUNET_PQ_result_spec_uint64 (
- "wire_reference",
- &td.details.kycauth_in.wire_reference),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "credit",
- &td.details.kycauth_in.credit),
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_source_h_payto",
- &td.details.kycauth_in.sender_account_h_payto),
- GNUNET_PQ_result_spec_string (
- "exchange_account_section",
- &td.details.kycauth_in.exchange_account_section),
- GNUNET_PQ_result_spec_timestamp (
- "execution_date",
- &td.details.kycauth_in.execution_date),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with reserves_close table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_reserves_close (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RESERVES_CLOSE
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.reserves_close.reserve_pub),
- GNUNET_PQ_result_spec_timestamp (
- "execution_date",
- &td.details.reserves_close.execution_date),
- GNUNET_PQ_result_spec_auto_from_type (
- "wtid",
- &td.details.reserves_close.wtid),
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_target_h_payto",
- &td.details.reserves_close.sender_account_h_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount",
- &td.details.reserves_close.amount),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "closing_fee",
- &td.details.reserves_close.closing_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with reserves_open_requests table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_reserves_open_requests (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.reserves_open_requests.reserve_pub),
- GNUNET_PQ_result_spec_timestamp (
- "request_timestamp",
- &td.details.reserves_open_requests.request_timestamp),
- GNUNET_PQ_result_spec_timestamp (
- "expiration_date",
- &td.details.reserves_open_requests.expiration_date),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.reserves_open_requests.reserve_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "reserve_payment",
- &td.details.reserves_open_requests.reserve_payment),
- GNUNET_PQ_result_spec_uint32 (
- "requested_purse_limit",
- &td.details.reserves_open_requests.requested_purse_limit),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with reserves_open_deposits table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_reserves_open_deposits (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.reserves_open_deposits.reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.reserves_open_deposits.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.reserves_open_deposits.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_sig",
- &td.details.reserves_open_deposits.coin_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "contribution",
- &td.details.reserves_open_deposits.contribution),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with auditors table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_auditors (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_AUDITORS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
- &td.details.auditors.auditor_pub),
- GNUNET_PQ_result_spec_string ("auditor_url",
- &td.details.auditors.auditor_url),
- GNUNET_PQ_result_spec_string ("auditor_name",
- &td.details.auditors.auditor_name),
- GNUNET_PQ_result_spec_bool ("is_active",
- &td.details.auditors.is_active),
- GNUNET_PQ_result_spec_timestamp ("last_change",
- &td.details.auditors.last_change),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with auditor_denom_sigs table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_auditor_denom_sigs (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "auditor_uuid",
- &td.details.auditor_denom_sigs.auditor_uuid),
- GNUNET_PQ_result_spec_uint64 (
- "denominations_serial",
- &td.details.auditor_denom_sigs.denominations_serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "auditor_sig",
- &td.details.auditor_denom_sigs.auditor_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with exchange_sign_keys table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_exchange_sign_keys (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
- &td.details.exchange_sign_keys.
- exchange_pub),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &td.details.exchange_sign_keys.
- master_sig),
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &td.details.exchange_sign_keys.meta.
- start),
- GNUNET_PQ_result_spec_timestamp ("expire_sign",
- &td.details.exchange_sign_keys.meta.
- expire_sign),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &td.details.exchange_sign_keys.meta.
- expire_legal),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with signkey_revocations table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_signkey_revocations (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 ("esk_serial",
- &td.details.signkey_revocations.esk_serial),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &td.details.signkey_revocations.
- master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with known_coins table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_known_coins (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_KNOWN_COINS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.known_coins.coin_pub),
- TALER_PQ_result_spec_denom_sig (
- "denom_sig",
- &td.details.known_coins.denom_sig),
- GNUNET_PQ_result_spec_uint64 (
- "denominations_serial",
- &td.details.known_coins.denominations_serial),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with refresh table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_refresh (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_REFRESH
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- bool no_cs_r_values;
- bool no_cs_r_choices;
- size_t num_denom_sigs;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "rc",
- &td.details.refresh.rc),
- GNUNET_PQ_result_spec_auto_from_type (
- "execution_date",
- &td.details.refresh.execution_date),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.refresh.amount_with_fee),
- GNUNET_PQ_result_spec_auto_from_type (
- "old_coin_pub",
- &td.details.refresh.old_coin_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "old_coin_sig",
- &td.details.refresh.old_coin_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "refresh_seed",
- &td.details.refresh.refresh_seed),
- GNUNET_PQ_result_spec_uint32 (
- "noreveal_index",
- &td.details.refresh.noreveal_index),
- GNUNET_PQ_result_spec_auto_from_type (
- "planchets_h",
- &td.details.refresh.planchets_h),
- GNUNET_PQ_result_spec_auto_from_type (
- "selected_h",
- &td.details.refresh.selected_h),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "blinding_seed",
- &td.details.refresh.blinding_seed),
- &td.details.refresh.no_blinding_seed),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_array_cs_r_pub (
- pg->conn,
- "cs_r_values",
- &td.details.refresh.num_cs_r_values,
- &td.details.refresh.cs_r_values),
- &no_cs_r_values),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 (
- "cs_r_choices",
- &td.details.refresh.cs_r_choices),
- &no_cs_r_choices),
- GNUNET_PQ_result_spec_array_uint64 (
- pg->conn,
- "denom_serials",
- &td.details.refresh.num_coins,
- &td.details.refresh.denom_serials),
- TALER_PQ_result_spec_array_blinded_denom_sig (
- pg->conn,
- "denom_sigs",
- &num_denom_sigs,
- &td.details.refresh.denom_sigs),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with batch deposits table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_batch_deposits (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_BATCH_DEPOSITS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "shard",
- &td.details.batch_deposits.shard),
- GNUNET_PQ_result_spec_auto_from_type (
- "merchant_pub",
- &td.details.batch_deposits.merchant_pub),
- GNUNET_PQ_result_spec_timestamp (
- "wallet_timestamp",
- &td.details.batch_deposits.wallet_timestamp),
- GNUNET_PQ_result_spec_timestamp (
- "exchange_timestamp",
- &td.details.batch_deposits.exchange_timestamp),
- GNUNET_PQ_result_spec_timestamp (
- "refund_deadline",
- &td.details.batch_deposits.refund_deadline),
- GNUNET_PQ_result_spec_timestamp (
- "wire_deadline",
- &td.details.batch_deposits.wire_deadline),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_contract_terms",
- &td.details.batch_deposits.h_contract_terms),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "wallet_data_hash",
- &td.details.batch_deposits.wallet_data_hash),
- &td.details.batch_deposits.no_wallet_data_hash),
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_salt",
- &td.details.batch_deposits.wire_salt),
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_target_h_payto",
- &td.details.batch_deposits.wire_target_h_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "total_amount",
- &td.details.batch_deposits.total_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "total_without_fee",
- &td.details.batch_deposits.total_without_fee),
- GNUNET_PQ_result_spec_auto_from_type (
- "merchant_sig",
- &td.details.batch_deposits.merchant_sig),
- GNUNET_PQ_result_spec_bool (
- "done",
- &td.details.batch_deposits.done),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with coin deposits table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_coin_deposits (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_COIN_DEPOSITS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "batch_deposit_serial_id",
- &td.details.coin_deposits.batch_deposit_serial_id),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.coin_deposits.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_sig",
- &td.details.coin_deposits.coin_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.coin_deposits.amount_with_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with refunds table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_refunds (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_REFUNDS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.refunds.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "merchant_sig",
- &td.details.refunds.merchant_sig),
- GNUNET_PQ_result_spec_uint64 (
- "rtransaction_id",
- &td.details.refunds.rtransaction_id),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.refunds.amount_with_fee),
- GNUNET_PQ_result_spec_uint64 (
- "batch_deposit_serial_id",
- &td.details.refunds.batch_deposit_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wire_out table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wire_out (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WIRE_OUT
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_timestamp (
- "execution_date",
- &td.details.wire_out.execution_date),
- GNUNET_PQ_result_spec_auto_from_type (
- "wtid_raw",
- &td.details.wire_out.wtid_raw),
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_target_h_payto",
- &td.details.wire_out.wire_target_h_payto),
- GNUNET_PQ_result_spec_string (
- "exchange_account_section",
- &td.details.wire_out.exchange_account_section),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount",
- &td.details.wire_out.amount),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with aggregation_tracking table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_aggregation_tracking (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "batch_deposit_serial_id",
- &td.details.aggregation_tracking.batch_deposit_serial_id),
- GNUNET_PQ_result_spec_auto_from_type (
- "wtid_raw",
- &td.details.aggregation_tracking.wtid_raw),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wire_fee table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wire_fee (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WIRE_FEE
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_string ("wire_method",
- &td.details.wire_fee.wire_method),
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &td.details.wire_fee.start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &td.details.wire_fee.end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
- &td.details.wire_fee.fees.wire),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &td.details.wire_fee.fees.closing),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &td.details.wire_fee.master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wire_fee table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_global_fee (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_GLOBAL_FEE
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_timestamp (
- "start_date",
- &td.details.global_fee.start_date),
- GNUNET_PQ_result_spec_timestamp (
- "end_date",
- &td.details.global_fee.end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "history_fee",
- &td.details.global_fee.fees.history),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "account_fee",
- &td.details.global_fee.fees.account),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "purse_fee",
- &td.details.global_fee.fees.purse),
- GNUNET_PQ_result_spec_relative_time (
- "purse_timeout",
- &td.details.global_fee.purse_timeout),
- GNUNET_PQ_result_spec_relative_time (
- "history_expiration",
- &td.details.global_fee.history_expiration),
- GNUNET_PQ_result_spec_uint32 (
- "purse_account_limit",
- &td.details.global_fee.purse_account_limit),
- GNUNET_PQ_result_spec_auto_from_type (
- "master_sig",
- &td.details.global_fee.master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with recoup table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_recoup (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RECOUP
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &td.details.recoup.coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &td.details.recoup.coin_blind),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &td.details.recoup.amount),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &td.details.recoup.timestamp),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.recoup.coin_pub),
- GNUNET_PQ_result_spec_uint64 ("withdraw_serial_id",
- &td.details.recoup.withdraw_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with recoup_refresh table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_recoup_refresh (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_RECOUP_REFRESH
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_sig",
- &td.details.recoup_refresh.coin_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_blind",
- &td.details.recoup_refresh.coin_blind),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount",
- &td.details.recoup_refresh.amount),
- GNUNET_PQ_result_spec_timestamp (
- "recoup_timestamp",
- &td.details.recoup_refresh.recoup_timestamp),
- GNUNET_PQ_result_spec_uint64 (
- "known_coin_id",
- &td.details.recoup_refresh.known_coin_id),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.recoup_refresh.coin_pub),
- GNUNET_PQ_result_spec_uint64 (
- "refresh_id",
- &td.details.recoup_refresh.refresh_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with purse_requests table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_purse_requests (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PURSE_REQUESTS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "purse_requests_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.purse_requests.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "merge_pub",
- &td.details.purse_requests.merge_pub),
- GNUNET_PQ_result_spec_timestamp (
- "purse_creation",
- &td.details.purse_requests.purse_creation),
- GNUNET_PQ_result_spec_timestamp (
- "purse_expiration",
- &td.details.purse_requests.purse_expiration),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_contract_terms",
- &td.details.purse_requests.h_contract_terms),
- GNUNET_PQ_result_spec_uint32 (
- "age_limit",
- &td.details.purse_requests.age_limit),
- GNUNET_PQ_result_spec_uint32 (
- "flags",
- &td.details.purse_requests.flags),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.purse_requests.amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "purse_fee",
- &td.details.purse_requests.purse_fee),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_sig",
- &td.details.purse_requests.purse_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with purse_decision table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_purse_decision (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PURSE_DECISION
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "purse_decision_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.purse_decision.purse_pub),
- GNUNET_PQ_result_spec_timestamp (
- "action_timestamp",
- &td.details.purse_decision.action_timestamp),
- GNUNET_PQ_result_spec_bool (
- "refunded",
- &td.details.purse_decision.refunded),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with purse_merges table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_purse_merges (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PURSE_MERGES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "purse_merge_request_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "partner_serial_id",
- &td.details.purse_merges.partner_serial_id),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.purse_merges.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.purse_merges.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "merge_sig",
- &td.details.purse_merges.merge_sig),
- GNUNET_PQ_result_spec_timestamp (
- "merge_timestamp",
- &td.details.purse_merges.merge_timestamp),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with purse_deposits table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_purse_deposits (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PURSE_DEPOSITS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "purse_deposit_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_uint64 (
- "partner_serial_id",
- &td.details.purse_deposits.partner_serial_id),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.purse_deposits.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.purse_deposits.coin_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.purse_deposits.amount_with_fee),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_sig",
- &td.details.purse_deposits.coin_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with account_merges table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_account_merges (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_ACCOUNT_MERGES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "account_merge_request_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.account_merges.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.account_merges.reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.account_merges.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "wallet_h_payto",
- &td.details.account_merges.wallet_h_payto),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with history_requests table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_history_requests (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_HISTORY_REQUESTS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "history_request_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.history_requests.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.history_requests.reserve_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "history_fee",
- &td.details.history_requests.history_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with close_requests table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_close_requests (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_CLOSE_REQUESTS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "close_request_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.close_requests.reserve_pub),
- GNUNET_PQ_result_spec_timestamp (
- "close_timestamp",
- &td.details.close_requests.close_timestamp),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.close_requests.reserve_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "close",
- &td.details.close_requests.close),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "close_fee",
- &td.details.close_requests.close_fee),
- GNUNET_PQ_result_spec_string (
- "payto_uri",
- &td.details.close_requests.payto_uri.full_payto),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wads_out table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wads_out (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WADS_OUT
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "wad_out_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "wad_id",
- &td.details.wads_out.wad_id),
- GNUNET_PQ_result_spec_uint64 (
- "partner_serial_id",
- &td.details.wads_out.partner_serial_id),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount",
- &td.details.wads_out.amount),
- GNUNET_PQ_result_spec_timestamp (
- "execution_time",
- &td.details.wads_out.execution_time),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wads_out_entries table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wads_out_entries (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "wad_out_entry_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.wads_out_entries.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.wads_out_entries.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_contract",
- &td.details.wads_out_entries.h_contract),
- GNUNET_PQ_result_spec_timestamp (
- "purse_expiration",
- &td.details.wads_out_entries.purse_expiration),
- GNUNET_PQ_result_spec_timestamp (
- "merge_timestamp",
- &td.details.wads_out_entries.merge_timestamp),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.wads_out_entries.amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "wad_fee",
- &td.details.wads_out_entries.wad_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "deposit_fees",
- &td.details.wads_out_entries.deposit_fees),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.wads_out_entries.reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_sig",
- &td.details.wads_out_entries.purse_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wads_in table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wads_in (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WADS_IN
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "wad_in_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "wad_id",
- &td.details.wads_in.wad_id),
- GNUNET_PQ_result_spec_string (
- "origin_exchange_url",
- &td.details.wads_in.origin_exchange_url),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount",
- &td.details.wads_in.amount),
- GNUNET_PQ_result_spec_timestamp (
- "arrival_time",
- &td.details.wads_in.arrival_time),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with wads_in_entries table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_wads_in_entries (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "wad_in_entry_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.wads_in_entries.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.wads_in_entries.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_contract",
- &td.details.wads_in_entries.h_contract),
- GNUNET_PQ_result_spec_timestamp (
- "purse_expiration",
- &td.details.wads_in_entries.purse_expiration),
- GNUNET_PQ_result_spec_timestamp (
- "merge_timestamp",
- &td.details.wads_in_entries.merge_timestamp),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.wads_in_entries.amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "wad_fee",
- &td.details.wads_in_entries.wad_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "deposit_fees",
- &td.details.wads_in_entries.deposit_fees),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.wads_in_entries.reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_sig",
- &td.details.wads_in_entries.purse_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with profit_drains table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_profit_drains (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PROFIT_DRAINS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "profit_drain_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "wtid",
- &td.details.profit_drains.wtid),
- GNUNET_PQ_result_spec_string (
- "account_section",
- &td.details.profit_drains.account_section),
- GNUNET_PQ_result_spec_string (
- "payto_uri",
- &td.details.profit_drains.payto_uri.full_payto),
- GNUNET_PQ_result_spec_timestamp (
- "trigger_date",
- &td.details.profit_drains.trigger_date),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount",
- &td.details.profit_drains.amount),
- GNUNET_PQ_result_spec_auto_from_type (
- "master_sig",
- &td.details.profit_drains.master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with aml_staff table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_aml_staff (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_AML_STAFF
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "aml_staff_uuid",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "decider_pub",
- &td.details.aml_staff.decider_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "master_sig",
- &td.details.aml_staff.master_sig),
- GNUNET_PQ_result_spec_string (
- "decider_name",
- &td.details.aml_staff.decider_name),
- GNUNET_PQ_result_spec_bool (
- "is_active",
- &td.details.aml_staff.is_active),
- GNUNET_PQ_result_spec_bool (
- "read_only",
- &td.details.aml_staff.read_only),
- GNUNET_PQ_result_spec_timestamp (
- "last_change",
- &td.details.aml_staff.last_change),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with purse_deletion table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_purse_deletion (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PURSE_DELETION
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "purse_deletion_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_sig",
- &td.details.purse_deletion.purse_sig),
- GNUNET_PQ_result_spec_auto_from_type (
- "purse_pub",
- &td.details.purse_deletion.purse_pub),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with withdraw table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_withdraw (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_WITHDRAW
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- bool no_max_age;
- bool no_noreveal_index;
- bool no_selected_h;
- bool no_cs_r_values;
- bool no_cs_r_choices;
- size_t num_sigs;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "withdraw_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "planchets_h",
- &td.details.withdraw.planchets_h),
- GNUNET_PQ_result_spec_timestamp (
- "execution_date",
- &td.details.withdraw.execution_date),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.withdraw.amount_with_fee),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_pub",
- &td.details.withdraw.reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "reserve_sig",
- &td.details.withdraw.reserve_sig),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint16 (
- "max_age",
- &td.details.withdraw.max_age),
- &no_max_age),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint16 (
- "noreveal_index",
- &td.details.withdraw.noreveal_index),
- &no_noreveal_index),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "selected_h",
- &td.details.withdraw.selected_h),
- &no_selected_h),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "blinding_seed",
- &td.details.withdraw.blinding_seed),
- &td.details.withdraw.no_blinding_seed),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_array_cs_r_pub (
- pg->conn,
- "cs_r_values",
- &td.details.withdraw.num_cs_r_values,
- &td.details.withdraw.cs_r_values),
- &no_cs_r_values),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 (
- "cs_r_choices",
- &td.details.withdraw.cs_r_choices),
- &no_cs_r_choices),
- GNUNET_PQ_result_spec_array_uint64 (
- pg->conn,
- "denom_serials",
- &td.details.withdraw.num_coins,
- &td.details.withdraw.denom_serials),
- TALER_PQ_result_spec_array_blinded_denom_sig (
- pg->conn,
- "denom_sigs",
- &num_sigs,
- &td.details.withdraw.denom_sigs),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- if (num_sigs != td.details.withdraw.num_coins)
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- if (no_max_age != no_noreveal_index)
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- if (no_max_age != no_selected_h)
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- if (no_cs_r_values != no_cs_r_choices)
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- if (no_cs_r_values != td.details.withdraw.no_blinding_seed)
- {
- GNUNET_break (0);
- ctx->error = true;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- td.details.withdraw.age_proof_required = ! no_max_age;
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with legitimization_measures table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_legitimization_measures (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "access_token",
- &td.details.legitimization_measures.target_token),
- GNUNET_PQ_result_spec_timestamp (
- "start_time",
- &td.details.legitimization_measures.start_time),
- TALER_PQ_result_spec_json (
- "jmeasures",
- &td.details.legitimization_measures.measures),
- GNUNET_PQ_result_spec_uint32 (
- "display_priority",
- &td.details.legitimization_measures.display_priority),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with legitimization_outcomes table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_legitimization_outcomes (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_payto",
- &td.details.legitimization_outcomes.h_payto),
- GNUNET_PQ_result_spec_timestamp (
- "decision_time",
- &td.details.legitimization_outcomes.decision_time),
- GNUNET_PQ_result_spec_timestamp (
- "expiration_time",
- &td.details.legitimization_outcomes.expiration_time),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json (
- "jproperties",
- &td.details.legitimization_outcomes.properties),
- NULL),
- GNUNET_PQ_result_spec_bool (
- "to_investigate_id",
- &td.details.legitimization_outcomes.to_investigate),
- TALER_PQ_result_spec_json (
- "jnew_rules",
- &td.details.legitimization_outcomes.new_rules),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with legitimization_processes table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_legitimization_processes (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_payto",
- &td.details.legitimization_processes.h_payto),
- GNUNET_PQ_result_spec_timestamp (
- "start_time",
- &td.details.legitimization_processes.start_time),
- GNUNET_PQ_result_spec_timestamp (
- "expiration_time",
- &td.details.legitimization_processes.expiration_time),
- GNUNET_PQ_result_spec_uint64 (
- "legitimization_measure_serial_id",
- &td.details.legitimization_processes.legitimization_measure_serial_id),
- GNUNET_PQ_result_spec_uint32 (
- "measure_index",
- &td.details.legitimization_processes.measure_index),
- GNUNET_PQ_result_spec_string (
- "provider_name",
- &td.details.legitimization_processes.provider_name),
- GNUNET_PQ_result_spec_string (
- "provider_user_id",
- &td.details.legitimization_processes.provider_user_id),
- GNUNET_PQ_result_spec_string (
- "provider_legitimization_id",
- &td.details.legitimization_processes.provider_legitimization_id),
- GNUNET_PQ_result_spec_string (
- "redirect_url",
- &td.details.legitimization_processes.redirect_url),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with kyc_attributes table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_kyc_attributes (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "kyc_attributes_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_payto",
- &td.details.kyc_attributes.h_payto),
- GNUNET_PQ_result_spec_uint64 (
- "legitimization_serial",
- &td.details.kyc_attributes.legitimization_serial),
- GNUNET_PQ_result_spec_timestamp (
- "collection_time",
- &td.details.kyc_attributes.collection_time),
- GNUNET_PQ_result_spec_timestamp (
- "expiration_time",
- &td.details.kyc_attributes.expiration_time),
- GNUNET_PQ_result_spec_uint64 (
- "trigger_outcome_serial",
- &td.details.kyc_attributes.trigger_outcome_serial),
- GNUNET_PQ_result_spec_variable_size (
- "encrypted_attributes",
- &td.details.kyc_attributes.encrypted_attributes,
- &td.details.kyc_attributes.encrypted_attributes_size),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with aml_history table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_aml_history (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_AML_HISTORY
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "aml_history_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_auto_from_type (
- "h_payto",
- &td.details.aml_history.h_payto),
- GNUNET_PQ_result_spec_uint64 (
- "outcome_serial_id",
- &td.details.aml_history.outcome_serial_id),
- GNUNET_PQ_result_spec_string (
- "justification",
- &td.details.aml_history.justification),
- GNUNET_PQ_result_spec_auto_from_type (
- "decider_pub",
- &td.details.aml_history.decider_pub),
- GNUNET_PQ_result_spec_auto_from_type (
- "decider_sig",
- &td.details.aml_history.decider_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called with kyc_events table entries.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lrbt_cb_table_kyc_events (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupRecordsByTableContext *ctx = cls;
- struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_KYC_EVENTS
- };
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "kyc_event_serial_id",
- &td.serial),
- GNUNET_PQ_result_spec_timestamp (
- "event_timestamp",
- &td.details.kyc_events.event_timestamp),
- GNUNET_PQ_result_spec_string (
- "event_type",
- &td.details.kyc_events.event_type),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->error = true;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &td);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Assign statement to @a n and PREPARE
- * @a sql under name @a n.
- */
-#define XPREPARE(n,sql) \
- statement = n; \
- PREPARE (pg, n, sql);
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_records_by_table (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- enum TALER_EXCHANGEDB_ReplicatedTable table,
- uint64_t serial,
- TALER_EXCHANGEDB_ReplicationCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial),
- GNUNET_PQ_query_param_end
- };
- struct LookupRecordsByTableContext ctx = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls
- };
- GNUNET_PQ_PostgresResultHandler rh = NULL;
- const char *statement = NULL;
- enum GNUNET_DB_QueryStatus qs;
-
- switch (table)
- {
- case TALER_EXCHANGEDB_RT_DENOMINATIONS:
- XPREPARE ("select_above_serial_by_table_denominations",
- "SELECT"
- " denominations_serial AS serial"
- ",denom_type"
- ",denom_pub"
- ",master_sig"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin"
- ",fee_withdraw"
- ",fee_deposit"
- ",fee_refresh"
- ",fee_refund"
- ",age_mask"
- " FROM denominations"
- " WHERE denominations_serial > $1"
- " ORDER BY denominations_serial ASC;");
- rh = &lrbt_cb_table_denominations;
- break;
- case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
- XPREPARE ("select_above_serial_by_table_denomination_revocations",
- "SELECT"
- " denom_revocations_serial_id AS serial"
- ",master_sig"
- ",denominations_serial"
- " FROM denomination_revocations"
- " WHERE denom_revocations_serial_id > $1"
- " ORDER BY denom_revocations_serial_id ASC;");
- rh = &lrbt_cb_table_denomination_revocations;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
- XPREPARE ("select_above_serial_by_table_wire_targets",
- "SELECT"
- " wire_target_serial_id AS serial"
- ",payto_uri"
- " FROM wire_targets"
- " WHERE wire_target_serial_id > $1"
- " ORDER BY wire_target_serial_id ASC;");
- rh = &lrbt_cb_table_wire_targets;
- break;
- case TALER_EXCHANGEDB_RT_KYC_TARGETS:
- XPREPARE ("select_above_serial_by_table_kyc_targets",
- "SELECT"
- " kyc_target_serial_id AS serial"
- ",h_normalized_payto"
- ",access_token"
- ",target_pub"
- ",is_wallet"
- " FROM kyc_targets"
- " WHERE kyc_target_serial_id > $1"
- " ORDER BY kyc_target_serial_id ASC;");
- rh = &lrbt_cb_table_kyc_targets;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES:
- XPREPARE ("select_above_serial_by_table_reserves",
- "SELECT"
- " reserve_uuid AS serial"
- ",reserve_pub"
- ",expiration_date"
- ",gc_date"
- " FROM reserves"
- " WHERE reserve_uuid > $1"
- " ORDER BY reserve_uuid ASC;");
- rh = &lrbt_cb_table_reserves;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_IN:
- XPREPARE ("select_above_serial_by_table_reserves_in",
- "SELECT"
- " reserve_in_serial_id AS serial"
- ",reserve_pub"
- ",wire_reference"
- ",credit"
- ",wire_source_h_payto"
- ",exchange_account_section"
- ",execution_date"
- " FROM reserves_in"
- " WHERE reserve_in_serial_id > $1"
- " ORDER BY reserve_in_serial_id ASC;");
- rh = &lrbt_cb_table_reserves_in;
- break;
- case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
- XPREPARE ("select_above_serial_by_table_kycauth_in",
- "SELECT"
- " kycauth_in_serial_id AS serial"
- ",account_pub"
- ",wire_reference"
- ",credit"
- ",wire_source_h_payto"
- ",exchange_account_section"
- ",execution_date"
- " FROM kycauths_in"
- " WHERE kycauth_in_serial_id > $1"
- " ORDER BY kycauth_in_serial_id ASC;");
- rh = &lrbt_cb_table_kycauth_in;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
- XPREPARE ("select_above_serial_by_table_reserves_close",
- "SELECT"
- " close_uuid AS serial"
- ",reserve_pub"
- ",execution_date"
- ",wtid"
- ",wire_target_h_payto"
- ",amount"
- ",closing_fee"
- " FROM reserves_close"
- " WHERE close_uuid > $1"
- " ORDER BY close_uuid ASC;");
- rh = &lrbt_cb_table_reserves_close;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
- XPREPARE ("select_above_serial_by_table_reserves_open_requests",
- "SELECT"
- " open_request_uuid AS serial"
- ",reserve_pub"
- ",request_timestamp"
- ",expiration_date"
- ",reserve_sig"
- ",reserve_payment"
- ",requested_purse_limit"
- " FROM reserves_open_requests"
- " WHERE open_request_uuid > $1"
- " ORDER BY open_request_uuid ASC;");
- rh = &lrbt_cb_table_reserves_open_requests;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
- XPREPARE ("select_above_serial_by_table_reserves_open_deposits",
- "SELECT"
- " reserves_open_deposit_uuid AS serial"
- ",reserve_sig"
- ",reserve_pub"
- ",coin_pub"
- ",coin_sig"
- ",contribution"
- " FROM reserves_open_deposits"
- " WHERE reserves_open_deposit_uuid > $1"
- " ORDER BY reserves_open_deposit_uuid ASC;");
- rh = &lrbt_cb_table_reserves_open_deposits;
- break;
- case TALER_EXCHANGEDB_RT_AUDITORS:
- XPREPARE ("select_above_serial_by_table_auditors",
- "SELECT"
- " auditor_uuid AS serial"
- ",auditor_pub"
- ",auditor_name"
- ",auditor_url"
- ",is_active"
- ",last_change"
- " FROM auditors"
- " WHERE auditor_uuid > $1"
- " ORDER BY auditor_uuid ASC;");
- rh = &lrbt_cb_table_auditors;
- break;
- case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
- XPREPARE ("select_above_serial_by_table_auditor_denom_sigs",
- "SELECT"
- " auditor_denom_serial AS serial"
- ",auditor_uuid"
- ",denominations_serial"
- ",auditor_sig"
- " FROM auditor_denom_sigs"
- " WHERE auditor_denom_serial > $1"
- " ORDER BY auditor_denom_serial ASC;");
- rh = &lrbt_cb_table_auditor_denom_sigs;
- break;
- case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
- XPREPARE ("select_above_serial_by_table_exchange_sign_keys",
- "SELECT"
- " esk_serial AS serial"
- ",exchange_pub"
- ",master_sig"
- ",valid_from"
- ",expire_sign"
- ",expire_legal"
- " FROM exchange_sign_keys"
- " WHERE esk_serial > $1"
- " ORDER BY esk_serial ASC;");
- rh = &lrbt_cb_table_exchange_sign_keys;
- break;
- case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
- XPREPARE ("select_above_serial_by_table_signkey_revocations",
- "SELECT"
- " signkey_revocations_serial_id AS serial"
- ",esk_serial"
- ",master_sig"
- " FROM signkey_revocations"
- " WHERE signkey_revocations_serial_id > $1"
- " ORDER BY signkey_revocations_serial_id ASC;");
- rh = &lrbt_cb_table_signkey_revocations;
- break;
- case TALER_EXCHANGEDB_RT_KNOWN_COINS:
- XPREPARE ("select_above_serial_by_table_known_coins",
- "SELECT"
- " known_coin_id AS serial"
- ",coin_pub"
- ",denom_sig"
- ",denominations_serial"
- " FROM known_coins"
- " WHERE known_coin_id > $1"
- " ORDER BY known_coin_id ASC;");
- rh = &lrbt_cb_table_known_coins;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH:
- XPREPARE ("select_above_serial_by_table_refresh",
- "SELECT"
- " refresh_id AS serial"
- ",rc"
- ",execution_date"
- ",amount_with_fee"
- ",old_coin_pub"
- ",old_coin_sig"
- ",refresh_seed"
- ",noreveal_index"
- ",planchets_h"
- ",selected_h"
- ",blinding_seed"
- ",cs_r_values"
- ",cs_r_choices"
- ",denom_serials"
- ",denom_sigs"
- " FROM refresh"
- " WHERE refresh_id > $1"
- " ORDER BY refresh_id ASC;");
- rh = &lrbt_cb_table_refresh;
- break;
- case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
- XPREPARE ("select_above_serial_by_table_batch_deposits",
- "SELECT"
- " batch_deposit_serial_id AS serial"
- ",shard"
- ",merchant_pub"
- ",wallet_timestamp"
- ",exchange_timestamp"
- ",refund_deadline"
- ",wire_deadline"
- ",h_contract_terms"
- ",wallet_data_hash"
- ",wire_salt"
- ",wire_target_h_payto"
- ",total_amount"
- ",total_without_fee"
- ",merchant_sig"
- ",done"
- " FROM batch_deposits"
- " WHERE batch_deposit_serial_id > $1"
- " ORDER BY batch_deposit_serial_id ASC;");
- rh = &lrbt_cb_table_batch_deposits;
- break;
- case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
- XPREPARE ("select_above_serial_by_table_coin_deposits",
- "SELECT"
- " coin_deposit_serial_id AS serial"
- ",batch_deposit_serial_id"
- ",coin_pub"
- ",coin_sig"
- ",amount_with_fee"
- " FROM coin_deposits"
- " WHERE coin_deposit_serial_id > $1"
- " ORDER BY coin_deposit_serial_id ASC;");
- rh = &lrbt_cb_table_coin_deposits;
- break;
- case TALER_EXCHANGEDB_RT_REFUNDS:
- XPREPARE ("select_above_serial_by_table_refunds",
- "SELECT"
- " refund_serial_id AS serial"
- ",coin_pub"
- ",merchant_sig"
- ",rtransaction_id"
- ",amount_with_fee"
- ",batch_deposit_serial_id"
- " FROM refunds"
- " WHERE refund_serial_id > $1"
- " ORDER BY refund_serial_id ASC;");
- rh = &lrbt_cb_table_refunds;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_OUT:
- XPREPARE ("select_above_serial_by_table_wire_out",
- "SELECT"
- " wireout_uuid AS serial"
- ",execution_date"
- ",wtid_raw"
- ",wire_target_h_payto"
- ",exchange_account_section"
- ",amount"
- " FROM wire_out"
- " WHERE wireout_uuid > $1"
- " ORDER BY wireout_uuid ASC;");
- rh = &lrbt_cb_table_wire_out;
- break;
- case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
- XPREPARE ("select_above_serial_by_table_aggregation_tracking",
- "SELECT"
- " aggregation_serial_id AS serial"
- ",batch_deposit_serial_id"
- ",wtid_raw"
- " FROM aggregation_tracking"
- " WHERE aggregation_serial_id > $1"
- " ORDER BY aggregation_serial_id ASC;");
- rh = &lrbt_cb_table_aggregation_tracking;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_FEE:
- XPREPARE ("select_above_serial_by_table_wire_fee",
- "SELECT"
- " wire_fee_serial AS serial"
- ",wire_method"
- ",start_date"
- ",end_date"
- ",wire_fee"
- ",closing_fee"
- ",master_sig"
- " FROM wire_fee"
- " WHERE wire_fee_serial > $1"
- " ORDER BY wire_fee_serial ASC;");
- rh = &lrbt_cb_table_wire_fee;
- break;
- case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
- XPREPARE ("select_above_serial_by_table_global_fee",
- "SELECT"
- " global_fee_serial AS serial"
- ",start_date"
- ",end_date"
- ",history_fee"
- ",account_fee"
- ",purse_fee"
- ",purse_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- " FROM global_fee"
- " WHERE global_fee_serial > $1"
- " ORDER BY global_fee_serial ASC;");
- rh = &lrbt_cb_table_global_fee;
- break;
- case TALER_EXCHANGEDB_RT_RECOUP:
- XPREPARE ("select_above_serial_by_table_recoup",
- "SELECT"
- " recoup_uuid AS serial"
- ",coin_sig"
- ",coin_blind"
- ",amount"
- ",recoup_timestamp"
- ",coin_pub"
- ",reserve_out_serial_id"
- " FROM recoup"
- " WHERE recoup_uuid > $1"
- " ORDER BY recoup_uuid ASC;");
- rh = &lrbt_cb_table_recoup;
- break;
- case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
- XPREPARE ("select_above_serial_by_table_recoup_refresh",
- "SELECT"
- " recoup_refresh_uuid AS serial"
- ",coin_sig"
- ",coin_blind"
- ",amount"
- ",recoup_timestamp"
- ",coin_pub"
- ",known_coin_id"
- ",refresh_id"
- " FROM recoup_refresh"
- " WHERE recoup_refresh_uuid > $1"
- " ORDER BY recoup_refresh_uuid ASC;");
- rh = &lrbt_cb_table_recoup_refresh;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
- XPREPARE ("select_above_serial_by_table_purse_requests",
- "SELECT"
- " purse_requests_serial_id"
- ",purse_pub"
- ",merge_pub"
- ",purse_creation"
- ",purse_expiration"
- ",h_contract_terms"
- ",age_limit"
- ",flags"
- ",amount_with_fee"
- ",purse_fee"
- ",purse_sig"
- " FROM purse_requests"
- " WHERE purse_requests_serial_id > $1"
- " ORDER BY purse_requests_serial_id ASC;");
- rh = &lrbt_cb_table_purse_requests;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DECISION:
- XPREPARE ("select_above_serial_by_table_purse_decision",
- "SELECT"
- " purse_decision_serial_id"
- ",purse_pub"
- ",action_timestamp"
- ",refunded"
- " FROM purse_decision"
- " WHERE purse_decision_serial_id > $1"
- " ORDER BY purse_decision_serial_id ASC;");
- rh = &lrbt_cb_table_purse_decision;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_MERGES:
- XPREPARE ("select_above_serial_by_table_purse_merges",
- "SELECT"
- " purse_merge_request_serial_id"
- ",partner_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",merge_sig"
- ",merge_timestamp"
- " FROM purse_merges"
- " WHERE purse_merge_request_serial_id > $1"
- " ORDER BY purse_merge_request_serial_id ASC;");
- rh = &lrbt_cb_table_purse_merges;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
- XPREPARE ("select_above_serial_by_table_purse_deposits",
- "SELECT"
- " purse_deposit_serial_id"
- ",partner_serial_id"
- ",purse_pub"
- ",coin_pub"
- ",amount_with_fee"
- ",coin_sig"
- " FROM purse_deposits"
- " WHERE purse_deposit_serial_id > $1"
- " ORDER BY purse_deposit_serial_id ASC;");
- rh = &lrbt_cb_table_purse_deposits;
- break;
- case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
- XPREPARE ("select_above_serial_by_table_account_merges",
- "SELECT"
- " account_merge_request_serial_id"
- ",reserve_pub"
- ",reserve_sig"
- ",purse_pub"
- ",wallet_h_payto"
- " FROM account_merges"
- " WHERE account_merge_request_serial_id > $1"
- " ORDER BY account_merge_request_serial_id ASC;");
- rh = &lrbt_cb_table_account_merges;
- break;
- case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
- XPREPARE ("select_above_serial_by_table_history_requests",
- "SELECT"
- " history_request_serial_id"
- ",reserve_pub"
- ",request_timestamp"
- ",reserve_sig"
- ",history_fee"
- " FROM history_requests"
- " WHERE history_request_serial_id > $1"
- " ORDER BY history_request_serial_id ASC;");
- rh = &lrbt_cb_table_history_requests;
- break;
- case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
- XPREPARE ("select_above_serial_by_table_close_requests",
- "SELECT"
- " close_request_serial_id"
- ",reserve_pub"
- ",close_timestamp"
- ",reserve_sig"
- ",close"
- " FROM close_requests"
- " WHERE close_request_serial_id > $1"
- " ORDER BY close_request_serial_id ASC;");
- rh = &lrbt_cb_table_close_requests;
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT:
- XPREPARE ("select_above_serial_by_table_wads_out",
- "SELECT"
- " wad_out_serial_id"
- ",wad_id"
- ",partner_serial_id"
- ",amount"
- ",execution_time"
- " FROM wads_out"
- " WHERE wad_out_serial_id > $1"
- " ORDER BY wad_out_serial_id ASC;");
- rh = &lrbt_cb_table_wads_out;
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
- XPREPARE ("select_above_serial_by_table_wads_out_entries",
- "SELECT"
- " wad_out_entry_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",h_contract"
- ",purse_expiration"
- ",merge_timestamp"
- ",amount_with_fee"
- ",wad_fee"
- ",deposit_fees"
- ",reserve_sig"
- ",purse_sig"
- " FROM wad_out_entries"
- " WHERE wad_out_entry_serial_id > $1"
- " ORDER BY wad_out_entry_serial_id ASC;");
- rh = &lrbt_cb_table_wads_out_entries;
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN:
- XPREPARE ("select_above_serial_by_table_wads_in",
- "SELECT"
- " wad_in_serial_id"
- ",wad_id"
- ",origin_exchange_url"
- ",amount"
- ",arrival_time"
- " FROM wads_in"
- " WHERE wad_in_serial_id > $1"
- " ORDER BY wad_in_serial_id ASC;");
- rh = &lrbt_cb_table_wads_in;
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
- XPREPARE ("select_above_serial_by_table_wads_in_entries",
- "SELECT"
- " wad_in_entry_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",h_contract"
- ",purse_expiration"
- ",merge_timestamp"
- ",amount_with_fee"
- ",wad_fee"
- ",deposit_fees"
- ",reserve_sig"
- ",purse_sig"
- " FROM wad_in_entries"
- " WHERE wad_in_entry_serial_id > $1"
- " ORDER BY wad_in_entry_serial_id ASC;");
- rh = &lrbt_cb_table_wads_in_entries;
- break;
- case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
- XPREPARE ("select_above_serial_by_table_profit_drains",
- "SELECT"
- " profit_drain_serial_id"
- ",wtid"
- ",account_section"
- ",payto_uri"
- ",trigger_date"
- ",amount"
- ",master_sig"
- " FROM profit_drains"
- " WHERE profit_drain_serial_id > $1"
- " ORDER BY profit_drain_serial_id ASC;");
- rh = &lrbt_cb_table_profit_drains;
- break;
-
- case TALER_EXCHANGEDB_RT_AML_STAFF:
- XPREPARE ("select_above_serial_by_table_aml_staff",
- "SELECT"
- " aml_staff_uuid"
- ",decider_pub"
- ",master_sig"
- ",decider_name"
- ",is_active"
- ",read_only"
- ",last_change"
- " FROM aml_staff"
- " WHERE aml_staff_uuid > $1"
- " ORDER BY aml_staff_uuid ASC;");
- rh = &lrbt_cb_table_aml_staff;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DELETION:
- XPREPARE ("select_above_serial_by_table_purse_deletion",
- "SELECT"
- " purse_deletion_serial_id"
- ",purse_pub"
- ",purse_sig"
- " FROM purse_deletion"
- " WHERE purse_deletion_serial_id > $1"
- " ORDER BY purse_deletion_serial_id ASC;");
- rh = &lrbt_cb_table_purse_deletion;
- break;
- case TALER_EXCHANGEDB_RT_WITHDRAW:
- XPREPARE ("select_above_serial_by_table_withdraw",
- "SELECT"
- " withdraw_id"
- ",planchets_h"
- ",execution_date"
- ",amount_with_fee"
- ",reserve_pub"
- ",reserve_sig"
- ",max_age"
- ",noreveal_index"
- ",selected_h"
- ",blinding_seed"
- ",cs_r_values"
- ",cs_r_choices"
- ",denom_serials"
- ",denom_sigs"
- " FROM withdraw"
- " WHERE withdraw_id > $1"
- " ORDER BY withdraw_id ASC;");
- rh = &lrbt_cb_table_withdraw;
- break;
- case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES:
- XPREPARE ("select_above_serial_by_table_legitimization_measures",
- "SELECT"
- " legitimization_measure_serial_id AS serial"
- ",access_token"
- ",start_time"
- ",jmeasures::TEXT"
- ",display_priority"
- " FROM legitimization_measures"
- " WHERE legitimization_measure_serial_id > $1"
- " ORDER BY legitimization_measure_serial_id ASC;");
- rh = &lrbt_cb_table_legitimization_measures;
- break;
- case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES:
- XPREPARE ("select_above_serial_by_table_legitimization_outcomes",
- "SELECT"
- " outcome_serial_id AS serial"
- ",h_payto"
- ",decision_time"
- ",expiration_time"
- ",jproperties::TEXT"
- ",to_investigate"
- ",jnew_rules::TEXT"
- " FROM legitimization_outcomes"
- " WHERE outcome_serial_id > $1"
- " ORDER BY outcome_serial_id ASC;");
- rh = &lrbt_cb_table_legitimization_outcomes;
- break;
- case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
- XPREPARE ("select_above_serial_by_table_legitimization_processes",
- "SELECT"
- " legitimization_process_serial_id AS serial"
- ",h_payto"
- ",start_time"
- ",expiration_time"
- ",legitimization_measure_serial_id"
- ",measure_index"
- ",provider_name"
- ",provider_user_id"
- ",provider_legitimization_id"
- ",redirect_url"
- " FROM legitimization_processes"
- " WHERE legitimization_process_serial_id > $1"
- " ORDER BY legitimization_process_serial_id ASC;");
- rh = &lrbt_cb_table_legitimization_processes;
- break;
- case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
- XPREPARE ("select_above_serial_by_table_kyc_attributes",
- "SELECT"
- " kyc_attributes_serial_id"
- ",h_payto"
- ",legitimization_serial"
- ",collection_time"
- ",expiration_time"
- ",trigger_outcome_serial"
- ",encrypted_attributes"
- " FROM kyc_attributes"
- " WHERE kyc_attributes_serial_id > $1"
- " ORDER BY kyc_attributes_serial_id ASC;");
- rh = &lrbt_cb_table_kyc_attributes;
- break;
- case TALER_EXCHANGEDB_RT_AML_HISTORY:
- XPREPARE ("select_above_serial_by_table_aml_history",
- "SELECT"
- " aml_history_serial_id"
- ",h_payto"
- ",outcome_serial_id"
- ",justification"
- ",decider_pub"
- ",decider_sig"
- " FROM aml_history"
- " WHERE aml_history_serial_id > $1"
- " ORDER BY aml_history_serial_id ASC;");
- rh = &lrbt_cb_table_aml_history;
- break;
- case TALER_EXCHANGEDB_RT_KYC_EVENTS:
- XPREPARE ("select_above_serial_by_table_kyc_events",
- "SELECT"
- " kyc_event_serial_id AS serial"
- ",event_timestamp"
- ",event_type"
- " FROM kyc_events"
- " WHERE kyc_event_serial_id > $1"
- " ORDER BY kyc_event_serial_id ASC;");
- rh = &lrbt_cb_table_kyc_events;
- break;
- }
- if (NULL == rh)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- statement,
- params,
- rh,
- &ctx);
- if (qs < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `%s'\n",
- statement);
- return qs;
- }
- if (ctx.error)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return qs;
-}
-
-
-#undef XPREPARE
-
-/* end of lookup_records_by_table.c */
diff --git a/src/exchangedb/lookup_rules_by_access_token.c b/src/exchangedb/lookup_rules_by_access_token.c
@@ -1,66 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_rules_by_access_token.c
- * @brief Implementation of the lookup_rules_by_access_token function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_rules_by_access_token.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_rules_by_access_token (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- json_t **jnew_rules,
- uint64_t *rowid)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json (
- "jnew_rules",
- jnew_rules),
- NULL),
- GNUNET_PQ_result_spec_uint64 (
- "row_id",
- rowid),
- GNUNET_PQ_result_spec_end
- };
-
- *jnew_rules = NULL;
- PREPARE (pg,
- "lookup_rules_by_access_token",
- "SELECT"
- " jnew_rules::TEXT"
- ",outcome_serial_id AS row_id"
- " FROM legitimization_outcomes"
- " WHERE h_payto=$1"
- " AND is_active"
- " ORDER BY expiration_time DESC,"
- " outcome_serial_id DESC"
- " LIMIT 1;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "lookup_rules_by_access_token",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_serial_by_table.c b/src/exchangedb/lookup_serial_by_table.c
@@ -1,441 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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 lookup_serial_by_table.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_serial_by_table.h"
-#include "helper.h"
-
-
-/**
- * Assign statement to @a n and PREPARE
- * @a sql under name @a n.
- */
-#define XPREPARE(n,sql) \
- statement = n; \
- PREPARE (pg, n, sql);
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_serial_by_table (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- enum TALER_EXCHANGEDB_ReplicatedTable
- table,
- uint64_t *serial)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- serial),
- GNUNET_PQ_result_spec_end
- };
- const char *statement = NULL;
-
- switch (table)
- {
- case TALER_EXCHANGEDB_RT_DENOMINATIONS:
- XPREPARE ("select_serial_by_table_denominations",
- "SELECT"
- " denominations_serial AS serial"
- " FROM denominations"
- " ORDER BY denominations_serial DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
- XPREPARE ("select_serial_by_table_denomination_revocations",
- "SELECT"
- " denom_revocations_serial_id AS serial"
- " FROM denomination_revocations"
- " ORDER BY denom_revocations_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
- XPREPARE ("select_serial_by_table_wire_targets",
- "SELECT"
- " wire_target_serial_id AS serial"
- " FROM wire_targets"
- " ORDER BY wire_target_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_KYC_TARGETS:
- XPREPARE ("select_serial_by_table_kyc_targets",
- "SELECT"
- " kyc_target_serial_id AS serial"
- " FROM kyc_targets"
- " ORDER BY kyc_target_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RESERVES:
- XPREPARE ("select_serial_by_table_reserves",
- "SELECT"
- " reserve_uuid AS serial"
- " FROM reserves"
- " ORDER BY reserve_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_IN:
- XPREPARE ("select_serial_by_table_reserves_in",
- "SELECT"
- " reserve_in_serial_id AS serial"
- " FROM reserves_in"
- " ORDER BY reserve_in_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
- XPREPARE ("select_serial_by_table_kycauths_in",
- "SELECT"
- " kycauth_in_serial_id AS serial"
- " FROM kycauths_in"
- " ORDER BY kycauth_in_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
- XPREPARE ("select_serial_by_table_reserves_close",
- "SELECT"
- " close_uuid AS serial"
- " FROM reserves_close"
- " ORDER BY close_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
- XPREPARE ("select_serial_by_table_reserves_open_requests",
- "SELECT"
- " open_request_uuid AS serial"
- " FROM reserves_open_requests"
- " ORDER BY open_request_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
- XPREPARE ("select_serial_by_table_reserves_open_deposits",
- "SELECT"
- " reserve_open_deposit_uuid AS serial"
- " FROM reserves_open_deposits"
- " ORDER BY reserve_open_deposit_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_AUDITORS:
- XPREPARE ("select_serial_by_table_auditors",
- "SELECT"
- " auditor_uuid AS serial"
- " FROM auditors"
- " ORDER BY auditor_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
- XPREPARE ("select_serial_by_table_auditor_denom_sigs",
- "SELECT"
- " auditor_denom_serial AS serial"
- " FROM auditor_denom_sigs"
- " ORDER BY auditor_denom_serial DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
- XPREPARE ("select_serial_by_table_exchange_sign_keys",
- "SELECT"
- " esk_serial AS serial"
- " FROM exchange_sign_keys"
- " ORDER BY esk_serial DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
- XPREPARE ("select_serial_by_table_signkey_revocations",
- "SELECT"
- " signkey_revocations_serial_id AS serial"
- " FROM signkey_revocations"
- " ORDER BY signkey_revocations_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_KNOWN_COINS:
- XPREPARE ("select_serial_by_table_known_coins",
- "SELECT"
- " known_coin_id AS serial"
- " FROM known_coins"
- " ORDER BY known_coin_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_REFRESH:
- XPREPARE ("select_serial_by_table_refresh",
- "SELECT"
- " refresh_id AS serial"
- " FROM refresh"
- " ORDER BY refresh_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
- XPREPARE ("select_serial_by_table_batch_deposits",
- "SELECT"
- " batch_deposit_serial_id AS serial"
- " FROM batch_deposits"
- " ORDER BY batch_deposit_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
- XPREPARE ("select_serial_by_table_coin_deposits",
- "SELECT"
- " coin_deposit_serial_id AS serial"
- " FROM coin_deposits"
- " ORDER BY coin_deposit_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_REFUNDS:
- XPREPARE ("select_serial_by_table_refunds",
- "SELECT"
- " refund_serial_id AS serial"
- " FROM refunds"
- " ORDER BY refund_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WIRE_OUT:
- XPREPARE ("select_serial_by_table_wire_out",
- "SELECT"
- " wireout_uuid AS serial"
- " FROM wire_out"
- " ORDER BY wireout_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
- XPREPARE ("select_serial_by_table_aggregation_tracking",
- "SELECT"
- " aggregation_serial_id AS serial"
- " FROM aggregation_tracking"
- " ORDER BY aggregation_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WIRE_FEE:
- XPREPARE ("select_serial_by_table_wire_fee",
- "SELECT"
- " wire_fee_serial AS serial"
- " FROM wire_fee"
- " ORDER BY wire_fee_serial DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
- XPREPARE ("select_serial_by_table_global_fee",
- "SELECT"
- " global_fee_serial AS serial"
- " FROM global_fee"
- " ORDER BY global_fee_serial DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RECOUP:
- XPREPARE ("select_serial_by_table_recoup",
- "SELECT"
- " recoup_uuid AS serial"
- " FROM recoup"
- " ORDER BY recoup_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
- XPREPARE ("select_serial_by_table_recoup_refresh",
- "SELECT"
- " recoup_refresh_uuid AS serial"
- " FROM recoup_refresh"
- " ORDER BY recoup_refresh_uuid DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
- XPREPARE ("select_serial_by_table_purse_requests",
- "SELECT"
- " purse_requests_serial_id AS serial"
- " FROM purse_requests"
- " ORDER BY purse_requests_serial_id DESC"
- " LIMIT 1;")
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DECISION:
- XPREPARE ("select_serial_by_table_purse_decision",
- "SELECT"
- " purse_decision_serial_id AS serial"
- " FROM purse_decision"
- " ORDER BY purse_decision_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_PURSE_MERGES:
- XPREPARE ("select_serial_by_table_purse_merges",
- "SELECT"
- " purse_merge_request_serial_id AS serial"
- " FROM purse_merges"
- " ORDER BY purse_merge_request_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
- XPREPARE ("select_serial_by_table_purse_deposits",
- "SELECT"
- " purse_deposit_serial_id AS serial"
- " FROM purse_deposits"
- " ORDER BY purse_deposit_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
- XPREPARE ("select_serial_by_table_account_merges",
- "SELECT"
- " account_merge_request_serial_id AS serial"
- " FROM account_merges"
- " ORDER BY account_merge_request_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
- XPREPARE ("select_serial_by_table_history_requests",
- "SELECT"
- " history_request_serial_id AS serial"
- " FROM history_requests"
- " ORDER BY history_request_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
- XPREPARE ("select_serial_by_table_close_requests",
- "SELECT"
- " close_request_serial_id AS serial"
- " FROM close_requests"
- " ORDER BY close_request_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT:
- XPREPARE ("select_serial_by_table_wads_out",
- "SELECT"
- " wad_out_serial_id AS serial"
- " FROM wads_out"
- " ORDER BY wad_out_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
- XPREPARE ("select_serial_by_table_wads_out_entries",
- "SELECT"
- " wad_out_entry_serial_id AS serial"
- " FROM wad_out_entries"
- " ORDER BY wad_out_entry_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN:
- XPREPARE ("select_serial_by_table_wads_in",
- "SELECT"
- " wad_in_serial_id AS serial"
- " FROM wads_in"
- " ORDER BY wad_in_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
- XPREPARE ("select_serial_by_table_wads_in_entries",
- "SELECT"
- " wad_in_entry_serial_id AS serial"
- " FROM wad_in_entries"
- " ORDER BY wad_in_entry_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
- XPREPARE ("select_serial_by_table_profit_drains",
- "SELECT"
- " profit_drain_serial_id AS serial"
- " FROM profit_drains"
- " ORDER BY profit_drain_serial_id DESC"
- " LIMIT 1;");
- statement = "select_serial_by_table_profit_drains";
- break;
- case TALER_EXCHANGEDB_RT_AML_STAFF:
- XPREPARE ("select_serial_by_table_aml_staff",
- "SELECT"
- " aml_staff_uuid AS serial"
- " FROM aml_staff"
- " ORDER BY aml_staff_uuid DESC"
- " LIMIT 1;");
- statement = "select_serial_by_table_aml_staff";
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DELETION:
- XPREPARE ("select_serial_by_table_purse_deletion",
- "SELECT"
- " purse_deletion_serial_id AS serial"
- " FROM purse_deletion"
- " ORDER BY purse_deletion_serial_id DESC"
- " LIMIT 1;");
- statement = "select_serial_by_table_purse_deletion";
- break;
- case TALER_EXCHANGEDB_RT_WITHDRAW:
- XPREPARE ("select_serial_by_table_withdraw",
- "SELECT"
- " withdraw_id AS serial"
- " FROM withdraw"
- " ORDER BY withdraw_id DESC"
- " LIMIT 1;");
- statement = "select_serial_by_table_withdraw";
- break;
- case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES:
- XPREPARE ("select_serial_by_table_legitimization_measures",
- "SELECT"
- " legitimization_measure_serial_id AS serial"
- " FROM legitimization_measures"
- " ORDER BY legitimization_measure_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES:
- XPREPARE ("select_serial_by_table_legitimization_outcomes",
- "SELECT"
- " outcome_serial_id AS serial"
- " FROM legitimization_outcomes"
- " ORDER BY outcome_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
- XPREPARE ("select_serial_by_table_legitimization_processes",
- "SELECT"
- " legitimization_process_serial_id AS serial"
- " FROM legitimization_processes"
- " ORDER BY legitimization_process_serial_id DESC"
- " LIMIT 1;");
- break;
- case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
- XPREPARE ("select_serial_by_table_kyc_attributes",
- "SELECT"
- " kyc_attributes_serial_id AS serial"
- " FROM kyc_attributes"
- " ORDER BY kyc_attributes_serial_id DESC"
- " LIMIT 1;");
- statement = "select_serial_by_table_kyc_attributes";
- break;
- case TALER_EXCHANGEDB_RT_AML_HISTORY:
- XPREPARE ("select_serial_by_table_aml_history",
- "SELECT"
- " aml_history_serial_id AS serial"
- " FROM aml_history"
- " ORDER BY aml_history_serial_id DESC"
- " LIMIT 1;");
- statement = "select_serial_by_table_aml_history";
- break;
- case TALER_EXCHANGEDB_RT_KYC_EVENTS:
- XPREPARE ("select_serial_by_table_kyc_events",
- "SELECT"
- " kyc_event_serial_id AS serial"
- " FROM kyc_events"
- " ORDER BY kyc_event_serial_id DESC"
- " LIMIT 1;");
- break;
- }
- if (NULL == statement)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- statement,
- params,
- rs);
-}
-
-
-#undef XPREPARE
diff --git a/src/exchangedb/lookup_signing_key.c b/src/exchangedb/lookup_signing_key.c
@@ -1,60 +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 exchangedb/lookup_signing_key.c
- * @brief Implementation of the lookup_signing_key function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_signing_key.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_signing_key (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- struct TALER_EXCHANGEDB_SignkeyMetaData *meta)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &meta->start),
- GNUNET_PQ_result_spec_timestamp ("expire_sign",
- &meta->expire_sign),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &meta->expire_legal),
- GNUNET_PQ_result_spec_end
- };
-
-
- PREPARE (pg,
- "lookup_signing_key",
- "SELECT"
- " valid_from"
- ",expire_sign"
- ",expire_legal"
- " FROM exchange_sign_keys"
- " WHERE exchange_pub=$1");
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_signing_key",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_signkey_revocation.c b/src/exchangedb/lookup_signkey_revocation.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 exchangedb/lookup_signkey_revocation.c
- * @brief Implementation of the lookup_signkey_revocation function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_signkey_revocation.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_signkey_revocation (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- struct TALER_MasterSignatureP *master_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_signkey_revocation",
- "SELECT "
- " master_sig"
- " FROM signkey_revocations"
- " WHERE esk_serial="
- " (SELECT esk_serial"
- " FROM exchange_sign_keys"
- " WHERE exchange_pub=$1);");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_signkey_revocation",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_transfer_by_deposit.c b/src/exchangedb/lookup_transfer_by_deposit.c
@@ -1,220 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_transfer_by_deposit.c
- * @brief Implementation of the lookup_transfer_by_deposit function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_transfer_by_deposit.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_transfer_by_deposit (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- bool *pending,
- struct TALER_WireTransferIdentifierRawP *wtid,
- struct GNUNET_TIME_Timestamp *exec_time,
- struct TALER_Amount *amount_with_fee,
- struct TALER_Amount *deposit_fee,
- struct TALER_EXCHANGEDB_KycStatus *kyc,
- union TALER_AccountPublicKeyP *account_pub)
-{
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_end
- };
- struct TALER_FullPayto payto_uri;
- struct TALER_WireSaltP wire_salt;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- wtid),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &wire_salt),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri.full_payto),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- exec_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- deposit_fee),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("target_pub",
- account_pub),
- NULL),
- GNUNET_PQ_result_spec_end
- };
-
- memset (kyc,
- 0,
- sizeof (*kyc));
- /* check if the aggregation record exists and get it */
- PREPARE (pg,
- "lookup_deposit_wtid",
- "SELECT"
- " atr.wtid_raw"
- ",wire_out.execution_date"
- ",cdep.amount_with_fee"
- ",bdep.wire_salt"
- ",wt.payto_uri"
- ",kt.target_pub"
- ",denom.fee_deposit"
- " FROM coin_deposits cdep"
- " JOIN batch_deposits bdep"
- " USING (batch_deposit_serial_id)"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- /* kyc_targets might not match; then target_pub will be NULL */
- " LEFT JOIN kyc_targets kt"
- " USING (h_normalized_payto)"
- " JOIN aggregation_tracking atr"
- " ON (cdep.batch_deposit_serial_id = atr.batch_deposit_serial_id)"
- " JOIN known_coins kc"
- " ON (kc.coin_pub = cdep.coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " JOIN wire_out"
- " USING (wtid_raw)"
- " WHERE cdep.coin_pub=$1"
- " AND bdep.merchant_pub=$3"
- " AND bdep.h_contract_terms=$2");
- /* NOTE: above query might be more efficient if we computed the shard
- from the merchant_pub and included that in the query */
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_deposit_wtid",
- params,
- rs);
- if (0 > qs)
- return qs;
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- {
- struct TALER_MerchantWireHashP wh;
-
- TALER_merchant_wire_signature_hash (payto_uri,
- &wire_salt,
- &wh);
- if (0 ==
- GNUNET_memcmp (&wh,
- h_wire))
- {
- *pending = false;
- kyc->ok = true;
- GNUNET_PQ_cleanup_result (rs);
- return qs;
- }
- qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- GNUNET_PQ_cleanup_result (rs);
- }
- *pending = true;
- memset (wtid,
- 0,
- sizeof (*wtid));
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "lookup_deposit_wtid returned 0 matching rows\n");
- {
- /* Check if transaction exists in deposits, so that we just
- do not have a WTID yet. In that case, return without wtid
- (by setting 'pending' true). */
- struct GNUNET_PQ_ResultSpec rs2[] = {
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &wire_salt),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri.full_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- deposit_fee),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- exec_time),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 ("legitimization_requirement_serial_id",
- &kyc->requirement_row),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("target_pub",
- account_pub),
- NULL),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "get_deposit_without_wtid",
- "SELECT"
- " bdep.wire_salt"
- ",wt.payto_uri"
- ",cdep.amount_with_fee"
- ",denom.fee_deposit"
- ",bdep.wire_deadline"
- ",agt.legitimization_requirement_serial_id"
- ",kt.target_pub"
- " FROM coin_deposits cdep"
- " JOIN batch_deposits bdep"
- " USING (batch_deposit_serial_id)"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- /* kyc_targets might not match; then target_pub will be NULL */
- " LEFT JOIN kyc_targets kt"
- " USING (h_normalized_payto)"
- " JOIN known_coins kc"
- " ON (kc.coin_pub = cdep.coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " LEFT JOIN aggregation_transient agt "
- " ON ( (bdep.wire_target_h_payto = agt.wire_target_h_payto) AND"
- " (bdep.merchant_pub = agt.merchant_pub) )"
- " WHERE cdep.coin_pub=$1"
- " AND bdep.merchant_pub=$3"
- " AND bdep.h_contract_terms=$2"
- " LIMIT 1;");
- /* NOTE: above query might be more efficient if we computed the shard
- from the merchant_pub and included that in the query */
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_deposit_without_wtid",
- params,
- rs2);
- if (0 > qs)
- return qs;
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- {
- struct TALER_MerchantWireHashP wh;
-
- TALER_merchant_wire_signature_hash (payto_uri,
- &wire_salt,
- &wh);
- if (0 !=
- GNUNET_memcmp (&wh,
- h_wire))
- {
- GNUNET_PQ_cleanup_result (rs2);
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- GNUNET_PQ_cleanup_result (rs2);
- if (0 == kyc->requirement_row)
- kyc->ok = true; /* technically: unknown */
- }
- return qs;
- }
-}
diff --git a/src/exchangedb/lookup_wire_fee_by_time.c b/src/exchangedb/lookup_wire_fee_by_time.c
@@ -1,152 +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 exchangedb/lookup_wire_fee_by_time.c
- * @brief Implementation of the lookup_wire_fee_by_time function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_wire_fee_by_time.h"
-#include "helper.h"
-
-
-/**
- * Closure for #wire_fee_by_time_helper()
- */
-struct WireFeeLookupContext
-{
-
- /**
- * Set to the wire fees. Set to invalid if fees conflict over
- * the given time period.
- */
- struct TALER_WireFeeSet *fees;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-};
-
-
-/**
- * Helper function for #TALER_EXCHANGEDB_lookup_wire_fee_by_time().
- * Calls the callback with the wire fee structure.
- *
- * @param cls a `struct WireFeeLookupContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-wire_fee_by_time_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireFeeLookupContext *wlc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = wlc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_WireFeeSet fs;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
- &fs.wire),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &fs.closing),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_WireFeeSet));
- return;
- }
- if (0 == i)
- {
- *wlc->fees = fs;
- continue;
- }
- if (0 !=
- TALER_wire_fee_set_cmp (&fs,
- wlc->fees))
- {
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_WireFeeSet));
- return;
- }
- }
-}
-
-
-/**
- * Lookup information about known wire fees. Finds all applicable
- * fees in the given range. If they are identical, returns the
- * respective @a fees. If any of the fees
- * differ between @a start_time and @a end_time, the transaction
- * succeeds BUT returns an invalid amount for both fees.
- *
- * @param pg the database context
- * @param wire_method the wire method to lookup fees for
- * @param start_time starting time of fee
- * @param end_time end time of fee
- * @param[out] fees wire fees for that time period; if
- * different fees exists within this time
- * period, an 'invalid' amount is returned.
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_wire_fee_by_time (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const char *wire_method,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- struct TALER_WireFeeSet *fees)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (wire_method),
- GNUNET_PQ_query_param_timestamp (&start_time),
- GNUNET_PQ_query_param_timestamp (&end_time),
- GNUNET_PQ_query_param_end
- };
- struct WireFeeLookupContext wlc = {
- .fees = fees,
- .pg = pg
- };
-
- PREPARE (pg,
- "lookup_wire_fee_by_time",
- "SELECT"
- " wire_fee"
- ",closing_fee"
- " FROM wire_fee"
- " WHERE wire_method=$1"
- " AND end_date > $2"
- " AND start_date < $3;");
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_wire_fee_by_time",
- params,
- &wire_fee_by_time_helper,
- &wlc);
-}
diff --git a/src/exchangedb/lookup_wire_timestamp.c b/src/exchangedb/lookup_wire_timestamp.c
@@ -1,52 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_wire_timestamp.c
- * @brief Implementation of the lookup_wire_timestamp function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_wire_timestamp.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_wire_timestamp (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPayto payto_uri,
- struct GNUNET_TIME_Timestamp *last_date)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (payto_uri.full_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("last_change",
- last_date),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_wire_timestamp",
- "SELECT"
- " last_change"
- " FROM wire_accounts"
- " WHERE payto_uri=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_wire_timestamp",
- params,
- rs);
-}
diff --git a/src/exchangedb/lookup_wire_transfer.c b/src/exchangedb/lookup_wire_transfer.c
@@ -1,184 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/lookup_wire_transfer.c
- * @brief Implementation of the lookup_wire_transfer function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/lookup_wire_transfer.h"
-#include "helper.h"
-
-/**
- * Closure for #handle_wt_result.
- */
-struct WireTransferResultContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AggregationDataCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_lookup_wire_transfer().
- *
- * @param cls closure of type `struct WireTransferResultContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_wt_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireTransferResultContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_PrivateContractHashP h_contract_terms;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_FullPaytoHashP h_payto;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct GNUNET_TIME_Timestamp exec_time;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount deposit_fee;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_FullPayto payto_uri;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &h_contract_terms),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri.full_payto),
- GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
- &h_payto),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &merchant_pub),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &exec_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &deposit_fee),
- 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,
- rowid,
- &merchant_pub,
- payto_uri,
- &h_payto,
- exec_time,
- &h_contract_terms,
- &denom_pub,
- &coin_pub,
- &amount_with_fee,
- &deposit_fee);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_wire_transfer (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- TALER_EXCHANGEDB_AggregationDataCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
- struct WireTransferResultContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "lookup_transactions",
- "SELECT"
- " aggregation_serial_id"
- ",bdep.h_contract_terms"
- ",payto_uri"
- ",wt.wire_target_h_payto"
- ",kc.coin_pub"
- ",bdep.merchant_pub"
- ",wire_out.execution_date"
- ",cdep.amount_with_fee"
- ",denom.fee_deposit"
- ",denom.denom_pub"
- " FROM aggregation_tracking"
- " JOIN batch_deposits bdep"
- " USING (batch_deposit_serial_id)"
- " JOIN coin_deposits cdep"
- " USING (batch_deposit_serial_id)"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " JOIN known_coins kc"
- " USING (coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " JOIN wire_out"
- " USING (wtid_raw)"
- " WHERE wtid_raw=$1;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_transactions",
- params,
- &handle_wt_result,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/mark_refresh_reveal_success.c b/src/exchangedb/mark_refresh_reveal_success.c
@@ -1,45 +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 exchangedb/mark_refresh_reveal_success.c
- * @brief Implementation of the mark_refresh_reveal_success function for Postgres
- * @author Özgür Kesim
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/mark_refresh_reveal_success.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_mark_refresh_reveal_success (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_RefreshCommitmentP *rc)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (rc),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "mark_refresh_reveal_success",
- "UPDATE refresh"
- " SET revealed=true"
- " WHERE rc = $1");
-
- return GNUNET_PQ_eval_prepared_non_select (
- pg->conn,
- "mark_refresh_reveal_success",
- params);
-}
diff --git a/src/exchangedb/meson.build b/src/exchangedb/meson.build
@@ -49,20 +49,19 @@ libtalerexchangedb = library(
'exchangedb_transactions.c',
'free_coin_transaction_list.c',
'free_reserve_history.c',
- 'persist_aml_program_result.c',
+ 'do_persist_aml_program_result.c',
'abort_shard.c',
- 'activate_signing_key.c',
- 'add_denomination_key.c',
- 'aggregate.c',
+ 'insert_signkey.c',
+ 'do_aggregate.c',
'begin_revolving_shard.c',
'begin_shard.c',
'pg.c',
- 'clear_aml_lock.c',
+ 'update_to_aml_unlocked.c',
'commit.c',
'complete_shard.c',
'compute_shard.c',
- 'count_known_coins.c',
- 'create_aggregation_transient.c',
+ 'get_count_known_coins.c',
+ 'insert_aggregation_transient.c',
'create_tables.c',
'delete_aggregation_transient.c',
'delete_shard_locks.c',
@@ -79,29 +78,29 @@ libtalerexchangedb = library(
'do_reserve_open.c',
'do_reserve_purse.c',
'do_withdraw.c',
- 'drain_kyc_alert.c',
+ 'do_drain_kyc_alert.c',
'drop_tables.c',
'enable_rules.c',
- 'ensure_coin_known.c',
+ 'do_insert_known_coin.c',
'event_listen.c',
'event_listen_cancel.c',
'event_notify.c',
- 'expire_purse.c',
- 'find_aggregation_transient.c',
+ 'do_expire_purse.c',
+ 'get_aggregation_transient_by_normalized_payto.c',
'gc.c',
'get_coin_denomination.c',
'get_coin_transactions.c',
'get_denomination_by_serial.c',
'get_denomination_info.c',
'get_denomination_revocation.c',
- 'get_drain_profit.c',
- 'get_expired_reserves.c',
+ 'get_profit_drain.c',
+ 'iterate_expired_reserves.c',
'get_global_fee.c',
- 'get_global_fees.c',
+ 'iterate_global_fees.c',
'get_known_coin.c',
'get_kyc_rules.c',
'get_old_coin_by_h_blind.c',
- 'get_pending_kyc_requirement_process.c',
+ 'get_pending_legitimization_process.c',
'get_purse_deposit.c',
'get_purse_request.c',
'get_ready_deposit.c',
@@ -110,13 +109,13 @@ libtalerexchangedb = library(
'get_reserve_by_h_planchets.c',
'get_reserve_history.c',
'get_signature_for_known_coin.c',
- 'get_unfinished_close_requests.c',
- 'get_wire_accounts.c',
+ 'iterate_unfinished_close_requests.c',
+ 'iterate_wire_accounts.c',
'get_wire_fee.c',
- 'get_wire_fees.c',
+ 'iterate_wire_fees.c',
'get_wire_hash_for_contract.c',
'get_withdraw.c',
- 'have_deposit2.c',
+ 'get_exists_deposit.c',
'inject_auditor_triggers.c',
'insert_active_legitimization_measure.c',
'insert_aml_decision.c',
@@ -128,10 +127,10 @@ libtalerexchangedb = library(
'insert_contract.c',
'insert_denomination_info.c',
'insert_denomination_revocation.c',
- 'insert_drain_profit.c',
+ 'insert_profit_drain.c',
'insert_global_fee.c',
'insert_kyc_failure.c',
- 'insert_kyc_requirement_process.c',
+ 'insert_legitimization_process.c',
'insert_partner.c',
'insert_purse_request.c',
'insert_records_by_table.c',
@@ -148,112 +147,112 @@ libtalerexchangedb = library(
'iterate_auditor_denominations.c',
'iterate_denomination_info.c',
'iterate_denominations.c',
- 'iterate_kyc_reference.c',
+ 'iterate_kyc_references.c',
'iterate_reserve_close_info.c',
- 'kycauth_in_insert.c',
- 'kyc_provider_account_lookup.c',
- 'lookup_active_legitimization.c',
- 'lookup_aml_file_number.c',
- 'lookup_aml_history.c',
- 'lookup_aml_officer.c',
- 'lookup_auditor_status.c',
- 'lookup_auditor_timestamp.c',
- 'lookup_completed_legitimization.c',
- 'lookup_denomination_key.c',
- 'lookup_global_fee_by_time.c',
- 'lookup_h_payto_by_access_token.c',
- 'lookup_kyc_history.c',
- 'lookup_kyc_process_by_account.c',
- 'lookup_kyc_requirement_by_row.c',
- 'lookup_kyc_status_by_token.c',
- 'lookup_pending_legitimization.c',
- 'lookup_records_by_table.c',
- 'lookup_rules_by_access_token.c',
- 'lookup_serial_by_table.c',
- 'lookup_signing_key.c',
- 'lookup_signkey_revocation.c',
- 'lookup_transfer_by_deposit.c',
- 'lookup_wire_fee_by_time.c',
- 'lookup_wire_timestamp.c',
- 'lookup_wire_transfer.c',
- 'mark_refresh_reveal_success.c',
- 'persist_kyc_attributes.c',
+ 'insert_kycauth_in.c',
+ 'get_kyc_provider_account.c',
+ 'get_active_legitimization.c',
+ 'get_aml_file_number.c',
+ 'iterate_aml_history.c',
+ 'get_aml_officer.c',
+ 'get_auditor_status.c',
+ 'get_auditor_timestamp.c',
+ 'get_completed_legitimization.c',
+ 'get_denomination_meta.c',
+ 'get_global_fee_by_time.c',
+ 'get_h_payto_by_access_token.c',
+ 'iterate_kyc_history.c',
+ 'get_legitimization_process_by_account.c',
+ 'get_legitimization_requirement_by_row.c',
+ 'get_kyc_status_by_token.c',
+ 'get_pending_legitimization.c',
+ 'iterate_records_by_table.c',
+ 'get_rules_by_access_token.c',
+ 'get_serial_by_table.c',
+ 'get_signkey.c',
+ 'get_signkey_revocation.c',
+ 'get_transfer_by_deposit.c',
+ 'get_wire_fee_by_time.c',
+ 'get_wire_timestamp.c',
+ 'iterate_wire_transfers.c',
+ 'update_to_refresh_revealed.c',
+ 'do_insert_kyc_attributes.c',
'preflight.c',
- 'profit_drains_get_pending.c',
- 'profit_drains_set_finished.c',
+ 'get_pending_profit_drain.c',
+ 'update_to_profit_drain_finished.c',
'release_revolving_shard.c',
- 'reserves_get.c',
- 'reserves_get_origin.c',
- 'reserves_in_insert.c',
- 'reserves_update.c',
+ 'get_reserve.c',
+ 'get_reserve_origin.c',
+ 'do_insert_reserve_in.c',
+ 'update_reserve.c',
'rollback.c',
- 'select_account_merges_above_serial_id.c',
- 'select_aggregation_amounts_for_kyc_check.c',
- 'select_aggregations_above_serial.c',
- 'select_aggregation_transient.c',
- 'select_all_kyc_attributes.c',
- 'select_all_purse_decisions_above_serial_id.c',
- 'select_all_purse_deletions_above_serial_id.c',
- 'select_aml_attributes.c',
- 'select_aml_decisions.c',
- 'select_aml_measures.c',
- 'select_aml_statistics.c',
- 'select_auditor_denom_sig.c',
- 'select_batch_deposits_missing_wire.c',
- 'select_coin_deposits_above_serial_id.c',
- 'select_contract_by_purse.c',
- 'select_contract.c',
- 'select_deposit_amounts_for_kyc_check.c',
- 'select_exchange_credit_transfers.c',
- 'select_exchange_debit_transfers.c',
- 'select_exchange_kycauth_transfers.c',
- 'select_kyc_accounts.c',
- 'select_kyc_attributes.c',
- 'select_merge_amounts_for_kyc_check.c',
- 'select_purse_by_merge_pub.c',
- 'select_purse.c',
- 'select_purse_decisions_above_serial_id.c',
- 'select_purse_deposits_above_serial_id.c',
- 'select_purse_deposits_by_purse.c',
- 'select_purse_merge.c',
- 'select_purse_merges_above_serial_id.c',
- 'select_purse_requests_above_serial_id.c',
- 'select_recoup_above_serial_id.c',
- 'select_recoup_refresh_above_serial_id.c',
- 'select_refreshes_above_serial_id.c',
- 'select_refunds_above_serial_id.c',
- 'select_refunds_by_coin.c',
- 'select_reserve_closed_above_serial_id.c',
- 'select_reserve_close_info.c',
- 'select_reserve_close_request_info.c',
- 'select_reserve_open_above_serial_id.c',
- 'select_reserves_in_above_serial_id_by_account.c',
- 'select_reserves_in_above_serial_id.c',
- 'select_wallet_merges.c',
- 'select_wire_out_above_serial_id_by_account.c',
- 'select_wire_out_above_serial_id.c',
- 'select_withdrawals_above_serial_id.c',
- 'select_withdraw_amounts_for_kyc_check.c',
- 'set_aml_lock.c',
- 'set_purse_balance.c',
+ 'iterate_account_merges_above_serial_id.c',
+ 'iterate_aggregation_amounts_for_kyc_check.c',
+ 'iterate_aggregations_above_serial_id.c',
+ 'get_aggregation_transient.c',
+ 'iterate_all_kyc_attributes.c',
+ 'iterate_all_purse_decisions_above_serial_id.c',
+ 'iterate_all_purse_deletions_above_serial_id.c',
+ 'iterate_aml_attributes.c',
+ 'iterate_aml_decisions.c',
+ 'iterate_aml_measures.c',
+ 'iterate_aml_statistics.c',
+ 'get_auditor_denom_sig.c',
+ 'iterate_batch_deposits_missing_wire.c',
+ 'iterate_coin_deposits_above_serial_id.c',
+ 'get_contract_by_purse.c',
+ 'get_contract.c',
+ 'iterate_deposit_amounts_for_kyc_check.c',
+ 'iterate_exchange_credit_transfers.c',
+ 'iterate_exchange_debit_transfers.c',
+ 'iterate_exchange_kycauth_transfers.c',
+ 'iterate_kyc_accounts.c',
+ 'iterate_kyc_attributes.c',
+ 'iterate_merge_amounts_for_kyc_check.c',
+ 'get_purse_by_merge_pub.c',
+ 'get_purse.c',
+ 'iterate_purse_decisions_above_serial_id.c',
+ 'iterate_purse_deposits_above_serial_id.c',
+ 'iterate_purse_deposits_by_purse.c',
+ 'get_purse_merge.c',
+ 'iterate_purse_merges_above_serial_id.c',
+ 'iterate_purse_requests_above_serial_id.c',
+ 'iterate_recoups_above_serial_id.c',
+ 'iterate_recoup_refreshes_above_serial_id.c',
+ 'iterate_refreshes_above_serial_id.c',
+ 'iterate_refunds_above_serial_id.c',
+ 'iterate_refunds_by_coin.c',
+ 'iterate_reserve_closed_above_serial_id.c',
+ 'get_reserve_close_info.c',
+ 'get_reserve_close_request_info.c',
+ 'iterate_reserve_open_above_serial_id.c',
+ 'iterate_reserves_in_above_serial_id_by_account.c',
+ 'iterate_reserves_in_above_serial_id.c',
+ 'iterate_wallet_merges.c',
+ 'iterate_wire_outs_above_serial_id_by_account.c',
+ 'iterate_wire_outs_above_serial_id.c',
+ 'iterate_withdrawals_above_serial_id.c',
+ 'iterate_withdraw_amounts_for_kyc_check.c',
+ 'update_to_aml_locked.c',
+ 'update_purse_balance.c',
'start.c',
'start_deferred_wire_out.c',
'start_read_committed.c',
'start_read_only.c',
- 'store_wire_transfer_out.c',
+ 'insert_wire_out.c',
'template.c',
- 'test_aml_officer.c',
- 'trigger_kyc_rule_for_account.c',
+ 'get_exists_aml_officer.c',
+ 'do_trigger_kyc_rule_for_account.c',
'update_aggregation_transient.c',
'update_auditor.c',
- 'update_kyc_process_by_row.c',
+ 'update_legitimization_process_by_row.c',
'update_wire.c',
- 'wad_in_insert.c',
- 'wire_prepare_data_get.c',
- 'wire_prepare_data_insert.c',
- 'wire_prepare_data_mark_failed.c',
- 'wire_prepare_data_mark_finished.c',
- 'update_rules.c',
+ 'insert_wad_in.c',
+ 'iterate_prewires.c',
+ 'insert_prewire.c',
+ 'update_to_prewire_failed.c',
+ 'update_to_prewire_finished.c',
+ 'begin_rule_update.c',
],
soversion: solibversions['libtalerexchangedb']['soversion'],
version: solibversions['libtalerexchangedb']['soversion'],
diff --git a/src/exchangedb/persist_aml_program_result.c b/src/exchangedb/persist_aml_program_result.c
@@ -1,154 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2023, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file persist_aml_program_result.c
- * @brief helper function store results of AML programs
- * @author Christian Grothoff
- */
-#include "exchangedb_lib.h"
-#include "taler/taler_kyclogic_lib.h"
-#include "exchange-database/insert_aml_decision.h"
-#include "exchange-database/insert_aml_program_failure.h"
-#include "exchange-database/insert_successor_measure.h"
-#include "exchange-database/persist_aml_program_result.h"
-#include "helper.h"
-#include <gnunet/gnunet_common.h>
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_persist_aml_program_result (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t process_row,
- const struct TALER_NormalizedPaytoHashP *account_id,
- const struct TALER_KYCLOGIC_AmlProgramResult *apr,
- enum TALER_EXCHANGEDB_PersistProgramResultStatus *ret_pprs)
-{
- enum GNUNET_DB_QueryStatus qs;
- json_t *jmeasures = NULL;
- struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs = NULL;
-
- GNUNET_assert (NULL != ret_pprs);
-
- *ret_pprs = TALER_EXCHANGEDB_PPRS_OK;
-
- if ( (TALER_KYCLOGIC_AMLR_SUCCESS == apr->status) &&
- (NULL != apr->details.success.new_measures) )
- {
- lrs = TALER_KYCLOGIC_rules_parse (apr->details.success.new_rules);
- if (NULL == lrs)
- {
- qs = TALER_EXCHANGEDB_insert_aml_program_failure (
- pg,
- process_row,
- account_id,
- "Failed to parse AML program output",
- TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT);
- GNUNET_break (qs > 0);
- return qs;
- }
- jmeasures = TALER_KYCLOGIC_get_jmeasures (
- lrs,
- apr->details.success.new_measures);
- if (NULL == jmeasures)
- {
- char *err;
-
- GNUNET_break (0);
- GNUNET_asprintf (&err,
- "Failed to find measures `%s' specified in AML program output",
- apr->details.success.new_measures);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "AML program specified invalid measures `%s'\n",
- apr->details.success.new_measures);
- qs = TALER_EXCHANGEDB_insert_aml_program_failure (
- pg,
- process_row,
- account_id,
- err,
- TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT);
- *ret_pprs = TALER_EXCHANGEDB_PPRS_BAD_OUTCOME;
- TALER_KYCLOGIC_rules_free (lrs);
- GNUNET_free (err);
- GNUNET_break (qs > 0);
- return qs;
- }
- }
-
- qs = TALER_EXCHANGEDB_clear_aml_lock (
- pg,
- account_id);
- if (qs < 0)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- switch (apr->status)
- {
- case TALER_KYCLOGIC_AMLR_FAILURE:
- qs = TALER_EXCHANGEDB_insert_aml_program_failure (
- pg,
- process_row,
- account_id,
- apr->details.failure.error_message,
- apr->details.failure.ec);
- GNUNET_break (qs > 0);
- goto cleanup;
- case TALER_KYCLOGIC_AMLR_SUCCESS:
- {
- struct TALER_FullPayto null_payto_uri = { 0 };
- bool invalid_officer;
- bool unknown_account;
- struct GNUNET_TIME_Timestamp last_date;
- uint64_t legitimization_measure_serial_id;
- bool is_wallet;
-
- qs = TALER_EXCHANGEDB_insert_aml_decision (
- pg,
- null_payto_uri,
- account_id,
- GNUNET_TIME_timestamp_get (),
- apr->details.success.expiration_time,
- apr->details.success.account_properties,
- apr->details.success.new_rules,
- apr->details.success.to_investigate,
- apr->details.success.new_measures,
- jmeasures,
- NULL, /* justification */
- NULL, /* decider_pub */
- NULL, /* decider_sig */
- apr->details.success.num_events,
- apr->details.success.events,
- NULL, /* form ID */
- 0, /* enc_attributes_size*/
- NULL, /* enc_attributes*/
- NULL, /* attributes_hash */
- GNUNET_TIME_UNIT_ZERO_TS, /* attributes_expiration_time */
- &invalid_officer,
- &unknown_account,
- &last_date,
- &legitimization_measure_serial_id,
- &is_wallet);
- GNUNET_break (qs > 0);
- goto cleanup;
- }
- }
- GNUNET_break (0);
- qs = GNUNET_DB_STATUS_HARD_ERROR;
-cleanup:
- TALER_KYCLOGIC_rules_free (lrs);
- json_decref (jmeasures);
- return qs;
-}
diff --git a/src/exchangedb/persist_kyc_attributes.c b/src/exchangedb/persist_kyc_attributes.c
@@ -1,103 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/persist_kyc_attributes.c
- * @brief Implementation of the persist_kyc_attributes function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/persist_kyc_attributes.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_persist_kyc_attributes (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t process_row,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_name,
- const char *provider_account_id,
- const char *provider_legitimization_id,
- uint32_t birthday,
- struct GNUNET_TIME_Absolute expiration_time,
- const char *form_name,
- size_t enc_attributes_size,
- const void *enc_attributes)
-{
- struct GNUNET_TIME_Timestamp collection_time
- = GNUNET_TIME_timestamp_get ();
- struct GNUNET_TIME_Timestamp expiration
- = GNUNET_TIME_absolute_to_timestamp (expiration_time);
- struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
- .h_payto = *h_payto
- };
- char *kyc_completed_notify_s
- = GNUNET_PQ_get_event_notify_channel (&rep.header);
- struct GNUNET_PQ_QueryParam params[] = {
- (0 == process_row)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_uint64 (&process_row),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint32 (&birthday),
- GNUNET_PQ_query_param_string (provider_name),
- (NULL == provider_account_id)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (provider_account_id),
- (NULL == provider_legitimization_id)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (provider_legitimization_id),
- GNUNET_PQ_query_param_timestamp (&collection_time),
- GNUNET_PQ_query_param_absolute_time (&expiration_time),
- GNUNET_PQ_query_param_timestamp (&expiration),
- (NULL == enc_attributes)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_fixed_size (enc_attributes,
- enc_attributes_size),
- GNUNET_PQ_query_param_string (kyc_completed_notify_s),
- (NULL == form_name)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (form_name),
- GNUNET_PQ_query_param_end
- };
- bool ok;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("out_ok",
- &ok),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Inserting KYC attributes, wake up on %s\n",
- kyc_completed_notify_s);
- GNUNET_break (NULL != h_payto);
- PREPARE (pg,
- "persist_kyc_attributes",
- "SELECT "
- " out_ok"
- " FROM exchange_do_persist_kyc_attributes "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "persist_kyc_attributes",
- params,
- rs);
- GNUNET_PQ_cleanup_query_params_closures (params);
- GNUNET_free (kyc_completed_notify_s);
- GNUNET_PQ_event_do_poll (pg->conn);
- return qs;
-}
diff --git a/src/exchangedb/profit_drains_get_pending.c b/src/exchangedb/profit_drains_get_pending.c
@@ -1,76 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/profit_drains_get_pending.c
- * @brief Implementation of the profit_drains_get_pending function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/profit_drains_get_pending.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_profit_drains_get_pending (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t *serial,
- struct TALER_WireTransferIdentifierRawP *wtid,
- char **account_section,
- struct TALER_FullPayto *payto_uri,
- struct GNUNET_TIME_Timestamp *request_timestamp,
- struct TALER_Amount *amount,
- struct TALER_MasterSignatureP *master_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
- serial),
- GNUNET_PQ_result_spec_auto_from_type ("wtid",
- wtid),
- GNUNET_PQ_result_spec_string ("account_section",
- account_section),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri->full_payto),
- GNUNET_PQ_result_spec_timestamp ("trigger_date",
- request_timestamp),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- amount),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_end
- };
- /* Used in #postgres_profit_drains_get_pending() */
- PREPARE (pg,
- "get_ready_profit_drain",
- "SELECT"
- " profit_drain_serial_id"
- ",wtid"
- ",account_section"
- ",payto_uri"
- ",trigger_date"
- ",amount"
- ",master_sig"
- " FROM profit_drains"
- " WHERE NOT executed"
- " ORDER BY trigger_date ASC"
- " LIMIT 1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_ready_profit_drain",
- params,
- rs);
-}
diff --git a/src/exchangedb/profit_drains_set_finished.c b/src/exchangedb/profit_drains_set_finished.c
@@ -1,45 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/profit_drains_set_finished.c
- * @brief Implementation of the profit_drains_set_finished function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/profit_drains_set_finished.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_profit_drains_set_finished (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "drain_profit_set_finished",
- "UPDATE profit_drains"
- " SET"
- " executed=TRUE"
- " WHERE profit_drain_serial_id=$1;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "drain_profit_set_finished",
- params);
-}
diff --git a/src/exchangedb/reserves_get.c b/src/exchangedb/reserves_get.c
@@ -1,57 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/reserves_get.c
- * @brief Implementation of the reserves_get function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/reserves_get.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_reserves_get (struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct TALER_EXCHANGEDB_Reserve *reserve)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_amount ("current_balance",
- pg->currency,
- &reserve->balance),
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &reserve->expiry),
- GNUNET_PQ_result_spec_timestamp ("gc_date",
- &reserve->gc),
- GNUNET_PQ_result_spec_end
- };
- /* Used in #postgres_reserves_get() */
- PREPARE (pg,
- "reserves_get",
- "SELECT"
- " current_balance"
- ",expiration_date"
- ",gc_date"
- " FROM reserves"
- " WHERE reserve_pub=$1"
- " LIMIT 1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserves_get",
- params,
- rs);
-}
diff --git a/src/exchangedb/reserves_get_origin.c b/src/exchangedb/reserves_get_origin.c
@@ -1,61 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 exchangedb/reserves_get_origin.c
- * @brief Implementation of the reserves_get_origin function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/reserves_get_origin.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_reserves_get_origin (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_FullPaytoHashP *h_payto,
- struct TALER_FullPayto *payto_uri)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type (
- "wire_source_h_payto",
- h_payto),
- GNUNET_PQ_result_spec_string (
- "payto_uri",
- &payto_uri->full_payto),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "get_h_wire_source_of_reserve",
- "SELECT"
- " rt.wire_source_h_payto"
- ",wt.payto_uri"
- " FROM reserves_in rt"
- " JOIN wire_targets wt"
- " ON (rt.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE rt.reserve_pub=$1");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "get_h_wire_source_of_reserve",
- params,
- rs);
-}
diff --git a/src/exchangedb/reserves_in_insert.c b/src/exchangedb/reserves_in_insert.c
@@ -1,374 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/reserves_in_insert.c
- * @brief Implementation of the reserves_in_insert function for Postgres
- * @author Christian Grothoff
- * @author Joseph Xu
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/reserves_in_insert.h"
-#include "helper.h"
-#include "exchange-database/start.h"
-#include "exchange-database/start_read_committed.h"
-#include "exchange-database/commit.h"
-#include "exchange-database/preflight.h"
-#include "exchange-database/rollback.h"
-
-
-/**
- * Generate event notification for the reserve change.
- *
- * @param reserve_pub reserve to notfiy on
- * @return string to pass to postgres for the notification
- */
-static char *
-compute_notify_on_reserve (const struct TALER_ReservePublicKeyP *reserve_pub)
-{
- struct TALER_EXCHANGEDB_ReserveEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING),
- .reserve_pub = *reserve_pub
- };
-
- return GNUNET_PQ_get_event_notify_channel (&rep.header);
-}
-
-
-/**
- * Closure for our helper_cb()
- */
-struct Context
-{
- /**
- * Array of reserve UUIDs to initialize.
- */
- uint64_t *reserve_uuids;
-
- /**
- * Array with entries set to 'true' for duplicate transactions.
- */
- bool *transaction_duplicates;
-
- /**
- * Array with entries set to 'true' for rows with conflicts.
- */
- bool *conflicts;
-
- /**
- * Set to #GNUNET_SYSERR on failures.
- */
- enum GNUNET_GenericReturnValue status;
-
- /**
- * Single value (no array) set to true if we need
- * to follow-up with an update.
- */
- bool needs_update;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct Context *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct Context *ctx = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool (
- "transaction_duplicate",
- &ctx->transaction_duplicates[i]),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 ("ruuid",
- &ctx->reserve_uuids[i]),
- &ctx->conflicts[i]),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- if (! ctx->transaction_duplicates[i])
- ctx->needs_update |= ctx->conflicts[i];
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_reserves_in_insert (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_EXCHANGEDB_ReserveInInfo *reserves,
- unsigned int reserves_length,
- enum GNUNET_DB_QueryStatus *results)
-{
- unsigned int dups = 0;
-
- struct TALER_FullPaytoHashP h_full_paytos[
- GNUNET_NZL (reserves_length)];
- struct TALER_NormalizedPaytoHashP h_normalized_paytos[
- GNUNET_NZL (reserves_length)];
- char *notify_s[GNUNET_NZL (reserves_length)];
- struct TALER_ReservePublicKeyP reserve_pubs[GNUNET_NZL (reserves_length)];
- struct TALER_Amount balances[GNUNET_NZL (reserves_length)];
- struct GNUNET_TIME_Timestamp execution_times[GNUNET_NZL (reserves_length)];
- const char *sender_account_details[GNUNET_NZL (reserves_length)];
- const char *exchange_account_names[GNUNET_NZL (reserves_length)];
- uint64_t wire_references[GNUNET_NZL (reserves_length)];
- uint64_t reserve_uuids[GNUNET_NZL (reserves_length)];
- bool transaction_duplicates[GNUNET_NZL (reserves_length)];
- bool conflicts[GNUNET_NZL (reserves_length)];
- struct GNUNET_TIME_Timestamp reserve_expiration
- = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
- struct GNUNET_TIME_Timestamp gc
- = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
- enum GNUNET_DB_QueryStatus qs;
- bool need_update;
-
- for (unsigned int i = 0; i<reserves_length; i++)
- {
- const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i];
-
- TALER_full_payto_hash (reserve->sender_account_details,
- &h_full_paytos[i]);
- TALER_full_payto_normalize_and_hash (reserve->sender_account_details,
- &h_normalized_paytos[i]);
- notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub);
- reserve_pubs[i] = *reserve->reserve_pub;
- balances[i] = *reserve->balance;
- execution_times[i] = reserve->execution_time;
- sender_account_details[i] = reserve->sender_account_details.full_payto;
- exchange_account_names[i] = reserve->exchange_account_name;
- wire_references[i] = reserve->wire_reference;
- }
-
- /* NOTE: kind-of pointless to explicitly start a transaction here... */
- if (GNUNET_OK !=
- TALER_EXCHANGEDB_preflight (pg))
- {
- GNUNET_break (0);
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- goto finished;
- }
- if (GNUNET_OK !=
- TALER_TALER_EXCHANGEDB_start_read_committed (pg,
- "READ_COMMITED"))
- {
- GNUNET_break (0);
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- goto finished;
- }
- PREPARE (pg,
- "reserves_insert_with_array",
- "SELECT"
- " transaction_duplicate"
- ",ruuid"
- " FROM exchange_do_array_reserves_insert"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);");
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&gc),
- GNUNET_PQ_query_param_timestamp (&reserve_expiration),
- GNUNET_PQ_query_param_array_auto_from_type (reserves_length,
- reserve_pubs,
- pg->conn),
- GNUNET_PQ_query_param_array_uint64 (reserves_length,
- wire_references,
- pg->conn),
- TALER_PQ_query_param_array_amount (
- reserves_length,
- balances,
- pg->conn),
- GNUNET_PQ_query_param_array_ptrs_string (
- reserves_length,
- (const char **) exchange_account_names,
- pg->conn),
- GNUNET_PQ_query_param_array_timestamp (
- reserves_length,
- execution_times,
- pg->conn),
- GNUNET_PQ_query_param_array_auto_from_type (
- reserves_length,
- h_full_paytos,
- pg->conn),
- GNUNET_PQ_query_param_array_auto_from_type (
- reserves_length,
- h_normalized_paytos,
- pg->conn),
- GNUNET_PQ_query_param_array_ptrs_string (
- reserves_length,
- (const char **) sender_account_details,
- pg->conn),
- GNUNET_PQ_query_param_array_ptrs_string (
- reserves_length,
- (const char **) notify_s,
- pg->conn),
- GNUNET_PQ_query_param_end
- };
- struct Context ctx = {
- .reserve_uuids = reserve_uuids,
- .transaction_duplicates = transaction_duplicates,
- .conflicts = conflicts,
- .needs_update = false,
- .status = GNUNET_OK
- };
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "reserves_insert_with_array",
- params,
- &helper_cb,
- &ctx);
- GNUNET_PQ_cleanup_query_params_closures (params);
- if ( (qs < 0) ||
- (GNUNET_OK != ctx.status) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to insert into reserves (%d)\n",
- qs);
- goto finished;
- }
- need_update = ctx.needs_update;
- }
-
- {
- enum GNUNET_DB_QueryStatus cs;
-
- cs = TALER_EXCHANGEDB_commit (pg);
- if (cs < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to commit\n");
- qs = cs;
- goto finished;
- }
- }
-
- for (unsigned int i = 0; i<reserves_length; i++)
- {
- if (transaction_duplicates[i])
- dups++;
- results[i] = transaction_duplicates[i]
- ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
- : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
-
- if (! need_update)
- {
- qs = reserves_length;
- goto finished;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve update needed for some reserves in the batch\n");
- PREPARE (pg,
- "reserves_update",
- "SELECT"
- " out_duplicate AS duplicate "
- "FROM exchange_do_batch_reserves_update"
- " ($1,$2,$3,$4,$5,$6,$7);");
-
- if (GNUNET_OK !=
- TALER_EXCHANGEDB_start (pg,
- "reserve-insert-continued"))
- {
- GNUNET_break (0);
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- goto finished;
- }
-
- for (unsigned int i = 0; i<reserves_length; i++)
- {
- if (transaction_duplicates[i])
- continue;
- if (! conflicts[i])
- continue;
- {
- bool duplicate;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&reserve_pubs[i]),
- GNUNET_PQ_query_param_timestamp (&reserve_expiration),
- GNUNET_PQ_query_param_uint64 (&wire_references[i]),
- TALER_PQ_query_param_amount (pg->conn,
- &balances[i]),
- GNUNET_PQ_query_param_string (exchange_account_names[i]),
- GNUNET_PQ_query_param_auto_from_type (&h_full_paytos[i]),
- GNUNET_PQ_query_param_string (notify_s[i]),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("duplicate",
- &duplicate),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qsi;
-
- qsi = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserves_update",
- params,
- rs);
- if (qsi < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to update reserves (%d)\n",
- qsi);
- results[i] = qsi;
- goto finished;
- }
- results[i] = duplicate
- ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
- : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
- }
- {
- enum GNUNET_DB_QueryStatus cs;
-
- cs = TALER_EXCHANGEDB_commit (pg);
- if (cs < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to commit\n");
- qs = cs;
- goto finished;
- }
- }
-finished:
- for (unsigned int i = 0; i<reserves_length; i++)
- GNUNET_free (notify_s[i]);
- if (qs < 0)
- return qs;
- GNUNET_PQ_event_do_poll (pg->conn);
- if (0 != dups)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%u/%u duplicates among incoming transactions. Try increasing WIREWATCH_IDLE_SLEEP_INTERVAL in the [exchange] configuration section (if this happens a lot).\n",
- dups,
- reserves_length);
- return qs;
-}
diff --git a/src/exchangedb/reserves_update.c b/src/exchangedb/reserves_update.c
@@ -1,50 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/reserves_update.c
- * @brief Implementation of the reserves_update function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/reserves_update.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_reserves_update (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_EXCHANGEDB_Reserve *reserve
- )
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&reserve->expiry),
- GNUNET_PQ_query_param_timestamp (&reserve->gc),
- TALER_PQ_query_param_amount (pg->conn,
- &reserve->balance),
- GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "reserve_update",
- "UPDATE reserves"
- " SET"
- " expiration_date=$1"
- ",gc_date=$2"
- ",current_balance=$3"
- " WHERE reserve_pub=$4;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reserve_update",
- params);
-}
diff --git a/src/exchangedb/select_account_merges_above_serial_id.c b/src/exchangedb/select_account_merges_above_serial_id.c
@@ -1,188 +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 select_account_merges_above_serial_id.c
- * @brief Implementation of the select_account_merges_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_account_merges_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #account_merge_serial_helper_cb().
- */
-struct AccountMergeSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_AccountMergeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct AccountMergeSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-account_merge_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AccountMergeSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PrivateContractHashP h_contract_terms;
- struct GNUNET_TIME_Timestamp purse_expiration;
- struct TALER_Amount amount;
- uint32_t min_age;
- uint32_t flags32;
- enum TALER_WalletAccountMergeFlags flags;
- struct TALER_Amount purse_fee;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- struct TALER_ReserveSignatureP reserve_sig;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &purse_fee),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- &min_age),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- &purse_expiration),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- &merge_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_uint64 ("account_merge_request_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- flags = (enum TALER_WalletAccountMergeFlags) flags32;
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &reserve_pub,
- &purse_pub,
- &h_contract_terms,
- purse_expiration,
- &amount,
- min_age,
- flags,
- &purse_fee,
- merge_timestamp,
- &reserve_sig);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_account_merges_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AccountMergeCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct AccountMergeSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_get_account_merge_incr",
- "SELECT"
- " am.account_merge_request_serial_id"
- ",am.reserve_pub"
- ",am.purse_pub"
- ",pr.h_contract_terms"
- ",pr.purse_expiration"
- ",pr.amount_with_fee"
- ",pr.age_limit"
- ",pr.flags"
- ",pr.purse_fee"
- ",pm.merge_timestamp"
- ",am.reserve_sig"
- " FROM account_merges am"
- " JOIN purse_requests pr USING (purse_pub)"
- " JOIN purse_merges pm USING (purse_pub)"
- " WHERE ("
- " (account_merge_request_serial_id>=$1)"
- " )"
- " ORDER BY account_merge_request_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_account_merge_incr",
- params,
- &account_merge_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_aggregation_amounts_for_kyc_check.c b/src/exchangedb/select_aggregation_amounts_for_kyc_check.c
@@ -1,154 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_aggregation_amounts_for_kyc_check.c
- * @brief Implementation of the select_aggregation_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aggregation_amounts_for_kyc_check.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_kyc_amounts_cb().
- */
-struct KycAmountCheckContext
-{
- /**
- * Function to call per result.
- */
- TALER_KYCLOGIC_KycAmountCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 KycAmountCheckContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_kyc_amounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct KycAmountCheckContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct GNUNET_TIME_Absolute date;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_absolute_time ("date",
- &date),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ret = ctx->cb (ctx->cb_cls,
- &amount,
- date);
- GNUNET_PQ_cleanup_result (rs);
- switch (ret)
- {
- case GNUNET_OK:
- continue;
- case GNUNET_NO:
- break;
- case GNUNET_SYSERR:
- ctx->status = GNUNET_SYSERR;
- break;
- }
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aggregation_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_absolute_time (&time_limit),
- GNUNET_PQ_query_param_end
- };
- struct KycAmountCheckContext ctx = {
- .cb = kac,
- .cb_cls = kac_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_kyc_relevant_aggregation_events",
- "SELECT"
- " amount"
- ",execution_date AS date"
- " FROM wire_out"
- " WHERE wire_target_h_payto IN"
- " (SELECT wire_target_h_payto"
- " FROM wire_targets"
- " WHERE h_normalized_payto=$1"
- " )"
- " AND execution_date >= $2"
- " ORDER BY execution_date DESC");
-
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_kyc_relevant_aggregation_events",
- params,
- &get_kyc_amounts_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_aggregation_transient.c b/src/exchangedb/select_aggregation_transient.c
@@ -1,63 +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 exchangedb/select_aggregation_transient.c
- * @brief Implementation of the select_aggregation_transient function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aggregation_transient.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aggregation_transient (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPaytoHashP *h_payto,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const char *exchange_account_section,
- struct TALER_WireTransferIdentifierRawP *wtid,
- struct TALER_Amount *total)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_string (exchange_account_section),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- total),
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- wtid),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_aggregation_transient",
- "SELECT"
- " amount"
- " ,wtid_raw"
- " FROM aggregation_transient"
- " WHERE wire_target_h_payto=$1"
- " AND merchant_pub=$2"
- " AND exchange_account_section=$3;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_aggregation_transient",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_aggregations_above_serial.c b/src/exchangedb/select_aggregations_above_serial.c
@@ -1,137 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2023, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_aggregations_above_serial.c
- * @brief Implementation of the select_aggregations_above_serial function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aggregations_above_serial.h"
-#include "helper.h"
-
-/**
- * Closure for #aggregation_serial_helper_cb().
- */
-struct AggregationSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_AggregationCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct AggregationSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-aggregation_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AggregationSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t tracking_rowid;
- uint64_t batch_deposit_serial_id;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
- &amount),
- GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id",
- &tracking_rowid),
- GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
- &batch_deposit_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- dsc->cb (dsc->cb_cls,
- &amount,
- tracking_rowid,
- batch_deposit_serial_id);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aggregations_above_serial (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t min_tracking_serial_id,
- TALER_EXCHANGEDB_AggregationCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&min_tracking_serial_id),
- GNUNET_PQ_query_param_end
- };
- struct AggregationSerialContext asc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- /* Fetch aggregations with rowid '\geq' the given parameter */
- PREPARE (pg,
- "select_aggregations_above_serial",
- "SELECT"
- " aggregation_serial_id"
- ",batch_deposit_serial_id"
- ",total_amount"
- " FROM exchange_do_select_aggregations_above_serial($1);");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_aggregations_above_serial",
- params,
- &aggregation_serial_helper_cb,
- &asc);
- if (GNUNET_OK != asc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_all_kyc_attributes.c b/src/exchangedb/select_all_kyc_attributes.c
@@ -1,168 +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 exchangedb/select_all_kyc_attributes.c
- * @brief Implementation of the select_all_kyc_attributes function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_all_kyc_attributes.h"
-#include "helper.h"
-
-/**
- * Closure for #get_all_attributes_cb().
- */
-struct GetAttributesContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_AllAttributesCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 GetAttributesContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_attributes_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetAttributesContext *ctx = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t rowid;
- struct GNUNET_TIME_Timestamp collection_time;
- struct GNUNET_TIME_Timestamp expiration_time;
- struct TALER_NormalizedPaytoHashP h_payto;
- json_t *properties = NULL;
- size_t enc_attributes_size;
- void *enc_attributes;
- char *provider;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("provider_name",
- &provider),
- GNUNET_PQ_result_spec_uint64 ("kyc_attributes_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json ("jproperties",
- &properties),
- NULL),
- GNUNET_PQ_result_spec_timestamp ("collection_time",
- &collection_time),
- GNUNET_PQ_result_spec_timestamp ("expiration_time",
- &expiration_time),
- GNUNET_PQ_result_spec_auto_from_type ("h_payto",
- &h_payto),
- GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
- &enc_attributes,
- &enc_attributes_size),
- 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,
- rowid,
- &h_payto,
- provider,
- collection_time,
- expiration_time,
- properties,
- enc_attributes_size,
- enc_attributes);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_all_kyc_attributes (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t min_row_id,
- TALER_EXCHANGEDB_AllAttributesCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&min_row_id),
- GNUNET_PQ_query_param_end
- };
- struct GetAttributesContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_all_kyc_attributes",
- "SELECT "
- " lp.provider_name"
- ",ka.h_payto"
- ",ka.kyc_attributes_serial_id"
- ",lo.jproperties::TEXT"
- ",ka.collection_time"
- ",ka.expiration_time"
- ",ka.encrypted_attributes"
- " FROM kyc_attributes ka"
- " JOIN legitimization_processes lp"
- " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
- " LEFT JOIN legitimization_outcomes lo"
- " ON (ka.h_payto = lo.h_payto)"
- /* **IF** we joined with 'lo', the lo must be active */
- " WHERE COALESCE(lo.is_active,TRUE)"
- " AND kyc_attributes_serial_id > $1"
- " ORDER BY kyc_attributes_serial_id ASC"
- );
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_all_kyc_attributes",
- params,
- &get_attributes_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_all_purse_decisions_above_serial_id.c b/src/exchangedb/select_all_purse_decisions_above_serial_id.c
@@ -1,142 +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 select_all_purse_decisions_above_serial_id.c
- * @brief Implementation of the select_all_purse_decisions_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_all_purse_decisions_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #all_purse_decision_serial_helper_cb().
- */
-struct AllPurseDecisionSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_AllPurseDecisionCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRefundSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-all_purse_decision_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AllPurseDecisionSerialContext *dsc = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- bool refunded;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_bool ("refunded",
- &refunded),
- GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &purse_pub,
- refunded);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_all_purse_decisions_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct AllPurseDecisionSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_select_all_purse_decisions_above_serial_id",
- "SELECT"
- " purse_pub"
- ",refunded"
- ",purse_decision_serial_id"
- " FROM purse_decision"
- " WHERE purse_decision_serial_id>=$1"
- " ORDER BY purse_decision_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "audit_select_all_purse_decisions_above_serial_id",
- params,
- &all_purse_decision_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_all_purse_deletions_above_serial_id.c b/src/exchangedb/select_all_purse_deletions_above_serial_id.c
@@ -1,142 +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 exchangedb/select_all_purse_deletions_above_serial_id.c
- * @brief Implementation of the select_all_purse_deletions_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_all_purse_deletions_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #all_purse_deletion_serial_helper_cb().
- */
-struct AllPurseDeletionSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_AllPurseDeletionsCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRefundSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-all_purse_deletion_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AllPurseDeletionSerialContext *dsc = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PurseContractSignatureP purse_sig;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
- &purse_sig),
- GNUNET_PQ_result_spec_uint64 ("purse_deletion_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &purse_pub,
- &purse_sig);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_all_purse_deletions_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AllPurseDeletionsCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct AllPurseDeletionSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_select_all_purse_deletions_above_serial_id",
- "SELECT"
- " purse_pub"
- ",purse_sig"
- ",purse_deletion_serial_id"
- " FROM purse_deletion"
- " WHERE purse_deletion_serial_id>=$1"
- " ORDER BY purse_deletion_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "audit_select_all_purse_deletions_above_serial_id",
- params,
- &all_purse_deletion_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_aml_attributes.c b/src/exchangedb/select_aml_attributes.c
@@ -1,189 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_aml_attributes.c
- * @brief Implementation of the select_aml_attributes function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aml_attributes.h"
-#include "helper.h"
-
-
-/**
- * Closure for #handle_aml_result.
- */
-struct AmlAttributeResultContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlAttributeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_aml_attributes().
- *
- * @param cls closure of type `struct AmlAttributeResultContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_aml_attributes (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AmlAttributeResultContext *ctx = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct GNUNET_TIME_Timestamp collection_time;
- char *officer_name = NULL;
- bool by_aml_officer;
- size_t enc_attributes_size;
- void *enc_attributes;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("kyc_attributes_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("collection_time",
- &collection_time),
- GNUNET_PQ_result_spec_bool ("by_aml_officer",
- &by_aml_officer),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("decider_name",
- &officer_name),
- NULL),
- GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
- &enc_attributes,
- &enc_attributes_size),
- 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,
- rowid,
- collection_time,
- by_aml_officer,
- officer_name,
- enc_attributes_size,
- enc_attributes);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_attributes (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlAttributeCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_end
- };
- struct AmlAttributeResultContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
- const char *stmt = (limit > 0)
- ? "select_aml_attributes_inc"
- : "select_aml_attributes_dec";
-
- PREPARE (pg,
- "select_aml_attributes_inc",
- "SELECT"
- " ka.kyc_attributes_serial_id"
- ",ka.collection_time"
- ",ka.by_aml_officer"
- ",astaff.decider_name"
- ",ka.encrypted_attributes"
- " FROM kyc_attributes ka"
- " LEFT JOIN legitimization_processes lp"
- " ON (ka.by_aml_officer AND"
- " (ka.legitimization_serial = lp.legitimization_process_serial_id))"
- " LEFT JOIN aml_staff astaff"
- " ON (ka.by_aml_officer AND"
- " (DECODE(lp.provider_user_id, 'base64') = astaff.decider_pub))"
- " WHERE ka.h_payto=$1"
- " AND ka.kyc_attributes_serial_id > $2"
- " ORDER BY ka.kyc_attributes_serial_id ASC"
- " LIMIT $3");
- PREPARE (pg,
- "select_aml_attributes_dec",
- "SELECT"
- " ka.kyc_attributes_serial_id"
- ",ka.collection_time"
- ",ka.by_aml_officer"
- ",astaff.decider_name"
- ",ka.encrypted_attributes"
- " FROM kyc_attributes ka"
- " LEFT JOIN legitimization_processes lp"
- " ON (ka.by_aml_officer AND"
- " (ka.legitimization_serial = lp.legitimization_process_serial_id))"
- " LEFT JOIN aml_staff astaff"
- " ON (ka.by_aml_officer AND"
- " (DECODE(lp.provider_user_id, 'base64') = astaff.decider_pub))"
- " WHERE ka.h_payto=$1"
- " AND ka.kyc_attributes_serial_id < $2"
- " ORDER BY ka.kyc_attributes_serial_id DESC"
- " LIMIT $3");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- stmt,
- params,
- &handle_aml_attributes,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_aml_decisions.c b/src/exchangedb/select_aml_decisions.c
@@ -1,248 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_aml_decisions.c
- * @brief Implementation of the select_aml_decisions function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aml_decisions.h"
-#include "helper.h"
-
-
-/**
- * Closure for #handle_aml_result.
- */
-struct AmlProcessResultContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlDecisionCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_aml_decisions().
- *
- * @param cls closure of type `struct AmlProcessResultContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_aml_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AmlProcessResultContext *ctx = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_NormalizedPaytoHashP h_payto;
- uint64_t rowid;
- char *justification = NULL;
- struct GNUNET_TIME_Timestamp decision_time;
- struct GNUNET_TIME_Absolute expiration_time;
- json_t *jproperties = NULL;
- bool is_wallet;
- bool to_investigate;
- bool is_active;
- json_t *account_rules;
- struct TALER_FullPayto payto;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("outcome_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("h_payto",
- &h_payto),
- GNUNET_PQ_result_spec_bool ("is_wallet",
- &is_wallet),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("justification",
- &justification),
- NULL),
- GNUNET_PQ_result_spec_timestamp ("decision_time",
- &decision_time),
- GNUNET_PQ_result_spec_absolute_time ("expiration_time",
- &expiration_time),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json ("jproperties",
- &jproperties),
- NULL),
- TALER_PQ_result_spec_json ("jnew_rules",
- &account_rules),
- GNUNET_PQ_result_spec_bool ("to_investigate",
- &to_investigate),
- GNUNET_PQ_result_spec_bool ("is_active",
- &is_active),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto.full_payto),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- if (GNUNET_TIME_absolute_is_past (expiration_time))
- is_active = false;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning AML decisions for `%s' (%s)\n",
- TALER_B2S (&h_payto),
- is_wallet
- ? "wallet"
- : "account");
- ctx->cb (ctx->cb_cls,
- rowid,
- justification,
- &h_payto,
- decision_time,
- expiration_time,
- jproperties,
- to_investigate,
- is_active,
- is_wallet,
- payto,
- account_rules);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_decisions (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- enum TALER_EXCHANGE_YesNoAll investigation_only,
- enum TALER_EXCHANGE_YesNoAll active_only,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlDecisionCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_bool (NULL == h_payto),
- NULL == h_payto
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
- investigation_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
- investigation_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
- active_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
- active_only)),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_end
- };
- struct AmlProcessResultContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
- const char *stmt = (limit > 0)
- ? "select_aml_decisions_inc"
- : "select_aml_decisions_dec";
-
- PREPARE (pg,
- "select_aml_decisions_inc",
- "SELECT"
- " lo.outcome_serial_id"
- ",lo.h_payto"
- ",ah.justification"
- ",lo.decision_time"
- ",lo.expiration_time"
- ",lo.jproperties::TEXT"
- ",lo.to_investigate"
- ",lo.is_active"
- ",lo.jnew_rules::TEXT"
- ",kt.is_wallet"
- ",wt.payto_uri"
- " FROM legitimization_outcomes lo"
- " JOIN kyc_targets kt"
- " ON (lo.h_payto = kt.h_normalized_payto)"
- " JOIN wire_targets wt"
- " ON (lo.h_payto = wt.h_normalized_payto)"
- " LEFT JOIN aml_history ah"
- " USING (outcome_serial_id)"
- " WHERE (outcome_serial_id > $7)"
- " AND ($1 OR (lo.h_payto = $2))"
- " AND ($3 OR (lo.to_investigate = $4))"
- " AND ($5 OR (lo.is_active = $6))"
- " ORDER BY lo.outcome_serial_id ASC"
- " LIMIT $8");
- PREPARE (pg,
- "select_aml_decisions_dec",
- "SELECT"
- " lo.outcome_serial_id"
- ",lo.h_payto"
- ",ah.justification"
- ",lo.decision_time"
- ",lo.expiration_time"
- ",lo.jproperties::TEXT"
- ",lo.to_investigate"
- ",lo.is_active"
- ",lo.jnew_rules::TEXT"
- ",kt.is_wallet"
- ",wt.payto_uri"
- " FROM legitimization_outcomes lo"
- " JOIN kyc_targets kt"
- " ON (lo.h_payto = kt.h_normalized_payto)"
- " JOIN wire_targets wt"
- " ON (lo.h_payto = wt.h_normalized_payto)"
- " LEFT JOIN aml_history ah"
- " USING (outcome_serial_id)"
- " WHERE lo.outcome_serial_id < $7"
- " AND ($1 OR (lo.h_payto = $2))"
- " AND ($3 OR (lo.to_investigate = $4))"
- " AND ($5 OR (lo.is_active = $6))"
- " ORDER BY lo.outcome_serial_id DESC"
- " LIMIT $8");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- stmt,
- params,
- &handle_aml_result,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_aml_measures.c b/src/exchangedb/select_aml_measures.c
@@ -1,185 +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 exchangedb/select_aml_measures.c
- * @brief Implementation of the select_aml_measures function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aml_measures.h"
-#include "helper.h"
-
-
-/**
- * Closure for #handle_aml_result.
- */
-struct LegiMeasureResultContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_LegitimizationMeasureCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_aml_measures().
- *
- * @param cls closure of type `struct LegiMeasureResultContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_aml_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LegiMeasureResultContext *ctx = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_NormalizedPaytoHashP h_payto;
- uint64_t rowid;
- struct GNUNET_TIME_Absolute start_time;
- json_t *jmeasures;
- bool is_finished;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("legitimization_measure_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("h_normalized_payto",
- &h_payto),
- GNUNET_PQ_result_spec_absolute_time ("start_time",
- &start_time),
- TALER_PQ_result_spec_json ("jmeasures",
- &jmeasures),
- GNUNET_PQ_result_spec_bool ("is_finished",
- &is_finished),
- 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,
- &h_payto,
- start_time,
- jmeasures,
- is_finished,
- rowid);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_measures (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- enum TALER_EXCHANGE_YesNoAll active_only,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_LegitimizationMeasureCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_bool (NULL == h_payto),
- NULL == h_payto
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
- active_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_NO ==
- active_only)),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_end
- };
- struct LegiMeasureResultContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
- const char *stmt = (limit > 0)
- ? "select_aml_measures_inc"
- : "select_aml_measures_dec";
-
- PREPARE (pg,
- "select_aml_measures_inc",
- "SELECT"
- " lm.legitimization_measure_serial_id"
- ",kt.h_normalized_payto"
- ",lm.jmeasures::TEXT"
- ",lm.start_time"
- ",lm.is_finished"
- " FROM kyc_targets kt"
- " JOIN legitimization_measures lm"
- " USING (access_token)"
- " WHERE (legitimization_measure_serial_id > $5)"
- " AND ($1 OR (kt.h_normalized_payto = $2))"
- " AND ($3 OR (lm.is_finished = $4))"
- " ORDER BY lm.legitimization_measure_serial_id ASC"
- " LIMIT $6");
- PREPARE (pg,
- "select_aml_measures_dec",
- "SELECT"
- " lm.legitimization_measure_serial_id"
- ",kt.h_normalized_payto"
- ",lm.jmeasures::TEXT"
- ",lm.start_time"
- ",lm.is_finished"
- " FROM kyc_targets kt"
- " JOIN legitimization_measures lm"
- " USING (access_token)"
- " WHERE (legitimization_measure_serial_id < $5)"
- " AND ($1 OR (kt.h_normalized_payto = $2))"
- " AND ($3 OR (lm.is_finished = $4))"
- " ORDER BY lm.legitimization_measure_serial_id DESC"
- " LIMIT $6");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- stmt,
- params,
- &handle_aml_result,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_aml_statistics.c b/src/exchangedb/select_aml_statistics.c
@@ -1,142 +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 exchangedb/select_aml_statistics.c
- * @brief Implementation of the select_aml_statistics function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_aml_statistics.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_statistics_cb().
- */
-struct GetStatisticsContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_AmlStatisticsCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 GetStatisticsContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_statistics_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetStatisticsContext *ctx = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t val;
- char *name;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("name",
- &name),
- GNUNET_PQ_result_spec_uint64 ("value",
- &val),
- 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,
- name,
- val);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_statistics (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- size_t num_names,
- const char *names[static num_names],
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- TALER_EXCHANGEDB_AmlStatisticsCallback cb,
- void *cb_cls)
-{
- struct GetStatisticsContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_array_ptrs_string (num_names,
- names,
- pg->conn),
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_timestamp (&end_date),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_aml_statistics",
- "SELECT "
- " event_type AS name"
- ",COUNT(*) AS value"
- " FROM kyc_events"
- " WHERE event_type = ANY ($1)"
- " AND event_timestamp >= $2"
- " AND event_timestamp < $3"
- " GROUP BY event_type;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_aml_statistics",
- params,
- &get_statistics_cb,
- &ctx);
- GNUNET_PQ_cleanup_query_params_closures (params);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_auditor_denom_sig.c b/src/exchangedb/select_auditor_denom_sig.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 exchangedb/select_auditor_denom_sig.c
- * @brief Implementation of the select_auditor_denom_sig function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_auditor_denom_sig.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_auditor_denom_sig (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- struct TALER_AuditorSignatureP *auditor_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("auditor_sig",
- auditor_sig),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_auditor_denom_sig",
- "SELECT"
- " auditor_sig"
- " FROM auditor_denom_sigs"
- " WHERE auditor_uuid="
- " (SELECT auditor_uuid"
- " FROM auditors"
- " WHERE auditor_pub=$1)"
- " AND denominations_serial="
- " (SELECT denominations_serial"
- " FROM denominations"
- " WHERE denom_pub_hash=$2);");
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_auditor_denom_sig",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_batch_deposits_missing_wire.c b/src/exchangedb/select_batch_deposits_missing_wire.c
@@ -1,140 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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 exchangedb/select_batch_deposits_missing_wire.c
- * @brief Implementation of the select_batch_deposits_missing_wire function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_batch_deposits_missing_wire.h"
-#include "helper.h"
-
-/**
- * Closure for #missing_wire_cb().
- */
-struct MissingWireContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_WireMissingCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-missing_wire_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct MissingWireContext *mwc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = mwc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t batch_deposit_serial_id;
- struct GNUNET_TIME_Timestamp deadline;
- struct TALER_FullPaytoHashP wire_target_h_payto;
- struct TALER_Amount total_amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
- &batch_deposit_serial_id),
- GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
- &wire_target_h_payto),
- GNUNET_PQ_result_spec_timestamp ("deadline",
- &deadline),
- TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
- &total_amount),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- mwc->status = GNUNET_SYSERR;
- return;
- }
- mwc->cb (mwc->cb_cls,
- batch_deposit_serial_id,
- &total_amount,
- &wire_target_h_payto,
- deadline);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_batch_deposits_missing_wire (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t min_batch_deposit_serial_id,
- TALER_EXCHANGEDB_WireMissingCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&min_batch_deposit_serial_id),
- GNUNET_PQ_query_param_end
- };
- struct MissingWireContext mwc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "deposits_get_deposits_missing_wire",
- "SELECT"
- " batch_deposit_serial_id"
- ",wire_target_h_payto"
- ",deadline"
- ",total_amount"
- " FROM exchange_do_select_deposits_missing_wire"
- " ($1);");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "deposits_get_deposits_missing_wire",
- params,
- &missing_wire_cb,
- &mwc);
- if (GNUNET_OK != mwc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_coin_deposits_above_serial_id.c b/src/exchangedb/select_coin_deposits_above_serial_id.c
@@ -1,200 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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 exchangedb/select_coin_deposits_above_serial_id.c
- * @brief Implementation of the select_coin_deposits_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_coin_deposits_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #deposit_serial_helper_cb().
- */
-struct CoinDepositSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_DepositCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinDepositSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-coin_deposit_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinDepositSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_Deposit deposit;
- struct GNUNET_TIME_Timestamp exchange_timestamp;
- struct TALER_DenominationPublicKey denom_pub;
- bool done;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit.amount_with_fee),
- GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
- &deposit.timestamp),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- &exchange_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &deposit.merchant_pub),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &deposit.coin.coin_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &deposit.coin.h_age_commitment),
- &deposit.coin.no_age_commitment),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("wallet_data_hash",
- &deposit.wallet_data_hash),
- &deposit.no_wallet_data_hash),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &deposit.csig),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &deposit.refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &deposit.wire_deadline),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &deposit.h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &deposit.wire_salt),
- GNUNET_PQ_result_spec_string ("receiver_wire_account",
- &deposit.receiver_wire_account.full_payto),
- GNUNET_PQ_result_spec_bool ("done",
- &done),
- GNUNET_PQ_result_spec_uint64 ("coin_deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- memset (&deposit,
- 0,
- sizeof (deposit));
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- exchange_timestamp,
- &deposit,
- &denom_pub,
- done);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_coin_deposits_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_DepositCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct CoinDepositSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- /* Fetch deposits with rowid '\geq' the given parameter */
- PREPARE (pg,
- "audit_get_coin_deposits_incr",
- "SELECT"
- " cdep.amount_with_fee"
- ",bdep.wallet_timestamp"
- ",bdep.exchange_timestamp"
- ",bdep.merchant_pub"
- ",bdep.wallet_data_hash"
- ",denom.denom_pub"
- ",kc.coin_pub"
- ",kc.age_commitment_hash"
- ",cdep.coin_sig"
- ",bdep.refund_deadline"
- ",bdep.wire_deadline"
- ",bdep.h_contract_terms"
- ",bdep.wire_salt"
- ",wt.payto_uri AS receiver_wire_account"
- ",bdep.done"
- ",cdep.coin_deposit_serial_id"
- " FROM coin_deposits cdep"
- " JOIN batch_deposits bdep"
- " USING (batch_deposit_serial_id)"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " JOIN known_coins kc"
- " USING (coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " WHERE (coin_deposit_serial_id>=$1)"
- " ORDER BY coin_deposit_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_coin_deposits_incr",
- params,
- &coin_deposit_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_contract.c b/src/exchangedb/select_contract.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 exchangedb/select_contract.c
- * @brief Implementation of the select_contract function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_contract.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_contract (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ContractDiffiePublicP *pub_ckey,
- struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_PurseContractSignatureP *econtract_sig,
- size_t *econtract_size,
- void **econtract)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (pub_ckey),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
- econtract_sig),
- GNUNET_PQ_result_spec_variable_size ("e_contract",
- econtract,
- econtract_size),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_contract",
- "SELECT "
- " purse_pub"
- ",e_contract"
- ",contract_sig"
- " FROM contracts"
- " WHERE pub_ckey=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_contract",
- params,
- rs);
-
-}
diff --git a/src/exchangedb/select_contract_by_purse.c b/src/exchangedb/select_contract_by_purse.c
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_contract_by_purse.c
- * @brief Implementation of the select_contract_by_purse function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_contract_by_purse.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_contract_by_purse (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_EncryptedContract *econtract)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("pub_ckey",
- &econtract->contract_pub),
- GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
- &econtract->econtract_sig),
- GNUNET_PQ_result_spec_variable_size ("e_contract",
- &econtract->econtract,
- &econtract->econtract_size),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_contract_by_purse",
- "SELECT "
- " pub_ckey"
- ",e_contract"
- ",contract_sig"
- " FROM contracts"
- " WHERE purse_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_contract_by_purse",
- params,
- rs);
-
-}
diff --git a/src/exchangedb/select_deposit_amounts_for_kyc_check.c b/src/exchangedb/select_deposit_amounts_for_kyc_check.c
@@ -1,153 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_deposit_amounts_for_kyc_check.c
- * @brief Implementation of the select_deposit_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_deposit_amounts_for_kyc_check.h"
-#include "helper.h"
-
-/**
- * Closure for #get_kyc_amounts_cb().
- */
-struct KycAmountCheckContext
-{
- /**
- * Function to call per result.
- */
- TALER_KYCLOGIC_KycAmountCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 KycAmountCheckContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_kyc_amounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct KycAmountCheckContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct GNUNET_TIME_Absolute date;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_absolute_time ("date",
- &date),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ret = ctx->cb (ctx->cb_cls,
- &amount,
- date);
- GNUNET_PQ_cleanup_result (rs);
- switch (ret)
- {
- case GNUNET_OK:
- continue;
- case GNUNET_NO:
- break;
- case GNUNET_SYSERR:
- ctx->status = GNUNET_SYSERR;
- break;
- }
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_deposit_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_absolute_time (&time_limit),
- GNUNET_PQ_query_param_end
- };
- struct KycAmountCheckContext ctx = {
- .cb = kac,
- .cb_cls = kac_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_kyc_relevant_deposit_events",
- "SELECT"
- " cd.amount_with_fee AS amount"
- ",bd.exchange_timestamp AS date"
- " FROM batch_deposits bd"
- " JOIN coin_deposits cd"
- " USING (batch_deposit_serial_id)"
- " WHERE wire_target_h_payto IN ("
- " SELECT wire_target_h_payto"
- " FROM wire_targets"
- " WHERE h_normalized_payto=$1"
- " )"
- " AND bd.exchange_timestamp >= $2"
- " ORDER BY bd.exchange_timestamp DESC");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_kyc_relevant_deposit_events",
- params,
- &get_kyc_amounts_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_exchange_credit_transfers.c b/src/exchangedb/select_exchange_credit_transfers.c
@@ -1,180 +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 exchangedb/select_exchange_credit_transfers.c
- * @brief Implementation of the select_exchange_credit_transfers function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_exchange_credit_transfers.h"
-#include "helper.h"
-
-/**
- * Closure for #handle_aml_result.
- */
-struct SelectTransferContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlTransferCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_exchange_debit_transfers().
- *
- * @param cls closure of type `struct SelectTransferContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_transfer_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SelectTransferContext *stc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- char *payto_uri;
- uint64_t rowid;
- struct GNUNET_TIME_Absolute execution_time;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial_id",
- &rowid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_absolute_time ("execution_time",
- &execution_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- stc->status = GNUNET_SYSERR;
- return;
- }
- stc->cb (stc->cb_cls,
- rowid,
- payto_uri,
- execution_time,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_exchange_credit_transfers (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- void *cb_cls)
-{
- struct SelectTransferContext stc = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- TALER_PQ_query_param_amount (pg->conn,
- threshold),
- NULL != h_payto
- ? GNUNET_PQ_query_param_auto_from_type (h_payto)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_exchange_credit_transfers_inc",
- "SELECT"
- " ri.reserve_in_serial_id AS serial_id"
- ",wt.payto_uri"
- ",ri.execution_date AS execution_time"
- ",ri.credit AS amount"
- " FROM reserves_in ri"
- " LEFT JOIN wire_targets wt"
- " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE (ri.reserve_in_serial_id > $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (ri.credit).val > ($3::taler_amount).val)"
- " OR ( ( (ri.credit).val >= ($3::taler_amount).val)"
- " AND ( (ri.credit).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY ri.reserve_in_serial_id ASC"
- " LIMIT $2");
- PREPARE (pg,
- "select_exchange_credit_transfers_dec",
- "SELECT"
- " ri.reserve_in_serial_id AS serial_id"
- ",wt.payto_uri"
- ",ri.execution_date AS execution_time"
- ",ri.credit AS amount"
- " FROM reserves_in ri"
- " LEFT JOIN wire_targets wt"
- " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE (ri.reserve_in_serial_id < $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (ri.credit).val > ($3::taler_amount).val)"
- " OR ( ( (ri.credit).val >= ($3::taler_amount).val)"
- " AND ( (ri.credit).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY ri.reserve_in_serial_id DESC"
- " LIMIT $2");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "select_exchange_credit_transfers_inc"
- : "select_exchange_credit_transfers_dec",
- params,
- &handle_transfer_result,
- &stc);
- if (GNUNET_OK != stc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_exchange_debit_transfers.c b/src/exchangedb/select_exchange_debit_transfers.c
@@ -1,181 +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 exchangedb/select_exchange_debit_transfers.c
- * @brief Implementation of the select_exchange_debit_transfers function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_exchange_debit_transfers.h"
-#include "helper.h"
-
-
-/**
- * Closure for #handle_aml_result.
- */
-struct SelectTransferContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlTransferCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_exchange_debit_transfers().
- *
- * @param cls closure of type `struct SelectTransferContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_transfer_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SelectTransferContext *stc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- char *payto_uri;
- uint64_t rowid;
- struct GNUNET_TIME_Absolute execution_time;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial_id",
- &rowid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_absolute_time ("execution_time",
- &execution_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- stc->status = GNUNET_SYSERR;
- return;
- }
- stc->cb (stc->cb_cls,
- rowid,
- payto_uri,
- execution_time,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_exchange_debit_transfers (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- void *cb_cls)
-{
- struct SelectTransferContext stc = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- TALER_PQ_query_param_amount (pg->conn,
- threshold),
- NULL != h_payto
- ? GNUNET_PQ_query_param_auto_from_type (h_payto)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_exchange_debit_transfers_inc",
- "SELECT"
- " wo.wireout_uuid AS serial_id"
- ",wt.payto_uri"
- ",wo.execution_date AS execution_time"
- ",wo.amount"
- " FROM wire_out wo"
- " LEFT JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " WHERE (wo.wireout_uuid > $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (wo.amount).val > ($3::taler_amount).val)"
- " OR ( ( (wo.amount).val >= ($3::taler_amount).val)"
- " AND ( (wo.amount).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY wo.wireout_uuid ASC"
- " LIMIT $2");
- PREPARE (pg,
- "select_exchange_debit_transfers_dec",
- "SELECT"
- " wo.wireout_uuid AS serial_id"
- ",wt.payto_uri"
- ",wo.execution_date AS execution_time"
- ",wo.amount"
- " FROM wire_out wo"
- " LEFT JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " WHERE (wo.wireout_uuid < $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (wo.amount).val > ($3::taler_amount).val)"
- " OR ( ( (wo.amount).val >= ($3::taler_amount).val)"
- " AND ( (wo.amount).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY wo.wireout_uuid DESC"
- " LIMIT $2");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "select_exchange_debit_transfers_inc"
- : "select_exchange_debit_transfers_dec",
- params,
- &handle_transfer_cb,
- &stc);
- if (GNUNET_OK != stc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_exchange_kycauth_transfers.c b/src/exchangedb/select_exchange_kycauth_transfers.c
@@ -1,180 +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 exchangedb/select_exchange_kycauth_transfers.c
- * @brief Implementation of the select_exchange_kycauth_transfers function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_exchange_kycauth_transfers.h"
-#include "helper.h"
-
-/**
- * Closure for #handle_aml_result.
- */
-struct SelectTransferContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlTransferCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_exchange_debit_transfers().
- *
- * @param cls closure of type `struct SelectTransferContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_transfer_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SelectTransferContext *stc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- char *payto_uri;
- uint64_t rowid;
- struct GNUNET_TIME_Absolute execution_time;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial_id",
- &rowid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_absolute_time ("execution_time",
- &execution_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- stc->status = GNUNET_SYSERR;
- return;
- }
- stc->cb (stc->cb_cls,
- rowid,
- payto_uri,
- execution_time,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_exchange_kycauth_transfers (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- void *cb_cls)
-{
- struct SelectTransferContext stc = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- TALER_PQ_query_param_amount (pg->conn,
- threshold),
- NULL != h_payto
- ? GNUNET_PQ_query_param_auto_from_type (h_payto)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_exchange_kycauth_transfers_inc",
- "SELECT"
- " ki.kycauth_in_serial_id AS serial_id"
- ",wt.payto_uri"
- ",ki.execution_date AS execution_time"
- ",ki.credit AS amount"
- " FROM kycauths_in ki"
- " LEFT JOIN wire_targets wt"
- " ON (ki.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE (ki.kycauth_in_serial_id > $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (ki.credit).val > ($3::taler_amount).val)"
- " OR ( ( (ki.credit).val >= ($3::taler_amount).val)"
- " AND ( (ki.credit).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY ki.kycauth_in_serial_id ASC"
- " LIMIT $2");
- PREPARE (pg,
- "select_exchange_kycauth_transfers_dec",
- "SELECT"
- " ki.kycauth_in_serial_id AS serial_id"
- ",wt.payto_uri"
- ",ki.execution_date AS execution_time"
- ",ki.credit AS amount"
- " FROM kycauths_in ki"
- " LEFT JOIN wire_targets wt"
- " ON (ki.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE (ki.kycauth_in_serial_id < $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (ki.credit).val > ($3::taler_amount).val)"
- " OR ( ( (ki.credit).val >= ($3::taler_amount).val)"
- " AND ( (ki.credit).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY ki.kycauth_in_serial_id DESC"
- " LIMIT $2");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "select_exchange_kycauth_transfers_inc"
- : "select_exchange_kycauth_transfers_dec",
- params,
- &handle_transfer_result,
- &stc);
- if (GNUNET_OK != stc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_kyc_accounts.c b/src/exchangedb/select_kyc_accounts.c
@@ -1,238 +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 exchangedb/select_kyc_accounts.c
- * @brief Implementation of the select_kyc_accounts function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_kyc_accounts.h"
-#include "helper.h"
-
-
-/**
- * Closure for #handle_aml_result.
- */
-struct KycAccountResultContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlAccountListCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_kyc_accounts().
- *
- * @param cls closure of type `struct KycAccountResultContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_kyc_account_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct KycAccountResultContext *ctx = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_NormalizedPaytoHashP h_payto;
- char *comments = NULL;
- struct GNUNET_TIME_Timestamp open_time
- = GNUNET_TIME_UNIT_FOREVER_TS;
- struct GNUNET_TIME_Timestamp close_time
- = GNUNET_TIME_UNIT_FOREVER_TS;
- bool to_investigate;
- bool high_risk;
- struct TALER_FullPayto payto;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("kyc_target_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("h_payto",
- &h_payto),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("comments",
- &comments),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_timestamp ("open_time",
- &open_time),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_timestamp ("close_time",
- &close_time),
- NULL),
- GNUNET_PQ_result_spec_bool ("to_investigate",
- &to_investigate),
- GNUNET_PQ_result_spec_bool ("high_risk",
- &high_risk),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto.full_payto),
- 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,
- rowid,
- &h_payto,
- open_time,
- close_time,
- comments,
- high_risk,
- to_investigate,
- payto);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_kyc_accounts (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- enum TALER_EXCHANGE_YesNoAll investigation_only,
- enum TALER_EXCHANGE_YesNoAll open_only,
- enum TALER_EXCHANGE_YesNoAll high_risk_only,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlAccountListCallback cb,
- void *cb_cls)
-{
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
- investigation_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
- investigation_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
- open_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
- open_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL ==
- high_risk_only)),
- GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES ==
- high_risk_only)),
- GNUNET_PQ_query_param_end
- };
- struct KycAccountResultContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
- const char *stmt = (limit > 0)
- ? "select_kyc_accounts_inc"
- : "select_kyc_accounts_dec";
-
- PREPARE (pg,
- "select_kyc_accounts_inc",
- "SELECT"
- " kt.kyc_target_serial_id"
- ",kt.h_normalized_payto AS h_payto"
- ",kt.open_time"
- ",kt.close_time"
- ",lo.jproperties ->> 'FILE_NOTE' AS comments"
- ",COALESCE(lo.to_investigate,FALSE) AS to_investigate"
- ",COALESCE((lo.jproperties ->> 'HIGH_RISK_CUSTOMER')::bool,FALSE) AS high_risk"
- ",wt.payto_uri"
- " FROM kyc_targets kt"
- " LEFT JOIN legitimization_outcomes lo"
- " ON (lo.h_payto = kt.h_normalized_payto)"
- " LEFT JOIN LATERAL ("
- " SELECT payto_uri"
- " FROM wire_targets"
- " WHERE h_normalized_payto = kt.h_normalized_payto"
- " ORDER BY wire_target_serial_id DESC"
- " LIMIT 1"
- " ) wt ON true"
- " WHERE (kyc_target_serial_id > $1)"
- // select most recent outcomes only
- " AND COALESCE (lo.is_active, TRUE)"
- " AND ($3 OR (COALESCE(lo.to_investigate,FALSE) = $4))"
- // Account is open if we had an AML outcome
- " AND ($5 OR ((lo.outcome_serial_id IS NULL) = $6))"
- " AND ($7 OR ((COALESCE((lo.jproperties ->>'HIGH_RISK_CUSTOMER')::bool,FALSE) = $8)))"
- " ORDER BY kt.kyc_target_serial_id ASC"
- " LIMIT $2");
- PREPARE (pg,
- "select_kyc_accounts_dec",
- "SELECT"
- " kt.kyc_target_serial_id"
- ",kt.h_normalized_payto AS h_payto"
- ",kt.open_time"
- ",kt.close_time"
- ",lo.jproperties ->> 'FILE_NOTE' AS comments"
- ",COALESCE(lo.to_investigate,FALSE) AS to_investigate"
- ",COALESCE((lo.jproperties ->> 'HIGH_RISK_CUSTOMER')::bool,FALSE) AS high_risk"
- ",wt.payto_uri"
- " FROM kyc_targets kt"
- " LEFT JOIN legitimization_outcomes lo"
- " ON (lo.h_payto = kt.h_normalized_payto)"
- " LEFT JOIN LATERAL ("
- " SELECT payto_uri"
- " FROM wire_targets"
- " WHERE h_normalized_payto = kt.h_normalized_payto"
- " ORDER BY wire_target_serial_id DESC"
- " LIMIT 1"
- " ) wt ON true"
- " WHERE (kyc_target_serial_id < $1)"
- // select most recent outcomes only
- " AND COALESCE (lo.is_active, TRUE)"
- " AND ($3 OR (COALESCE(lo.to_investigate,FALSE) = $4))"
- // Account is open if we had an AML outcome
- " AND ($5 OR ((lo.outcome_serial_id IS NULL) = $6))"
- " AND ($7 OR ((COALESCE((lo.jproperties ->>'HIGH_RISK_CUSTOMER')::bool,FALSE) = $8)))"
- " ORDER BY kt.kyc_target_serial_id DESC"
- " LIMIT $2");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- stmt,
- params,
- &handle_kyc_account_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_kyc_attributes.c b/src/exchangedb/select_kyc_attributes.c
@@ -1,154 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_kyc_attributes.c
- * @brief Implementation of the select_kyc_attributes function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_kyc_attributes.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_attributes_cb().
- */
-struct GetAttributesContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_AttributeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Key of our query.
- */
- const struct TALER_NormalizedPaytoHashP *h_payto;
-
- /**
- * 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 GetAttributesContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_attributes_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetAttributesContext *ctx = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct GNUNET_TIME_Timestamp collection_time;
- struct GNUNET_TIME_Timestamp expiration_time;
- size_t enc_attributes_size;
- void *enc_attributes;
- char *provider;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("provider_name",
- &provider),
- GNUNET_PQ_result_spec_timestamp ("collection_time",
- &collection_time),
- GNUNET_PQ_result_spec_timestamp ("expiration_time",
- &expiration_time),
- GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
- &enc_attributes,
- &enc_attributes_size),
- 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,
- ctx->h_payto,
- provider,
- collection_time,
- expiration_time,
- enc_attributes_size,
- enc_attributes);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_kyc_attributes (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AttributeCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GetAttributesContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .h_payto = h_payto,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_kyc_attributes",
- "SELECT "
- " lp.provider_name"
- ",ka.collection_time"
- ",ka.expiration_time"
- ",ka.encrypted_attributes"
- " FROM kyc_attributes ka"
- " JOIN legitimization_processes lp"
- " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
- " WHERE ka.h_payto=$1");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_kyc_attributes",
- params,
- &get_attributes_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_merge_amounts_for_kyc_check.c b/src/exchangedb/select_merge_amounts_for_kyc_check.c
@@ -1,152 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_merge_amounts_for_kyc_check.c
- * @brief Implementation of the select_merge_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_merge_amounts_for_kyc_check.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_kyc_amounts_cb().
- */
-struct KycAmountCheckContext
-{
- /**
- * Function to call per result.
- */
- TALER_KYCLOGIC_KycAmountCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 KycAmountCheckContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_kyc_amounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct KycAmountCheckContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct GNUNET_TIME_Absolute date;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_absolute_time ("date",
- &date),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ret = ctx->cb (ctx->cb_cls,
- &amount,
- date);
- GNUNET_PQ_cleanup_result (rs);
- switch (ret)
- {
- case GNUNET_OK:
- continue;
- case GNUNET_NO:
- break;
- case GNUNET_SYSERR:
- ctx->status = GNUNET_SYSERR;
- break;
- }
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_merge_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_absolute_time (&time_limit),
- GNUNET_PQ_query_param_end
- };
- struct KycAmountCheckContext ctx = {
- .cb = kac,
- .cb_cls = kac_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_kyc_relevant_merge_events",
- "SELECT"
- " amount_with_fee AS amount"
- ",merge_timestamp AS date"
- " FROM account_merges"
- " JOIN purse_merges USING (purse_pub)"
- " JOIN purse_requests USING (purse_pub)"
- " JOIN purse_decision USING (purse_pub)"
- " WHERE wallet_h_payto=$1"
- " AND merge_timestamp >= $2"
- " AND NOT refunded"
- " ORDER BY merge_timestamp DESC");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_kyc_relevant_merge_events",
- params,
- &get_kyc_amounts_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_purse.c b/src/exchangedb/select_purse.c
@@ -1,90 +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 select_purse.c
- * @brief Implementation of the select_purse function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_purse (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp *purse_creation,
- struct GNUNET_TIME_Timestamp *purse_expiration,
- struct TALER_Amount *amount,
- struct TALER_Amount *deposited,
- struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp *merge_timestamp,
- bool *purse_deleted,
- bool *purse_refunded)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- purse_expiration),
- GNUNET_PQ_result_spec_timestamp ("purse_creation",
- purse_creation),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- deposited),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- h_contract_terms),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- merge_timestamp),
- NULL),
- GNUNET_PQ_result_spec_bool ("purse_deleted",
- purse_deleted),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_bool ("purse_refunded",
- purse_refunded),
- NULL),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_purse",
- "SELECT "
- " pr.merge_pub"
- ",pr.purse_creation"
- ",pr.purse_expiration"
- ",pr.h_contract_terms"
- ",pr.amount_with_fee"
- ",pr.balance"
- ",pm.merge_timestamp"
- ",pd.purse_sig IS NOT NULL AS purse_deleted"
- ",pc.refunded AS purse_refunded"
- " FROM purse_requests pr"
- " LEFT JOIN purse_merges pm ON (pm.purse_pub = pr.purse_pub)"
- " LEFT JOIN purse_decision pc ON (pc.purse_pub = pr.purse_pub)"
- " LEFT JOIN purse_deletion pd ON (pd.purse_pub = pr.purse_pub)"
- " WHERE pr.purse_pub=$1;");
- *merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
- *purse_refunded = false;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_purse_by_merge_pub.c b/src/exchangedb/select_purse_by_merge_pub.c
@@ -1,75 +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 exchangedb/select_purse_by_merge_pub.c
- * @brief Implementation of the select_purse_by_merge_pub function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_by_merge_pub.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_by_merge_pub (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp *purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
- uint32_t *age_limit,
- struct TALER_Amount *target_amount,
- struct TALER_Amount *balance,
- struct TALER_PurseContractSignatureP *purse_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (merge_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- purse_pub),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- purse_expiration),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- h_contract_terms),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- age_limit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- target_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- balance),
- GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
- purse_sig),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_purse_by_merge_pub",
- "SELECT "
- " purse_pub"
- ",purse_expiration"
- ",h_contract_terms"
- ",age_limit"
- ",amount_with_fee"
- ",balance"
- ",purse_sig"
- " FROM purse_requests"
- " WHERE merge_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_by_merge_pub",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_purse_decisions_above_serial_id.c b/src/exchangedb/select_purse_decisions_above_serial_id.c
@@ -1,158 +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 exchangedb/select_purse_decisions_above_serial_id.c
- * @brief Implementation of the select_purse_decisions_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_decisions_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #purse_decision_serial_helper_cb().
- */
-struct PurseDecisionSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseDecisionCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRefundSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_decision_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseDecisionSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_ReservePublicKeyP reserve_pub;
- bool no_reserve = true;
- uint64_t rowid;
- struct TALER_Amount val;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- &no_reserve),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &val),
- GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &purse_pub,
- no_reserve ? NULL : &reserve_pub,
- &val);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_decisions_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- bool refunded,
- TALER_EXCHANGEDB_PurseDecisionCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_bool (refunded),
- GNUNET_PQ_query_param_end
- };
- struct PurseDecisionSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_get_purse_decisions_incr",
- "SELECT"
- " pd.purse_pub"
- ",pm.reserve_pub"
- ",pd.purse_decision_serial_id"
- ",pr.amount_with_fee"
- " FROM purse_decision pd"
- " JOIN purse_requests pr ON (pd.purse_pub = pr.purse_pub)"
- " LEFT JOIN purse_merges pm ON (pm.purse_pub = pd.purse_pub)"
- " WHERE ("
- " (purse_decision_serial_id>=$1) AND "
- " (refunded=$2)"
- " )"
- " ORDER BY purse_decision_serial_id ASC;");
-
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_decisions_incr",
- params,
- &purse_decision_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_purse_deposits_above_serial_id.c b/src/exchangedb/select_purse_deposits_above_serial_id.c
@@ -1,198 +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 select_purse_deposits_above_serial_id.c
- * @brief Implementation of the select_purse_deposits_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_deposits_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #purse_deposit_serial_helper_cb().
- */
-struct PurseDepositSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseDepositCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_deposit_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseDepositSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_PurseDeposit deposit = {
- .exchange_base_url = NULL
- };
- struct TALER_DenominationPublicKey denom_pub;
- uint64_t rowid;
- uint32_t flags32;
- struct TALER_ReservePublicKeyP reserve_pub;
- bool not_merged = false;
- struct TALER_Amount purse_balance;
- struct TALER_Amount purse_total;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit.amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &purse_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("total",
- &purse_total),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &deposit.deposit_fee),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- &deposit.exchange_base_url),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- ¬_merged),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &deposit.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &deposit.coin_sig),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &deposit.coin_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &deposit.h_age_commitment),
- &deposit.no_age_commitment),
- GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- memset (&deposit,
- 0,
- sizeof (deposit));
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &deposit,
- not_merged ? NULL : &reserve_pub,
- (enum TALER_WalletAccountMergeFlags) flags32,
- &purse_balance,
- &purse_total,
- &denom_pub);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_deposits_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_PurseDepositCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct PurseDepositSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_get_purse_deposits_incr",
- "SELECT"
- " pd.amount_with_fee"
- ",pr.amount_with_fee AS total"
- ",pr.balance"
- ",pr.flags"
- ",pd.purse_pub"
- ",pd.coin_sig"
- ",partner_base_url"
- ",denom.denom_pub"
- ",denom.fee_deposit"
- ",pm.reserve_pub"
- ",kc.coin_pub"
- ",kc.age_commitment_hash"
- ",pd.purse_deposit_serial_id"
- " FROM purse_deposits pd"
- " LEFT JOIN partners USING (partner_serial_id)"
- " LEFT JOIN purse_merges pm USING (purse_pub)"
- " JOIN purse_requests pr USING (purse_pub)"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations denom USING (denominations_serial)"
- " WHERE ("
- " (purse_deposit_serial_id>=$1)"
- " )"
- " ORDER BY purse_deposit_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_deposits_incr",
- params,
- &purse_deposit_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_purse_deposits_by_purse.c b/src/exchangedb/select_purse_deposits_by_purse.c
@@ -1,149 +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 exchangedb/select_purse_deposits_by_purse.c
- * @brief Implementation of the select_purse_deposits_by_purse function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_deposits_by_purse.h"
-#include "helper.h"
-
-/**
- * Closure for #purse_refund_coin_helper_cb().
- */
-struct PurseRefundCoinContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseRefundCoinCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRefundCoinContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_refund_coin_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseRefundCoinContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_Amount amount_with_fee;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_DenominationPublicKey denom_pub;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &amount_with_fee,
- &coin_pub,
- &denom_pub);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_deposits_by_purse (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- TALER_EXCHANGEDB_PurseRefundCoinCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct PurseRefundCoinContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_get_purse_deposits_by_purse",
- "SELECT"
- " pd.purse_deposit_serial_id"
- ",pd.amount_with_fee"
- ",pd.coin_pub"
- ",denom.denom_pub"
- " FROM purse_deposits pd"
- " JOIN known_coins kc"
- " USING (coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " WHERE purse_pub=$1;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_deposits_by_purse",
- params,
- &purse_refund_coin_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_purse_merge.c b/src/exchangedb/select_purse_merge.c
@@ -1,76 +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 exchangedb/select_purse_merge.c
- * @brief Implementation of the select_purse_merge function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_merge.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_merge (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_PurseMergeSignatureP *merge_sig,
- struct GNUNET_TIME_Timestamp *merge_timestamp,
- char **partner_url,
- struct TALER_ReservePublicKeyP *reserve_pub,
- bool *refunded)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
- merge_sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- reserve_pub),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- merge_timestamp),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- partner_url),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_bool ("refunded",
- refunded),
- NULL),
- GNUNET_PQ_result_spec_end
- };
-
- *partner_url = NULL;
- *refunded = false;
- PREPARE (pg,
- "select_purse_merge",
- "SELECT "
- " pm.reserve_pub"
- ",pm.merge_sig"
- ",pm.merge_timestamp"
- ",pr.partner_base_url"
- ",pd.refunded"
- " FROM purse_merges pm"
- " LEFT JOIN purse_decision pd USING (purse_pub)"
- " LEFT JOIN partners pr USING (partner_serial_id)"
- " WHERE pm.purse_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_merge",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_purse_merges_above_serial_id.c b/src/exchangedb/select_purse_merges_above_serial_id.c
@@ -1,186 +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 select_purse_merges_above_serial_id.c
- * @brief Implementation of the select_purse_merges_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_merges_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #purse_deposit_serial_helper_cb().
- */
-struct PurseMergeSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseMergeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseMergeSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_merges_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseMergeSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- char *partner_base_url = NULL;
- struct TALER_Amount amount;
- struct TALER_Amount balance;
- uint32_t flags32;
- enum TALER_WalletAccountMergeFlags flags;
- struct TALER_PurseMergePublicKeyP merge_pub;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseMergeSignatureP merge_sig;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &balance),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- &partner_base_url),
- NULL),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- &merge_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
- &merge_sig),
- GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
- &merge_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_merge_request_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- flags = (enum TALER_WalletAccountMergeFlags) flags32;
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- partner_base_url,
- &amount,
- &balance,
- flags,
- &merge_pub,
- &reserve_pub,
- &merge_sig,
- &purse_pub,
- merge_timestamp);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_TALER_EXCHANGEDB_select_purse_merges_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_PurseMergeCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct PurseMergeSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_get_purse_merge_incr",
- "SELECT"
- " pm.purse_merge_request_serial_id"
- ",partner_base_url"
- ",pr.amount_with_fee"
- ",pr.balance"
- ",pr.flags"
- ",pr.merge_pub"
- ",pm.reserve_pub"
- ",pm.merge_sig"
- ",pm.purse_pub"
- ",pm.merge_timestamp"
- " FROM purse_merges pm"
- " JOIN purse_requests pr USING (purse_pub)"
- " LEFT JOIN partners USING (partner_serial_id)"
- " WHERE ("
- " (purse_merge_request_serial_id>=$1)"
- " )"
- " ORDER BY purse_merge_request_serial_id ASC;");
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_merge_incr",
- params,
- &purse_merges_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_purse_requests_above_serial_id.c b/src/exchangedb/select_purse_requests_above_serial_id.c
@@ -1,174 +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 select_purse_requests_above_serial_id.c
- * @brief Implementation of the select_purse_requests_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_purse_requests_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #purse_deposit_serial_helper_cb().
- */
-struct PurseRequestsSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseRequestCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRequestsSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_requests_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseRequestsSerialContext *dsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_Amount target_amount;
- uint32_t age_limit;
- struct TALER_PurseMergePublicKeyP merge_pub;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PrivateContractHashP h_contract_terms;
- struct TALER_PurseContractSignatureP purse_sig;
- struct GNUNET_TIME_Timestamp purse_creation;
- struct GNUNET_TIME_Timestamp purse_expiration;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &target_amount),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- &age_limit),
- GNUNET_PQ_result_spec_timestamp ("purse_creation",
- &purse_creation),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- &purse_expiration),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
- &purse_sig),
- GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
- &merge_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_requests_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &purse_pub,
- &merge_pub,
- purse_creation,
- purse_expiration,
- &h_contract_terms,
- age_limit,
- &target_amount,
- &purse_sig);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_requests_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_PurseRequestCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct PurseRequestsSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "audit_get_purse_requests_incr",
- "SELECT"
- " purse_requests_serial_id"
- ",purse_pub"
- ",amount_with_fee"
- ",age_limit"
- ",h_contract_terms"
- ",purse_creation"
- ",purse_expiration"
- ",merge_pub"
- ",purse_sig"
- " FROM purse_requests"
- " WHERE ("
- " (purse_requests_serial_id>=$1)"
- " )"
- " ORDER BY purse_requests_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_requests_incr",
- params,
- &purse_requests_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_recoup_above_serial_id.c b/src/exchangedb/select_recoup_above_serial_id.c
@@ -1,186 +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 exchangedb/select_recoup_above_serial_id.c
- * @brief Implementation of the select_recoup_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_recoup_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #recoup_serial_helper_cb().
- */
-struct RecoupSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RecoupCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RecoupSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-recoup_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RecoupSerialContext *psc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = psc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_CoinPublicInfo coin;
- struct TALER_CoinSpendSignatureP coin_sig;
- union GNUNET_CRYPTO_BlindingSecretP coin_blind;
- struct TALER_Amount amount;
- struct TALER_DenominationPublicKey denom_pub;
- struct GNUNET_TIME_Timestamp timestamp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- ×tamp),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin.coin_pub),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &coin_blind),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &coin.denom_pub_hash),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &coin.h_age_commitment),
- &coin.no_age_commitment),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &coin.denom_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- int ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- psc->status = GNUNET_SYSERR;
- return;
- }
- ret = psc->cb (psc->cb_cls,
- rowid,
- timestamp,
- &amount,
- &reserve_pub,
- &coin,
- &denom_pub,
- &coin_sig,
- &coin_blind);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_recoup_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RecoupCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RecoupSerialContext psc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- /* FIXME-9828: this query joins with table/columns
- that no longer exist... */
- PREPARE (pg,
- "recoup_get_incr",
- "SELECT"
- " recoup_uuid"
- ",recoup_timestamp"
- ",withdraw.reserve_pub"
- ",coins.coin_pub"
- ",coin_sig"
- ",coin_blind"
- ",denoms.denom_pub_hash"
- ",coins.denom_sig"
- ",coins.age_commitment_hash"
- ",denoms.denom_pub"
- ",amount"
- " FROM recoup"
- " JOIN known_coins coins"
- " USING (coin_pub)"
- " JOIN withdraw"
- " USING (withdraw_id)"
- " JOIN denominations denoms"
- " ON (coins.denominations_serial = denoms.denominations_serial)"
- " WHERE recoup_uuid>=$1"
- " ORDER BY recoup_uuid ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "recoup_get_incr",
- params,
- &recoup_serial_helper_cb,
- &psc);
- if (GNUNET_OK != psc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_recoup_refresh_above_serial_id.c b/src/exchangedb/select_recoup_refresh_above_serial_id.c
@@ -1,204 +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 exchangedb/select_recoup_refresh_above_serial_id.c
- * @brief Implementation of the select_recoup_refresh_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_recoup_refresh_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #recoup_refresh_serial_helper_cb().
- */
-struct RecoupRefreshSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RecoupRefreshCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RecoupRefreshSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-recoup_refresh_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RecoupRefreshSerialContext *psc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = psc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_CoinSpendPublicKeyP old_coin_pub;
- struct TALER_CoinPublicInfo coin;
- struct TALER_CoinSpendSignatureP coin_sig;
- union GNUNET_CRYPTO_BlindingSecretP coin_blind;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_DenominationHashP old_denom_pub_hash;
- struct TALER_Amount amount;
- struct TALER_BlindedCoinHashP h_blind_ev;
- struct GNUNET_TIME_Timestamp timestamp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- ×tamp),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &old_coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("old_denom_pub_hash",
- &old_denom_pub_hash),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &coin_blind),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
- &h_blind_ev),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &coin.denom_pub_hash),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &coin.h_age_commitment),
- &coin.no_age_commitment),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &coin.denom_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- psc->status = GNUNET_SYSERR;
- return;
- }
- ret = psc->cb (psc->cb_cls,
- rowid,
- timestamp,
- &amount,
- &old_coin_pub,
- &old_denom_pub_hash,
- &coin,
- &denom_pub,
- &coin_sig,
- &coin_blind);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_recoup_refresh_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RecoupRefreshCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RecoupRefreshSerialContext psc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_recoup_refresh_above_serial_id",
- "SELECT"
- " rr.recoup_refresh_uuid"
- ",rr.recoup_timestamp"
- ",rr.coin_sig"
- ",rr.coin_blind"
- ",rr.amount"
- ",rrc.h_coin_ev AS h_blind_ev" // FIXME:-#9828 r.rc? r.selected_h? Old logic wanted a TALER_BlindedCoinHash, which we now need to derive (from rr.coin_blind)
- ",new_coins.age_commitment_hash"
- ",new_coins.coin_pub AS coin_pub"
- ",new_denoms.denom_pub AS denom_pub"
- ",new_denoms.denom_pub_hash"
- ",new_coins.denom_sig AS denom_sig"
- ",old_coins.coin_pub AS old_coin_pub"
- ",old_denoms.denom_pub_hash AS old_denom_pub_hash"
- " FROM recoup_refresh rr"
- " INNER JOIN refresh_revealed_coins rrc" // FIXME-#9828: no such table anymore!
- // but we have 'refresh_id" which is an FK into 'refresh'!
- " USING (rrc_serial)"
- " INNER JOIN refresh r"
- // but we have 'refresh_id" which is an FK into 'refresh'!
- " USING (refresh_id)"
- " INNER JOIN known_coins old_coins"
- " ON (r.old_coin_pub = old_coins.coin_pub)"
- " INNER JOIN known_coins new_coins"
- " ON (rr.coin_pub = new_coins.coin_pub)"
- " INNER JOIN refresh_commitments rfc"
- " ON (rrc.melt_serial_id = rfc.melt_serial_id)"
- " INNER JOIN denominations new_denoms"
- " ON (new_coins.denominations_serial = new_denoms.denominations_serial)"
- " INNER JOIN denominations old_denoms"
- " ON (old_coins.denominations_serial = old_denoms.denominations_serial)"
- " WHERE recoup_refresh_uuid>=$1"
- " ORDER BY recoup_refresh_uuid ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_recoup_refresh_above_serial_id",
- params,
- &recoup_refresh_serial_helper_cb,
- &psc);
- if (GNUNET_OK != psc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_refreshes_above_serial_id.c b/src/exchangedb/select_refreshes_above_serial_id.c
@@ -1,180 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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 exchangedb/select_refreshes_above_serial_id.c
- * @brief Implementation of the select_refreshes_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_refreshes_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #refreshs_serial_helper_cb().
- */
-struct RefreshsSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RefreshesCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RefreshsSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-refreshs_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RefreshsSerialContext *rsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = rsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_DenominationPublicKey old_denom_pub;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct TALER_AgeCommitmentHashP h_age_commitment;
- bool ac_isnull;
- struct TALER_Amount amount_with_fee;
- uint64_t rowid;
- struct TALER_RefreshCommitmentP rc;
- size_t num_nds;
- uint64_t *nds;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_denom_pub ("old_denom_pub",
- &old_denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &h_age_commitment),
- &ac_isnull),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
- &coin_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_uint64 ("refresh_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("rc",
- &rc),
- GNUNET_PQ_result_spec_array_uint64 (pg->conn,
- "new_denominations_serials",
- &num_nds,
- &nds),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rsc->status = GNUNET_SYSERR;
- return;
- }
-
- ret = rsc->cb (rsc->cb_cls,
- rowid,
- &old_denom_pub,
- &coin_pub,
- &coin_sig,
- ac_isnull ? NULL : &h_age_commitment,
- &amount_with_fee,
- num_nds,
- nds,
- &rc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_refreshes_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RefreshesCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RefreshsSerialContext rsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_refreshes_above_serial_id",
- "SELECT"
- " denom.denom_pub AS old_denom_pub"
- ",r.old_coin_pub"
- ",kc.age_commitment_hash"
- ",r.old_coin_sig"
- ",r.amount_with_fee"
- ",r.refresh_id"
- ",r.rc"
- ",r.denom_serials AS new_denominations_serials"
- " FROM refresh r"
- " JOIN known_coins kc"
- " ON (r.old_coin_pub = kc.coin_pub)"
- " JOIN denominations denom"
- " ON (kc.denominations_serial = denom.denominations_serial)"
- " WHERE refresh_id>=$1"
- " ORDER BY refresh_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_refreshes_above_serial_id",
- params,
- &refreshs_serial_helper_cb,
- &rsc);
- if (GNUNET_OK != rsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_refunds_above_serial_id.c b/src/exchangedb/select_refunds_above_serial_id.c
@@ -1,221 +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 exchangedb/select_refunds_above_serial_id.c
- * @brief Implementation of the select_refunds_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_refunds_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #refunds_serial_helper_cb().
- */
-struct RefundsSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RefundCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RefundsSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-refunds_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RefundsSerialContext *rsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = rsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_Refund refund;
- struct TALER_DenominationPublicKey denom_pub;
- uint64_t rowid;
- bool full_refund;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &refund.details.merchant_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
- &refund.details.merchant_sig),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &refund.details.h_contract_terms),
- GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
- &refund.details.rtransaction_id),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &refund.coin.coin_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &refund.details.refund_amount),
- GNUNET_PQ_result_spec_uint64 ("refund_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rsc->status = GNUNET_SYSERR;
- return;
- }
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
- struct TALER_Amount amount_with_fee;
- uint64_t s_f;
- uint64_t s_v;
- struct GNUNET_PQ_ResultSpec rs2[] = {
- GNUNET_PQ_result_spec_uint64 ("s_v",
- &s_v),
- GNUNET_PQ_result_spec_uint64 ("s_f",
- &s_f),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "test_refund_full",
- params,
- rs2);
- if (qs <= 0)
- {
- GNUNET_break (0);
- rsc->status = GNUNET_SYSERR;
- return;
- }
- /* normalize */
- s_v += s_f / TALER_AMOUNT_FRAC_BASE;
- s_f %= TALER_AMOUNT_FRAC_BASE;
- full_refund = (s_v > amount_with_fee.value) ||
- ( (s_v == amount_with_fee.value) &&
- (s_f >= amount_with_fee.fraction) );
- }
- ret = rsc->cb (rsc->cb_cls,
- rowid,
- &denom_pub,
- &refund.coin.coin_pub,
- &refund.details.merchant_pub,
- &refund.details.merchant_sig,
- &refund.details.h_contract_terms,
- refund.details.rtransaction_id,
- full_refund,
- &refund.details.refund_amount);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_refunds_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RefundCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RefundsSerialContext rsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- /* Fetch refunds with rowid '\geq' the given parameter */
- PREPARE (pg,
- "audit_get_refunds_incr",
- "SELECT"
- " bdep.merchant_pub"
- ",ref.merchant_sig"
- ",bdep.h_contract_terms"
- ",ref.rtransaction_id"
- ",denom.denom_pub"
- ",kc.coin_pub"
- ",ref.amount_with_fee"
- ",ref.refund_serial_id"
- " FROM refunds ref"
- " JOIN batch_deposits bdep"
- " ON (ref.batch_deposit_serial_id=bdep.batch_deposit_serial_id)"
- " JOIN coin_deposits cdep"
- " ON (ref.coin_pub=cdep.coin_pub AND ref.batch_deposit_serial_id=cdep.batch_deposit_serial_id)"
- " JOIN known_coins kc"
- " ON (cdep.coin_pub=kc.coin_pub)"
- " JOIN denominations denom"
- " ON (kc.denominations_serial=denom.denominations_serial)"
- " WHERE ref.refund_serial_id>=$1"
- " ORDER BY ref.refund_serial_id ASC;");
- PREPARE (pg,
- "test_refund_full",
- "SELECT"
- " CAST(SUM(CAST((ref.amount_with_fee).frac AS INT8)) AS INT8) AS s_f"
- ",CAST(SUM((ref.amount_with_fee).val) AS INT8) AS s_v"
- ",cdep.amount_with_fee"
- " FROM refunds ref"
- " JOIN coin_deposits cdep"
- " ON (ref.coin_pub=cdep.coin_pub AND ref.batch_deposit_serial_id=cdep.batch_deposit_serial_id)"
- " WHERE ref.refund_serial_id=$1"
- " GROUP BY (cdep.amount_with_fee);");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_refunds_incr",
- params,
- &refunds_serial_helper_cb,
- &rsc);
- if (GNUNET_OK != rsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_refunds_by_coin.c b/src/exchangedb/select_refunds_by_coin.c
@@ -1,139 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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 exchangedb/select_refunds_by_coin.c
- * @brief Implementation of the select_refunds_by_coin function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_refunds_by_coin.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_refunds_cb().
- */
-struct SelectRefundContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_RefundCoinCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct SelectRefundContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-get_refunds_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SelectRefundContext *srctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = srctx->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_Amount amount_with_fee;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- srctx->status = GNUNET_SYSERR;
- return;
- }
- if (GNUNET_OK !=
- srctx->cb (srctx->cb_cls,
- &amount_with_fee))
- return;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_refunds_by_coin (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_PrivateContractHashP *h_contract,
- TALER_EXCHANGEDB_RefundCoinCallback cb,
- void *cb_cls)
-{
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (h_contract),
- GNUNET_PQ_query_param_end
- };
- struct SelectRefundContext srctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- const char *query = "get_refunds_by_coin_and_contract";
-
- PREPARE (pg,
- query,
- "SELECT"
- " ref.amount_with_fee"
- " FROM refunds ref"
- " JOIN coin_deposits cdep"
- " USING (coin_pub,batch_deposit_serial_id)"
- " JOIN batch_deposits bdep"
- " ON (ref.batch_deposit_serial_id = bdep.batch_deposit_serial_id)"
- " WHERE ref.coin_pub=$1"
- " AND bdep.merchant_pub=$2"
- " AND bdep.h_contract_terms=$3;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- query,
- params,
- &get_refunds_cb,
- &srctx);
- if (GNUNET_SYSERR == srctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_reserve_close_info.c b/src/exchangedb/select_reserve_close_info.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 select_reserve_close_info.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_reserve_close_info.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_close_info (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_Amount *balance,
- struct TALER_FullPayto *payto_uri)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_amount ("current_balance",
- pg->currency,
- balance),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri->full_payto),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_reserve_close_info",
- "SELECT "
- " r.current_balance"
- ",wt.payto_uri"
- " FROM reserves r"
- " LEFT JOIN reserves_in ri"
- " USING (reserve_pub)"
- " LEFT JOIN wire_targets wt"
- " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE r.reserve_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "select_reserve_close_info",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_reserve_close_request_info.c b/src/exchangedb/select_reserve_close_request_info.c
@@ -1,73 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2026 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 select_reserve_close_request_info.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_reserve_close_request_info.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_close_request_info (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- uint64_t rowid,
- struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp *request_timestamp,
- struct TALER_Amount *close_balance,
- struct TALER_Amount *close_fee,
- struct TALER_FullPayto *payto_uri)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- reserve_sig),
- GNUNET_PQ_result_spec_timestamp ("close_timestamp",
- request_timestamp),
- TALER_PQ_result_spec_amount ("close",
- pg->currency,
- close_balance),
- TALER_PQ_result_spec_amount ("close_fee",
- pg->currency,
- close_fee),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri->full_payto),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "select_reserve_close_request_info",
- "SELECT "
- " cr.reserve_sig"
- " ,cr.close_timestamp"
- " ,cr.close"
- " ,cr.close_fee"
- " ,cr.payto_uri"
- " FROM close_requests cr"
- " WHERE cr.reserve_pub=$1"
- " AND cr.row_id=$2;");
- return GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "select_reserve_close_request_info",
- params,
- rs);
-}
diff --git a/src/exchangedb/select_reserve_closed_above_serial_id.c b/src/exchangedb/select_reserve_closed_above_serial_id.c
@@ -1,172 +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 select_reserve_closed_above_serial_id.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_reserve_closed_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #reserve_closed_serial_helper_cb().
- */
-struct ReserveClosedSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_ReserveClosedCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin's context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveClosedSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_closed_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveClosedSerialContext *rcsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = rcsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_FullPayto receiver_account;
- struct TALER_WireTransferIdentifierRawP wtid;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount closing_fee;
- struct GNUNET_TIME_Timestamp execution_date;
- uint64_t close_request_row;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("close_uuid",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- GNUNET_PQ_result_spec_auto_from_type ("wtid",
- &wtid),
- GNUNET_PQ_result_spec_string ("receiver_account",
- &receiver_account.full_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &closing_fee),
- GNUNET_PQ_result_spec_uint64 ("close_request_row",
- &close_request_row),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rcsc->status = GNUNET_SYSERR;
- return;
- }
- ret = rcsc->cb (rcsc->cb_cls,
- rowid,
- execution_date,
- &amount_with_fee,
- &closing_fee,
- &reserve_pub,
- receiver_account,
- &wtid,
- close_request_row);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_closed_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveClosedCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct ReserveClosedSerialContext rcsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (
- pg,
- "reserves_close_get_incr",
- "SELECT"
- " close_uuid"
- ",reserves.reserve_pub"
- ",execution_date"
- ",wtid"
- ",wt.payto_uri AS receiver_account"
- ",amount"
- ",closing_fee"
- ",close_request_row"
- " FROM reserves_close"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " JOIN reserves"
- " USING (reserve_pub)"
- " WHERE close_uuid>=$1"
- " ORDER BY close_uuid ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "reserves_close_get_incr",
- params,
- &reserve_closed_serial_helper_cb,
- &rcsc);
- if (GNUNET_OK != rcsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_reserve_open_above_serial_id.c b/src/exchangedb/select_reserve_open_above_serial_id.c
@@ -1,163 +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 select_reserve_open_above_serial_id.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_reserve_open_above_serial_id.h"
-#include "helper.h"
-
-
-/**
- * Closure for #reserve_open_serial_helper_cb().
- */
-struct ReserveOpenSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_ReserveOpenCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin's context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveOpenSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_open_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveOpenSerialContext *rcsc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = rcsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- uint32_t requested_purse_limit;
- struct GNUNET_TIME_Timestamp request_timestamp;
- struct GNUNET_TIME_Timestamp reserve_expiration;
- struct TALER_Amount reserve_payment;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("open_request_uuid",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &reserve_sig),
- GNUNET_PQ_result_spec_timestamp ("request_timestamp",
- &request_timestamp),
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &reserve_expiration),
- GNUNET_PQ_result_spec_uint32 ("requested_purse_limit",
- &requested_purse_limit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_payment",
- &reserve_payment),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rcsc->status = GNUNET_SYSERR;
- return;
- }
- ret = rcsc->cb (rcsc->cb_cls,
- rowid,
- &reserve_payment,
- request_timestamp,
- reserve_expiration,
- requested_purse_limit,
- &reserve_pub,
- &reserve_sig);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_open_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveOpenCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct ReserveOpenSerialContext rcsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (
- pg,
- "reserves_open_get_incr",
- "SELECT"
- " open_request_uuid"
- ",reserve_pub"
- ",request_timestamp"
- ",expiration_date"
- ",reserve_sig"
- ",reserve_payment"
- ",requested_purse_limit"
- " FROM reserves_open_requests"
- " WHERE open_request_uuid>=$1"
- " ORDER BY open_request_uuid ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "reserves_open_get_incr",
- params,
- &reserve_open_serial_helper_cb,
- &rcsc);
- if (GNUNET_OK != rcsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_reserves_in_above_serial_id.c b/src/exchangedb/select_reserves_in_above_serial_id.c
@@ -1,163 +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 exchangedb/select_reserves_in_above_serial_id.c
- * @brief Implementation of the select_reserves_in_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_reserves_in_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #reserves_in_serial_helper_cb().
- */
-struct ReservesInSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_ReserveInCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReservesInSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserves_in_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReservesInSerialContext *risc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = risc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount credit;
- struct TALER_FullPayto sender_account_details;
- struct GNUNET_TIME_Timestamp execution_date;
- uint64_t rowid;
- uint64_t wire_reference;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_uint64 ("wire_reference",
- &wire_reference),
- TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
- &credit),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- GNUNET_PQ_result_spec_string ("sender_account_details",
- &sender_account_details.full_payto),
- GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- risc->status = GNUNET_SYSERR;
- return;
- }
- ret = risc->cb (risc->cb_cls,
- rowid,
- &reserve_pub,
- &credit,
- sender_account_details,
- wire_reference,
- execution_date);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserves_in_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveInCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct ReservesInSerialContext risc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_reserves_in_above_serial_id",
- "SELECT"
- " reserves.reserve_pub"
- ",wire_reference"
- ",credit"
- ",execution_date"
- ",wt.payto_uri AS sender_account_details"
- ",reserve_in_serial_id"
- " FROM reserves_in"
- " JOIN reserves"
- " USING (reserve_pub)"
- " JOIN wire_targets wt"
- " ON (wire_source_h_payto = wire_target_h_payto)"
- " WHERE reserve_in_serial_id>=$1"
- " ORDER BY reserve_in_serial_id;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_reserves_in_above_serial_id",
- params,
- &reserves_in_serial_helper_cb,
- &risc);
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
- if (GNUNET_OK != risc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_reserves_in_above_serial_id_by_account.c b/src/exchangedb/select_reserves_in_above_serial_id_by_account.c
@@ -1,166 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_reserves_in_above_serial_id_by_account.c
- * @brief Implementation of the select_reserves_in_above_serial_id_by_account function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include \
- "exchange-database/select_reserves_in_above_serial_id_by_account.h"
-#include "helper.h"
-
-
-/**
- * Closure for #reserves_in_serial_helper_cb().
- */
-struct ReservesInSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_ReserveInCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReservesInSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserves_in_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReservesInSerialContext *risc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = risc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount credit;
- struct TALER_FullPayto sender_account_details;
- struct GNUNET_TIME_Timestamp execution_date;
- uint64_t rowid;
- uint64_t wire_reference;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_uint64 ("wire_reference",
- &wire_reference),
- TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
- &credit),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- GNUNET_PQ_result_spec_string ("sender_account_details",
- &sender_account_details.full_payto),
- GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- risc->status = GNUNET_SYSERR;
- return;
- }
- ret = risc->cb (risc->cb_cls,
- rowid,
- &reserve_pub,
- &credit,
- sender_account_details,
- wire_reference,
- execution_date);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_reserves_in_above_serial_id_by_account (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const char *account_name,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveInCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
- struct ReservesInSerialContext risc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_reserves_in_above_serial_id_by_account",
- "SELECT"
- " reserves.reserve_pub"
- ",wire_reference"
- ",credit"
- ",execution_date"
- ",wt.payto_uri AS sender_account_details"
- ",reserve_in_serial_id"
- " FROM reserves_in"
- " JOIN reserves "
- " USING (reserve_pub)"
- " JOIN wire_targets wt"
- " ON (wire_source_h_payto = wire_target_h_payto)"
- " WHERE reserve_in_serial_id>=$1"
- " AND exchange_account_section=$2"
- " ORDER BY reserve_in_serial_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_reserves_in_above_serial_id_by_account",
- params,
- &reserves_in_serial_helper_cb,
- &risc);
- if (GNUNET_OK != risc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_wallet_merges.c b/src/exchangedb/select_wallet_merges.c
@@ -1,196 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2026 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_wallet_merges.c
- * @brief Implementation of the select_wallet_merges function
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_wallet_merges.h"
-#include "helper.h"
-
-/**
- * Closure for #handle_aml_result.
- */
-struct SelectTransferContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AmlTransferCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #TALER_EXCHANGEDB_select_wallet_merges().
- *
- * @param cls closure of type `struct SelectTransferContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_transfer_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SelectTransferContext *stc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = stc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- char *payto_uri;
- uint64_t rowid;
- struct GNUNET_TIME_Absolute execution_time;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial_id",
- &rowid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_absolute_time ("execution_time",
- &execution_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- stc->status = GNUNET_SYSERR;
- return;
- }
- stc->cb (stc->cb_cls,
- rowid,
- payto_uri,
- execution_time,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_wallet_merges (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- void *cb_cls)
-{
- struct SelectTransferContext stc = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- uint64_t ulimit = (limit > 0) ? limit : -limit;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&ulimit),
- TALER_PQ_query_param_amount (pg->conn,
- threshold),
- NULL != h_payto
- ? GNUNET_PQ_query_param_auto_from_type (h_payto)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_wallet_merges_inc",
- "SELECT"
- " pd.purse_decision_serial_id AS serial_id"
- ",wt.payto_uri"
- ",pd.action_timestamp AS execution_time"
- ",pr.amount_with_fee AS amount"
- " FROM purse_decision pd"
- " JOIN purse_requests pr"
- " ON (pr.purse_pub = pd.purse_pub)"
- " JOIN purse_merges pm"
- " ON (pm.purse_pub = pd.purse_pub)"
- " JOIN kyc_targets kt"
- " ON (kt.target_pub = pm.reserve_pub)"
- " JOIN wire_targets wt"
- " ON (wt.h_normalized_payto = kt.h_normalized_payto)"
- " WHERE kt.is_wallet"
- " AND NOT pd.refunded"
- " AND (pd.purse_decision_serial_id > $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (pr.amount_with_fee).val > ($3::taler_amount).val)"
- " OR ( ( (pr.amount_with_fee).val >= ($3::taler_amount).val)"
- " AND ( (pr.amount_with_fee).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY pd.purse_decision_serial_id ASC"
- " LIMIT $2");
- PREPARE (pg,
- "select_wallet_merges_dec",
- "SELECT"
- " pd.purse_decision_serial_id AS serial_id"
- ",wt.payto_uri"
- ",pd.action_timestamp AS execution_time"
- ",pr.amount_with_fee AS amount"
- " FROM purse_decision pd"
- " JOIN purse_requests pr"
- " ON (pr.purse_pub = pd.purse_pub)"
- " JOIN purse_merges pm"
- " ON (pm.purse_pub = pd.purse_pub)"
- " JOIN kyc_targets kt"
- " ON (kt.target_pub = pm.reserve_pub)"
- " JOIN wire_targets wt"
- " ON (wt.h_normalized_payto = kt.h_normalized_payto)"
- " WHERE kt.is_wallet"
- " AND NOT pd.refunded"
- " AND (pd.purse_decision_serial_id < $1)"
- " AND ( ($4::BYTEA IS NULL) OR (wt.h_normalized_payto=$4) )"
- " AND ( ( (pr.amount_with_fee).val > ($3::taler_amount).val)"
- " OR ( ( (pr.amount_with_fee).val >= ($3::taler_amount).val)"
- " AND ( (pr.amount_with_fee).frac >= ($3::taler_amount).frac) ) )"
- " ORDER BY pd.purse_decision_serial_id DESC"
- " LIMIT $2");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- (limit > 0)
- ? "select_wallet_merges_inc"
- : "select_wallet_merges_dec",
- params,
- &handle_transfer_result,
- &stc);
- if (GNUNET_OK != stc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_wire_out_above_serial_id.c b/src/exchangedb/select_wire_out_above_serial_id.c
@@ -1,154 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_wire_out_above_serial_id.c
- * @brief Implementation of the select_wire_out_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_wire_out_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #wire_out_serial_helper_cb().
- */
-struct WireOutSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_WireTransferOutCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- int status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WireOutSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-wire_out_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireOutSerialContext *wosc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = wosc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct GNUNET_TIME_Timestamp date;
- struct TALER_WireTransferIdentifierRawP wtid;
- struct TALER_FullPayto payto_uri;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &date),
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- &wtid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri.full_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- int ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- wosc->status = GNUNET_SYSERR;
- return;
- }
- ret = wosc->cb (wosc->cb_cls,
- rowid,
- date,
- &wtid,
- payto_uri,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_wire_out_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct WireOutSerialContext wosc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_wire_out_above_serial_id",
- "SELECT"
- " wo.wireout_uuid"
- ",wo.execution_date"
- ",wo.wtid_raw"
- ",wt.payto_uri"
- ",wo.amount"
- " FROM wire_out wo"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " WHERE wireout_uuid>=$1"
- " ORDER BY wireout_uuid ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_wire_out_above_serial_id",
- params,
- &wire_out_serial_helper_cb,
- &wosc);
- if (GNUNET_OK != wosc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_wire_out_above_serial_id_by_account.c b/src/exchangedb/select_wire_out_above_serial_id_by_account.c
@@ -1,157 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_wire_out_above_serial_id_by_account.c
- * @brief Implementation of the select_wire_out_above_serial_id_by_account function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_wire_out_above_serial_id_by_account.h"
-#include "helper.h"
-
-/**
- * Closure for #wire_out_serial_helper_cb().
- */
-struct WireOutSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_WireTransferOutCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- int status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WireOutSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-wire_out_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireOutSerialContext *wosc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = wosc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct GNUNET_TIME_Timestamp date;
- struct TALER_WireTransferIdentifierRawP wtid;
- struct TALER_FullPayto payto_uri;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &date),
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- &wtid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri.full_payto),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- int ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- wosc->status = GNUNET_SYSERR;
- return;
- }
- ret = wosc->cb (wosc->cb_cls,
- rowid,
- date,
- &wtid,
- payto_uri,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_wire_out_above_serial_id_by_account (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const char *account_name,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
- struct WireOutSerialContext wosc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_wire_out_above_serial_id_by_account",
- "SELECT"
- " wo.wireout_uuid"
- ",wo.execution_date"
- ",wo.wtid_raw"
- ",wt.payto_uri"
- ",wo.amount"
- " FROM wire_out wo"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " WHERE wo.wireout_uuid>=$1 "
- " AND wo.exchange_account_section=$2"
- " ORDER BY wo.wireout_uuid ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_wire_out_above_serial_id_by_account",
- params,
- &wire_out_serial_helper_cb,
- &wosc);
- if (GNUNET_OK != wosc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_withdraw_amounts_for_kyc_check.c b/src/exchangedb/select_withdraw_amounts_for_kyc_check.c
@@ -1,158 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/select_withdraw_amounts_for_kyc_check.c
- * @brief Implementation of the select_withdraw_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_withdraw_amounts_for_kyc_check.h"
-#include "exchange-database/select_aggregation_amounts_for_kyc_check.h"
-#include "helper.h"
-
-
-/**
- * Closure for #get_kyc_amounts_cb().
- */
-struct KycAmountCheckContext
-{
- /**
- * Function to call per result.
- */
- TALER_KYCLOGIC_KycAmountCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * 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 KycAmountCheckContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_kyc_amounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct KycAmountCheckContext *ctx = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct GNUNET_TIME_Absolute date;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_absolute_time ("date",
- &date),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ret = ctx->cb (ctx->cb_cls,
- &amount,
- date);
- GNUNET_PQ_cleanup_result (rs);
- switch (ret)
- {
- case GNUNET_OK:
- continue;
- case GNUNET_NO:
- break;
- case GNUNET_SYSERR:
- ctx->status = GNUNET_SYSERR;
- break;
- }
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_withdraw_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_absolute_time (&time_limit),
- GNUNET_PQ_query_param_end
- };
- struct KycAmountCheckContext ctx = {
- .cb = kac,
- .cb_cls = kac_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "select_withdraw_amounts_for_kyc_check",
- "SELECT"
- " wd.amount_with_fee AS amount"
- ",wd.execution_date AS date"
- " FROM reserves_in ri"
- " JOIN reserve_history rh"
- " ON (rh.reserve_pub = ri.reserve_pub)"
- " JOIN withdraw wd"
- " ON (wd.withdraw_id = rh.serial_id)"
- " WHERE ri.wire_source_h_payto IN ("
- " SELECT wire_target_h_payto"
- " FROM wire_targets"
- " WHERE h_normalized_payto=$1"
- " )"
- " AND rh.table_name='withdraw'"
- " AND wd.execution_date >= $2"
- " ORDER BY rh.reserve_history_serial_id DESC");
- qs = GNUNET_PQ_eval_prepared_multi_select (
- pg->conn,
- "select_withdraw_amounts_for_kyc_check",
- params,
- &get_kyc_amounts_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/select_withdrawals_above_serial_id.c b/src/exchangedb/select_withdrawals_above_serial_id.c
@@ -1,216 +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 exchangedb/select_withdrawals_above_serial_id.c
- * @brief Implementation of the select_withdrawals_above_serial_id function for Postgres
- * @author Christian Grothoff
- * @author Özgür Kesim
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/select_withdrawals_above_serial_id.h"
-#include "helper.h"
-
-/**
- * Closure for #withdraw_serial_helper_cb().
- */
-struct WithdrawSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_WithdrawCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WithdrawSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-withdraw_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WithdrawSerialContext *rosc = cls;
- struct TALER_EXCHANGEDB_PostgresContext *pg = rosc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_HashBlindedPlanchetsP h_planchets;
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_Amount amount_with_fee;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- uint16_t max_age;
- bool no_max_age;
- uint16_t noreveal_index;
- bool no_noreveal_index;
- struct TALER_HashBlindedPlanchetsP selected_h;
- bool no_selected_h;
- struct TALER_BlindingMasterSeedP blinding_seed;
- bool no_blinding_seed;
- size_t num_denom_serials;
- uint64_t *denom_serials = NULL;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("withdraw_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("planchets_h",
- &h_planchets),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &reserve_sig),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint16 ("max_age",
- &max_age),
- &no_max_age),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint16 ("noreveal_index",
- &noreveal_index),
- &no_noreveal_index),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "selected_h",
- &selected_h),
- &no_selected_h),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type (
- "blinding_seed",
- &blinding_seed),
- &no_blinding_seed),
- GNUNET_PQ_result_spec_array_uint64 (
- pg->conn,
- "denom_serials",
- &num_denom_serials,
- &denom_serials),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rosc->status = GNUNET_SYSERR;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- /* Note: here we just check that the uint8_t
- limitations are met, other constraints are checked later */
- if (( (! no_noreveal_index) &&
- (UINT8_MAX <= noreveal_index)) ||
- ( (! no_max_age) &&
- (UINT8_MAX <= max_age)))
- {
- GNUNET_break (0);
- rosc->status = GNUNET_SYSERR;
- GNUNET_PQ_cleanup_result (rs);
- return;
- }
- ret = rosc->cb (rosc->cb_cls,
- rowid,
- num_denom_serials,
- denom_serials,
- no_selected_h ? NULL : &selected_h,
- &h_planchets,
- no_blinding_seed ? NULL : &blinding_seed,
- ! no_max_age,
- (uint8_t) max_age,
- (uint8_t) noreveal_index,
- &reserve_pub,
- &reserve_sig,
- execution_date,
- &amount_with_fee);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_withdrawals_above_serial_id (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WithdrawCallback cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct WithdrawSerialContext rosc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- /* Fetch deposits with rowid '\geq' the given parameter */
- PREPARE (pg,
- "audit_get_withdraw_incr",
- "SELECT"
- " withdraw_id"
- ",planchets_h"
- ",execution_date"
- ",amount_with_fee"
- ",reserve_pub"
- ",reserve_sig"
- ",max_age"
- ",noreveal_index"
- ",selected_h"
- ",blinding_seed"
- ",denom_serials"
- " FROM withdraw"
- " WHERE withdraw_id>=$1"
- " ORDER BY withdraw_id ASC;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_withdraw_incr",
- params,
- &withdraw_serial_helper_cb,
- &rosc);
- if (GNUNET_OK != rosc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/set_aml_lock.c b/src/exchangedb/set_aml_lock.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 exchangedb/set_aml_lock.c
- * @brief Implementation of the set_aml_lock function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/set_aml_lock.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_set_aml_lock (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Relative lock_duration,
- struct GNUNET_TIME_Absolute *existing_lock)
-{
-
- struct GNUNET_TIME_Absolute expires
- = GNUNET_TIME_relative_to_absolute (lock_duration);
- struct GNUNET_TIME_Absolute now
- = GNUNET_TIME_absolute_get ();
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_absolute_time (&expires),
- GNUNET_PQ_query_param_end
- };
- bool nx; /* true if the *account* is not known */
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_absolute_time ("out_aml_program_lock_timeout",
- existing_lock),
- &nx),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "set_aml_lock",
- "SELECT out_aml_program_lock_timeout"
- " FROM exchange_do_set_aml_lock($1,$2,$3);");
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "set_aml_lock",
- params,
- rs);
- if (qs <= 0)
- return qs;
- if (nx)
- {
- *existing_lock = GNUNET_TIME_UNIT_ZERO_ABS;
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- return qs;
-}
diff --git a/src/exchangedb/set_purse_balance.c b/src/exchangedb/set_purse_balance.c
@@ -1,48 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/set_purse_balance.c
- * @brief Implementation of the set_purse_balance function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/set_purse_balance.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_set_purse_balance (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_Amount *balance)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- TALER_PQ_query_param_amount (pg->conn,
- balance),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "set_purse_balance",
- "UPDATE purse_requests"
- " SET balance=$2"
- " WHERE purse_pub=$1;");
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "set_purse_balance",
- params);
-}
diff --git a/src/exchangedb/sql-schema/meson.build b/src/exchangedb/sql-schema/meson.build
@@ -15,7 +15,7 @@ procedures_sql = [
'../do_check_deposit_idempotent.sql',
# dead!?
'exchange_do_melt.sql',
- '../select_batch_deposits_missing_wire.sql',
+ '../iterate_batch_deposits_missing_wire.sql',
# dead!?
'exchange_do_select_justification_for_missing_wire.sql',
'../do_refund.sql',
@@ -26,23 +26,23 @@ procedures_sql = [
'../do_purse_deposit.sql',
'../do_purse_merge.sql',
'../do_reserve_purse.sql',
- '../expire_purse.sql',
+ '../do_expire_purse.sql',
'../insert_reserve_open_deposit.sql',
'../do_reserve_open.sql',
'../insert_aml_decision.sql',
'../insert_successor_measure.sql',
'../insert_aml_officer.sql',
- '../reserves_in_insert.sql',
+ '../do_insert_reserve_in.sql',
# semi-dead...
'exchange_do_get_link_data.sql',
- '../kycauth_in_insert.sql',
- '../trigger_kyc_rule_for_account.sql',
- '../lookup_kyc_requirement_by_row.sql',
+ '../insert_kycauth_in.sql',
+ '../do_trigger_kyc_rule_for_account.sql',
+ '../get_legitimization_requirement_by_row.sql',
'../insert_active_legitimization_measure.sql',
- '../select_aggregations_above_serial.sql',
- '../persist_kyc_attributes.sql',
+ '../iterate_aggregations_above_serial_id.sql',
+ '../do_insert_kyc_attributes.sql',
'../insert_aml_program_failure.sql',
- '../set_aml_lock.sql',
+ '../update_to_aml_locked.sql',
'../insert_sanction_list_hit.sql',
'exchange_statistics_helpers.sql',
'exchange_trigger_purse_requests_insert.sql',
diff --git a/src/exchangedb/start_deferred_wire_out.c b/src/exchangedb/start_deferred_wire_out.c
@@ -24,9 +24,9 @@
#include "exchange-database/rollback.h"
enum GNUNET_GenericReturnValue
-TALER_TALER_EXCHANGEDB_start_deferred_wire_out (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg)
+TALER_EXCHANGEDB_start_deferred_wire_out (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg)
{
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute (
diff --git a/src/exchangedb/start_read_committed.c b/src/exchangedb/start_read_committed.c
@@ -23,10 +23,10 @@
#include "helper.h"
enum GNUNET_GenericReturnValue
-TALER_TALER_EXCHANGEDB_start_read_committed (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const char *name)
+TALER_EXCHANGEDB_start_read_committed (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const char *name)
{
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"),
diff --git a/src/exchangedb/start_read_only.c b/src/exchangedb/start_read_only.c
@@ -23,9 +23,9 @@
#include "helper.h"
enum GNUNET_GenericReturnValue
-TALER_TALER_EXCHANGEDB_start_read_only (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *name)
+TALER_EXCHANGEDB_start_read_only (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *name)
{
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute (
diff --git a/src/exchangedb/store_wire_transfer_out.c b/src/exchangedb/store_wire_transfer_out.c
@@ -1,63 +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 exchangedb/store_wire_transfer_out.c
- * @brief Implementation of the store_wire_transfer_out function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/store_wire_transfer_out.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_store_wire_transfer_out (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct GNUNET_TIME_Timestamp date,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_FullPaytoHashP *h_payto,
- const char *exchange_account_section,
- const struct TALER_Amount *amount,
- const char *extra_wire_subject_metadata)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&date),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (exchange_account_section),
- TALER_PQ_query_param_amount (pg->conn,
- amount),
- NULL == extra_wire_subject_metadata
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (extra_wire_subject_metadata),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "insert_wire_out",
- "INSERT INTO wire_out "
- "(execution_date"
- ",wtid_raw"
- ",wire_target_h_payto"
- ",exchange_account_section"
- ",amount"
- ",extra_wire_subject_metadata"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_wire_out",
- params);
-}
diff --git a/src/exchangedb/test_aml_officer.c b/src/exchangedb/test_aml_officer.c
@@ -1,52 +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 exchangedb/test_aml_officer.c
- * @brief Implementation of the test_aml_officer function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/test_aml_officer.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_test_aml_officer (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AmlOfficerPublicKeyP *decider_pub,
- bool *read_only)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (decider_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("read_only",
- read_only),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "test_aml_staff",
- "SELECT read_only"
- " FROM aml_staff"
- " WHERE decider_pub=$1"
- " AND is_active;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "test_aml_staff",
- params,
- rs);
-}
diff --git a/src/exchangedb/trigger_kyc_rule_for_account.c b/src/exchangedb/trigger_kyc_rule_for_account.c
@@ -1,98 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/trigger_kyc_rule_for_account.c
- * @brief Implementation of the trigger_kyc_rule_for_account function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/trigger_kyc_rule_for_account.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_trigger_kyc_rule_for_account (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPayto payto_uri,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const union TALER_AccountPublicKeyP *set_account_pub,
- const struct TALER_MerchantPublicKeyP *check_merchant_pub,
- const json_t *jmeasures,
- uint32_t display_priority,
- uint64_t *requirement_row,
- bool *bad_kyc_auth)
-{
- struct GNUNET_TIME_Absolute now
- = GNUNET_TIME_absolute_get ();
- struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
- .h_payto = *h_payto
- };
- char *notify_str
- = GNUNET_PQ_get_event_notify_channel (&rep.header);
- struct TALER_FullPaytoHashP h_full_payto;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- NULL == set_account_pub
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (set_account_pub),
- NULL == check_merchant_pub
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (check_merchant_pub),
- NULL == payto_uri.full_payto
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (payto_uri.full_payto),
- NULL == payto_uri.full_payto
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
- GNUNET_PQ_query_param_absolute_time (&now),
- TALER_PQ_query_param_json (jmeasures),
- GNUNET_PQ_query_param_uint32 (&display_priority),
- GNUNET_PQ_query_param_string (notify_str),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 (
- "legitimization_measure_serial_id",
- requirement_row),
- GNUNET_PQ_result_spec_bool (
- "bad_kyc_auth",
- bad_kyc_auth),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "trigger_kyc_rule_for_account",
- "SELECT"
- " out_legitimization_measure_serial_id"
- " AS legitimization_measure_serial_id"
- " ,out_bad_kyc_auth"
- " AS bad_kyc_auth"
- " FROM exchange_do_trigger_kyc_rule_for_account"
- "($1, $2, $3, $4, $5, $6, $7::TEXT::JSONB, $8, $9);");
- if (NULL != payto_uri.full_payto)
- TALER_full_payto_hash (payto_uri,
- &h_full_payto);
- qs = GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "trigger_kyc_rule_for_account",
- params,
- rs);
- GNUNET_free (notify_str);
- return qs;
-}
diff --git a/src/exchangedb/update_kyc_process_by_row.c b/src/exchangedb/update_kyc_process_by_row.c
@@ -1,131 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/update_kyc_process_by_row.c
- * @brief Implementation of the update_kyc_process_by_row function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_error_codes.h"
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/update_kyc_process_by_row.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_update_kyc_process_by_row (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t process_row,
- const char *provider_name,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_account_id,
- const char *provider_legitimization_id,
- const char *redirect_url,
- struct GNUNET_TIME_Absolute expiration,
- enum TALER_ErrorCode ec,
- const char *error_message_hint,
- bool finished)
-{
- uint32_t ec32 = (uint32_t) ec;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&process_row),
- GNUNET_PQ_query_param_string (provider_name),
- GNUNET_PQ_query_param_auto_from_type (h_payto), /*3*/
- (NULL != provider_account_id)
- ? GNUNET_PQ_query_param_string (provider_account_id)
- : GNUNET_PQ_query_param_null (), /*4*/
- (NULL != provider_legitimization_id)
- ? GNUNET_PQ_query_param_string (provider_legitimization_id)
- : GNUNET_PQ_query_param_null (), /*5*/
- (NULL != redirect_url)
- ? GNUNET_PQ_query_param_string (redirect_url)
- : GNUNET_PQ_query_param_null (), /*6*/
- GNUNET_PQ_query_param_absolute_time (&expiration),
- GNUNET_PQ_query_param_uint32 (&ec32), /* 8 */
- (NULL != error_message_hint)
- ? GNUNET_PQ_query_param_string (error_message_hint)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_bool (finished), /* 10 */
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Updating KYC data for %llu (%s)\n",
- (unsigned long long) process_row,
- provider_name);
- PREPARE (pg,
- "update_legitimization_process",
- "UPDATE legitimization_processes"
- " SET provider_user_id=$4"
- " ,provider_legitimization_id=$5"
- " ,redirect_url=$6"
- " ,expiration_time=GREATEST(expiration_time,$7)"
- " ,error_code=$8"
- " ,error_message=$9"
- " ,finished=$10"
- " WHERE"
- " h_payto=$3"
- " AND legitimization_process_serial_id=$1"
- " AND provider_name=$2;");
- qs = GNUNET_PQ_eval_prepared_non_select (
- pg->conn,
- "update_legitimization_process",
- params);
- if (qs <= 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to update legitimization process %llu: %d\n",
- (unsigned long long) process_row,
- qs);
- return qs;
- }
- if (GNUNET_TIME_absolute_is_future (expiration))
- {
- enum GNUNET_DB_QueryStatus qs2;
- struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
- .h_payto = *h_payto
- };
- uint32_t trigger_type = 1;
- struct GNUNET_PQ_QueryParam params2[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint32 (&trigger_type),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_PQ_event_notify (pg->conn,
- &rep.header,
- NULL,
- 0);
- PREPARE (pg,
- "alert_kyc_status_change",
- "INSERT INTO kyc_alerts"
- " (h_payto"
- " ,trigger_type)"
- " VALUES"
- " ($1,$2);");
- qs2 = GNUNET_PQ_eval_prepared_non_select (
- pg->conn,
- "alert_kyc_status_change",
- params2);
- if (qs2 < 0)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to store KYC alert: %d\n",
- qs2);
- }
- return qs;
-}
diff --git a/src/exchangedb/update_legitimization_process_by_row.c b/src/exchangedb/update_legitimization_process_by_row.c
@@ -0,0 +1,131 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/update_legitimization_process_by_row.c
+ * @brief Implementation of the update_legitimization_process_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_error_codes.h"
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_legitimization_process_by_row.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_legitimization_process_by_row (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t process_row,
+ const char *provider_name,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ const char *redirect_url,
+ struct GNUNET_TIME_Absolute expiration,
+ enum TALER_ErrorCode ec,
+ const char *error_message_hint,
+ bool finished)
+{
+ uint32_t ec32 = (uint32_t) ec;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&process_row),
+ GNUNET_PQ_query_param_string (provider_name),
+ GNUNET_PQ_query_param_auto_from_type (h_payto), /*3*/
+ (NULL != provider_account_id)
+ ? GNUNET_PQ_query_param_string (provider_account_id)
+ : GNUNET_PQ_query_param_null (), /*4*/
+ (NULL != provider_legitimization_id)
+ ? GNUNET_PQ_query_param_string (provider_legitimization_id)
+ : GNUNET_PQ_query_param_null (), /*5*/
+ (NULL != redirect_url)
+ ? GNUNET_PQ_query_param_string (redirect_url)
+ : GNUNET_PQ_query_param_null (), /*6*/
+ GNUNET_PQ_query_param_absolute_time (&expiration),
+ GNUNET_PQ_query_param_uint32 (&ec32), /* 8 */
+ (NULL != error_message_hint)
+ ? GNUNET_PQ_query_param_string (error_message_hint)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_bool (finished), /* 10 */
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Updating KYC data for %llu (%s)\n",
+ (unsigned long long) process_row,
+ provider_name);
+ PREPARE (pg,
+ "update_legitimization_process_by_row_update_legitimization_process",
+ "UPDATE legitimization_processes"
+ " SET provider_user_id=$4"
+ " ,provider_legitimization_id=$5"
+ " ,redirect_url=$6"
+ " ,expiration_time=GREATEST(expiration_time,$7)"
+ " ,error_code=$8"
+ " ,error_message=$9"
+ " ,finished=$10"
+ " WHERE"
+ " h_payto=$3"
+ " AND legitimization_process_serial_id=$1"
+ " AND provider_name=$2;");
+ qs = GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "update_legitimization_process_by_row_update_legitimization_process",
+ params);
+ if (qs <= 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to update legitimization process %llu: %d\n",
+ (unsigned long long) process_row,
+ qs);
+ return qs;
+ }
+ if (GNUNET_TIME_absolute_is_future (expiration))
+ {
+ enum GNUNET_DB_QueryStatus qs2;
+ struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ uint32_t trigger_type = 1;
+ struct GNUNET_PQ_QueryParam params2[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint32 (&trigger_type),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_PQ_event_notify (pg->conn,
+ &rep.header,
+ NULL,
+ 0);
+ PREPARE (pg,
+ "update_legitimization_process_by_row_alert_kyc_status_change",
+ "INSERT INTO kyc_alerts"
+ " (h_payto"
+ " ,trigger_type)"
+ " VALUES"
+ " ($1,$2);");
+ qs2 = GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "update_legitimization_process_by_row_alert_kyc_status_change",
+ params2);
+ if (qs2 < 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to store KYC alert: %d\n",
+ qs2);
+ }
+ return qs;
+}
diff --git a/src/exchangedb/update_purse_balance.c b/src/exchangedb/update_purse_balance.c
@@ -0,0 +1,48 @@
+/*
+ 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 exchangedb/update_purse_balance.c
+ * @brief Implementation of the update_purse_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_purse_balance.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_purse_balance (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_purse_balance",
+ "UPDATE purse_requests"
+ " SET balance=$2"
+ " WHERE purse_pub=$1;");
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_purse_balance",
+ params);
+}
diff --git a/src/exchangedb/update_reserve.c b/src/exchangedb/update_reserve.c
@@ -0,0 +1,50 @@
+/*
+ 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 exchangedb/update_reserve.c
+ * @brief Implementation of the update_reserve function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_reserve.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_reserve (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_EXCHANGEDB_Reserve *reserve
+ )
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&reserve->expiry),
+ GNUNET_PQ_query_param_timestamp (&reserve->gc),
+ TALER_PQ_query_param_amount (pg->conn,
+ &reserve->balance),
+ GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_reserve",
+ "UPDATE reserves"
+ " SET"
+ " expiration_date=$1"
+ ",gc_date=$2"
+ ",current_balance=$3"
+ " WHERE reserve_pub=$4;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_reserve",
+ params);
+}
diff --git a/src/exchangedb/update_rules.c b/src/exchangedb/update_rules.c
@@ -1,672 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2023, 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file update_rules.c
- * @brief helper function to handle AML programs
- * @author Christian Grothoff
- */
-#include "exchangedb_lib.h"
-#include "taler/taler_kyclogic_lib.h"
-#include "taler/taler_dbevents.h"
-#include "exchange-database/start.h"
-#include "exchange-database/rollback.h"
-#include "exchange-database/commit.h"
-#include "exchange-database/set_aml_lock.h"
-#include "exchange-database/clear_aml_lock.h"
-#include "exchange-database/persist_aml_program_result.h"
-#include "exchange-database/insert_successor_measure.h"
-#include "exchange-database/event_notify.h"
-#include "exchange-database/event_listen.h"
-#include "exchange-database/event_listen_cancel.h"
-#include "exchange-database/lookup_rules_by_access_token.h"
-#include "exchange-database/update_rules.h"
-#include "exchange-database/account_history.h"
-#include "helper.h"
-#include <gnunet/gnunet_common.h>
-
-/**
- * Maximum recursion depth we allow for AML programs.
- * Basically, after this number of "skip" processes
- * we forcefully terminate the recursion and fail hard.
- */
-#define MAX_DEPTH 16
-
-
-struct TALER_EXCHANGEDB_RuleUpdater
-{
- /**
- * database pg to use
- */
- struct TALER_EXCHANGEDB_PostgresContext *pg;
-
- /**
- * key to use to decrypt attributes
- */
- struct TALER_AttributeEncryptionKeyP attribute_key;
-
- /**
- * account to get the rule set for
- */
- struct TALER_NormalizedPaytoHashP account;
-
- /**
- * function to call with the result
- */
- TALER_EXCHANGEDB_CurrentRulesCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Current rule set we are working on.
- */
- struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs;
-
- /**
- * Task for asynchronous continuations.
- */
- struct GNUNET_SCHEDULER_Task *t;
-
- /**
- * Handler waiting notification that (previous) AML program
- * finished.
- */
- struct GNUNET_DB_EventHandler *eh;
-
- /**
- * Handle to running AML program.
- */
- struct TALER_KYCLOGIC_AmlProgramRunnerHandle *amlh;
-
- /**
- * Name of the AML program we were running asynchronously,
- * for diagnostics.
- */
- char *aml_program_name;
-
- /**
- * Error hint to return with @e ec.
- */
- const char *hint;
-
- /**
- * Row the rule set in @a lrs is based on.
- */
- uint64_t legitimization_outcome_last_row;
-
- /**
- * Taler error code to return.
- */
- enum TALER_ErrorCode ec;
-
- /**
- * Counter used to limit recursion depth.
- */
- unsigned int depth;
-
- /**
- * True if @e account is for a wallet.
- */
- bool is_wallet;
-};
-
-
-/**
- * Function that finally returns the result to the application and cleans
- * up. Called with an open database transaction on success; on failure, the
- * transaction will have already been rolled back.
- *
- * @param[in,out] ru rule updater to return result for
- */
-static void
-return_result (struct TALER_EXCHANGEDB_RuleUpdater *ru)
-{
- struct TALER_EXCHANGEDB_RuleUpdaterResult rur = {
- .legitimization_outcome_last_row = ru->legitimization_outcome_last_row,
- .lrs = ru->lrs,
- .ec = ru->ec,
- };
-
- ru->cb (ru->cb_cls,
- &rur);
- ru->lrs = NULL;
- TALER_EXCHANGEDB_update_rules_cancel (ru);
-}
-
-
-/**
- * Fail the update with the given @a ec and @a hint.
- * Called with an open database transaction, which will
- * be rolled back (!).
- *
- * @param[in,out] ru account we are processing
- * @param ec error code to fail with
- * @param hint hint to return, can be NULL
- */
-static void
-fail_update (struct TALER_EXCHANGEDB_RuleUpdater *ru,
- enum TALER_ErrorCode ec,
- const char *hint)
-{
- GNUNET_assert (NULL == ru->t);
- TALER_EXCHANGEDB_rollback (ru->pg);
- ru->ec = ec;
- ru->hint = hint;
- return_result (ru);
-}
-
-
-/**
- * Check the rules in @a ru to see if they are current, and
- * if not begin the updating process. Called with an open
- * database transaction.
- *
- * @param[in] ru rule updater context
- */
-static void
-check_rules (struct TALER_EXCHANGEDB_RuleUpdater *ru);
-
-
-/**
- * Run the measure @a m in the context of the legitimisation rules
- * of @a ru. Called with an open database transaction.
- *
- * @param ru updating context we are using
- * @param m measure we need to run next
- */
-static void
-run_measure (struct TALER_EXCHANGEDB_RuleUpdater *ru,
- const struct TALER_KYCLOGIC_Measure *m);
-
-
-/**
- * Function called after AML program was run. Called
- * without an open database transaction, will start one!
- *
- * @param cls the `struct TALER_EXCHANGEDB_RuleUpdater *`
- * @param apr result of the AML program.
- */
-static void
-aml_result_callback (
- void *cls,
- const struct TALER_KYCLOGIC_AmlProgramResult *apr)
-{
- struct TALER_EXCHANGEDB_RuleUpdater *ru = cls;
- enum GNUNET_DB_QueryStatus qs;
- enum GNUNET_GenericReturnValue res;
- enum TALER_EXCHANGEDB_PersistProgramResultStatus pprs;
-
- ru->amlh = NULL;
- res = TALER_EXCHANGEDB_start (ru->pg,
- "aml-persist-aml-program-result");
- if (GNUNET_OK != res)
- {
- GNUNET_break (0);
- fail_update (ru,
- TALER_EC_GENERIC_DB_START_FAILED,
- "aml-persist-aml-program-result");
- return;
- }
- /* Update database update based on result */
- qs = TALER_EXCHANGEDB_persist_aml_program_result (
- ru->pg,
- 0LLU, /* 0: no existing legitimization process, creates new row */
- &ru->account,
- apr,
- &pprs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- fail_update (ru,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "persist_aml_program_result");
- return;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- /* Bad, couldn't persist AML result. Try again... */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Serialization issue persisting result of AML program. Restarting.\n");
- fail_update (ru,
- TALER_EC_GENERIC_DB_SOFT_FAILURE,
- "persist_aml_program_result");
- return;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* Strange, but let's just continue */
- break;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* normal case */
- break;
- }
- switch (pprs)
- {
- case TALER_EXCHANGEDB_PPRS_OK:
- break;
- case TALER_EXCHANGEDB_PPRS_BAD_OUTCOME:
- fail_update (ru,
- TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT,
- "persist_aml_program_result");
- return;
- }
- switch (apr->status)
- {
- case TALER_KYCLOGIC_AMLR_SUCCESS:
- TALER_KYCLOGIC_rules_free (ru->lrs);
- ru->lrs = NULL;
- ru->lrs = TALER_KYCLOGIC_rules_parse (apr->details.success.new_rules);
- /* Fall back to default rules on parse error! */
- GNUNET_break (NULL != ru->lrs);
- check_rules (ru);
- return;
- case TALER_KYCLOGIC_AMLR_FAILURE:
- {
- const char *fmn = apr->details.failure.fallback_measure;
- const struct TALER_KYCLOGIC_Measure *m;
-
- m = TALER_KYCLOGIC_get_measure (ru->lrs,
- fmn);
- if (NULL == m)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Fallback measure `%s' does not exist (anymore?).\n",
- fmn);
- TALER_KYCLOGIC_rules_free (ru->lrs);
- ru->lrs = NULL;
- return_result (ru);
- return;
- }
- run_measure (ru,
- m);
- return;
- }
- }
- /* This should be impossible */
- GNUNET_assert (0);
-}
-
-
-/**
- * Entrypoint that fetches the latest rules from the database
- * and starts processing them. Called without an open database
- * transaction, will start one.
- *
- * @param[in] cls the `struct TALER_EXCHANGEDB_RuleUpdater *` to run
- */
-static void
-fetch_latest_rules (void *cls);
-
-
-/**
- * Notification called when we either timeout on the AML program lock
- * or when the (previous) AML program finished and we can thus try again.
- *
- * @param cls the `struct TALER_EXCHANGEDB_RuleUpdater *` to continue
- * @param extra additional event data provided (unused)
- * @param extra_size number of bytes in @a extra (unused)
- */
-static void
-trigger_fetch_latest_rules (void *cls,
- const void *extra,
- size_t extra_size)
-{
- struct TALER_EXCHANGEDB_RuleUpdater *ru = cls;
-
- (void) extra;
- (void) extra_size;
- if (NULL != ru->t)
- return; /* multiple events triggered us, ignore */
- ru->t = GNUNET_SCHEDULER_add_now (&fetch_latest_rules,
- ru);
-}
-
-
-static void
-run_measure (struct TALER_EXCHANGEDB_RuleUpdater *ru,
- const struct TALER_KYCLOGIC_Measure *m)
-{
- if (NULL == m)
- {
- /* fall back to default rules */
- TALER_KYCLOGIC_rules_free (ru->lrs);
- ru->lrs = NULL;
- return_result (ru);
- return;
- }
- ru->depth++;
- if (ru->depth > MAX_DEPTH)
- {
- fail_update (ru,
- TALER_EC_EXCHANGE_GENERIC_AML_PROGRAM_RECURSION_DETECTED,
- NULL);
- return;
- }
- if ( (NULL == m->check_name) ||
- (0 ==
- strcasecmp ("SKIP",
- m->check_name)) )
- {
- struct TALER_EXCHANGEDB_HistoryBuilderContext hbc = {
- .account = &ru->account,
- .is_wallet = ru->is_wallet,
- .pg = ru->pg,
- .attribute_key = &ru->attribute_key
- };
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Absolute xlock;
-
- /* Free previous one, in case we are iterating... */
- GNUNET_free (ru->aml_program_name);
- if (NULL != m->prog_name)
- {
- ru->aml_program_name = GNUNET_strdup (m->prog_name);
- }
- else
- {
- /* How do we get to run a measure if the check type
- is INFO (which is the only case where prog_name
- is allowed to be NULL?) */
- GNUNET_break (0);
- ru->aml_program_name = NULL;
- }
- qs = TALER_EXCHANGEDB_set_aml_lock (
- ru->pg,
- &ru->account,
- GNUNET_TIME_relative_multiply (ru->pg->max_aml_program_runtime,
- 2),
- &xlock);
- if (qs <= 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- fail_update (ru,
- GNUNET_DB_STATUS_SOFT_ERROR == qs
- ? TALER_EC_GENERIC_DB_SOFT_FAILURE
- : TALER_EC_GENERIC_DB_STORE_FAILED,
- "set_aml_lock");
- return;
- }
- if (GNUNET_TIME_absolute_is_future (xlock))
- {
- struct TALER_EXCHANGEDB_KycCompletedEventP eh = {
- .header.size = htons (sizeof (eh)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
- .h_payto = ru->account
- };
- /* Wait for either timeout or notification */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "AML program already running, waiting for it to finish\n");
- TALER_EXCHANGEDB_rollback (ru->pg);
- ru->eh
- = TALER_EXCHANGEDB_event_listen (
- ru->pg,
- GNUNET_TIME_absolute_get_remaining (xlock),
- &eh.header,
- &trigger_fetch_latest_rules,
- ru);
- return;
- }
- qs = TALER_EXCHANGEDB_commit (ru->pg);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- fail_update (ru,
- GNUNET_DB_STATUS_SOFT_ERROR == qs
- ? TALER_EC_GENERIC_DB_SOFT_FAILURE
- : TALER_EC_GENERIC_DB_COMMIT_FAILED,
- "current-aml-rule-fetch");
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Check is of type 'SKIP', running AML program %s.\n",
- m->prog_name);
- GNUNET_assert (NULL == ru->t);
- ru->amlh = TALER_KYCLOGIC_run_aml_program3 (
- ru->is_wallet,
- m,
- &TALER_EXCHANGEDB_current_attributes_builder,
- &hbc,
- &TALER_EXCHANGEDB_current_rule_builder,
- &hbc,
- &TALER_EXCHANGEDB_aml_history_builder,
- &hbc,
- &TALER_EXCHANGEDB_kyc_history_builder,
- &hbc,
- ru->pg->max_aml_program_runtime,
- &aml_result_callback,
- ru);
- return;
- }
-
- /* User MUST pass interactive check */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Measure %s involves check %s\n",
- m->measure_name,
- m->check_name);
- {
- /* activate the measure/check */
- json_t *succ_jmeasures
- = TALER_KYCLOGIC_get_jmeasures (
- ru->lrs,
- m->measure_name);
- bool unknown_account;
- struct GNUNET_TIME_Timestamp last_date;
- enum GNUNET_DB_QueryStatus qs;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Inserting LEGI OUTCOME as successor measure\n");
- qs = TALER_EXCHANGEDB_insert_successor_measure (
- ru->pg,
- &ru->account,
- GNUNET_TIME_timestamp_get (),
- m->measure_name,
- succ_jmeasures,
- &unknown_account,
- &last_date);
- json_decref (succ_jmeasures);
- switch (qs)
- {
- case GNUNET_DB_STATUS_SOFT_ERROR:
- GNUNET_log (
- GNUNET_ERROR_TYPE_INFO,
- "Serialization issue!\n");
- fail_update (ru,
- TALER_EC_GENERIC_DB_SOFT_FAILURE,
- "insert_successor_measure");
- return;
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- fail_update (ru,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "insert_successor_measure");
- return;
- default:
- break;
- }
-
- if (unknown_account)
- {
- fail_update (ru,
- TALER_EC_EXCHANGE_GENERIC_BANK_ACCOUNT_UNKNOWN,
- NULL);
- return;
- }
- }
- /* The rules remain these rules until the user passes the check */
- return_result (ru);
-}
-
-
-/**
- * Update the expired legitimization rules in @a ru, checking for expiration
- * first. Called with an open database transaction.
- *
- * @param[in,out] ru account we are processing
- */
-static void
-update_rules (struct TALER_EXCHANGEDB_RuleUpdater *ru)
-{
- const struct TALER_KYCLOGIC_Measure *m;
-
- GNUNET_assert (NULL != ru->lrs);
- GNUNET_assert (GNUNET_TIME_absolute_is_past (
- TALER_KYCLOGIC_rules_get_expiration (ru->lrs).abs_time));
- m = TALER_KYCLOGIC_rules_get_successor (ru->lrs);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Successor measure is %s.\n",
- (NULL != m) ? m->measure_name : "(null)");
- run_measure (ru,
- m);
-}
-
-
-static void
-check_rules (struct TALER_EXCHANGEDB_RuleUpdater *ru)
-{
- ru->depth++;
- if (ru->depth > MAX_DEPTH)
- {
- fail_update (ru,
- TALER_EC_EXCHANGE_GENERIC_AML_PROGRAM_RECURSION_DETECTED,
- NULL);
- return;
- }
- if (NULL == ru->lrs)
- {
- /* return NULL, aka default rules */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Default rules apply\n");
- return_result (ru);
- return;
- }
- if (! GNUNET_TIME_absolute_is_past
- (TALER_KYCLOGIC_rules_get_expiration (ru->lrs).abs_time) )
- {
- /* Rules did not expire, return them! */
- return_result (ru);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Custom rules expired, updating...\n");
- update_rules (ru);
-}
-
-
-static void
-fetch_latest_rules (void *cls)
-{
- struct TALER_EXCHANGEDB_RuleUpdater *ru = cls;
- enum GNUNET_DB_QueryStatus qs;
- json_t *jnew_rules;
- enum GNUNET_GenericReturnValue res;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Fetching latest rules.");
-
- ru->t = NULL;
- if (NULL != ru->eh)
- {
- /* cancel event listener, if we have one */
- TALER_TALER_EXCHANGEDB_event_listen_cancel (ru->pg,
- ru->eh);
- ru->eh = NULL;
- }
- GNUNET_break (NULL == ru->lrs);
- res = TALER_EXCHANGEDB_start (ru->pg,
- "aml-begin-lookup-rules-by-access-token");
- if (GNUNET_OK != res)
- {
- GNUNET_break (0);
- fail_update (ru,
- TALER_EC_GENERIC_DB_START_FAILED,
- "aml-begin-lookup-rules-by-access-token");
- return;
- }
- qs = TALER_EXCHANGEDB_lookup_rules_by_access_token (
- ru->pg,
- &ru->account,
- &jnew_rules,
- &ru->legitimization_outcome_last_row);
- if (qs < 0)
- {
- GNUNET_break (0);
- fail_update (ru,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "lookup_rules_by_access_token");
- return;
- }
- if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) &&
- (NULL != jnew_rules) )
- {
- ru->lrs = TALER_KYCLOGIC_rules_parse (jnew_rules);
- GNUNET_break (NULL != ru->lrs);
- json_decref (jnew_rules);
- }
- check_rules (ru);
-}
-
-
-struct TALER_EXCHANGEDB_RuleUpdater *
-TALER_EXCHANGEDB_update_rules (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AttributeEncryptionKeyP *attribute_key,
- const struct TALER_NormalizedPaytoHashP *account,
- bool is_wallet,
- TALER_EXCHANGEDB_CurrentRulesCallback cb,
- void *cb_cls)
-{
- struct TALER_EXCHANGEDB_RuleUpdater *ru;
-
- ru = GNUNET_new (struct TALER_EXCHANGEDB_RuleUpdater);
- ru->pg = pg;
- ru->attribute_key = *attribute_key;
- ru->account = *account;
- ru->is_wallet = is_wallet;
- ru->cb = cb;
- ru->cb_cls = cb_cls;
- ru->t = GNUNET_SCHEDULER_add_now (&fetch_latest_rules,
- ru);
- return ru;
-}
-
-
-void
-TALER_EXCHANGEDB_update_rules_cancel (
- struct TALER_EXCHANGEDB_RuleUpdater *ru)
-{
- if (NULL != ru->t)
- {
- GNUNET_SCHEDULER_cancel (ru->t);
- ru->t = NULL;
- }
- if (NULL != ru->amlh)
- {
- TALER_KYCLOGIC_run_aml_program_cancel (ru->amlh);
- ru->amlh = NULL;
- }
- if (NULL != ru->lrs)
- {
- TALER_KYCLOGIC_rules_free (ru->lrs);
- ru->lrs = NULL;
- }
- if (NULL != ru->eh)
- {
- TALER_TALER_EXCHANGEDB_event_listen_cancel (ru->pg,
- ru->eh);
- ru->eh = NULL;
- }
- GNUNET_free (ru->aml_program_name);
- GNUNET_free (ru);
-}
diff --git a/src/exchangedb/update_to_aml_locked.c b/src/exchangedb/update_to_aml_locked.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 exchangedb/update_to_aml_locked.c
+ * @brief Implementation of the update_to_aml_locked function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_to_aml_locked.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_aml_locked (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Relative lock_duration,
+ struct GNUNET_TIME_Absolute *existing_lock)
+{
+
+ struct GNUNET_TIME_Absolute expires
+ = GNUNET_TIME_relative_to_absolute (lock_duration);
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_absolute_time (&expires),
+ GNUNET_PQ_query_param_end
+ };
+ bool nx; /* true if the *account* is not known */
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_absolute_time ("out_aml_program_lock_timeout",
+ existing_lock),
+ &nx),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "update_to_aml_locked",
+ "SELECT out_aml_program_lock_timeout"
+ " FROM exchange_do_set_aml_lock($1,$2,$3);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "update_to_aml_locked",
+ params,
+ rs);
+ if (qs <= 0)
+ return qs;
+ if (nx)
+ {
+ *existing_lock = GNUNET_TIME_UNIT_ZERO_ABS;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/set_aml_lock.sql b/src/exchangedb/update_to_aml_locked.sql
diff --git a/src/exchangedb/update_to_aml_unlocked.c b/src/exchangedb/update_to_aml_unlocked.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 exchangedb/update_to_aml_unlocked.c
+ * @brief Implementation of the update_to_aml_unlocked function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_to_aml_unlocked.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_aml_unlocked (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_to_aml_unlocked",
+ "UPDATE kyc_targets"
+ " SET aml_program_lock_timeout=NULL"
+ " WHERE h_normalized_payto=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_to_aml_unlocked",
+ params);
+}
diff --git a/src/exchangedb/update_to_prewire_failed.c b/src/exchangedb/update_to_prewire_failed.c
@@ -0,0 +1,44 @@
+/*
+ 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 exchangedb/update_to_prewire_failed.c
+ * @brief Implementation of the update_to_prewire_failed function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_to_prewire_failed.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_prewire_failed (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t rowid)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_to_prewire_failed",
+ "UPDATE prewire"
+ " SET failed=TRUE"
+ " WHERE prewire_uuid=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_to_prewire_failed",
+ params);
+}
diff --git a/src/exchangedb/update_to_prewire_finished.c b/src/exchangedb/update_to_prewire_finished.c
@@ -0,0 +1,43 @@
+/*
+ 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 exchangedb/update_to_prewire_finished.c
+ * @brief Implementation of the update_to_prewire_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_to_prewire_finished.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_prewire_finished (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t rowid)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_to_prewire_finished",
+ "UPDATE prewire"
+ " SET finished=TRUE"
+ " WHERE prewire_uuid=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_to_prewire_finished",
+ params);
+}
diff --git a/src/exchangedb/update_to_profit_drain_finished.c b/src/exchangedb/update_to_profit_drain_finished.c
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/update_to_profit_drain_finished.c
+ * @brief Implementation of the update_to_profit_drain_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_to_profit_drain_finished.h"
+#include "helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_profit_drain_finished (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t serial)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_to_profit_drain_finished",
+ "UPDATE profit_drains"
+ " SET"
+ " executed=TRUE"
+ " WHERE profit_drain_serial_id=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_to_profit_drain_finished",
+ params);
+}
diff --git a/src/exchangedb/update_to_refresh_revealed.c b/src/exchangedb/update_to_refresh_revealed.c
@@ -0,0 +1,45 @@
+/*
+ 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 exchangedb/update_to_refresh_revealed.c
+ * @brief Implementation of the update_to_refresh_revealed function for Postgres
+ * @author Özgür Kesim
+ */
+#include "taler/taler_pq_lib.h"
+#include "exchange-database/update_to_refresh_revealed.h"
+#include "helper.h"
+
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_refresh_revealed (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_RefreshCommitmentP *rc)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (rc),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_to_refresh_revealed",
+ "UPDATE refresh"
+ " SET revealed=true"
+ " WHERE rc = $1");
+
+ return GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "update_to_refresh_revealed",
+ params);
+}
diff --git a/src/exchangedb/wad_in_insert.c b/src/exchangedb/wad_in_insert.c
@@ -1,58 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/wad_in_insert.c
- * @brief Implementation of the wad_in_insert function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/wad_in_insert.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wad_in_insert (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_WadIdentifierP *wad_id,
- const char *origin_exchange_url,
- const struct TALER_Amount *amount,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_FullPayto debit_account_uri,
- const char *section_name,
- uint64_t serial_id)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (wad_id),
- GNUNET_PQ_query_param_string (origin_exchange_url),
- TALER_PQ_query_param_amount (pg->conn,
- amount),
- GNUNET_PQ_query_param_timestamp (&execution_date),
- GNUNET_PQ_query_param_end
- };
-
- // FIXME-#7271: should we keep the account data + serial_id?
- PREPARE (pg,
- "wad_in_insert",
- "INSERT INTO wads_in "
- "(wad_id"
- ",origin_exchange_url"
- ",amount"
- ",arrival_time"
- ") VALUES "
- "($1, $2, $3, $4);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wad_in_insert",
- params);
-}
diff --git a/src/exchangedb/wire_prepare_data_get.c b/src/exchangedb/wire_prepare_data_get.c
@@ -1,138 +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 exchangedb/wire_prepare_data_get.c
- * @brief Implementation of the wire_prepare_data_get function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/wire_prepare_data_get.h"
-#include "helper.h"
-
-/**
- * Closure for #prewire_cb().
- */
-struct PrewireContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_WirePreparationIterator cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * #GNUNET_OK if everything went fine.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-prewire_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PrewireContext *pc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t prewire_uuid;
- char *wire_method;
- void *buf = NULL;
- size_t buf_size;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("prewire_uuid",
- &prewire_uuid),
- GNUNET_PQ_result_spec_string ("wire_method",
- &wire_method),
- GNUNET_PQ_result_spec_variable_size ("buf",
- &buf,
- &buf_size),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- pc->status = GNUNET_SYSERR;
- return;
- }
- pc->cb (pc->cb_cls,
- prewire_uuid,
- wire_method,
- buf,
- buf_size);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_get (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t start_row,
- uint64_t limit,
- TALER_EXCHANGEDB_WirePreparationIterator
- cb,
- void *cb_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&start_row),
- GNUNET_PQ_query_param_uint64 (&limit),
- GNUNET_PQ_query_param_end
- };
- struct PrewireContext pc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "wire_prepare_data_get",
- "SELECT"
- " prewire_uuid"
- ",wire_method"
- ",buf"
- " FROM prewire"
- " WHERE prewire_uuid >= $1"
- " AND finished=FALSE"
- " AND failed=FALSE"
- " ORDER BY prewire_uuid ASC"
- " LIMIT $2;");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "wire_prepare_data_get",
- params,
- &prewire_cb,
- &pc);
- if (GNUNET_OK != pc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
diff --git a/src/exchangedb/wire_prepare_data_insert.c b/src/exchangedb/wire_prepare_data_insert.c
@@ -1,51 +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 exchangedb/wire_prepare_data_insert.c
- * @brief Implementation of the wire_prepare_data_insert function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/wire_prepare_data_insert.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_insert (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *type,
- const char *buf,
- size_t buf_size)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (type),
- GNUNET_PQ_query_param_fixed_size (buf, buf_size),
- GNUNET_PQ_query_param_end
- };
-
-
- /* Used in #postgres_wire_prepare_data_insert() to store
- wire transfer information before actually committing it with the bank */
- PREPARE (pg,
- "wire_prepare_data_insert",
- "INSERT INTO prewire "
- "(wire_method"
- ",buf"
- ") VALUES "
- "($1, $2);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_prepare_data_insert",
- params);
-}
diff --git a/src/exchangedb/wire_prepare_data_mark_failed.c b/src/exchangedb/wire_prepare_data_mark_failed.c
@@ -1,44 +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 exchangedb/wire_prepare_data_mark_failed.c
- * @brief Implementation of the wire_prepare_data_mark_failed function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/wire_prepare_data_mark_failed.h"
-#include "helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_mark_failed (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t rowid)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "wire_prepare_data_mark_failed",
- "UPDATE prewire"
- " SET failed=TRUE"
- " WHERE prewire_uuid=$1;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_prepare_data_mark_failed",
- params);
-}
diff --git a/src/exchangedb/wire_prepare_data_mark_finished.c b/src/exchangedb/wire_prepare_data_mark_finished.c
@@ -1,43 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/wire_prepare_data_mark_finished.c
- * @brief Implementation of the wire_prepare_data_mark_finished function for Postgres
- * @author Christian Grothoff
- */
-#include "taler/taler_pq_lib.h"
-#include "exchange-database/wire_prepare_data_mark_finished.h"
-#include "helper.h"
-
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_mark_finished (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t rowid)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "wire_prepare_data_mark_done",
- "UPDATE prewire"
- " SET finished=TRUE"
- " WHERE prewire_uuid=$1;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_prepare_data_mark_done",
- params);
-}
diff --git a/src/include/auditor-database/del_denomination_balance.h b/src/include/auditor-database/del_denomination_balance.h
@@ -1,41 +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/auditor-database/del_denomination_balance.h
- * @brief implementation of the del_denomination_balance function for Postgres
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_DEL_DENOMINATION_BALANCE_H
-#define AUDITOR_DATABASE_DEL_DENOMINATION_BALANCE_H
-
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Delete information about a denomination key's balances.
- *
- * @param pg the database context
- * @param denom_pub_hash hash of the denomination public key
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_del_denomination_balance (struct
- TALER_AUDITORDB_PostgresContext *pg,
- const struct TALER_DenominationHashP *
- denom_pub_hash);
-
-#endif
diff --git a/src/include/auditor-database/del_reserve_info.h b/src/include/auditor-database/del_reserve_info.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 del_reserve_info.h
- * @brief implementation of the del_reserve_info function
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_DEL_RESERVE_INFO_H
-#define AUDITOR_DATABASE_DEL_RESERVE_INFO_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Delete information about a reserve.
- *
- * @param pg the database context
- * @param reserve_pub public key of the reserve
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_del_reserve_info (struct TALER_AUDITORDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *
- reserve_pub);
-
-
-#endif
diff --git a/src/include/auditor-database/delete_denomination_balance.h b/src/include/auditor-database/delete_denomination_balance.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/auditor-database/delete_denomination_balance.h
+ * @brief implementation of the delete_denomination_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_DELETE_DENOMINATION_BALANCE_H
+#define AUDITOR_DATABASE_DELETE_DENOMINATION_BALANCE_H
+
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Delete information about a denomination key's balances.
+ *
+ * @param pg the database context
+ * @param denom_pub_hash hash of the denomination public key
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_delete_denomination_balance (struct
+ TALER_AUDITORDB_PostgresContext *pg
+ ,
+ const struct
+ TALER_DenominationHashP *
+ denom_pub_hash);
+
+#endif
diff --git a/src/include/auditor-database/delete_reserve_info.h b/src/include/auditor-database/delete_reserve_info.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 delete_reserve_info.h
+ * @brief implementation of the del_reserve_info function
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_DELETE_RESERVE_INFO_H
+#define AUDITOR_DATABASE_DELETE_RESERVE_INFO_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Delete information about a reserve.
+ *
+ * @param pg the database context
+ * @param reserve_pub public key of the reserve
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_delete_reserve_info (struct TALER_AUDITORDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *
+ reserve_pub);
+
+
+#endif
diff --git a/src/include/auditor-database/get_amount_arithmetic_inconsistency.h b/src/include/auditor-database/get_amount_arithmetic_inconsistency.h
@@ -1,67 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_AMOUNT_ARITHMETIC_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_AMOUNT_ARITHMETIC_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with arithmetic inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_AmountArithmeticInconsistencyCallback.
- */
-#define TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_AmountArithmeticInconsistencyCallback)(
- TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc);
-
-
-/**
- * Get information about deposit confirmations from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_amount_arithmetic_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_AmountArithmeticInconsistencyCallback
- cb,
- TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_auditor_closure_lags.h b/src/include/auditor-database/get_auditor_closure_lags.h
@@ -1,82 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_AUDITOR_CLOSURE_LAGS_H
-#define AUDITOR_DATABASE_GET_AUDITOR_CLOSURE_LAGS_H
-
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with closure lags stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ClosureLagsCallback.
- */
-#define TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ClosureLagsCallback)(
- TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_ClosureLags *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with closure lags stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ClosureLagsCallback)(
- TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_ClosureLags *dc);
-
-/**
- * Get information about auditor closure lags from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_auditor_closure_lags (struct
- TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_ClosureLagsCallback cb
- ,
- TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_bad_sig_losses.h b/src/include/auditor-database/get_bad_sig_losses.h
@@ -1,83 +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/>
- */
-#ifndef AUDITOR_DATABASE_GET_BAD_SIG_LOSSES_H
-#define AUDITOR_DATABASE_GET_BAD_SIG_LOSSES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with bad signature losses stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_BadSigLossesCallback.
- */
-#define TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_BadSigLossesCallback)(
- TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_BadSigLosses *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with bad signature losses stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_BadSigLossesCallback)(
- TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_BadSigLosses *dc);
-
-/**
- * Get information about bad signature losses from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param op_spec_pub public key to filter by; FIXME: replace by pointer
- * @param op operation to filter by
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_bad_sig_losses (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- const struct GNUNET_CRYPTO_EddsaPublicKey *
- op_spec_pub,
- const char *op,
- TALER_AUDITORDB_BadSigLossesCallback cb,
- TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_balances.h b/src/include/auditor-database/get_balances.h
@@ -1,69 +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/>
- */
-#ifndef AUDITOR_DATABASE_GET_BALANCES_H
-#define AUDITOR_DATABASE_GET_BALANCES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Information about a balance
- */
-struct TALER_AUDITORDB_Balances
-{
- uint64_t row_id;
- char *balance_key;
- struct TALER_Amount balance_value;
- bool suppressed;
-
-};
-
-#ifndef TALER_AUDITORDB_BALANCES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_BalancesCallback.
- */
-#define TALER_AUDITORDB_BALANCES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_BalancesCallback)(
- TALER_AUDITORDB_BALANCES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_Balances *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_BalancesCallback)(
- TALER_AUDITORDB_BALANCES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_Balances *dc);
-
-/**
- * Get information about balances from the database.
- *
- * @param pg the database context
- * @param balance_key key to filter by, NULL to match all balance keys
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_balances (struct TALER_AUDITORDB_PostgresContext *pg,
- const char *balance_key,
- TALER_AUDITORDB_BalancesCallback cb,
- TALER_AUDITORDB_BALANCES_RESULT_CLOSURE *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_coin_inconsistency.h b/src/include/auditor-database/get_coin_inconsistency.h
@@ -1,85 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_COIN_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_COIN_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with coin inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param serial_id location of the @a dc in the database
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_CoinInconsistencyCallback.
- */
-#define TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_CoinInconsistencyCallback)(
- TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_CoinInconsistency *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with coin inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param serial_id location of the @a dc in the database
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_CoinInconsistencyCallback)(
- TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_CoinInconsistency *dc);
-
-/**
- * Get information about deposit confirmations from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_coin_inconsistency (struct TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_CoinInconsistencyCallback
- cb,
- TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/auditor-database/get_denomination_key_validity_withdraw_inconsistency.h b/src/include/auditor-database/get_denomination_key_validity_withdraw_inconsistency.h
@@ -1,91 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with fee denomination key validity withdraw inconsistency stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef \
- TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback.
- */
-#define \
- TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE \
- void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback)(
- TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
- *cls,
- const struct
- TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with fee denomination key validity withdraw inconsistency stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback)(
- TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
- *cls,
- const struct
- TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc);
-
-/**
- * Get information about denominations key validity withdraw inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_denomination_key_validity_withdraw_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t
- limit,
- uint64_t
- offset,
- bool
- return_suppressed,
- TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback
- cb,
- TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_denomination_pending.h b/src/include/auditor-database/get_denomination_pending.h
@@ -1,64 +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/>
- */
-#ifndef AUDITOR_DATABASE_GET_DENOMINATION_PENDING_H
-#define AUDITOR_DATABASE_GET_DENOMINATION_PENDING_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_DenominationPendingCallback.
- */
-#define TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DenominationPendingCallback)(
- TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_DenominationPending *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DenominationPendingCallback)(
- TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_DenominationPending *dc);
-
-/**
- * Get information about denomination-pending from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_denomination_pending (struct
- TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_DenominationPendingCallback
- cb,
- TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_denominations_without_sigs.h b/src/include/auditor-database/get_denominations_without_sigs.h
@@ -1,67 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_DENOMINATIONS_WITHOUT_SIGS_H
-#define AUDITOR_DATABASE_GET_DENOMINATIONS_WITHOUT_SIGS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_DenominationsWithoutSigsCallback.
- */
-#define TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DenominationsWithoutSigsCallback)(
- TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DenominationsWithoutSigsCallback)(
- TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc);
-
-/**
- * Get information about denominations-without-sigs from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_denominations_without_sigs (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_DenominationsWithoutSigsCallback
- cb,
- TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_deposit_confirmations.h b/src/include/auditor-database/get_deposit_confirmations.h
@@ -1,68 +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 get_deposit_confirmations.h
- * @brief implementation of the get_deposit_confirmations function
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_GET_DEPOSIT_CONFIRMATIONS_H
-#define AUDITOR_DATABASE_GET_DEPOSIT_CONFIRMATIONS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with deposit confirmations stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the deposit confirmation itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_DepositConfirmationCallback.
- */
-#define TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_DepositConfirmationCallback)(
- TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_DepositConfirmation *dc);
-
-/**
- * Get information about deposit confirmations from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_deposit_confirmations (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_DepositConfirmationCallback cb,
- TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_emergency.h b/src/include/auditor-database/get_emergency.h
@@ -1,78 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_EMERGENCY_H
-#define AUDITOR_DATABASE_GET_EMERGENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with emergencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_EmergencyCallback.
- */
-#define TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_EmergencyCallback)(
- TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_Emergency *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with emergencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_EmergencyCallback)(
- TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_Emergency *dc);
-
-/**
- * Get information about emergency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_emergency (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_EmergencyCallback cb,
- TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE *cb_cls)
-;
-
-#endif
diff --git a/src/include/auditor-database/get_emergency_by_count.h b/src/include/auditor-database/get_emergency_by_count.h
@@ -1,80 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_EMERGENCY_BY_COUNT_H
-#define AUDITOR_DATABASE_GET_EMERGENCY_BY_COUNT_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with emergencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_EmergenciesByCountCallback.
- */
-#define TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_EmergenciesByCountCallback)(
- TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_EmergenciesByCount *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with emergencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_EmergenciesByCountCallback)(
- TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_EmergenciesByCount *dc);
-
-/**
- * Get information about emergency by count from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_emergency_by_count (struct TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_EmergenciesByCountCallback
- cb,
- TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_exchange_signkeys.h b/src/include/auditor-database/get_exchange_signkeys.h
@@ -1,65 +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/>
- */
-#ifndef AUDITOR_DATABASE_GET_EXCHANGE_SIGNKEYS_H
-#define AUDITOR_DATABASE_GET_EXCHANGE_SIGNKEYS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-struct TALER_AUDITORDB_ExchangeSignkeys
-{
- uint64_t row_id;
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_TIME_Absolute ep_valid_from;
- struct GNUNET_TIME_Absolute ep_expire_sign;
- struct GNUNET_TIME_Absolute ep_expire_legal;
-};
-
-#ifndef TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ExchangeSignkeysCallback.
- */
-#define TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ExchangeSignkeysCallback)(
- TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_ExchangeSignkeys *dc);
-
-
-/**
- * Get information about exchange-signkeys from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_exchange_signkeys (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_ExchangeSignkeysCallback cb,
- TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_fee_time_inconsistency.h b/src/include/auditor-database/get_fee_time_inconsistency.h
@@ -1,80 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_FEE_TIME_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_FEE_TIME_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with fee time inconsistency stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_FeeTimeInconsistencyCallback.
- */
-#define TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_FeeTimeInconsistencyCallback)(
- TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_FeeTimeInconsistency *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with fee time inconsistency stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_FeeTimeInconsistencyCallback)(
- TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_FeeTimeInconsistency *dc);
-
-/**
- * Get information about fee time inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_fee_time_inconsistency (struct
- TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_FeeTimeInconsistencyCallback
- cb,
- TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_misattribution_in_inconsistency.h b/src/include/auditor-database/get_misattribution_in_inconsistency.h
@@ -1,67 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_MISATTRIBUTION_IN_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_MISATTRIBUTION_IN_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_MisattributionInInconsistencyCallback.
- */
-#define TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_MisattributionInInconsistencyCallback)(
- TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_MisattributionInInconsistency *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_MisattributionInInconsistencyCallback)(
- TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_MisattributionInInconsistency *dc);
-
-/**
- * Get information about misattribution-in-inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_misattribution_in_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_MisattributionInInconsistencyCallback
- cb,
- TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_progress_points.h b/src/include/auditor-database/get_progress_points.h
@@ -1,73 +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/auditor-database/get_progress_points.h
- * @brief implementation of the get_progress_points function for Postgres
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_GET_PROGRESS_POINTS_H
-#define AUDITOR_DATABASE_GET_PROGRESS_POINTS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Information about progress of the audit.
- */
-struct TALER_AUDITORDB_Progress
-{
- char *progress_key;
- uint64_t progress_offset;
-};
-
-#ifndef TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ProgressPointsCallback.
- */
-#define TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ProgressPointsCallback)(
- TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_Progress *pp);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ProgressPointsCallback)(
- TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_Progress *pp);
-
-/**
- * Get information about progress from the database.
- *
- * @param pg the database context
- * @param progress_key only return this particular progress point
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_progress_points (struct TALER_AUDITORDB_PostgresContext *pg,
- const char *progress_key,
- TALER_AUDITORDB_ProgressPointsCallback cb,
- TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/auditor-database/get_purse_not_closed_inconsistencies.h b/src/include/auditor-database/get_purse_not_closed_inconsistencies.h
@@ -1,81 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_PURSE_NOT_CLOSED_INCONSISTENCIES_H
-#define AUDITOR_DATABASE_GET_PURSE_NOT_CLOSED_INCONSISTENCIES_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with purse not closed inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback.
- */
-#define TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback)(
- TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with purse not closed inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback)(
- TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc);
-
-/**
- * Get information about purse not closed inconsistencies from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_purse_not_closed_inconsistencies (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback
- cb,
- TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_purses.h b/src/include/auditor-database/get_purses.h
@@ -1,73 +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/>
- */
-#ifndef AUDITOR_DATABASE_GET_PURSES_H
-#define AUDITOR_DATABASE_GET_PURSES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-struct TALER_AUDITORDB_Purses
-{
- uint64_t row_id;
- uint64_t auditor_purses_rowid;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_Amount balance;
- struct TALER_Amount target;
- struct GNUNET_TIME_Absolute expiration_date;
- bool suppressed;
-
-};
-
-#ifndef TALER_AUDITORDB_PURSES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_PursesCallback.
- */
-#define TALER_AUDITORDB_PURSES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_PursesCallback)(
- TALER_AUDITORDB_PURSES_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_Purses *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_PursesCallback)(
- TALER_AUDITORDB_PURSES_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_Purses *dc);
-
-/**
- * Get information about purses from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_purses (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_PursesCallback cb,
- TALER_AUDITORDB_PURSES_RESULT_CLOSURE *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_reserve_balance_insufficient_inconsistency.h b/src/include/auditor-database/get_reserve_balance_insufficient_inconsistency.h
@@ -1,88 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with reserve balance insufficient inconsistency stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef \
- TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback.
- */
-#define \
- TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE \
- void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE *cls
- ,
- const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with reserve balance insufficient inconsistency stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE *cls
- ,
- const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc);
-
-/**
- * Get information about reserve balance insufficient inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_balance_insufficient_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool
- return_suppressed
- ,
- TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback
- cb,
- TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_reserve_balance_summary_wrong_inconsistency.h b/src/include/auditor-database/get_reserve_balance_summary_wrong_inconsistency.h
@@ -1,74 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef \
- TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback.
- */
-#define \
- TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE \
- void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE *
- cls,
- const struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE *
- cls,
- const struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency *dc);
-
-/**
- * Get information about reserve-balance-summary-wrong-inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_balance_summary_wrong_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset
- ,
- bool
- return_suppressed,
- TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback
- cb,
- TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_reserve_in_inconsistency.h b/src/include/auditor-database/get_reserve_in_inconsistency.h
@@ -13,55 +13,33 @@
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/auditor-database/get_reserve_in_inconsistency.h
+ * @brief implementation of the get_reserve_in_inconsistency function for Postgres
+ * @author Christian Grothoff
+ */
#ifndef AUDITOR_DATABASE_GET_RESERVE_IN_INCONSISTENCY_H
#define AUDITOR_DATABASE_GET_RESERVE_IN_INCONSISTENCY_H
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
#include "auditordb_lib.h"
-#ifndef TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE
/**
- * Type of the closure for #TALER_AUDITORDB_ReserveInInconsistencyCallback.
- */
-#define TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveInInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_ReserveInInconsistency *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveInInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_ReserveInInconsistency *dc);
-
-/**
- * Get information about reserve-in-inconsistency from the database.
+ * Return any reserve incoming inconsistency associated with the
+ * given @a bank_row_id.
*
* @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
+ * @param bank_row_id row to select by
+ * @param[out] dc details to return
*/
enum GNUNET_DB_QueryStatus
TALER_AUDITORDB_get_reserve_in_inconsistency (struct
- TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_ReserveInInconsistencyCallback
- cb,
- TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ uint64_t bank_row_id,
+ struct
+ TALER_AUDITORDB_ReserveInInconsistency
+ *dc);
+
#endif
diff --git a/src/include/auditor-database/get_reserve_not_closed_inconsistency.h b/src/include/auditor-database/get_reserve_not_closed_inconsistency.h
@@ -1,67 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_RESERVE_NOT_CLOSED_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_RESERVE_NOT_CLOSED_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback.
- */
-#define TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_ReserveNotClosedInconsistency *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback)(
- TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_ReserveNotClosedInconsistency *dc);
-
-/**
- * Get information about reserve-not-closed-inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserve_not_closed_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback
- cb,
- TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_reserves.h b/src/include/auditor-database/get_reserves.h
@@ -1,79 +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/>
- */
-#ifndef AUDITOR_DATABASE_GET_RESERVES_H
-#define AUDITOR_DATABASE_GET_RESERVES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-struct TALER_AUDITORDB_Reserves
-{
- uint64_t row_id;
- uint64_t auditor_reserves_rowid;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount reserve_balance;
- struct TALER_Amount reserve_loss;
- struct TALER_Amount withdraw_fee_balance;
- struct TALER_Amount close_fee_balance;
- struct TALER_Amount purse_fee_balance;
- struct TALER_Amount open_fee_balance;
- struct TALER_Amount history_fee_balance;
- struct GNUNET_TIME_Absolute expiration_date;
- struct TALER_FullPayto origin_account;
- bool suppressed;
-
-};
-
-#ifndef TALER_AUDITORDB_RESERVES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ReservesCallback.
- */
-#define TALER_AUDITORDB_RESERVES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReservesCallback)(
- TALER_AUDITORDB_RESERVES_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_Reserves *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ReservesCallback)(
- TALER_AUDITORDB_RESERVES_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_Reserves *dc);
-
-/**
- * Get information about reserves from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_reserves (struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_ReservesCallback cb,
- TALER_AUDITORDB_RESERVES_RESULT_CLOSURE *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_row_inconsistency.h b/src/include/auditor-database/get_row_inconsistency.h
@@ -1,85 +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/>
- */
-
-#ifndef AUDITOR_DATABASE_GET_ROW_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_ROW_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with row inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param serial_id location of the @a dc in the database
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-#ifndef TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_RowInconsistencyCallback.
- */
-#define TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_RowInconsistencyCallback)(
- TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_RowInconsistency *dc);
-
-
-/* Callback typedefs */
-/**
- * Function called with row inconsistencies stored in
- * the auditor's database.
- *
- * @param cls closure
- * @param serial_id location of the @a dc in the database
- * @param dc the structure itself
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_RowInconsistencyCallback)(
- TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_AUDITORDB_RowInconsistency *dc);
-
-/**
- * Get information about deposit confirmations from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_row_inconsistency (struct TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_RowInconsistencyCallback
- cb,
- TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/auditor-database/get_row_minor_inconsistencies.h b/src/include/auditor-database/get_row_minor_inconsistencies.h
@@ -1,67 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_ROW_MINOR_INCONSISTENCIES_H
-#define AUDITOR_DATABASE_GET_ROW_MINOR_INCONSISTENCIES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_RowMinorInconsistenciesCallback.
- */
-#define TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_RowMinorInconsistenciesCallback)(
- TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_RowMinorInconsistencies *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_RowMinorInconsistenciesCallback)(
- TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_RowMinorInconsistencies *dc);
-
-/**
- * Get information about row-minor-inconsistencies from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_row_minor_inconsistencies (struct
- TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_RowMinorInconsistenciesCallback
- cb,
- TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/get_wire_format_inconsistency.h b/src/include/auditor-database/get_wire_format_inconsistency.h
@@ -1,67 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_WIRE_FORMAT_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_WIRE_FORMAT_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_WireFormatInconsistencyCallback.
- */
-#define TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_WireFormatInconsistencyCallback)(
- TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_WireFormatInconsistency *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_WireFormatInconsistencyCallback)(
- TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_WireFormatInconsistency *dc);
-
-/**
- * Get information about wire-format-inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_wire_format_inconsistency (struct
- TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_WireFormatInconsistencyCallback
- cb,
- TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif // AUDITOR_DATABASE_GET_WIRE_FORMAT_INCONSISTENCY_H
diff --git a/src/include/auditor-database/get_wire_out_inconsistency.h b/src/include/auditor-database/get_wire_out_inconsistency.h
@@ -1,66 +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/>
- */
-
-
-#ifndef AUDITOR_DATABASE_GET_WIRE_OUT_INCONSISTENCY_H
-#define AUDITOR_DATABASE_GET_WIRE_OUT_INCONSISTENCY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-#ifndef TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_WireOutInconsistencyCallback.
- */
-#define TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_WireOutInconsistencyCallback)(
- TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_WireOutInconsistency *dc);
-
-
-/* Callback typedefs */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_WireOutInconsistencyCallback)(
- TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_WireOutInconsistency *dc);
-
-/**
- * Get information about wire-out-inconsistency from the database.
- *
- * @param pg the database context
- * @param limit number of records to return, negative for descending
- * @param offset table row to start from, exclusive, direction determined by @a limit
- * @param return_suppressed should suppressed rows be returned anyway?
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_get_wire_out_inconsistency (struct
- TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_WireOutInconsistencyCallback
- cb,
- TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE
- *cb_cls);
-
-#endif // AUDITOR_DATABASE_GET_WIRE_OUT_INCONSISTENCY_H
diff --git a/src/include/auditor-database/iterate_amount_arithmetic_inconsistencies.h b/src/include/auditor-database/iterate_amount_arithmetic_inconsistencies.h
@@ -0,0 +1,68 @@
+/*
+ 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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_AMOUNT_ARITHMETIC_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_AMOUNT_ARITHMETIC_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with arithmetic inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_AmountArithmeticInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_AmountArithmeticInconsistencyCallback)(
+ TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc);
+
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_amount_arithmetic_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_AmountArithmeticInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_auditor_closure_lags.h b/src/include/auditor-database/iterate_auditor_closure_lags.h
@@ -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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_AUDITOR_CLOSURE_LAGS_H
+#define AUDITOR_DATABASE_ITERATE_AUDITOR_CLOSURE_LAGS_H
+
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with closure lags stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ClosureLagsCallback.
+ */
+#define TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ClosureLagsCallback)(
+ TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_ClosureLags *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with closure lags stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ClosureLagsCallback)(
+ TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_ClosureLags *dc);
+
+/**
+ * Get information about auditor closure lags from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_auditor_closure_lags (struct
+ TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_ClosureLagsCallback
+ cb
+ ,
+ TALER_AUDITORDB_CLOSURE_LAGS_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_bad_sig_losses.h b/src/include/auditor-database/iterate_bad_sig_losses.h
@@ -0,0 +1,85 @@
+/*
+ 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/>
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_BAD_SIG_LOSSES_H
+#define AUDITOR_DATABASE_ITERATE_BAD_SIG_LOSSES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with bad signature losses stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_BadSigLossesCallback.
+ */
+#define TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_BadSigLossesCallback)(
+ TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_BadSigLosses *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with bad signature losses stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_BadSigLossesCallback)(
+ TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_BadSigLosses *dc);
+
+/**
+ * Get information about bad signature losses from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param op_spec_pub public key to filter by; FIXME: replace by pointer
+ * @param op operation to filter by
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_bad_sig_losses (struct TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ const struct
+ GNUNET_CRYPTO_EddsaPublicKey *
+ op_spec_pub,
+ const char *op,
+ TALER_AUDITORDB_BadSigLossesCallback cb,
+ TALER_AUDITORDB_BAD_SIG_LOSSES_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_balances.h b/src/include/auditor-database/iterate_balances.h
@@ -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/>
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_BALANCES_H
+#define AUDITOR_DATABASE_ITERATE_BALANCES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Information about a balance
+ */
+struct TALER_AUDITORDB_Balances
+{
+ uint64_t row_id;
+ char *balance_key;
+ struct TALER_Amount balance_value;
+ bool suppressed;
+
+};
+
+#ifndef TALER_AUDITORDB_BALANCES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_BalancesCallback.
+ */
+#define TALER_AUDITORDB_BALANCES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_BalancesCallback)(
+ TALER_AUDITORDB_BALANCES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_Balances *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_BalancesCallback)(
+ TALER_AUDITORDB_BALANCES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_Balances *dc);
+
+/**
+ * Get information about balances from the database.
+ *
+ * @param pg the database context
+ * @param balance_key key to filter by, NULL to match all balance keys
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_balances (struct TALER_AUDITORDB_PostgresContext *pg,
+ const char *balance_key,
+ TALER_AUDITORDB_BalancesCallback cb,
+ TALER_AUDITORDB_BALANCES_RESULT_CLOSURE *
+ cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_coin_inconsistencies.h b/src/include/auditor-database/iterate_coin_inconsistencies.h
@@ -0,0 +1,86 @@
+/*
+ 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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_COIN_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_COIN_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with coin inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param serial_id location of the @a dc in the database
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_CoinInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_CoinInconsistencyCallback)(
+ TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_CoinInconsistency *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with coin inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param serial_id location of the @a dc in the database
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_CoinInconsistencyCallback)(
+ TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_CoinInconsistency *dc);
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_coin_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_CoinInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/auditor-database/iterate_denomination_key_validity_withdraw_inconsistencies.h b/src/include/auditor-database/iterate_denomination_key_validity_withdraw_inconsistencies.h
@@ -0,0 +1,95 @@
+/*
+ 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/>
+ */
+
+#ifndef \
+ AUDITOR_DATABASE_ITERATE_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCIES_H
+#define \
+ AUDITOR_DATABASE_ITERATE_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with fee denomination key validity withdraw inconsistency stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef \
+ TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback.
+ */
+#define \
+ TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE \
+ void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback)(
+ TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
+ *cls,
+ const struct
+ TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with fee denomination key validity withdraw inconsistency stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback)(
+ TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
+ *cls,
+ const struct
+ TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc);
+
+/**
+ * Get information about denominations key validity withdraw inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_denomination_key_validity_withdraw_inconsistencies (
+ struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t
+ limit,
+ uint64_t
+ offset,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE
+ *
+ cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_denomination_pending.h b/src/include/auditor-database/iterate_denomination_pending.h
@@ -0,0 +1,65 @@
+/*
+ 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/>
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_DENOMINATION_PENDING_H
+#define AUDITOR_DATABASE_ITERATE_DENOMINATION_PENDING_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_DenominationPendingCallback.
+ */
+#define TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DenominationPendingCallback)(
+ TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_DenominationPending *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DenominationPendingCallback)(
+ TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_DenominationPending *dc);
+
+/**
+ * Get information about denomination-pending from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_denomination_pending (struct
+ TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_DenominationPendingCallback
+ cb,
+ TALER_AUDITORDB_DENOMINATION_PENDING_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_denominations_without_sigs.h b/src/include/auditor-database/iterate_denominations_without_sigs.h
@@ -0,0 +1,67 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_DENOMINATIONS_WITHOUT_SIGS_H
+#define AUDITOR_DATABASE_ITERATE_DENOMINATIONS_WITHOUT_SIGS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_DenominationsWithoutSigsCallback.
+ */
+#define TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DenominationsWithoutSigsCallback)(
+ TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DenominationsWithoutSigsCallback)(
+ TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc);
+
+/**
+ * Get information about denominations-without-sigs from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_denominations_without_sigs (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_DenominationsWithoutSigsCallback
+ cb,
+ TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIGS_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_deposit_confirmations.h b/src/include/auditor-database/iterate_deposit_confirmations.h
@@ -0,0 +1,68 @@
+/*
+ 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 iterate_deposit_confirmations.h
+ * @brief implementation of the get_deposit_confirmations function
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_DEPOSIT_CONFIRMATIONS_H
+#define AUDITOR_DATABASE_ITERATE_DEPOSIT_CONFIRMATIONS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with deposit confirmations stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the deposit confirmation itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_DepositConfirmationCallback.
+ */
+#define TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_DepositConfirmationCallback)(
+ TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc);
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_deposit_confirmations (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_DepositConfirmationCallback cb,
+ TALER_AUDITORDB_DEPOSIT_CONFIRMATION_RESULT_CLOSURE *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_early_aggregations.h b/src/include/auditor-database/iterate_early_aggregations.h
@@ -0,0 +1,102 @@
+/*
+ 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/auditor-database/iterate_early_aggregations.h
+ * @brief implementation of the iterate_early_aggregations function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_EARLY_AGGREGATIONS_H
+#define AUDITOR_DATABASE_ITERATE_EARLY_AGGREGATIONS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Information about an early aggregation event.
+ */
+struct TALER_AUDITORDB_EarlyAggregation
+{
+ /**
+ * Row of the event in the auditor database.
+ */
+ uint64_t row_id;
+
+ /**
+ * Row of the batch deposit in the exchange database.
+ */
+ uint64_t batch_deposit_serial_id;
+
+ /**
+ * FIXME
+ */
+ uint64_t tracking_serial_id;
+
+ /**
+ * Total amount involved.
+ */
+ struct TALER_Amount total;
+
+ /**
+ * True if this report was previously suppressed.
+ */
+ bool suppressed;
+};
+
+
+/**
+ * Function to call with information about early aggregations.
+ *
+ * @param cls closure
+ * @param ea event data
+ * @return #GNUNET_OK to continue to iterate
+ */
+#ifndef TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_EarlyAggregationsCallback.
+ */
+#define TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_EarlyAggregationsCallback)(
+ TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_EarlyAggregation *ea);
+
+
+/**
+ * Returns all aggregations that were found that were done
+ * too early.
+ *
+ * @param pg the database context
+ * @param limit number of rows to return, negative to iterate backwards
+ * @param offset starting offset, exclusive
+ * @param return_suppressed true to also return suppressed events
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_early_aggregations (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_EarlyAggregationsCallback cb,
+ TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE *cb_cls);
+
+
+#endif
diff --git a/src/include/auditor-database/iterate_emergencies.h b/src/include/auditor-database/iterate_emergencies.h
@@ -0,0 +1,79 @@
+/*
+ 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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_EMERGENCIES_H
+#define AUDITOR_DATABASE_ITERATE_EMERGENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with emergencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_EmergencyCallback.
+ */
+#define TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_EmergencyCallback)(
+ TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_Emergency *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with emergencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_EmergencyCallback)(
+ TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_Emergency *dc);
+
+/**
+ * Get information about emergency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_emergencies (struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_EmergencyCallback cb,
+ TALER_AUDITORDB_EMERGENCY_RESULT_CLOSURE *
+ cb_cls)
+;
+
+#endif
diff --git a/src/include/auditor-database/iterate_emergencies_by_count.h b/src/include/auditor-database/iterate_emergencies_by_count.h
@@ -0,0 +1,81 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_EMERGENCIES_BY_COUNT_H
+#define AUDITOR_DATABASE_ITERATE_EMERGENCIES_BY_COUNT_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with emergencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_EmergenciesByCountCallback.
+ */
+#define TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_EmergenciesByCountCallback)(
+ TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_EmergenciesByCount *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with emergencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_EmergenciesByCountCallback)(
+ TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_EmergenciesByCount *dc);
+
+/**
+ * Get information about emergency by count from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_emergencies_by_count (struct
+ TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_EmergenciesByCountCallback
+ cb,
+ TALER_AUDITORDB_EMERGENCIES_BY_COUNT_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_exchange_signkeys.h b/src/include/auditor-database/iterate_exchange_signkeys.h
@@ -0,0 +1,65 @@
+/*
+ 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/>
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_EXCHANGE_SIGNKEYS_H
+#define AUDITOR_DATABASE_ITERATE_EXCHANGE_SIGNKEYS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+struct TALER_AUDITORDB_ExchangeSignkeys
+{
+ uint64_t row_id;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_TIME_Absolute ep_valid_from;
+ struct GNUNET_TIME_Absolute ep_expire_sign;
+ struct GNUNET_TIME_Absolute ep_expire_legal;
+};
+
+#ifndef TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ExchangeSignkeysCallback.
+ */
+#define TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ExchangeSignkeysCallback)(
+ TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_ExchangeSignkeys *dc);
+
+
+/**
+ * Get information about exchange-signkeys from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_exchange_signkeys (
+ struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_ExchangeSignkeysCallback cb,
+ TALER_AUDITORDB_EXCHANGE_SIGNKEYS_RESULT_CLOSURE *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_fee_time_inconsistencies.h b/src/include/auditor-database/iterate_fee_time_inconsistencies.h
@@ -0,0 +1,81 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_FEE_TIME_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_FEE_TIME_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with fee time inconsistency stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_FeeTimeInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_FeeTimeInconsistencyCallback)(
+ TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_FeeTimeInconsistency *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with fee time inconsistency stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_FeeTimeInconsistencyCallback)(
+ TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_FeeTimeInconsistency *dc);
+
+/**
+ * Get information about fee time inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_fee_time_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_FeeTimeInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_FEE_TIME_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_historic_denom_revenue.h b/src/include/auditor-database/iterate_historic_denom_revenue.h
@@ -0,0 +1,119 @@
+/*
+ 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 iterate_historic_denom_revenue.h
+ * @brief implementation of the select_historic_denom_revenue function
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_HISTORIC_DENOM_REVENUE_H
+#define AUDITOR_DATABASE_ITERATE_HISTORIC_DENOM_REVENUE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with the results of select_historic_denom_revenue()
+ *
+ * @param cls closure
+ * @param serial_id row for the denomination revenue in the auditor database
+ * @param denom_pub_hash hash of the denomination key
+ * @param revenue_timestamp when did this profit get realized
+ * @param revenue_balance what was the total profit made from
+ * deposit fees, melting fees, refresh fees
+ * and coins that were never returned?
+ * @param loss_balance what was the total loss
+ * @return sets the return value of select_denomination_info(),
+ * #GNUNET_OK to continue,
+ * #GNUNET_NO to stop processing further rows
+ * #GNUNET_SYSERR or other values on error.
+ */
+#ifndef TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_HistoricDenominationRevenueDataCallback.
+ */
+#define TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_HistoricDenominationRevenueDataCallback)(
+ TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct GNUNET_TIME_Timestamp revenue_timestamp,
+ const struct TALER_Amount *revenue_balance,
+ const struct TALER_Amount *loss_balance);
+
+struct TALER_AUDITORDB_HistoricDenominationRevenue
+{
+ uint64_t row_id;
+ struct TALER_DenominationHashP denom_pub_hash;
+ struct GNUNET_TIME_Absolute revenue_timestamp;
+ struct TALER_Amount revenue_balance;
+ struct TALER_Amount loss_balance;
+ bool suppressed;
+
+};
+
+
+/**
+ * Function called with the results of select_historic_denom_revenue()
+ *
+ * @param cls closure
+ * @param serial_id row for the denomination revenue in the auditor database
+ * @param denom_pub_hash hash of the denomination key
+ * @param revenue_timestamp when did this profit get realized
+ * @param revenue_balance what was the total profit made from
+ * deposit fees, melting fees, refresh fees
+ * and coins that were never returned?
+ * @param loss_balance what was the total loss
+ * @return sets the return value of select_denomination_info(),
+ * #GNUNET_OK to continue,
+ * #GNUNET_NO to stop processing further rows
+ * #GNUNET_SYSERR or other values on error.
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_HistoricDenominationRevenueDataCallback)(
+ TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct GNUNET_TIME_Timestamp revenue_timestamp,
+ const struct TALER_Amount *revenue_balance,
+ const struct TALER_Amount *loss_balance);
+
+/**
+ * Obtain all of the historic denomination key revenue
+ *
+ * @param pg the database context
+ * @param limit return at most this number of results, negative to descend from @a offset
+ * @param offset row from which to return @a limit results
+ * @param cb function to call with the results
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_historic_denom_revenue (struct
+ TALER_AUDITORDB_PostgresContext
+ *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_HistoricDenominationRevenueDataCallback
+ cb,
+ TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_historic_reserve_revenue.h b/src/include/auditor-database/iterate_historic_reserve_revenue.h
@@ -0,0 +1,103 @@
+/*
+ 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 iterate_historic_reserve_revenue.h
+ * @brief implementation of the select_historic_reserve_revenue function
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_HISTORIC_RESERVE_REVENUE_H
+#define AUDITOR_DATABASE_ITERATE_HISTORIC_RESERVE_REVENUE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with the results of select_historic_reserve_revenue()
+ *
+ * @param cls closure
+ * @param serial_id row ID in the history table
+ * @param start_time beginning of aggregated time interval
+ * @param end_time end of aggregated time interval
+ * @param reserve_profits total profits made
+ *
+ * @return sets the return value of select_denomination_info(),
+ * #GNUNET_OK to continue,
+ * #GNUNET_NO to stop processing further rows
+ * #GNUNET_SYSERR or other values on error.
+ */
+#ifndef TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_HistoricReserveRevenueDataCallback.
+ */
+#define TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_HistoricReserveRevenueDataCallback)(
+ TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ const struct TALER_Amount *reserve_profits);
+
+
+/* Callback typedefs */
+/**
+ * Function called with the results of select_historic_reserve_revenue()
+ *
+ * @param cls closure
+ * @param serial_id row ID in the history table
+ * @param start_time beginning of aggregated time interval
+ * @param end_time end of aggregated time interval
+ * @param reserve_profits total profits made
+ *
+ * @return sets the return value of select_denomination_info(),
+ * #GNUNET_OK to continue,
+ * #GNUNET_NO to stop processing further rows
+ * #GNUNET_SYSERR or other values on error.
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_HistoricReserveRevenueDataCallback)(
+ TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ const struct TALER_Amount *reserve_profits);
+
+/**
+ * Return information about an exchange's historic revenue from reserves.
+ *
+ * @param pg the database context
+ * @param limit return at most this number of results, negative to descend from @a offset
+ * @param offset row from which to return @a limit results
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_historic_reserve_revenue (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_HistoricReserveRevenueDataCallback
+ cb,
+ TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/auditor-database/iterate_misattribution_in_inconsistencies.h b/src/include/auditor-database/iterate_misattribution_in_inconsistencies.h
@@ -0,0 +1,68 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_MISATTRIBUTION_IN_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_MISATTRIBUTION_IN_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_MisattributionInInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_MisattributionInInconsistencyCallback)(
+ TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_MisattributionInInconsistency *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_MisattributionInInconsistencyCallback)(
+ TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_MisattributionInInconsistency *dc);
+
+/**
+ * Get information about misattribution-in-inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_misattribution_in_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_MisattributionInInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_pending_deposits.h b/src/include/auditor-database/iterate_pending_deposits.h
@@ -0,0 +1,106 @@
+/*
+ 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/auditor-database/iterate_pending_deposits.h
+ * @brief implementation of the iterate_pending_deposits function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_PENDING_DEPOSITS_H
+#define AUDITOR_DATABASE_ITERATE_PENDING_DEPOSITS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called on deposits that are past their due date
+ * and have not yet seen a wire transfer.
+ *
+ * @param cls closure
+ * @param row_id row ID of the alert in the auditor database
+ * @param batch_deposit_serial_id where in the exchange table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
+ * @param suppressed true if this report was suppressed
+ */
+#ifndef TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_WireMissingCallback.
+ */
+#define TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_AUDITORDB_WireMissingCallback) (
+ TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_FullPaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline,
+ bool suppressed);
+
+
+/* Callback typedefs */
+/**
+ * Function called on deposits that are past their due date
+ * and have not yet seen a wire transfer.
+ *
+ * @param cls closure
+ * @param row_id row ID of the alert in the auditor database
+ * @param batch_deposit_serial_id where in the exchange table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
+ * @param suppressed true if this report was suppressed
+ */
+typedef void
+(*TALER_AUDITORDB_WireMissingCallback) (
+ TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_FullPaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline,
+ bool suppressed);
+
+/**
+ * Return (batch) deposits for which we have not yet
+ * seen the required wire transfer.
+ *
+ * @param pg the database context
+ * @param deadline only return up to this deadline
+ * @param limit number of rows to return, negative to iterate backwards
+ * @param offset starting offset, exclusive
+ * @param return_suppressed true to also return suppressed events
+ * @param cb function to call on each entry
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_pending_deposits (struct
+ TALER_AUDITORDB_PostgresContext *pg,
+ struct GNUNET_TIME_Absolute deadline,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_WireMissingCallback cb
+ ,
+ TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_progress_points.h b/src/include/auditor-database/iterate_progress_points.h
@@ -0,0 +1,75 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/auditor-database/iterate_progress_points.h
+ * @brief implementation of the iterate_progress_points function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_PROGRESS_POINTS_H
+#define AUDITOR_DATABASE_ITERATE_PROGRESS_POINTS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Information about progress of the audit.
+ */
+struct TALER_AUDITORDB_Progress
+{
+ char *progress_key;
+ uint64_t progress_offset;
+};
+
+#ifndef TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ProgressPointsCallback.
+ */
+#define TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ProgressPointsCallback)(
+ TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_Progress *pp);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ProgressPointsCallback)(
+ TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_Progress *pp);
+
+/**
+ * Get information about progress from the database.
+ *
+ * @param pg the database context
+ * @param progress_key only return this particular progress point
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_progress_points (struct
+ TALER_AUDITORDB_PostgresContext *pg,
+ const char *progress_key,
+ TALER_AUDITORDB_ProgressPointsCallback
+ cb,
+ TALER_AUDITORDB_PROGRESS_POINTS_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/auditor-database/iterate_purse_expired.h b/src/include/auditor-database/iterate_purse_expired.h
@@ -0,0 +1,85 @@
+/*
+ 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/auditor-database/iterate_purse_expired.h
+ * @brief implementation of the iterate_purse_expired function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_PURSE_EXPIRED_H
+#define AUDITOR_DATABASE_ITERATE_PURSE_EXPIRED_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called on expired purses.
+ *
+ * @param cls closure
+ * @param purse_pub public key of the purse
+ * @param balance amount of money in the purse
+ * @param expiration_date when did the purse expire?
+ * @return #GNUNET_OK to continue to iterate
+ */
+#ifndef TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ExpiredPurseCallback.
+ */
+#define TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ExpiredPurseCallback)(
+ TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date);
+
+
+/* Callback typedefs */
+/**
+ * Function called on expired purses.
+ *
+ * @param cls closure
+ * @param purse_pub public key of the purse
+ * @param balance amount of money in the purse
+ * @param expiration_date when did the purse expire?
+ * @return #GNUNET_OK to continue to iterate
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ExpiredPurseCallback)(
+ TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date);
+
+/**
+ * Get information about expired purses.
+ *
+ * @param pg the database context
+ * @param cb function to call on expired purses
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_purse_expired (struct TALER_AUDITORDB_PostgresContext *
+ pg
+ ,
+ TALER_AUDITORDB_ExpiredPurseCallback cb,
+ TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_purse_not_closed_inconsistencies.h b/src/include/auditor-database/iterate_purse_not_closed_inconsistencies.h
@@ -0,0 +1,82 @@
+/*
+ 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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_PURSE_NOT_CLOSED_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_PURSE_NOT_CLOSED_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with purse not closed inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback.
+ */
+#define TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback)(
+ TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with purse not closed inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback)(
+ TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc);
+
+/**
+ * Get information about purse not closed inconsistencies from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_purse_not_closed_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed
+ ,
+ TALER_AUDITORDB_PurseNotClosedInconsistenciesCallback
+ cb,
+ TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_purses.h b/src/include/auditor-database/iterate_purses.h
@@ -0,0 +1,73 @@
+/*
+ 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/>
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_PURSES_H
+#define AUDITOR_DATABASE_ITERATE_PURSES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+struct TALER_AUDITORDB_Purses
+{
+ uint64_t row_id;
+ uint64_t auditor_purses_rowid;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_Amount balance;
+ struct TALER_Amount target;
+ struct GNUNET_TIME_Absolute expiration_date;
+ bool suppressed;
+
+};
+
+#ifndef TALER_AUDITORDB_PURSES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_PursesCallback.
+ */
+#define TALER_AUDITORDB_PURSES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_PursesCallback)(
+ TALER_AUDITORDB_PURSES_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_Purses *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_PursesCallback)(
+ TALER_AUDITORDB_PURSES_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_Purses *dc);
+
+/**
+ * Get information about purses from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_purses (struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_PursesCallback cb,
+ TALER_AUDITORDB_PURSES_RESULT_CLOSURE *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_reserve_balance_insufficient_inconsistencies.h b/src/include/auditor-database/iterate_reserve_balance_insufficient_inconsistencies.h
@@ -0,0 +1,90 @@
+/*
+ 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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with reserve balance insufficient inconsistency stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef \
+ TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback.
+ */
+#define \
+ TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE \
+ void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE *cls
+ ,
+ const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with reserve balance insufficient inconsistency stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE *cls
+ ,
+ const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc);
+
+/**
+ * Get information about reserve balance insufficient inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_balance_insufficient_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t
+ limit,
+ uint64_t
+ offset,
+ bool
+ return_suppressed
+ ,
+ TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_reserve_balance_summary_wrong_inconsistencies.h b/src/include/auditor-database/iterate_reserve_balance_summary_wrong_inconsistencies.h
@@ -0,0 +1,76 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef \
+ TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback.
+ */
+#define \
+ TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE \
+ void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE *
+ cls,
+ const struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE *
+ cls,
+ const struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency *dc);
+
+/**
+ * Get information about reserve-balance-summary-wrong-inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_balance_summary_wrong_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t
+ limit,
+ uint64_t
+ offset
+ ,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_reserve_in_inconsistencies.h b/src/include/auditor-database/iterate_reserve_in_inconsistencies.h
@@ -0,0 +1,68 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_RESERVE_IN_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_RESERVE_IN_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ReserveInInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveInInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_ReserveInInconsistency *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveInInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_ReserveInInconsistency *dc);
+
+/**
+ * Get information about reserve-in-inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_in_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_ReserveInInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_reserve_not_closed_inconsistencies.h b/src/include/auditor-database/iterate_reserve_not_closed_inconsistencies.h
@@ -0,0 +1,68 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_RESERVE_NOT_CLOSED_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_RESERVE_NOT_CLOSED_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_ReserveNotClosedInconsistency *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback)(
+ TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_ReserveNotClosedInconsistency *dc);
+
+/**
+ * Get information about reserve-not-closed-inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserve_not_closed_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool
+ return_suppressed,
+ TALER_AUDITORDB_ReserveNotClosedInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_reserves.h b/src/include/auditor-database/iterate_reserves.h
@@ -0,0 +1,80 @@
+/*
+ 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/>
+ */
+#ifndef AUDITOR_DATABASE_ITERATE_RESERVES_H
+#define AUDITOR_DATABASE_ITERATE_RESERVES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+struct TALER_AUDITORDB_Reserves
+{
+ uint64_t row_id;
+ uint64_t auditor_reserves_rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount reserve_balance;
+ struct TALER_Amount reserve_loss;
+ struct TALER_Amount withdraw_fee_balance;
+ struct TALER_Amount close_fee_balance;
+ struct TALER_Amount purse_fee_balance;
+ struct TALER_Amount open_fee_balance;
+ struct TALER_Amount history_fee_balance;
+ struct GNUNET_TIME_Absolute expiration_date;
+ struct TALER_FullPayto origin_account;
+ bool suppressed;
+
+};
+
+#ifndef TALER_AUDITORDB_RESERVES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_ReservesCallback.
+ */
+#define TALER_AUDITORDB_RESERVES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReservesCallback)(
+ TALER_AUDITORDB_RESERVES_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_Reserves *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ReservesCallback)(
+ TALER_AUDITORDB_RESERVES_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_Reserves *dc);
+
+/**
+ * Get information about reserves from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_reserves (struct TALER_AUDITORDB_PostgresContext *pg,
+ int64_t limit,
+ uint64_t offset,
+ TALER_AUDITORDB_ReservesCallback cb,
+ TALER_AUDITORDB_RESERVES_RESULT_CLOSURE *
+ cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_row_inconsistencies.h b/src/include/auditor-database/iterate_row_inconsistencies.h
@@ -0,0 +1,86 @@
+/*
+ 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/>
+ */
+
+#ifndef AUDITOR_DATABASE_ITERATE_ROW_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_ROW_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "auditordb_lib.h"
+
+
+/**
+ * Function called with row inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param serial_id location of the @a dc in the database
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+#ifndef TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_RowInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_RowInconsistencyCallback)(
+ TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_RowInconsistency *dc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with row inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param serial_id location of the @a dc in the database
+ * @param dc the structure itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_RowInconsistencyCallback)(
+ TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_RowInconsistency *dc);
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_row_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_RowInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/auditor-database/iterate_row_minor_inconsistencies.h b/src/include/auditor-database/iterate_row_minor_inconsistencies.h
@@ -0,0 +1,68 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_ROW_MINOR_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_ROW_MINOR_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_RowMinorInconsistenciesCallback.
+ */
+#define TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_RowMinorInconsistenciesCallback)(
+ TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_RowMinorInconsistencies *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_RowMinorInconsistenciesCallback)(
+ TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_RowMinorInconsistencies *dc);
+
+/**
+ * Get information about row-minor-inconsistencies from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_row_minor_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_RowMinorInconsistenciesCallback
+ cb,
+ TALER_AUDITORDB_ROW_MINOR_INCONSISTENCIES_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/auditor-database/iterate_wire_format_inconsistencies.h b/src/include/auditor-database/iterate_wire_format_inconsistencies.h
@@ -0,0 +1,68 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_WIRE_FORMAT_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_WIRE_FORMAT_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_WireFormatInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_WireFormatInconsistencyCallback)(
+ TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_WireFormatInconsistency *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_WireFormatInconsistencyCallback)(
+ TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_WireFormatInconsistency *dc);
+
+/**
+ * Get information about wire-format-inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_wire_format_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *
+ pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_WireFormatInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif // AUDITOR_DATABASE_ITERATE_WIRE_FORMAT_INCONSISTENCIES_H
diff --git a/src/include/auditor-database/iterate_wire_out_inconsistencies.h b/src/include/auditor-database/iterate_wire_out_inconsistencies.h
@@ -0,0 +1,67 @@
+/*
+ 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/>
+ */
+
+
+#ifndef AUDITOR_DATABASE_ITERATE_WIRE_OUT_INCONSISTENCIES_H
+#define AUDITOR_DATABASE_ITERATE_WIRE_OUT_INCONSISTENCIES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "auditordb_lib.h"
+
+
+#ifndef TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_AUDITORDB_WireOutInconsistencyCallback.
+ */
+#define TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_WireOutInconsistencyCallback)(
+ TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_WireOutInconsistency *dc);
+
+
+/* Callback typedefs */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_WireOutInconsistencyCallback)(
+ TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE *cls,
+ const struct TALER_AUDITORDB_WireOutInconsistency *dc);
+
+/**
+ * Get information about wire-out-inconsistency from the database.
+ *
+ * @param pg the database context
+ * @param limit number of records to return, negative for descending
+ * @param offset table row to start from, exclusive, direction determined by @a limit
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_iterate_wire_out_inconsistencies (struct
+ TALER_AUDITORDB_PostgresContext
+ *pg,
+ int64_t limit,
+ uint64_t offset,
+ bool return_suppressed,
+ TALER_AUDITORDB_WireOutInconsistencyCallback
+ cb,
+ TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif // AUDITOR_DATABASE_ITERATE_WIRE_OUT_INCONSISTENCIES_H
diff --git a/src/include/auditor-database/lookup_reserve_in_inconsistency.h b/src/include/auditor-database/lookup_reserve_in_inconsistency.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/>
- */
-#ifndef AUDITOR_DATABASE_LOOKUP_RESERVE_IN_INCONSISTENCY_H
-#define AUDITOR_DATABASE_LOOKUP_RESERVE_IN_INCONSISTENCY_H
-
-#include "auditordb_lib.h"
-
-
-/**
- * Lookup information about reserve-in-inconsistency from the database.
- *
- * @param pg the database context
- * @param bank_row_id row of the transaction at the bank
- * @param[out] dc set to the transaction details
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_lookup_reserve_in_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- uint64_t bank_row_id,
- struct
- TALER_AUDITORDB_ReserveInInconsistency
- *dc);
-
-#endif
diff --git a/src/include/auditor-database/select_early_aggregations.h b/src/include/auditor-database/select_early_aggregations.h
@@ -1,102 +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/auditor-database/select_early_aggregations.h
- * @brief implementation of the select_early_aggregations function for Postgres
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_SELECT_EARLY_AGGREGATIONS_H
-#define AUDITOR_DATABASE_SELECT_EARLY_AGGREGATIONS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Information about an early aggregation event.
- */
-struct TALER_AUDITORDB_EarlyAggregation
-{
- /**
- * Row of the event in the auditor database.
- */
- uint64_t row_id;
-
- /**
- * Row of the batch deposit in the exchange database.
- */
- uint64_t batch_deposit_serial_id;
-
- /**
- * FIXME
- */
- uint64_t tracking_serial_id;
-
- /**
- * Total amount involved.
- */
- struct TALER_Amount total;
-
- /**
- * True if this report was previously suppressed.
- */
- bool suppressed;
-};
-
-
-/**
- * Function to call with information about early aggregations.
- *
- * @param cls closure
- * @param ea event data
- * @return #GNUNET_OK to continue to iterate
- */
-#ifndef TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_EarlyAggregationsCallback.
- */
-#define TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_EarlyAggregationsCallback)(
- TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE *cls,
- const struct TALER_AUDITORDB_EarlyAggregation *ea);
-
-
-/**
- * Returns all aggregations that were found that were done
- * too early.
- *
- * @param pg the database context
- * @param limit number of rows to return, negative to iterate backwards
- * @param offset starting offset, exclusive
- * @param return_suppressed true to also return suppressed events
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_early_aggregations (
- struct TALER_AUDITORDB_PostgresContext *pg,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_EarlyAggregationsCallback cb,
- TALER_AUDITORDB_EARLY_AGGREGATIONS_RESULT_CLOSURE *cb_cls);
-
-
-#endif
diff --git a/src/include/auditor-database/select_historic_denom_revenue.h b/src/include/auditor-database/select_historic_denom_revenue.h
@@ -1,118 +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 select_historic_denom_revenue.h
- * @brief implementation of the select_historic_denom_revenue function
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_SELECT_HISTORIC_DENOM_REVENUE_H
-#define AUDITOR_DATABASE_SELECT_HISTORIC_DENOM_REVENUE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with the results of select_historic_denom_revenue()
- *
- * @param cls closure
- * @param serial_id row for the denomination revenue in the auditor database
- * @param denom_pub_hash hash of the denomination key
- * @param revenue_timestamp when did this profit get realized
- * @param revenue_balance what was the total profit made from
- * deposit fees, melting fees, refresh fees
- * and coins that were never returned?
- * @param loss_balance what was the total loss
- * @return sets the return value of select_denomination_info(),
- * #GNUNET_OK to continue,
- * #GNUNET_NO to stop processing further rows
- * #GNUNET_SYSERR or other values on error.
- */
-#ifndef TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_HistoricDenominationRevenueDataCallback.
- */
-#define TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_HistoricDenominationRevenueDataCallback)(
- TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_DenominationHashP *denom_pub_hash,
- struct GNUNET_TIME_Timestamp revenue_timestamp,
- const struct TALER_Amount *revenue_balance,
- const struct TALER_Amount *loss_balance);
-
-struct TALER_AUDITORDB_HistoricDenominationRevenue
-{
- uint64_t row_id;
- struct TALER_DenominationHashP denom_pub_hash;
- struct GNUNET_TIME_Absolute revenue_timestamp;
- struct TALER_Amount revenue_balance;
- struct TALER_Amount loss_balance;
- bool suppressed;
-
-};
-
-
-/**
- * Function called with the results of select_historic_denom_revenue()
- *
- * @param cls closure
- * @param serial_id row for the denomination revenue in the auditor database
- * @param denom_pub_hash hash of the denomination key
- * @param revenue_timestamp when did this profit get realized
- * @param revenue_balance what was the total profit made from
- * deposit fees, melting fees, refresh fees
- * and coins that were never returned?
- * @param loss_balance what was the total loss
- * @return sets the return value of select_denomination_info(),
- * #GNUNET_OK to continue,
- * #GNUNET_NO to stop processing further rows
- * #GNUNET_SYSERR or other values on error.
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_HistoricDenominationRevenueDataCallback)(
- TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- const struct TALER_DenominationHashP *denom_pub_hash,
- struct GNUNET_TIME_Timestamp revenue_timestamp,
- const struct TALER_Amount *revenue_balance,
- const struct TALER_Amount *loss_balance);
-
-/**
- * Obtain all of the historic denomination key revenue
- *
- * @param pg the database context
- * @param limit return at most this number of results, negative to descend from @a offset
- * @param offset row from which to return @a limit results
- * @param cb function to call with the results
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_historic_denom_revenue (struct
- TALER_AUDITORDB_PostgresContext *
- pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_HistoricDenominationRevenueDataCallback
- cb,
- TALER_AUDITORDB_HISTORIC_DENOMINATION_REVENUE_DATA_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/select_historic_reserve_revenue.h b/src/include/auditor-database/select_historic_reserve_revenue.h
@@ -1,103 +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 select_historic_reserve_revenue.h
- * @brief implementation of the select_historic_reserve_revenue function
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_SELECT_HISTORIC_RESERVE_REVENUE_H
-#define AUDITOR_DATABASE_SELECT_HISTORIC_RESERVE_REVENUE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called with the results of select_historic_reserve_revenue()
- *
- * @param cls closure
- * @param serial_id row ID in the history table
- * @param start_time beginning of aggregated time interval
- * @param end_time end of aggregated time interval
- * @param reserve_profits total profits made
- *
- * @return sets the return value of select_denomination_info(),
- * #GNUNET_OK to continue,
- * #GNUNET_NO to stop processing further rows
- * #GNUNET_SYSERR or other values on error.
- */
-#ifndef TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_HistoricReserveRevenueDataCallback.
- */
-#define TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_HistoricReserveRevenueDataCallback)(
- TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- const struct TALER_Amount *reserve_profits);
-
-
-/* Callback typedefs */
-/**
- * Function called with the results of select_historic_reserve_revenue()
- *
- * @param cls closure
- * @param serial_id row ID in the history table
- * @param start_time beginning of aggregated time interval
- * @param end_time end of aggregated time interval
- * @param reserve_profits total profits made
- *
- * @return sets the return value of select_denomination_info(),
- * #GNUNET_OK to continue,
- * #GNUNET_NO to stop processing further rows
- * #GNUNET_SYSERR or other values on error.
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_HistoricReserveRevenueDataCallback)(
- TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE *cls,
- uint64_t serial_id,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- const struct TALER_Amount *reserve_profits);
-
-/**
- * Return information about an exchange's historic revenue from reserves.
- *
- * @param pg the database context
- * @param limit return at most this number of results, negative to descend from @a offset
- * @param offset row from which to return @a limit results
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_historic_reserve_revenue (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- int64_t limit,
- uint64_t offset,
- TALER_AUDITORDB_HistoricReserveRevenueDataCallback
- cb,
- TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/auditor-database/select_pending_deposits.h b/src/include/auditor-database/select_pending_deposits.h
@@ -1,105 +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/auditor-database/select_pending_deposits.h
- * @brief implementation of the select_pending_deposits function for Postgres
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_SELECT_PENDING_DEPOSITS_H
-#define AUDITOR_DATABASE_SELECT_PENDING_DEPOSITS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called on deposits that are past their due date
- * and have not yet seen a wire transfer.
- *
- * @param cls closure
- * @param row_id row ID of the alert in the auditor database
- * @param batch_deposit_serial_id where in the exchange table are we
- * @param total_amount value of all missing deposits, including fees
- * @param wire_target_h_payto hash of the recipient account's payto URI
- * @param deadline what was the earliest requested wire transfer deadline
- * @param suppressed true if this report was suppressed
- */
-#ifndef TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_WireMissingCallback.
- */
-#define TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_AUDITORDB_WireMissingCallback) (
- TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE *cls,
- uint64_t row_id,
- uint64_t batch_deposit_serial_id,
- const struct TALER_Amount *total_amount,
- const struct TALER_FullPaytoHashP *wire_target_h_payto,
- struct GNUNET_TIME_Timestamp deadline,
- bool suppressed);
-
-
-/* Callback typedefs */
-/**
- * Function called on deposits that are past their due date
- * and have not yet seen a wire transfer.
- *
- * @param cls closure
- * @param row_id row ID of the alert in the auditor database
- * @param batch_deposit_serial_id where in the exchange table are we
- * @param total_amount value of all missing deposits, including fees
- * @param wire_target_h_payto hash of the recipient account's payto URI
- * @param deadline what was the earliest requested wire transfer deadline
- * @param suppressed true if this report was suppressed
- */
-typedef void
-(*TALER_AUDITORDB_WireMissingCallback) (
- TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE *cls,
- uint64_t row_id,
- uint64_t batch_deposit_serial_id,
- const struct TALER_Amount *total_amount,
- const struct TALER_FullPaytoHashP *wire_target_h_payto,
- struct GNUNET_TIME_Timestamp deadline,
- bool suppressed);
-
-/**
- * Return (batch) deposits for which we have not yet
- * seen the required wire transfer.
- *
- * @param pg the database context
- * @param deadline only return up to this deadline
- * @param limit number of rows to return, negative to iterate backwards
- * @param offset starting offset, exclusive
- * @param return_suppressed true to also return suppressed events
- * @param cb function to call on each entry
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_pending_deposits (struct
- TALER_AUDITORDB_PostgresContext *pg,
- struct GNUNET_TIME_Absolute deadline,
- int64_t limit,
- uint64_t offset,
- bool return_suppressed,
- TALER_AUDITORDB_WireMissingCallback cb,
- TALER_AUDITORDB_WIRE_MISSING_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/select_purse_expired.h b/src/include/auditor-database/select_purse_expired.h
@@ -1,84 +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/auditor-database/select_purse_expired.h
- * @brief implementation of the select_purse_expired function for Postgres
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_SELECT_PURSE_EXPIRED_H
-#define AUDITOR_DATABASE_SELECT_PURSE_EXPIRED_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "auditordb_lib.h"
-
-
-/**
- * Function called on expired purses.
- *
- * @param cls closure
- * @param purse_pub public key of the purse
- * @param balance amount of money in the purse
- * @param expiration_date when did the purse expire?
- * @return #GNUNET_OK to continue to iterate
- */
-#ifndef TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_AUDITORDB_ExpiredPurseCallback.
- */
-#define TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ExpiredPurseCallback)(
- TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_Amount *balance,
- struct GNUNET_TIME_Timestamp expiration_date);
-
-
-/* Callback typedefs */
-/**
- * Function called on expired purses.
- *
- * @param cls closure
- * @param purse_pub public key of the purse
- * @param balance amount of money in the purse
- * @param expiration_date when did the purse expire?
- * @return #GNUNET_OK to continue to iterate
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_AUDITORDB_ExpiredPurseCallback)(
- TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_Amount *balance,
- struct GNUNET_TIME_Timestamp expiration_date);
-
-/**
- * Get information about expired purses.
- *
- * @param pg the database context
- * @param cb function to call on expired purses
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_purse_expired (struct TALER_AUDITORDB_PostgresContext *pg
- ,
- TALER_AUDITORDB_ExpiredPurseCallback cb,
- TALER_AUDITORDB_EXPIRED_PURSE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/auditor-database/select_reserve_in_inconsistency.h b/src/include/auditor-database/select_reserve_in_inconsistency.h
@@ -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/include/auditor-database/select_reserve_in_inconsistency.h
- * @brief implementation of the select_reserve_in_inconsistency function for Postgres
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_SELECT_RESERVE_IN_INCONSISTENCY_H
-#define AUDITOR_DATABASE_SELECT_RESERVE_IN_INCONSISTENCY_H
-
-#include "auditordb_lib.h"
-
-
-/**
- * Return any reserve incoming inconsistency associated with the
- * given @a bank_row_id.
- *
- * @param pg the database context
- * @param bank_row_id row to select by
- * @param[out] dc details to return
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_select_reserve_in_inconsistency (struct
- TALER_AUDITORDB_PostgresContext
- *pg,
- uint64_t bank_row_id,
- struct
- TALER_AUDITORDB_ReserveInInconsistency
- *dc);
-
-
-#endif
diff --git a/src/include/auditor-database/update_generic_suppressed.h b/src/include/auditor-database/update_generic_suppressed.h
@@ -1,40 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file update_generic_suppressed.h
- * @brief implementation of the update_auditor_progress function
- * @author Christian Grothoff
- */
-#ifndef AUDITOR_DATABASE_UPDATE_GENERIC_SUPPRESSED_H
-#define AUDITOR_DATABASE_UPDATE_GENERIC_SUPPRESSED_H
-
-#include "auditordb_lib.h"
-
-
-/**
- // FIXME: add comments
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_AUDITORDB_update_generic_suppressed (struct
- TALER_AUDITORDB_PostgresContext *pg,
- enum
- TALER_AUDITORDB_DeletableSuppressableTables
- table,
- uint64_t row_id,
- bool suppressed);
-
-#endif
diff --git a/src/include/auditor-database/update_to_suppressed.h b/src/include/auditor-database/update_to_suppressed.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file update_to_suppressed.h
+ * @brief implementation of the update_auditor_progress function
+ * @author Christian Grothoff
+ */
+#ifndef AUDITOR_DATABASE_UPDATE_TO_SUPPRESSED_H
+#define AUDITOR_DATABASE_UPDATE_TO_SUPPRESSED_H
+
+#include "auditordb_lib.h"
+
+
+/**
+ // FIXME: add comments
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_AUDITORDB_update_to_suppressed (struct
+ TALER_AUDITORDB_PostgresContext *pg,
+ enum
+ TALER_AUDITORDB_DeletableSuppressableTables
+ table,
+ uint64_t row_id,
+ bool suppressed);
+
+#endif
diff --git a/src/include/exchange-database/activate_signing_key.h b/src/include/exchange-database/activate_signing_key.h
@@ -1,48 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/activate_signing_key.h
- * @brief implementation of the activate_signing_key function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_ACTIVATE_SIGNING_KEY_H
-#define EXCHANGE_DATABASE_ACTIVATE_SIGNING_KEY_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Add signing key.
- *
- * @param pg the database context
- * @param exchange_pub the exchange online signing public key
- * @param meta meta data about @a exchange_pub
- * @param master_sig master signature to add
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_activate_signing_key (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct TALER_ExchangePublicKeyP *
- exchange_pub,
- const struct
- TALER_EXCHANGEDB_SignkeyMetaData *
- meta,
- const struct TALER_MasterSignatureP *
- master_sig
- );
-
-#endif
diff --git a/src/include/exchange-database/add_denomination_key.h b/src/include/exchange-database/add_denomination_key.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/exchange-database/add_denomination_key.h
- * @brief implementation of the add_denomination_key function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_ADD_DENOMINATION_KEY_H
-#define EXCHANGE_DATABASE_ADD_DENOMINATION_KEY_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Activate denomination key, turning it into a "current" or "valid"
- * denomination key by adding the master signature.
- *
- * @param pg the database context
- * @param h_denom_pub hash of the denomination public key
- * @param denom_pub the actual denomination key
- * @param meta meta data about the denomination
- * @param master_sig master signature to add
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_add_denomination_key (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct TALER_DenominationHashP *
- h_denom_pub,
- const struct
- TALER_DenominationPublicKey *
- denom_pub,
- const struct
- TALER_EXCHANGEDB_DenominationKeyMetaData
- *meta,
- const struct TALER_MasterSignatureP *
- master_sig
- );
-
-#endif
diff --git a/src/include/exchange-database/aggregate.h b/src/include/exchange-database/aggregate.h
@@ -1,46 +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/exchange-database/aggregate.h
- * @brief implementation of the aggregate function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_AGGREGATE_H
-#define EXCHANGE_DATABASE_AGGREGATE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Aggregate all matching deposits for @a h_payto and
- * @a merchant_pub, returning the total amounts.
- *
- * @param pg the database context
- * @param h_payto destination of the wire transfer
- * @param merchant_pub public key of the merchant
- * @param wtid wire transfer ID to set for the aggregate
- * @param[out] total set to the sum of the total deposits minus applicable deposit fees and refunds
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_aggregate (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPaytoHashP *h_payto,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- struct TALER_Amount *total);
-
-#endif
diff --git a/src/include/exchange-database/batch_ensure_coin_known.h b/src/include/exchange-database/batch_ensure_coin_known.h
@@ -1,115 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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/exchange-database/batch_ensure_coin_known.h
- * @brief implementation of the batch_ensure_coin_known function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_BATCH_ENSURE_COIN_KNOWN_H
-#define EXCHANGE_DATABASE_BATCH_ENSURE_COIN_KNOWN_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * The conflict that can occur for the age restriction
- */
-enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict
-{
- /**
- * Value OK, no conflict
- */
- TALER_AgeCommitmentHashP_NoConflict = 0,
-
- /**
- * Given hash had a value, but NULL (or zero) was expected
- */
- TALER_AgeCommitmentHashP_NullExpected = 1,
-
- /**
- * Given hash was NULL, but value was expected
- */
- TALER_AgeCommitmentHashP_ValueExpected = 2,
-
- /**
- * Given hash differs from value in the known coin
- */
- TALER_AgeCommitmentHashP_ValueDiffers = 3,
-};
-
-/**
- * Per-coin information returned when doing a batch insert.
- */
-struct TALER_EXCHANGEDB_CoinInfo
-{
- /**
- * Row of the coin in the known_coins table.
- */
- uint64_t known_coin_id;
-
- /**
- * Hash of the denomination, relevant on @e denom_conflict.
- */
- struct TALER_DenominationHashP denom_hash;
-
- /**
- * Hash of the age commitment, relevant on @e age_conflict.
- */
- struct TALER_AgeCommitmentHashP h_age_commitment;
-
- /**
- * True if the coin was known previously.
- */
- bool existed;
-
- /**
- * True if the known coin has a different denomination;
- * application will find denomination of the already
- * known coin in @e denom_hash.
- */
- bool denom_conflict;
-
- /**
- * Indicates if and what kind of conflict with the age
- * restriction of the known coin was present;
- * application will find age commitment of the already
- * known coin in @e h_age_commitment.
- */
- enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict age_conflict;
-};
-
-
-/**
- * Make sure the array of given @a coin is known to the database.
- *
- * @param pg the database context
- * @param coin array of coins that must be made known
- * @param[out] result array where to store information about each coin
- * @param coin_length length of the @a coin and @a result arraysf
- * @param batch_size desired (maximum) batch size
- * @return database transaction status, non-negative on success
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_batch_ensure_coin_known (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_CoinPublicInfo *
- coin,
- struct TALER_EXCHANGEDB_CoinInfo *
- result,
- unsigned int coin_length,
- unsigned int batch_size);
-
-#endif
diff --git a/src/include/exchange-database/begin_rule_update.h b/src/include/exchange-database/begin_rule_update.h
@@ -0,0 +1,127 @@
+/*
+ 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 begin_rule_update.h
+ * @brief implementation to update rules for an account
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_BEGIN_RULE_UPDATE_H
+#define EXCHANGE_DATABASE_BEGIN_RULE_UPDATE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Handle for helper logic that advances rules to the currently
+ * valid rule set.
+ */
+struct TALER_EXCHANGEDB_RuleUpdater;
+
+/**
+ * Main result returned in the
+ * #TALER_EXCHANGEDB_CurrentRulesCallback
+ */
+struct TALER_EXCHANGEDB_RuleUpdaterResult
+{
+ /**
+ * Row the rule set is based on.
+ */
+ uint64_t legitimization_outcome_last_row;
+
+ /**
+ * Current legitimization rule set, owned by callee. Will be NULL on error
+ * or for default rules. Will not contain skip rules and not be expired.
+ */
+ struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs;
+
+ /**
+ * Hint to return, if @e ec is not #TALER_EC_NONE. Can be NULL.
+ */
+ const char *hint;
+
+ /**
+ * Error code in case a problem was encountered
+ * when fetching or updating the legitimization rules.
+ */
+ enum TALER_ErrorCode ec;
+};
+
+
+/**
+ * Function called with the current rule set.
+ *
+ * @param cls closure
+ * @param rur includes legitimziation rule set that applies to the account
+ * (owned by callee, callee must free the lrs!)
+ */
+#ifndef TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_CurrentRulesCallback.
+ */
+#define TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_CurrentRulesCallback)(
+ TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE *cls,
+ struct TALER_EXCHANGEDB_RuleUpdaterResult *rur);
+
+
+/**
+ * Obtains the current rule set for an account and advances it
+ * to the rule set that should apply right now. Considers
+ * expiration of rules as well as "skip" measures. Runs
+ * AML programs as needed to advance the rule book to the currently
+ * valid state.
+ *
+ * On success, the result is returned in a (fresh) transaction
+ * that must be committed for the result to be valid. This should
+ * be used to ensure transactionality of the AML program result.
+ *
+ * This function should be called *outside* of any other transaction.
+ * Calling it while a transaction is already running risks aborting
+ * that transaction.
+ *
+ * @param pg database plugin to use
+ * @param attribute_key key to use to decrypt attributes
+ * @param account account to get the rule set for
+ * @param is_wallet true if @a account is a wallet
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel the operation
+ */
+struct TALER_EXCHANGEDB_RuleUpdater *
+TALER_EXCHANGEDB_begin_rule_update (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AttributeEncryptionKeyP *attribute_key,
+ const struct TALER_NormalizedPaytoHashP *account,
+ bool is_wallet,
+ TALER_EXCHANGEDB_CurrentRulesCallback cb,
+ TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE *cb_cls);
+
+
+/**
+ * Cancel operation to get the current legitimization rule set.
+ *
+ * @param[in] ru operation to cancel
+ */
+void
+TALER_EXCHANGEDB_begin_rule_update_cancel (
+ struct TALER_EXCHANGEDB_RuleUpdater *ru);
+
+
+#endif
diff --git a/src/include/exchange-database/clear_aml_lock.h b/src/include/exchange-database/clear_aml_lock.h
@@ -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/include/exchange-database/clear_aml_lock.h
- * @brief implementation of the clear_aml_lock function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_CLEAR_AML_LOCK_H
-#define EXCHANGE_DATABASE_CLEAR_AML_LOCK_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Clear a lock on running AML programs for the @a h_payto
- * account. Returns 0 if @a h_payto is not known; does not
- * actually care if there was a lock. Also does not by
- * itself notify clients waiting for the lock, that
- * notification the caller must do separately after finishing
- * the database update.
- *
- * @param pg the database context
- * @param h_payto account to clear the lock for
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_clear_aml_lock (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *
- h_payto);
-
-#endif
diff --git a/src/include/exchange-database/count_known_coins.h b/src/include/exchange-database/count_known_coins.h
@@ -1,39 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/count_known_coins.h
- * @brief implementation of the count_known_coins function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_COUNT_KNOWN_COINS_H
-#define EXCHANGE_DATABASE_COUNT_KNOWN_COINS_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Count the number of known coins by denomination.
- *
- * @param pg the database context
- * @param denom_pub_hash denomination to count by
- * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus`
- */
-long long
-TALER_EXCHANGEDB_count_known_coins (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_DenominationHashP *denom_pub_hash);
-
-#endif
diff --git a/src/include/exchange-database/create_aggregation_transient.h b/src/include/exchange-database/create_aggregation_transient.h
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/create_aggregation_transient.h
- * @brief implementation of the create_aggregation_transient function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_CREATE_AGGREGATION_TRANSIENT_H
-#define EXCHANGE_DATABASE_CREATE_AGGREGATION_TRANSIENT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Create a new entry in the transient aggregation table.
- *
- * @param pg the database context
- * @param h_payto destination of the wire transfer
- * @param exchange_account_section exchange account to use
- * @param merchant_pub public key of the merchant receiving the transfer
- * @param wtid the raw wire transfer identifier to be used
- * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none
- * @param total amount to be wired in the future
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_create_aggregation_transient (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_FullPaytoHashP *
- h_payto,
- const char *
- exchange_account_section,
- const struct
- TALER_MerchantPublicKeyP *
- merchant_pub,
- const struct
- TALER_WireTransferIdentifierRawP
- *wtid,
- uint64_t kyc_requirement_row,
- const struct TALER_Amount *total)
-;
-
-#endif
diff --git a/src/include/exchange-database/do_aggregate.h b/src/include/exchange-database/do_aggregate.h
@@ -0,0 +1,48 @@
+/*
+ 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/exchange-database/do_do_aggregate.h
+ * @brief implementation of the do_aggregate function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_AGGREGATE_H
+#define EXCHANGE_DATABASE_DO_AGGREGATE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Aggregate all matching deposits for @a h_payto and
+ * @a merchant_pub, returning the total amounts.
+ *
+ * @param pg the database context
+ * @param h_payto destination of the wire transfer
+ * @param merchant_pub public key of the merchant
+ * @param wtid wire transfer ID to set for the aggregate
+ * @param[out] total set to the sum of the total deposits minus applicable deposit fees and refunds
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_aggregate (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *
+ merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *
+ wtid,
+ struct TALER_Amount *total);
+
+#endif
diff --git a/src/include/exchange-database/do_drain_kyc_alert.h b/src/include/exchange-database/do_drain_kyc_alert.h
@@ -0,0 +1,42 @@
+/*
+ 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/exchange-database/do_do_drain_kyc_alert.h
+ * @brief implementation of the do_drain_kyc_alert function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_DRAIN_KYC_ALERT_H
+#define EXCHANGE_DATABASE_DO_DRAIN_KYC_ALERT_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Extract next KYC alert. Deletes the alert.
+ *
+ * @param pg the database context
+ * @param trigger_type which type of alert to drain
+ * @param[out] h_payto set to hash of payto-URI where KYC status changed
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_drain_kyc_alert (struct TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ uint32_t trigger_type,
+ struct TALER_NormalizedPaytoHashP *h_payto)
+;
+
+#endif
diff --git a/src/include/exchange-database/do_expire_purse.h b/src/include/exchange-database/do_expire_purse.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/do_do_expire_purse.h
+ * @brief implementation of the do_expire_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_EXPIRE_PURSE_H
+#define EXCHANGE_DATABASE_DO_EXPIRE_PURSE_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Function called to clean up one expired purse.
+ *
+ * @param pg the database context
+ * @param start_time select purse expired after this time
+ * @param end_time select purse expired before this time
+ * @return transaction status code (#GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no purse expired in the given time interval).
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_expire_purse (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct GNUNET_TIME_Absolute start_time,
+ struct GNUNET_TIME_Absolute end_time);
+
+#endif
diff --git a/src/include/exchange-database/do_insert_known_coin.h b/src/include/exchange-database/do_insert_known_coin.h
@@ -0,0 +1,96 @@
+/*
+ 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/exchange-database/do_insert_known_coin.h
+ * @brief implementation of the do_insert_known_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_INSERT_KNOWN_COIN_H
+#define EXCHANGE_DATABASE_DO_INSERT_KNOWN_COIN_H
+
+#include "exchangedb_lib.h"
+
+/**
+ * Possible status codes from making sure a coin is known.
+ */
+enum TALER_EXCHANGEDB_CoinKnownStatus
+{
+ /**
+ * The coin was successfully added.
+ */
+ TALER_EXCHANGEDB_CKS_ADDED = 1,
+
+ /**
+ * The coin was already present.
+ */
+ TALER_EXCHANGEDB_CKS_PRESENT = 0,
+
+ /**
+ * Serialization failure.
+ */
+ TALER_EXCHANGEDB_CKS_SOFT_FAIL = -1,
+
+ /**
+ * Hard database failure.
+ */
+ TALER_EXCHANGEDB_CKS_HARD_FAIL = -2,
+
+ /**
+ * Conflicting coin (different denomination key) already in database.
+ */
+ TALER_EXCHANGEDB_CKS_DENOM_CONFLICT = -3,
+
+ /**
+ * Conflicting coin (expected NULL age hash) already in database.
+ */
+ TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL = -4,
+
+ /**
+ * Conflicting coin (unexpected NULL age hash) already in database.
+ */
+ TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL = -5,
+
+ /**
+ * Conflicting coin (different age hash) already in database.
+ */
+ TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS = -6,
+
+};
+
+
+/**
+ * Make sure the given @a coin is known to the database.
+ *
+ * @param pg the database context
+ * @param coin the coin that must be made known
+ * @param[out] known_coin_id set to the unique row of the coin
+ * @param[out] denom_hash set to the denomination hash of the existing
+ * coin (for conflict error reporting)
+ * @param[out] h_age_commitment set to the conflicting age commitment hash on conflict
+ * @return database transaction status, non-negative on success
+ */
+enum TALER_EXCHANGEDB_CoinKnownStatus
+TALER_EXCHANGEDB_do_insert_known_coin (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct TALER_CoinPublicInfo *coin,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *
+ denom_hash,
+ struct TALER_AgeCommitmentHashP *
+ h_age_commitment)
+;
+
+#endif
diff --git a/src/include/exchange-database/do_insert_kyc_attributes.h b/src/include/exchange-database/do_insert_kyc_attributes.h
@@ -0,0 +1,64 @@
+/*
+ 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/exchange-database/do_insert_kyc_attributes.h
+ * @brief implementation of the do_insert_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_INSERT_KYC_ATTRIBUTES_H
+#define EXCHANGE_DATABASE_DO_INSERT_KYC_ATTRIBUTES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Store KYC attribute data.
+ *
+ * @param pg the database context
+ * @param process_row KYC process row to update
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_name name of the provider that provided the attributes
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param birthday birthdate of user, in days after 1990, or 0 if unknown or definitively adult
+ * @param expiration_time when does the data expire
+ * @param form_name name of the form from which the @a enc_attributes originate, can be NULL
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_insert_kyc_attributes (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t process_row,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ const char *provider_name,
+ const char *provider_account_id,
+ const char *
+ provider_legitimization_id,
+ uint32_t birthday,
+ struct GNUNET_TIME_Absolute
+ expiration_time,
+ const char *form_name,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+
+#endif
diff --git a/src/include/exchange-database/do_insert_reserve_in.h b/src/include/exchange-database/do_insert_reserve_in.h
@@ -0,0 +1,59 @@
+/*
+ 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/exchange-database/do_insert_reserve_in.h
+ * @brief implementation of the do_insert_reserve_in function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_INSERT_RESERVE_IN_H
+#define EXCHANGE_DATABASE_DO_INSERT_RESERVE_IN_H
+
+#include "exchangedb_lib.h"
+
+
+struct TALER_EXCHANGEDB_ReserveInInfo
+{
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+ const struct TALER_Amount *balance;
+ struct GNUNET_TIME_Timestamp execution_time;
+ struct TALER_FullPayto sender_account_details;
+ const char *exchange_account_name;
+ uint64_t wire_reference;
+};
+
+
+/**
+ * Insert an incoming transaction into reserves. New reserves are also
+ * created through this function. Runs its own transaction(s).
+ *
+ * @param pg the database context
+ * @param reserves array of reserves to insert
+ * @param reserves_length length of the @a reserves array
+ * @param[out] results set to query status per reserve, must be of length @a reserves_length
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_insert_reserve_in (struct TALER_EXCHANGEDB_PostgresContext *
+ pg
+ ,
+ const struct
+ TALER_EXCHANGEDB_ReserveInInfo *
+ reserves,
+ unsigned int reserves_length,
+ enum GNUNET_DB_QueryStatus *results);
+
+
+#endif
diff --git a/src/include/exchange-database/do_persist_aml_program_result.h b/src/include/exchange-database/do_persist_aml_program_result.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file do_persist_aml_program_result.h
+ * @brief implementation of the do_persist_aml_program_result function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_PERSIST_AML_PROGRAM_RESULT_H
+#define EXCHANGE_DATABASE_DO_PERSIST_AML_PROGRAM_RESULT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+#include "exchange-database/update_to_aml_locked.h"
+#include "exchange-database/update_to_aml_unlocked.h"
+
+
+/**
+ * Persist the given @a apr for the given process and account
+ * into the database via @a pg. Called within an open
+ * database transaction.
+ *
+ * @param pg database API handle
+ * @param process_row row identifying the legitimization process that was run,
+ * 0 if there was no legi process (for example, due to rule
+ * expiration triggering something) and we should simply
+ * create a new row
+ * @param account_id hash of account the result is about
+ * @param ret_pprs
+ * @param apr AML program result to persist
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_persist_aml_program_result (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t process_row,
+ const struct TALER_NormalizedPaytoHashP *account_id,
+ const struct TALER_KYCLOGIC_AmlProgramResult *apr,
+ enum TALER_EXCHANGEDB_PersistProgramResultStatus *ret_pprs);
+
+#endif
diff --git a/src/include/exchange-database/do_recoup_refresh.h b/src/include/exchange-database/do_recoup_refresh.h
@@ -42,23 +42,23 @@
* @return query execution status
*/
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_do_recoup_refresh (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_CoinSpendPublicKeyP *
- old_coin_pub,
- uint64_t rrc_serial,
- const union
- GNUNET_CRYPTO_BlindingSecretP *
- coin_bks,
- const struct
- TALER_CoinSpendPublicKeyP *coin_pub,
- uint64_t known_coin_id,
- const struct
- TALER_CoinSpendSignatureP *coin_sig,
- struct GNUNET_TIME_Timestamp *
- recoup_timestamp,
- bool *recoup_ok,
- bool *internal_failure);
+TALER_EXCHANGEDB_do_recoup_refresh (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_CoinSpendPublicKeyP *
+ old_coin_pub,
+ uint64_t rrc_serial,
+ const union
+ GNUNET_CRYPTO_BlindingSecretP *
+ coin_bks,
+ const struct
+ TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t known_coin_id,
+ const struct
+ TALER_CoinSpendSignatureP *coin_sig,
+ struct GNUNET_TIME_Timestamp *
+ recoup_timestamp,
+ bool *recoup_ok,
+ bool *internal_failure);
#endif
diff --git a/src/include/exchange-database/do_trigger_kyc_rule_for_account.h b/src/include/exchange-database/do_trigger_kyc_rule_for_account.h
@@ -0,0 +1,69 @@
+/*
+ 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/exchange-database/do_do_trigger_kyc_rule_for_account.h
+ * @brief implementation of the do_trigger_kyc_rule_for_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_DO_TRIGGER_KYC_RULE_FOR_ACCOUNT_H
+#define EXCHANGE_DATABASE_DO_TRIGGER_KYC_RULE_FOR_ACCOUNT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Insert KYC requirement for @a h_payto account into table.
+ *
+ * @param pg the database context
+ * @param payto_uri account that must be KYC'ed,
+ * can be NULL if @a h_payto is already
+ * guaranteed to be in wire_targets
+ * @param h_payto hash of @a payto_uri
+ * @param set_account_pub public key to enable for the
+ * KYC authorization, NULL if not known
+ * @param check_merchant_pub public key that must already
+ * be enabled for a KYC authorzation for it to be
+ * valid, NULL if not known
+ * @param jmeasures serialized MeasureSet to put in place
+ * @param display_priority priority of the rule
+ * @param[out] requirement_row set to legitimization requirement row for this check
+ * @param[out] bad_kyc_auth set if @a check_account_pub
+ * did not match the existing KYC auth
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_do_trigger_kyc_rule_for_account (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct TALER_FullPayto
+ payto_uri,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ const union
+ TALER_AccountPublicKeyP *
+ set_account_pub,
+ const struct
+ TALER_MerchantPublicKeyP *
+ check_merchant_pub,
+ const json_t *jmeasures,
+ uint32_t display_priority,
+ uint64_t *requirement_row,
+ bool *bad_kyc_auth);
+
+#endif
diff --git a/src/include/exchange-database/drain_kyc_alert.h b/src/include/exchange-database/drain_kyc_alert.h
@@ -1,40 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/drain_kyc_alert.h
- * @brief implementation of the drain_kyc_alert function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_DRAIN_KYC_ALERT_H
-#define EXCHANGE_DATABASE_DRAIN_KYC_ALERT_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-/**
- * Extract next KYC alert. Deletes the alert.
- *
- * @param pg the database context
- * @param trigger_type which type of alert to drain
- * @param[out] h_payto set to hash of payto-URI where KYC status changed
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_drain_kyc_alert (struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint32_t trigger_type,
- struct TALER_NormalizedPaytoHashP *h_payto);
-
-#endif
diff --git a/src/include/exchange-database/ensure_coin_known.h b/src/include/exchange-database/ensure_coin_known.h
@@ -1,94 +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/exchange-database/ensure_coin_known.h
- * @brief implementation of the ensure_coin_known function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_ENSURE_COIN_KNOWN_H
-#define EXCHANGE_DATABASE_ENSURE_COIN_KNOWN_H
-
-#include "exchangedb_lib.h"
-
-/**
- * Possible status codes from making sure a coin is known.
- */
-enum TALER_EXCHANGEDB_CoinKnownStatus
-{
- /**
- * The coin was successfully added.
- */
- TALER_EXCHANGEDB_CKS_ADDED = 1,
-
- /**
- * The coin was already present.
- */
- TALER_EXCHANGEDB_CKS_PRESENT = 0,
-
- /**
- * Serialization failure.
- */
- TALER_EXCHANGEDB_CKS_SOFT_FAIL = -1,
-
- /**
- * Hard database failure.
- */
- TALER_EXCHANGEDB_CKS_HARD_FAIL = -2,
-
- /**
- * Conflicting coin (different denomination key) already in database.
- */
- TALER_EXCHANGEDB_CKS_DENOM_CONFLICT = -3,
-
- /**
- * Conflicting coin (expected NULL age hash) already in database.
- */
- TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL = -4,
-
- /**
- * Conflicting coin (unexpected NULL age hash) already in database.
- */
- TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL = -5,
-
- /**
- * Conflicting coin (different age hash) already in database.
- */
- TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS = -6,
-
-};
-
-
-/**
- * Make sure the given @a coin is known to the database.
- *
- * @param pg the database context
- * @param coin the coin that must be made known
- * @param[out] known_coin_id set to the unique row of the coin
- * @param[out] denom_hash set to the denomination hash of the existing
- * coin (for conflict error reporting)
- * @param[out] h_age_commitment set to the conflicting age commitment hash on conflict
- * @return database transaction status, non-negative on success
- */
-enum TALER_EXCHANGEDB_CoinKnownStatus
-TALER_EXCHANGEDB_ensure_coin_known (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_CoinPublicInfo *coin,
- uint64_t *known_coin_id,
- struct TALER_DenominationHashP *denom_hash,
- struct TALER_AgeCommitmentHashP *
- h_age_commitment)
-;
-
-#endif
diff --git a/src/include/exchange-database/event_listen_cancel.h b/src/include/exchange-database/event_listen_cancel.h
@@ -32,9 +32,9 @@
* @param eh handle to unregister.
*/
void
-TALER_TALER_EXCHANGEDB_event_listen_cancel (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- struct GNUNET_DB_EventHandler *eh);
+TALER_EXCHANGEDB_event_listen_cancel (struct
+ TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ struct GNUNET_DB_EventHandler *eh);
#endif
diff --git a/src/include/exchange-database/expire_purse.h b/src/include/exchange-database/expire_purse.h
@@ -1,40 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/expire_purse.h
- * @brief implementation of the expire_purse function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_EXPIRE_PURSE_H
-#define EXCHANGE_DATABASE_EXPIRE_PURSE_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Function called to clean up one expired purse.
- *
- * @param pg the database context
- * @param start_time select purse expired after this time
- * @param end_time select purse expired before this time
- * @return transaction status code (#GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no purse expired in the given time interval).
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_expire_purse (struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct GNUNET_TIME_Absolute start_time,
- struct GNUNET_TIME_Absolute end_time);
-
-#endif
diff --git a/src/include/exchange-database/find_aggregation_transient.h b/src/include/exchange-database/find_aggregation_transient.h
@@ -1,54 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 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/exchange-database/find_aggregation_transient.h
- * @brief implementation of the find_aggregation_transient function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_FIND_AGGREGATION_TRANSIENT_H
-#define EXCHANGE_DATABASE_FIND_AGGREGATION_TRANSIENT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Find existing entry in the transient aggregation table.
- *
- * @param pg the database context
- * @param h_payto destination of the wire transfer
- * @param[out] payto_uri corresponding payto URI, to be freed by caller
- * @param[out] wtid wire transfer identifier of transient aggregation
- * @param[out] merchant_pub public key of the merchant
- * @param[out] total amount aggregated so far
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_find_aggregation_transient (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- struct TALER_FullPayto *payto_uri,
- struct
- TALER_WireTransferIdentifierRawP *
- wtid,
- struct TALER_MerchantPublicKeyP *
- merchant_pub,
- struct TALER_Amount *total);
-
-#endif
diff --git a/src/include/exchange-database/get_active_legitimization.h b/src/include/exchange-database/get_active_legitimization.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_active_legitimization.h
+ * @brief implementation of the get_active_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_ACTIVE_LEGITIMIZATION_H
+#define EXCHANGE_DATABASE_GET_ACTIVE_LEGITIMIZATION_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup measure data for an active legitimization process.
+ *
+ * @param pg the database context
+ * @param legitimization_process_serial_id
+ * row in legitimization_processes table to access
+ * @param[out] measure_index set to the measure the
+ * process is trying to satisfy
+ * @param[out] jmeasures set to the legitimization
+ * measures that were put on the account
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_active_legitimization (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t
+ legitimization_process_serial_id,
+ uint32_t *measure_index,
+ json_t **jmeasures);
+
+
+#endif
diff --git a/src/include/exchange-database/get_aggregation_transient.h b/src/include/exchange-database/get_aggregation_transient.h
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_aggregation_transient.h
+ * @brief implementation of the get_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AGGREGATION_TRANSIENT_H
+#define EXCHANGE_DATABASE_GET_AGGREGATION_TRANSIENT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Find existing entry in the transient aggregation table.
+ *
+ * @param pg the database context
+ * @param h_payto destination of the wire transfer
+ * @param merchant_pub public key of the merchant receiving the transfer
+ * @param exchange_account_section exchange account to use
+ * @param[out] wtid set to the raw wire transfer identifier to be used
+ * @param[out] total existing amount to be wired in the future
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aggregation_transient (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_FullPaytoHashP *
+ h_payto,
+ const struct
+ TALER_MerchantPublicKeyP *
+ merchant_pub,
+ const char *
+ exchange_account_section,
+ struct
+ TALER_WireTransferIdentifierRawP
+ *wtid,
+ struct TALER_Amount *total);
+
+
+#endif
diff --git a/src/include/exchange-database/get_aggregation_transient_by_normalized_payto.h b/src/include/exchange-database/get_aggregation_transient_by_normalized_payto.h
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 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/exchange-database/get_aggregation_transient_by_normalized_payto.h
+ * @brief implementation of the get_aggregation_transient_by_normalized_payto function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AGGREGATION_TRANSIENT_BY_NORMALIZED_PAYTO_H
+#define EXCHANGE_DATABASE_GET_AGGREGATION_TRANSIENT_BY_NORMALIZED_PAYTO_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Find existing entry in the transient aggregation table.
+ *
+ * @param pg the database context
+ * @param h_payto destination of the wire transfer
+ * @param[out] payto_uri corresponding payto URI, to be freed by caller
+ * @param[out] wtid wire transfer identifier of transient aggregation
+ * @param[out] merchant_pub public key of the merchant
+ * @param[out] total amount aggregated so far
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aggregation_transient_by_normalized_payto (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ struct
+ TALER_FullPayto
+ *payto_uri,
+ struct
+ TALER_WireTransferIdentifierRawP
+ *
+ wtid,
+ struct
+ TALER_MerchantPublicKeyP
+ *
+ merchant_pub,
+ struct
+ TALER_Amount *
+ total);
+
+#endif
diff --git a/src/include/exchange-database/get_aml_file_number.h b/src/include/exchange-database/get_aml_file_number.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2025 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_aml_file_number.h
+ * @brief implementation of the get_aml_file_number function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AML_FILE_NUMBER_H
+#define EXCHANGE_DATABASE_GET_AML_FILE_NUMBER_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup AML file number by the payto address.
+ *
+ * @param pg the database context
+ * @param h_payto account for which to find the row ID
+ * @param[out] kyc_target_row set to row in the kyc_targets table for @a h_payto
+ * @param[out] is_wallet set to true if this account is for a wallet
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aml_file_number (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ uint64_t *kyc_target_row,
+ bool *is_wallet);
+
+
+#endif
diff --git a/src/include/exchange-database/get_aml_officer.h b/src/include/exchange-database/get_aml_officer.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_aml_officer.h
+ * @brief implementation of the get_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AML_OFFICER_H
+#define EXCHANGE_DATABASE_GET_AML_OFFICER_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Fetch AML staff record.
+ *
+ * @param pg the database context
+ * @param decider_pub public key of the staff member
+ * @param[out] master_sig offline signature affirming the AML officer
+ * @param[out] decider_name full name of the staff member
+ * @param[out] is_active true to enable, false to set as inactive
+ * @param[out] read_only true to set read-only access
+ * @param[out] last_change when was the change made effective
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_aml_officer (struct TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ const struct TALER_AmlOfficerPublicKeyP *
+ decider_pub,
+ struct TALER_MasterSignatureP *master_sig,
+ char **decider_name,
+ bool *is_active,
+ bool *read_only,
+ struct GNUNET_TIME_Absolute *last_change);
+
+#endif
diff --git a/src/include/exchange-database/get_auditor_denom_sig.h b/src/include/exchange-database/get_auditor_denom_sig.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_auditor_denom_sig.h
+ * @brief implementation of the get_auditor_denom_sig function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AUDITOR_DENOM_SIG_H
+#define EXCHANGE_DATABASE_GET_AUDITOR_DENOM_SIG_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Select information about an auditor auditing a denomination key.
+ *
+ * @param pg the database context
+ * @param h_denom_pub the audited denomination
+ * @param auditor_pub the auditor's key
+ * @param[out] auditor_sig set to signature affirming the auditor's audit activity
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_auditor_denom_sig (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_DenominationHashP *
+ h_denom_pub,
+ const struct
+ TALER_AuditorPublicKeyP *
+ auditor_pub,
+ struct TALER_AuditorSignatureP *
+ auditor_sig
+ );
+
+#endif
diff --git a/src/include/exchange-database/get_auditor_status.h b/src/include/exchange-database/get_auditor_status.h
@@ -0,0 +1,44 @@
+/*
+ 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/exchange-database/get_auditor_status.h
+ * @brief implementation of the get_auditor_status function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AUDITOR_STATUS_H
+#define EXCHANGE_DATABASE_GET_AUDITOR_STATUS_H
+
+#include "exchangedb_lib.h"
+
+/**
+ * Lookup current state of an auditor.
+ *
+ * @param pg the database context
+ * @param auditor_pub key to look up information for
+ * @param[out] auditor_url set to the base URL of the auditor's REST API; memory to be
+ * released by the caller!
+ * @param[out] enabled set if the auditor is currently in use
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_auditor_status (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_AuditorPublicKeyP *
+ auditor_pub,
+ char **auditor_url,
+ bool *enabled);
+
+#endif
diff --git a/src/include/exchange-database/get_auditor_timestamp.h b/src/include/exchange-database/get_auditor_timestamp.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_auditor_timestamp.h
+ * @brief implementation of the get_auditor_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_AUDITOR_TIMESTAMP_H
+#define EXCHANGE_DATABASE_GET_AUDITOR_TIMESTAMP_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Check the last date an auditor was modified.
+ *
+ * @param pg the database context
+ * @param auditor_pub key to look up information for
+ * @param[out] last_date last modification date to auditor status
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_auditor_timestamp (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_AuditorPublicKeyP *
+ auditor_pub,
+ struct GNUNET_TIME_Timestamp *
+ last_date);
+
+#endif
diff --git a/src/include/exchange-database/get_completed_legitimization.h b/src/include/exchange-database/get_completed_legitimization.h
@@ -0,0 +1,74 @@
+/*
+ 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 get_completed_legitimization.h
+ * @brief implementation of the lookup_pending_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_COMPLETED_LEGITIMIZATION_H
+#define EXCHANGE_DATABASE_GET_COMPLETED_LEGITIMIZATION_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup measure data for a legitimization process.
+ *
+ * @param pg the database context
+ * @param legitimization_measure_serial_id
+ * row in legitimization_measures table to access
+ * @param measure_index index of the measure to return
+ * attribute data for
+ * @param[out] access_token
+ * set to token for access control that must match
+ * @param[out] h_payto set to the the hash of the
+ * payto URI of the account undergoing legitimization
+ * @param[out] is_wallet set to true if @a h_payto is for a wallet
+ * @param[out] jmeasures set to the legitimization
+ * measures that were put on the account
+ * @param[out] is_finished set to true if the legitimization was
+ * already finished
+ * @param[out] encrypted_attributes_len set to length of
+ * @a encrypted_attributes
+ * @param[out] encrypted_attributes set to the attributes
+ * obtained for the legitimization process, if it
+ * succeeded, otherwise set to NULL
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_completed_legitimization (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t
+ legitimization_measure_serial_id,
+ uint32_t measure_index,
+ struct
+ TALER_AccountAccessTokenP *
+ access_token,
+ struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ bool *is_wallet,
+ json_t **jmeasures,
+ bool *is_finished,
+ size_t *
+ encrypted_attributes_len,
+ void **encrypted_attributes);
+
+#endif
diff --git a/src/include/exchange-database/get_contract.h b/src/include/exchange-database/get_contract.h
@@ -0,0 +1,50 @@
+/*
+ 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/exchange-database/get_contract.h
+ * @brief implementation of the get_contract function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_CONTRACT_H
+#define EXCHANGE_DATABASE_GET_CONTRACT_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to retrieve an encrypted contract.
+ *
+ * @param pg the database context
+ * @param purse_pub key to lookup the contract by
+ * @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract
+ * @param[out] econtract_sig set to the signature over the encrypted contract
+ * @param[out] econtract_size set to the number of bytes in @a econtract
+ * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_contract (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ContractDiffiePublicP *
+ pub_ckey,
+ struct TALER_PurseContractPublicKeyP *
+ purse_pub,
+ struct TALER_PurseContractSignatureP *
+ econtract_sig,
+ size_t *econtract_size,
+ void **econtract);
+
+#endif
diff --git a/src/include/exchange-database/get_contract_by_purse.h b/src/include/exchange-database/get_contract_by_purse.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_contract_by_purse.h
+ * @brief implementation of the get_contract_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_CONTRACT_BY_PURSE_H
+#define EXCHANGE_DATABASE_GET_CONTRACT_BY_PURSE_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to retrieve an encrypted contract.
+ *
+ * @param pg the database context
+ * @param purse_pub key to lookup the contract by
+ * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_contract_by_purse (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_PurseContractPublicKeyP *
+ purse_pub,
+ struct TALER_EncryptedContract
+ *econtract);
+
+#endif
diff --git a/src/include/exchange-database/get_count_known_coins.h b/src/include/exchange-database/get_count_known_coins.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/exchange-database/get_get_count_known_coins.h
+ * @brief implementation of the get_count_known_coins function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_COUNT_KNOWN_COINS_H
+#define EXCHANGE_DATABASE_GET_COUNT_KNOWN_COINS_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Count the number of known coins by denomination.
+ *
+ * @param pg the database context
+ * @param denom_pub_hash denomination to count by
+ * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus`
+ */
+long long
+TALER_EXCHANGEDB_get_count_known_coins (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_DenominationHashP *denom_pub_hash)
+;
+
+#endif
diff --git a/src/include/exchange-database/get_denomination_meta.h b/src/include/exchange-database/get_denomination_meta.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_denomination_meta.h
+ * @brief implementation of the get_denomination_meta function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_DENOMINATION_META_H
+#define EXCHANGE_DATABASE_GET_DENOMINATION_META_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Lookup information about current denomination key.
+ *
+ * @param pg the database context
+ * @param h_denom_pub hash of the denomination public key
+ * @param[out] meta set to various meta data about the key
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_denomination_meta (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_DenominationHashP *
+ h_denom_pub,
+ struct
+ TALER_EXCHANGEDB_DenominationKeyMetaData
+ *
+ meta);
+
+#endif
diff --git a/src/include/exchange-database/get_drain_profit.h b/src/include/exchange-database/get_drain_profit.h
@@ -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/include/exchange-database/get_drain_profit.h
- * @brief implementation of the get_drain_profit function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_DRAIN_PROFIT_H
-#define EXCHANGE_DATABASE_GET_DRAIN_PROFIT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to get information about a profit drain event.
- *
- * @param pg the database context
- * @param wtid wire transfer ID to look up drain event for
- * @param[out] serial set to serial ID of the entry
- * @param[out] account_section set to account to drain
- * @param[out] payto_uri set to account to wire funds to
- * @param[out] request_timestamp set to time of the signature
- * @param[out] amount set to amount to wire
- * @param[out] master_sig set to signature affirming the operation
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_drain_profit (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_WireTransferIdentifierRawP *wtid
- ,
- uint64_t *serial,
- char **account_section,
- struct TALER_FullPayto *payto_uri,
- struct GNUNET_TIME_Timestamp *
- request_timestamp,
- struct TALER_Amount *amount,
- struct TALER_MasterSignatureP *master_sig);
-
-#endif
diff --git a/src/include/exchange-database/get_exists_aml_officer.h b/src/include/exchange-database/get_exists_aml_officer.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_exists_aml_officer.h
+ * @brief implementation of the get_exists_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_EXISTS_AML_OFFICER_H
+#define EXCHANGE_DATABASE_GET_EXISTS_AML_OFFICER_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Test if the given AML staff member is active
+ * (at least read-only).
+ *
+ * @param pg the database context
+ * @param decider_pub public key of the staff member
+ * @param[out] read_only set to true if the member is read-only
+ * @return database transaction status, if member is unknown or not active, 1 if member is active
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_exists_aml_officer (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_AmlOfficerPublicKeyP *
+ decider_pub,
+ bool *read_only);
+
+
+#endif
diff --git a/src/include/exchange-database/get_exists_deposit.h b/src/include/exchange-database/get_exists_deposit.h
@@ -0,0 +1,63 @@
+/*
+ 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/exchange-database/get_exists_deposit.h
+ * @brief implementation of the get_exists_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_EXISTS_DEPOSIT_H
+#define EXCHANGE_DATABASE_GET_EXISTS_DEPOSIT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Check if we have the specified deposit already in the database.
+ *
+ * @param pg the database context
+ * @param h_contract_terms contract to check for
+ * @param h_wire wire hash to check for
+ * @param coin_pub public key of the coin to check for
+ * @param merchant merchant public key to check for
+ * @param refund_deadline expected refund deadline
+ * @param[out] deposit_fee set to the deposit fee the exchange charged
+ * @param[out] exchange_timestamp set to the time when the exchange received the deposit
+ * @return 1 if we know this operation,
+ * 0 if this exact deposit is unknown to us,
+ * otherwise transaction error status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_exists_deposit (struct TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ const struct TALER_PrivateContractHashP *
+ h_contract_terms,
+ const struct TALER_MerchantWireHashP *
+ h_wire,
+ const struct TALER_CoinSpendPublicKeyP *
+ coin_pub
+ ,
+ const struct TALER_MerchantPublicKeyP *
+ merchant,
+ struct GNUNET_TIME_Timestamp
+ refund_deadline,
+ struct TALER_Amount *deposit_fee,
+ struct GNUNET_TIME_Timestamp *
+ exchange_timestamp
+ );
+
+#endif
diff --git a/src/include/exchange-database/get_expired_reserves.h b/src/include/exchange-database/get_expired_reserves.h
@@ -1,78 +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 get_expired_reserves.h
- * @brief implementation of the get_expired_reserves function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_EXPIRED_RESERVES_H
-#define EXCHANGE_DATABASE_GET_EXPIRED_RESERVES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Function called with details about expired reserves.
- *
- * @param cls closure
- * @param reserve_pub public key of the reserve
- * @param left amount left in the reserve
- * @param account_details information about the reserve's bank account, in payto://-format
- * @param expiration_date when did the reserve expire
- * @param close_request_row row that caused the reserve
- * to be closed, 0 if it expired without request
- * @return #GNUNET_OK on success,
- * #GNUNET_NO to retry
- * #GNUNET_SYSERR on hard failures (exit)
- */
-#ifndef TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReserveExpiredCallback.
- */
-#define TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveExpiredCallback)(
- TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *left,
- const struct TALER_FullPayto account_details,
- struct GNUNET_TIME_Timestamp expiration_date,
- uint64_t close_request_row);
-
-/**
- * Obtain information about expired reserves and their
- * remaining balances.
- *
- * @param pg the database context
- * @param now timestamp based on which we decide expiration
- * @param rec function to call on expired reserves
- * @param rec_cls closure for @a rec
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_expired_reserves (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- struct GNUNET_TIME_Timestamp now,
- TALER_EXCHANGEDB_ReserveExpiredCallback
- rec,
- TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
- *rec_cls);
-
-#endif
diff --git a/src/include/exchange-database/get_global_fee_by_time.h b/src/include/exchange-database/get_global_fee_by_time.h
@@ -0,0 +1,59 @@
+/*
+ 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/exchange-database/get_global_fee_by_time.h
+ * @brief implementation of the get_global_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_GLOBAL_FEE_BY_TIME_H
+#define EXCHANGE_DATABASE_GET_GLOBAL_FEE_BY_TIME_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup information about known global fees.
+ *
+ * @param pg the database context
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees set to wire fees for that time period; if
+ * different global fee exists within this time
+ * period, an 'invalid' amount is returned.
+ * @param[out] purse_timeout set to when unmerged purses expire
+ * @param[out] history_expiration set to when we expire reserve histories
+ * @param[out] purse_account_limit set to number of free purses
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_global_fee_by_time (struct
+ TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ struct GNUNET_TIME_Timestamp
+ start_time,
+ struct GNUNET_TIME_Timestamp
+ end_time,
+ struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative *
+ purse_timeout
+ ,
+ struct GNUNET_TIME_Relative *
+ history_expiration,
+ uint32_t *purse_account_limit);
+
+#endif
diff --git a/src/include/exchange-database/get_global_fees.h b/src/include/exchange-database/get_global_fees.h
@@ -1,100 +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/exchange-database/get_global_fees.h
- * @brief implementation of the get_global_fees function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_GLOBAL_FEES_H
-#define EXCHANGE_DATABASE_GET_GLOBAL_FEES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Provide information about global fees.
- *
- * @param cls closure
- * @param fees the global fees we charge
- * @param purse_timeout when do purses time out
- * @param history_expiration how long are account histories preserved
- * @param purse_account_limit how many purses are free per account
- * @param start_date from when are these fees valid (start date)
- * @param end_date until when are these fees valid (end date, exclusive)
- * @param master_sig master key signature affirming that this is the correct
- * fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES)
- */
-#ifndef TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_GlobalFeeCallback.
- */
-#define TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_GlobalFeeCallback)(
- TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE *cls,
- const struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative history_expiration,
- uint32_t purse_account_limit,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_MasterSignatureP *master_sig);
-
-
-/* Callback typedefs */
-/**
- * Provide information about global fees.
- *
- * @param cls closure
- * @param fees the global fees we charge
- * @param purse_timeout when do purses time out
- * @param history_expiration how long are account histories preserved
- * @param purse_account_limit how many purses are free per account
- * @param start_date from when are these fees valid (start date)
- * @param end_date until when are these fees valid (end date, exclusive)
- * @param master_sig master key signature affirming that this is the correct
- * fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES)
- */
-typedef void
-(*TALER_EXCHANGEDB_GlobalFeeCallback)(
- TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE *cls,
- const struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative history_expiration,
- uint32_t purse_account_limit,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_MasterSignatureP *master_sig);
-
-/**
- * Obtain global fees from database.
- *
- * @param pg the database context
- * @param cb function to call on each fee entry
- * @param cb_cls closure for @a cb
- * @return status of the transaction
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_get_global_fees (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- TALER_EXCHANGEDB_GlobalFeeCallback cb,
- TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/get_h_payto_by_access_token.h b/src/include/exchange-database/get_h_payto_by_access_token.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/exchange-database/get_h_payto_by_access_token.h
+ * @brief implementation of the get_h_payto_by_access_token function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_H_PAYTO_BY_ACCESS_TOKEN_H
+#define EXCHANGE_DATABASE_GET_H_PAYTO_BY_ACCESS_TOKEN_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup @a h_payto based on an @a access_token.
+ *
+ * @param pg the database context
+ * @param access_token
+ * set to token for access control
+ * @param[out] h_payto set to the the hash of the
+ * payto URI of the account (if found)
+ * @param[out] is_wallet set to true if @a h_payto
+ * is for a wallet
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_h_payto_by_access_token (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ const struct
+ TALER_AccountAccessTokenP *
+ access_token,
+ struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ bool *is_wallet);
+
+#endif
diff --git a/src/include/exchange-database/get_kyc_provider_account.h b/src/include/exchange-database/get_kyc_provider_account.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_kyc_provider_account.h
+ * @brief implementation of the get_kyc_provider_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_KYC_PROVIDER_ACCOUNT_H
+#define EXCHANGE_DATABASE_GET_KYC_PROVIDER_ACCOUNT_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup an
+ * @a h_payto by @a provider_legitimization_id.
+ *
+ * @param pg the database context
+ * @param provider_name
+ * @param provider_legitimization_id legi to look up
+ * @param[out] h_payto where to write the result
+ * @param[out] is_wallet set to true if @a h_payto is for a wallet
+ * @param[out] process_row where to write the row of the entry
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_kyc_provider_account (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const char *provider_name,
+ const char *
+ provider_legitimization_id,
+ struct TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ bool *is_wallet,
+ uint64_t *process_row);
+
+#endif
diff --git a/src/include/exchange-database/get_kyc_rules.h b/src/include/exchange-database/get_kyc_rules.h
@@ -45,16 +45,22 @@
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_kyc_rules (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto
- ,
- const struct TALER_MerchantPublicKeyP *
- merchant_pub,
- bool *no_account_pub,
- union TALER_AccountPublicKeyP *account_pub,
- bool *no_reserve_pub,
- struct TALER_ReservePublicKeyP *reserve_pub,
- json_t **jrules);
+TALER_EXCHANGEDB_get_kyc_rules_with_account (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_NormalizedPaytoHashP *h_payto
+ ,
+ const struct
+ TALER_MerchantPublicKeyP *
+ merchant_pub,
+ bool *no_account_pub,
+ union TALER_AccountPublicKeyP *
+ account_pub,
+ bool *no_reserve_pub,
+ struct TALER_ReservePublicKeyP *
+ reserve_pub,
+ json_t **jrules);
/**
@@ -67,10 +73,10 @@ TALER_EXCHANGEDB_get_kyc_rules (struct TALER_EXCHANGEDB_PostgresContext *pg,
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_get_kyc_rules2 (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct TALER_NormalizedPaytoHashP *
- h_payto,
- json_t **jrules);
+TALER_EXCHANGEDB_get_kyc_rules (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct TALER_NormalizedPaytoHashP *
+ h_payto,
+ json_t **jrules);
#endif
diff --git a/src/include/exchange-database/get_kyc_status_by_token.h b/src/include/exchange-database/get_kyc_status_by_token.h
@@ -0,0 +1,47 @@
+/*
+ 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/exchange-database/get_kyc_status_by_token.h
+ * @brief implementation of the get_kyc_status_by_token function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_KYC_STATUS_BY_TOKEN_H
+#define EXCHANGE_DATABASE_GET_KYC_STATUS_BY_TOKEN_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup KYC status by account access token.
+ *
+ * @param pg the database context
+ * @param access_token key to look under
+ * @param[out] row set to requirement row that matches
+ * @param[out] jmeasures set to the LegitimizationMeasures for the @a access_token; must be freed by caller!
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_kyc_status_by_token (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_AccountAccessTokenP *
+ access_token,
+ uint64_t *row,
+ json_t **jmeasures);
+
+
+#endif
diff --git a/src/include/exchange-database/get_legitimization_process_by_account.h b/src/include/exchange-database/get_legitimization_process_by_account.h
@@ -0,0 +1,63 @@
+/*
+ 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/exchange-database/get_legitimization_process_by_account.h
+ * @brief implementation of the get_legitimization_process_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_LEGITIMIZATION_PROCESS_BY_ACCOUNT_H
+#define EXCHANGE_DATABASE_GET_LEGITIMIZATION_PROCESS_BY_ACCOUNT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup KYC provider meta data.
+ *
+ * @param pg the database context
+ * @param provider_name provider that must be checked
+ * @param h_payto account that must be KYC'ed
+ * @param[out] process_row row with the legitimization data
+ * @param[out] expiration how long is this KYC check set to be valid (in the past if invalid)
+ * @param[out] provider_account_id provider account ID
+ * @param[out] provider_legitimization_id provider legitimization ID
+ * @param[out] is_wallet set to true if @a h_payto is for a wallet
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_legitimization_process_by_account (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ const char *
+ provider_name,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ uint64_t *process_row,
+ struct
+ GNUNET_TIME_Absolute *
+ expiration,
+ char **
+ provider_account_id,
+ char **
+ provider_legitimization_id,
+ bool *is_wallet);
+
+#endif
diff --git a/src/include/exchange-database/get_legitimization_requirement_by_row.h b/src/include/exchange-database/get_legitimization_requirement_by_row.h
@@ -0,0 +1,77 @@
+/*
+ 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/exchange-database/get_legitimization_requirement_by_row.h
+ * @brief implementation of the get_legitimization_requirement_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_LEGITIMIZATION_REQUIREMENT_BY_ROW_H
+#define EXCHANGE_DATABASE_GET_LEGITIMIZATION_REQUIREMENT_BY_ROW_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup KYC requirement.
+ *
+ * @param pg the database context
+ * @param h_payto identifies account to look up requirement for
+ * @param account_pub set to public key of the account
+ * needed to authorize access
+ * @param[out] is_wallet set to #GNUNET_YES if the account is
+ * that of a wallet (#GNUNET_SYSERR is used if unknown)
+ * @param[out] access_token set to the access token to begin
+ * work on KYC processes for this account
+ * @param[out] rule_gen row ID of the last decision this
+ * response is based on (for long-polling by clients)
+ * @param[out] jrules set to active ``LegitimizationRuleSet``
+ * of the account impacted by the requirement
+ * @param[out] aml_review set to true if the account is under
+ * active review by AML staff
+ * @param[out] kyc_required set to true if the user must pass
+ * some KYC check before some previous operation may continue
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_legitimization_requirement_by_row (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ const union
+ TALER_AccountPublicKeyP
+ *
+ account_pub,
+ enum
+ GNUNET_GenericReturnValue
+ *
+ is_wallet,
+ struct
+ TALER_AccountAccessTokenP
+ *
+ access_token,
+ uint64_t *rule_gen,
+ json_t **jrules,
+ bool *aml_review,
+ bool *kyc_required);
+
+
+#endif
diff --git a/src/include/exchange-database/get_pending_kyc_requirement_process.h b/src/include/exchange-database/get_pending_kyc_requirement_process.h
@@ -1,48 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/get_pending_kyc_requirement_process.h
- * @brief implementation of the get_pending_kyc_requirement_process function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_PENDING_KYC_REQUIREMENT_PROCESS_H
-#define EXCHANGE_DATABASE_GET_PENDING_KYC_REQUIREMENT_PROCESS_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Fetch information about pending KYC requirement process.
- *
- * @param pg the database context
- * @param h_payto account that must be KYC'ed
- * @param provider_name provider that must be checked
- * @param[out] redirect_url set to redirect URL for the process
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_pending_kyc_requirement_process (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_NormalizedPaytoHashP
- *
- h_payto,
- const char *provider_name,
- char **redirect_url);
-
-#endif
diff --git a/src/include/exchange-database/get_pending_legitimization.h b/src/include/exchange-database/get_pending_legitimization.h
@@ -0,0 +1,62 @@
+/*
+ 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/exchange-database/get_pending_legitimization.h
+ * @brief implementation of the get_pending_legitimization function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PENDING_LEGITIMIZATION_H
+#define EXCHANGE_DATABASE_GET_PENDING_LEGITIMIZATION_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup measure data for a legitimization process.
+ *
+ * @param pg the database context
+ * @param legitimization_measure_serial_id
+ * row in legitimization_measures table to access
+ * @param[out] access_token
+ * set to token for access control that must match
+ * @param[out] h_payto set to the the hash of the
+ * payto URI of the account undergoing legitimization
+ * @param[out] jmeasures set to the legitimization
+ * measures that were put on the account
+ * @param[out] is_finished set to true if the legitimization was
+ * already finished
+ * @param[out] is_wallet set to true if @a h_payto is for a wallet
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_pending_legitimization (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ uint64_t
+ legitimization_measure_serial_id,
+ struct TALER_AccountAccessTokenP
+ *
+ access_token,
+ struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ json_t **jmeasures,
+ bool *is_finished,
+ bool *is_wallet);
+
+#endif
diff --git a/src/include/exchange-database/get_pending_legitimization_process.h b/src/include/exchange-database/get_pending_legitimization_process.h
@@ -0,0 +1,48 @@
+/*
+ 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/exchange-database/get_pending_legitimization_process.h
+ * @brief implementation of the get_pending_legitimization_process function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PENDING_LEGITIMIZATION_PROCESS_H
+#define EXCHANGE_DATABASE_GET_PENDING_LEGITIMIZATION_PROCESS_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Fetch information about pending KYC requirement process.
+ *
+ * @param pg the database context
+ * @param h_payto account that must be KYC'ed
+ * @param provider_name provider that must be checked
+ * @param[out] redirect_url set to redirect URL for the process
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_pending_legitimization_process (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ const char *provider_name,
+ char **redirect_url);
+
+#endif
diff --git a/src/include/exchange-database/get_pending_profit_drain.h b/src/include/exchange-database/get_pending_profit_drain.h
@@ -0,0 +1,59 @@
+/*
+ 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/exchange-database/get_pending_profit_drain.h
+ * @brief implementation of the get_pending_profit_drain function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PENDING_PROFIT_DRAIN_H
+#define EXCHANGE_DATABASE_GET_PENDING_PROFIT_DRAIN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Get profit drain operation ready to execute.
+ *
+ * @param pg the database context
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] wtid set set to wire transfer ID to use
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_pending_profit_drain (struct
+ TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ uint64_t *serial,
+ struct
+ TALER_WireTransferIdentifierRawP *
+ wtid,
+ char **account_section,
+ struct TALER_FullPayto *payto_uri,
+ struct GNUNET_TIME_Timestamp *
+ request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *
+ master_sig)
+;
+
+#endif
diff --git a/src/include/exchange-database/get_profit_drain.h b/src/include/exchange-database/get_profit_drain.h
@@ -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/include/exchange-database/get_profit_drain.h
+ * @brief implementation of the get_profit_drain function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PROFIT_DRAIN_H
+#define EXCHANGE_DATABASE_GET_PROFIT_DRAIN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to get information about a profit drain event.
+ *
+ * @param pg the database context
+ * @param wtid wire transfer ID to look up drain event for
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_profit_drain (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_WireTransferIdentifierRawP *wtid
+ ,
+ uint64_t *serial,
+ char **account_section,
+ struct TALER_FullPayto *payto_uri,
+ struct GNUNET_TIME_Timestamp *
+ request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/include/exchange-database/get_purse.h b/src/include/exchange-database/get_purse.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file get_purse.h
+ * @brief implementation of the get_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PURSE_H
+#define EXCHANGE_DATABASE_GET_PURSE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to obtain information about a purse.
+ *
+ * @param pg the database context
+ * @param purse_pub public key of the new purse
+ * @param[out] purse_creation set to time when the purse was created
+ * @param[out] purse_expiration set to time when the purse will expire
+ * @param[out] amount set to target amount (with fees) to be put into the purse
+ * @param[out] deposited set to actual amount put into the purse so far
+ * @param[out] h_contract_terms set to hash of the contract for the purse
+ * @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
+ * @param[out] purse_deleted set to true if purse was deleted
+ * @param[out] purse_refunded set to true if purse was refunded
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_purse (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_creation,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_Amount *amount,
+ struct TALER_Amount *deposited,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ bool *purse_deleted,
+ bool *purse_refunded);
+
+#endif
diff --git a/src/include/exchange-database/get_purse_by_merge_pub.h b/src/include/exchange-database/get_purse_by_merge_pub.h
@@ -0,0 +1,69 @@
+/*
+ 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/exchange-database/get_purse_by_merge_pub.h
+ * @brief implementation of the get_purse_by_merge_pub function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PURSE_BY_MERGE_PUB_H
+#define EXCHANGE_DATABASE_GET_PURSE_BY_MERGE_PUB_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to return meta data about a purse by the
+ * merge capability key.
+ *
+ * @param pg the database context
+ * @param merge_pub public key representing the merge capability
+ * @param[out] purse_pub public key of the purse
+ * @param[out] purse_expiration when would an unmerged purse expire
+ * @param[out] h_contract_terms contract associated with the purse
+ * @param[out] age_limit the age limit for deposits into the purse
+ * @param[out] target_amount amount to be put into the purse
+ * @param[out] balance amount put so far into the purse
+ * @param[out] purse_sig signature of the purse over the initialization data
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_purse_by_merge_pub (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_PurseMergePublicKeyP *
+ merge_pub,
+ struct
+ TALER_PurseContractPublicKeyP
+ *
+ purse_pub,
+ struct GNUNET_TIME_Timestamp *
+ purse_expiration,
+ struct
+ TALER_PrivateContractHashP *
+ h_contract_terms,
+ uint32_t *age_limit,
+ struct TALER_Amount *
+ target_amount,
+ struct TALER_Amount *balance,
+ struct
+ TALER_PurseContractSignatureP
+ *
+ purse_sig);
+
+#endif
diff --git a/src/include/exchange-database/get_purse_merge.h b/src/include/exchange-database/get_purse_merge.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_purse_merge.h
+ * @brief implementation of the get_purse_merge function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_PURSE_MERGE_H
+#define EXCHANGE_DATABASE_GET_PURSE_MERGE_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to approve merging of a purse with
+ * an account, made by the receiving account.
+ *
+ * @param pg the database context
+ * @param purse_pub public key of the purse
+ * @param[out] merge_sig set to the signature confirming the merge
+ * @param[out] merge_timestamp set to the time of the merge
+ * @param[out] partner_url set to the URL of the target exchange, or NULL if the target exchange is us. To be freed by the caller.
+ * @param[out] reserve_pub set to the public key of the reserve/account being credited
+ * @param[out] refunded set to true if purse was refunded
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_purse_merge (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_PurseContractPublicKeyP *
+ purse_pub,
+ struct TALER_PurseMergeSignatureP *
+ merge_sig,
+ struct GNUNET_TIME_Timestamp *
+ merge_timestamp,
+ char **partner_url,
+ struct TALER_ReservePublicKeyP *
+ reserve_pub,
+ bool *refunded);
+
+#endif
diff --git a/src/include/exchange-database/get_reserve.h b/src/include/exchange-database/get_reserve.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_reserve.h
+ * @brief implementation of the get_reserve function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_RESERVE_H
+#define EXCHANGE_DATABASE_GET_RESERVE_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Get the summary of a reserve.
+ *
+ * @param pg the database context
+ * @param[in,out] reserve the reserve data. The public key of the reserve should be
+ * set in this structure; it is used to query the database. The balance
+ * and expiration are then filled accordingly.
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ struct TALER_EXCHANGEDB_Reserve *reserve);
+
+#endif
diff --git a/src/include/exchange-database/get_reserve_close_info.h b/src/include/exchange-database/get_reserve_close_info.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file get_reserve_close_info.h
+ * @brief implementation of the select_reserve_close_info function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_RESERVE_CLOSE_INFO_H
+#define EXCHANGE_DATABASE_GET_RESERVE_CLOSE_INFO_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Select information needed to see if we can close
+ * a reserve.
+ *
+ * @param pg the database context
+ * @param reserve_pub which reserve is this about?
+ * @param[out] balance current reserve balance
+ * @param[out] payto_uri set to URL of account that
+ * originally funded the reserve;
+ * could be set to NULL if not known
+ * @return transaction status code, 0 if reserve unknown
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve_close_info (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance,
+ struct TALER_FullPayto *payto_uri);
+
+
+#endif
diff --git a/src/include/exchange-database/get_reserve_close_request_info.h b/src/include/exchange-database/get_reserve_close_request_info.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2026 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 get_reserve_close_request_info.h
+ * @brief implementation of the select_reserve_close_request_info function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_RESERVE_CLOSE_REQUEST_INFO_H
+#define EXCHANGE_DATABASE_GET_RESERVE_CLOSE_REQUEST_INFO_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Select information about reserve close requests.
+ *
+ * @param pg the database context
+ * @param reserve_pub which reserve is this about?
+ * @param rowid row ID of the close request
+ * @param[out] reserve_sig reserve signature affirming
+ * @param[out] request_timestamp when was the request made
+ * @param[out] close_balance reserve balance at close time
+ * @param[out] close_fee closing fee to be charged
+ * @param[out] payto_uri set to URL of account that
+ * should receive the money;
+ * could be set to NULL for origin
+ * @return transaction status code, 0 if reserve unknown
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve_close_request_info (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t rowid,
+ struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *close_balance,
+ struct TALER_Amount *close_fee,
+ struct TALER_FullPayto *payto_uri);
+
+#endif
diff --git a/src/include/exchange-database/get_reserve_origin.h b/src/include/exchange-database/get_reserve_origin.h
@@ -0,0 +1,48 @@
+/*
+ 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/exchange-database/get_reserve_origin.h
+ * @brief implementation of the get_reserve_origin function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_RESERVE_ORIGIN_H
+#define EXCHANGE_DATABASE_GET_RESERVE_ORIGIN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Get the origin of funds of a reserve.
+ *
+ * @param pg the database context
+ * @param reserve_pub public key of the reserve
+ * @param[out] h_payto set to hash of the wire source payto://-URI
+ * @param[out] payto_uri set to the wire source payto://-URI
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_reserve_origin (struct
+ TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ const struct
+ TALER_ReservePublicKeyP *
+ reserve_pub,
+ struct TALER_FullPaytoHashP *h_payto
+ ,
+ struct TALER_FullPayto *payto_uri);
+
+#endif
diff --git a/src/include/exchange-database/get_rules_by_access_token.h b/src/include/exchange-database/get_rules_by_access_token.h
@@ -0,0 +1,47 @@
+/*
+ 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/exchange-database/get_rules_by_access_token.h
+ * @brief implementation of the get_rules_by_access_token function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_RULES_BY_ACCESS_TOKEN_H
+#define EXCHANGE_DATABASE_GET_RULES_BY_ACCESS_TOKEN_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup KYC rules by account access token.
+ *
+ * @param pg the database context
+ * @param h_payto account hash to look under
+ * @param[out] jnew_rules set to active LegitimizationRuleSet
+ * @param[out] rowid set to outcome_serial_id of the row
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_rules_by_access_token (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ json_t **jnew_rules,
+ uint64_t *rowid);
+
+#endif
diff --git a/src/include/exchange-database/get_serial_by_table.h b/src/include/exchange-database/get_serial_by_table.h
@@ -0,0 +1,44 @@
+/*
+ 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 get_serial_by_table.h
+ * @brief implementation of the lookup_serial_by_table function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_SERIAL_BY_TABLE_H
+#define EXCHANGE_DATABASE_GET_SERIAL_BY_TABLE_H
+
+#include "exchangedb_lib.h"
+#include "exchange-database/iterate_records_by_table.h"
+
+/**
+ * Lookup the latest serial number of @a table. Used in
+ * exchange-auditor database replication.
+ *
+ * @param pg the database context
+ * @param table table for which we should return the serial
+ * @param[out] serial latest serial number in use
+ * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
+ * @a table does not have a serial number
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_serial_by_table (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t *serial);
+
+
+#endif
diff --git a/src/include/exchange-database/get_signkey.h b/src/include/exchange-database/get_signkey.h
@@ -0,0 +1,43 @@
+/*
+ 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/exchange-database/get_signkey.h
+ * @brief implementation of the get_signkey function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_SIGNKEY_H
+#define EXCHANGE_DATABASE_GET_SIGNKEY_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup signing key meta data.
+ *
+ * @param pg the database context
+ * @param exchange_pub the exchange online signing public key
+ * @param[out] meta meta data about @a exchange_pub
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_signkey (struct TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ const struct TALER_ExchangePublicKeyP *
+ exchange_pub,
+ struct TALER_EXCHANGEDB_SignkeyMetaData *
+ meta);
+
+#endif
diff --git a/src/include/exchange-database/get_signkey_revocation.h b/src/include/exchange-database/get_signkey_revocation.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_signkey_revocation.h
+ * @brief implementation of the get_signkey_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_SIGNKEY_REVOCATION_H
+#define EXCHANGE_DATABASE_GET_SIGNKEY_REVOCATION_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Obtain information about a revoked online signing key.
+ *
+ * @param pg the database context
+ * @param exchange_pub exchange online signing key
+ * @param[out] master_sig set to signature affirming the revocation (if revoked)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_signkey_revocation (struct
+ TALER_EXCHANGEDB_PostgresContext *pg
+ ,
+ const struct
+ TALER_ExchangePublicKeyP *
+ exchange_pub,
+ struct TALER_MasterSignatureP *
+ master_sig)
+;
+
+#endif
diff --git a/src/include/exchange-database/get_transfer_by_deposit.h b/src/include/exchange-database/get_transfer_by_deposit.h
@@ -0,0 +1,79 @@
+/*
+ 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/exchange-database/get_transfer_by_deposit.h
+ * @brief implementation of the get_transfer_by_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_TRANSFER_BY_DEPOSIT_H
+#define EXCHANGE_DATABASE_GET_TRANSFER_BY_DEPOSIT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Try to find the wire transfer details for a deposit operation.
+ * If we did not execute the deposit yet, return when it is supposed
+ * to be executed.
+ *
+ * @param pg the database context
+ * @param h_contract_terms hash of the proposal data
+ * @param h_wire hash of merchant wire details
+ * @param coin_pub public key of deposited coin
+ * @param merchant_pub merchant public key
+ * @param[out] pending set to true if the transaction is still pending
+ * @param[out] wtid wire transfer identifier, only set if @a pending is false
+ * @param[out] exec_time when was the transaction done, or
+ * when we expect it to be done (if @a pending is false)
+ * @param[out] amount_with_fee set to the total deposited amount
+ * @param[out] deposit_fee set to how much the exchange did charge for the deposit
+ * @param[out] kyc set to the kyc status of the receiver (if @a pending)
+ * @param[out] account_pub set to public key that is authorized to start the KYC process; unchanged if no such key is known
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_transfer_by_deposit (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_PrivateContractHashP *
+ h_contract_terms,
+ const struct
+ TALER_MerchantWireHashP *
+ h_wire,
+ const struct
+ TALER_CoinSpendPublicKeyP *
+ coin_pub,
+ const struct
+ TALER_MerchantPublicKeyP *
+ merchant_pub,
+ bool *pending,
+ struct
+ TALER_WireTransferIdentifierRawP *
+ wtid,
+ struct GNUNET_TIME_Timestamp *
+ exec_time,
+ struct TALER_Amount *
+ amount_with_fee,
+ struct TALER_Amount *deposit_fee,
+ struct TALER_EXCHANGEDB_KycStatus *
+ kyc,
+ union TALER_AccountPublicKeyP *
+ account_pub);
+
+#endif
diff --git a/src/include/exchange-database/get_unfinished_close_requests.h b/src/include/exchange-database/get_unfinished_close_requests.h
@@ -1,80 +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 get_unfinished_close_requests.h
- * @brief implementation of the get_unfinished_close_requests function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_UNFINISHED_CLOSE_REQUESTS_H
-#define EXCHANGE_DATABASE_GET_UNFINISHED_CLOSE_REQUESTS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Function called with details about expired reserves.
- *
- * @param cls closure
- * @param reserve_pub public key of the reserve
- * @param left amount left in the reserve
- * @param account_details information about the reserve's bank account, in payto://-format
- * @param expiration_date when did the reserve expire
- * @param close_request_row row that caused the reserve
- * to be closed, 0 if it expired without request
- * @return #GNUNET_OK on success,
- * #GNUNET_NO to retry
- * #GNUNET_SYSERR on hard failures (exit)
- */
-#ifndef TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReserveExpiredCallback.
- */
-#define TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveExpiredCallback)(
- TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *left,
- const struct TALER_FullPayto account_details,
- struct GNUNET_TIME_Timestamp expiration_date,
- uint64_t close_request_row);
-
-/**
- * Obtain information about force-closed reserves
- * where the close was not yet done (and their remaining
- * balances). Updates the returned reserve's close
- * status to "done".
- *
- * @param pg the database context
- * @param rec function to call on expired reserves
- * @param rec_cls closure for @a rec
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_unfinished_close_requests (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- TALER_EXCHANGEDB_ReserveExpiredCallback
- rec,
- TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
- *rec_cls);
-
-#endif
diff --git a/src/include/exchange-database/get_wire_accounts.h b/src/include/exchange-database/get_wire_accounts.h
@@ -1,107 +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/exchange-database/get_wire_accounts.h
- * @brief implementation of the get_wire_accounts function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_WIRE_ACCOUNTS_H
-#define EXCHANGE_DATABASE_GET_WIRE_ACCOUNTS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Provide information about a wire account.
- *
- * @param cls closure
- * @param payto_uri the exchange bank account URI
- * @param conversion_url URL of a conversion service, NULL if there is no conversion
- * @param open_banking_gateway open banking gateway service, NULL if unavailable
- * @param prepared_transfer_url prepared transfer service, NULL if unavailable
- * @param debit_restrictions JSON array with debit restrictions on the account
- * @param credit_restrictions JSON array with credit restrictions on the account
- * @param master_sig master key signature affirming that this is a bank
- * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
- * @param bank_label label the wallet should use to display the account, can be NULL
- * @param priority priority for ordering bank account labels
- */
-#ifndef TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_WireAccountCallback.
- */
-#define TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_WireAccountCallback)(
- TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE *cls,
- const struct TALER_FullPayto payto_uri,
- const char *conversion_url,
- const char *open_banking_gateway,
- const char *prepared_transfer_url,
- const json_t *debit_restrictions,
- const json_t *credit_restrictions,
- const struct TALER_MasterSignatureP *master_sig,
- const char *bank_label,
- int64_t priority);
-
-
-/* Callback typedefs */
-/**
- * Provide information about a wire account.
- *
- * @param cls closure
- * @param payto_uri the exchange bank account URI
- * @param conversion_url URL of a conversion service, NULL if there is no conversion
- * @param open_banking_gateway open banking gateway service, NULL if unavailable
- * @param prepared_transfer_url prepared transfer service, NULL if unavailable
- * @param debit_restrictions JSON array with debit restrictions on the account
- * @param credit_restrictions JSON array with credit restrictions on the account
- * @param master_sig master key signature affirming that this is a bank
- * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
- * @param bank_label label the wallet should use to display the account, can be NULL
- * @param priority priority for ordering bank account labels
- */
-typedef void
-(*TALER_EXCHANGEDB_WireAccountCallback)(
- TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE *cls,
- const struct TALER_FullPayto payto_uri,
- const char *conversion_url,
- const char *open_banking_gateway,
- const char *prepared_transfer_url,
- const json_t *debit_restrictions,
- const json_t *credit_restrictions,
- const struct TALER_MasterSignatureP *master_sig,
- const char *bank_label,
- int64_t priority);
-
-/**
- * Obtain information about the enabled wire accounts of the exchange.
- *
- * @param pg the database context
- * @param cb function to call on each account
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_get_wire_accounts (struct TALER_EXCHANGEDB_PostgresContext *pg,
- TALER_EXCHANGEDB_WireAccountCallback cb,
- TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/get_wire_fee_by_time.h b/src/include/exchange-database/get_wire_fee_by_time.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/get_wire_fee_by_time.h
+ * @brief implementation of the get_wire_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_WIRE_FEE_BY_TIME_H
+#define EXCHANGE_DATABASE_GET_WIRE_FEE_BY_TIME_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Lookup information about known wire fees. Finds all applicable
+ * fees in the given range. If they are identical, returns the
+ * respective @a fees. If any of the fees
+ * differ between @a start_time and @a end_time, the transaction
+ * succeeds BUT returns an invalid amount for both fees.
+ *
+ * @param pg the database context
+ * @param wire_method the wire method to lookup fees for
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees wire fees for that time period; if
+ * different fees exists within this time
+ * period, an 'invalid' amount is returned.
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_wire_fee_by_time (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *wire_method,
+ struct GNUNET_TIME_Timestamp
+ start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_WireFeeSet *fees);
+
+#endif
diff --git a/src/include/exchange-database/get_wire_fees.h b/src/include/exchange-database/get_wire_fees.h
@@ -1,91 +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/exchange-database/get_wire_fees.h
- * @brief implementation of the get_wire_fees function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_GET_WIRE_FEES_H
-#define EXCHANGE_DATABASE_GET_WIRE_FEES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Provide information about wire fees.
- *
- * @param cls closure
- * @param fees the wire fees we charge
- * @param start_date from when are these fees valid (start date)
- * @param end_date until when are these fees valid (end date, exclusive)
- * @param master_sig master key signature affirming that this is the correct
- * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES)
- */
-#ifndef TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_WireFeeCallback.
- */
-#define TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_WireFeeCallback)(
- TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE *cls,
- const struct TALER_WireFeeSet *fees,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_MasterSignatureP *master_sig);
-
-
-/* Callback typedefs */
-/**
- * Provide information about wire fees.
- *
- * @param cls closure
- * @param fees the wire fees we charge
- * @param start_date from when are these fees valid (start date)
- * @param end_date until when are these fees valid (end date, exclusive)
- * @param master_sig master key signature affirming that this is the correct
- * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES)
- */
-typedef void
-(*TALER_EXCHANGEDB_WireFeeCallback)(
- TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE *cls,
- const struct TALER_WireFeeSet *fees,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_MasterSignatureP *master_sig);
-
-/**
- * Obtain information about the fee structure of the exchange for
- * a given @a wire_method
- *
- * @param pg the database context
- * @param wire_method which wire method to obtain fees for
- * @param cb function to call on each account
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_get_wire_fees (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const char *wire_method,
- TALER_EXCHANGEDB_WireFeeCallback cb,
- TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/get_wire_timestamp.h b/src/include/exchange-database/get_wire_timestamp.h
@@ -0,0 +1,44 @@
+/*
+ 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/exchange-database/get_wire_timestamp.h
+ * @brief implementation of the get_wire_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_GET_WIRE_TIMESTAMP_H
+#define EXCHANGE_DATABASE_GET_WIRE_TIMESTAMP_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Check the last date an exchange wire account was modified.
+ *
+ * @param pg the database context
+ * @param payto_uri key to look up information for
+ * @param[out] last_date last modification date to auditor status
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_get_wire_timestamp (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_FullPayto payto_uri,
+ struct GNUNET_TIME_Timestamp *last_date)
+;
+
+#endif
diff --git a/src/include/exchange-database/have_deposit2.h b/src/include/exchange-database/have_deposit2.h
@@ -1,57 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/have_deposit2.h
- * @brief implementation of the have_deposit2 function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_HAVE_DEPOSIT2_H
-#define EXCHANGE_DATABASE_HAVE_DEPOSIT2_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Check if we have the specified deposit already in the database.
- *
- * @param pg the database context
- * @param h_contract_terms contract to check for
- * @param h_wire wire hash to check for
- * @param coin_pub public key of the coin to check for
- * @param merchant merchant public key to check for
- * @param refund_deadline expected refund deadline
- * @param[out] deposit_fee set to the deposit fee the exchange charged
- * @param[out] exchange_timestamp set to the time when the exchange received the deposit
- * @return 1 if we know this operation,
- * 0 if this exact deposit is unknown to us,
- * otherwise transaction error status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_have_deposit2 (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PrivateContractHashP *
- h_contract_terms,
- const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_CoinSpendPublicKeyP *coin_pub
- ,
- const struct TALER_MerchantPublicKeyP *merchant,
- struct GNUNET_TIME_Timestamp refund_deadline,
- struct TALER_Amount *deposit_fee,
- struct GNUNET_TIME_Timestamp *exchange_timestamp
- );
-
-#endif
diff --git a/src/include/exchange-database/insert_aggregation_transient.h b/src/include/exchange-database/insert_aggregation_transient.h
@@ -0,0 +1,59 @@
+/*
+ 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/exchange-database/insert_aggregation_transient.h
+ * @brief implementation of the insert_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_AGGREGATION_TRANSIENT_H
+#define EXCHANGE_DATABASE_INSERT_AGGREGATION_TRANSIENT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Create a new entry in the transient aggregation table.
+ *
+ * @param pg the database context
+ * @param h_payto destination of the wire transfer
+ * @param exchange_account_section exchange account to use
+ * @param merchant_pub public key of the merchant receiving the transfer
+ * @param wtid the raw wire transfer identifier to be used
+ * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none
+ * @param total amount to be wired in the future
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_aggregation_transient (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_FullPaytoHashP *
+ h_payto,
+ const char *
+ exchange_account_section,
+ const struct
+ TALER_MerchantPublicKeyP *
+ merchant_pub,
+ const struct
+ TALER_WireTransferIdentifierRawP
+ *wtid,
+ uint64_t kyc_requirement_row,
+ const struct TALER_Amount *total)
+;
+
+#endif
diff --git a/src/include/exchange-database/insert_auditor_denom_sig.h b/src/include/exchange-database/insert_auditor_denom_sig.h
@@ -35,17 +35,17 @@
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_insert_auditor_denom_sig (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_DenominationHashP *
- h_denom_pub,
- const struct
- TALER_AuditorPublicKeyP *
- auditor_pub,
- const struct
- TALER_AuditorSignatureP *
- auditor_sig);
+TALER_EXCHANGEDB_insert_auditor_denom_sig (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct
+ TALER_DenominationHashP *
+ h_denom_pub,
+ const struct
+ TALER_AuditorPublicKeyP *
+ auditor_pub,
+ const struct
+ TALER_AuditorSignatureP *
+ auditor_sig);
#endif
diff --git a/src/include/exchange-database/insert_drain_profit.h b/src/include/exchange-database/insert_drain_profit.h
@@ -1,56 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/insert_drain_profit.h
- * @brief implementation of the insert_drain_profit function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_INSERT_DRAIN_PROFIT_H
-#define EXCHANGE_DATABASE_INSERT_DRAIN_PROFIT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to persist a request to drain profits.
- *
- * @param pg the database context
- * @param wtid wire transfer ID to use
- * @param account_section account to drain
- * @param payto_uri account to wire funds to
- * @param request_timestamp when was the request made
- * @param amount amount to wire
- * @param master_sig signature affirming the operation
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_insert_drain_profit (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct
- TALER_WireTransferIdentifierRawP *
- wtid,
- const char *account_section,
- const struct TALER_FullPayto payto_uri,
- struct GNUNET_TIME_Timestamp
- request_timestamp,
- const struct TALER_Amount *amount,
- const struct TALER_MasterSignatureP *
- master_sig)
-;
-
-#endif
diff --git a/src/include/exchange-database/insert_kyc_requirement_process.h b/src/include/exchange-database/insert_kyc_requirement_process.h
@@ -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/include/exchange-database/insert_kyc_requirement_process.h
- * @brief implementation of the insert_kyc_requirement_process function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_INSERT_KYC_REQUIREMENT_PROCESS_H
-#define EXCHANGE_DATABASE_INSERT_KYC_REQUIREMENT_PROCESS_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Begin KYC requirement process.
- *
- * @param pg the database context
- * @param h_payto account that must be KYC'ed
- * @param measure_index which of the measures in
- * jmeasures does this KYC process relate to
- * @param legitimization_measure_serial_id which
- * legitimization measure set does this KYC process
- * relate to (uniquely identifies jmeasures)
- * @param provider_name provider that must be checked
- * @param provider_account_id provider account ID
- * @param provider_legitimization_id provider legitimization ID
- * @param[out] process_row row the process is stored under
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_insert_kyc_requirement_process (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- uint32_t measure_index,
- uint64_t
- legitimization_measure_serial_id,
- const char *provider_name,
- const char *provider_account_id
- ,
- const char *
- provider_legitimization_id,
- uint64_t *process_row);
-
-#endif
diff --git a/src/include/exchange-database/insert_kycauth_in.h b/src/include/exchange-database/insert_kycauth_in.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/insert_kycauth_in.h
+ * @brief implementation of the insert_kycauth_in function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_KYCAUTH_IN_H
+#define EXCHANGE_DATABASE_INSERT_KYCAUTH_IN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Insert an incoming KCYAUTH wire transfer into
+ * the database and update the authentication key
+ * for the origin account.
+ *
+ * @param pg the database context
+ * @param account_pub public key of the account
+ * @param credit_amount amount we were credited
+ * @param execution_date when was the transfer made
+ * @param debit_account_uri URI of the debit account
+ * @param section_name section of the exchange bank account that received the transfer
+ * @param serial_id bank-specific row identifying the transfer
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_kycauth_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const union TALER_AccountPublicKeyP *
+ account_pub,
+ const struct TALER_Amount *credit_amount,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_FullPayto
+ debit_account_uri,
+ const char *section_name,
+ uint64_t serial_id);
+
+
+#endif
diff --git a/src/include/exchange-database/insert_legitimization_process.h b/src/include/exchange-database/insert_legitimization_process.h
@@ -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/include/exchange-database/insert_legitimization_process.h
+ * @brief implementation of the insert_legitimization_process function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_LEGITIMIZATION_PROCESS_H
+#define EXCHANGE_DATABASE_INSERT_LEGITIMIZATION_PROCESS_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Begin KYC requirement process.
+ *
+ * @param pg the database context
+ * @param h_payto account that must be KYC'ed
+ * @param measure_index which of the measures in
+ * jmeasures does this KYC process relate to
+ * @param legitimization_measure_serial_id which
+ * legitimization measure set does this KYC process
+ * relate to (uniquely identifies jmeasures)
+ * @param provider_name provider that must be checked
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param[out] process_row row the process is stored under
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_legitimization_process (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ uint32_t measure_index,
+ uint64_t
+ legitimization_measure_serial_id,
+ const char *provider_name,
+ const char *provider_account_id
+ ,
+ const char *
+ provider_legitimization_id,
+ uint64_t *process_row);
+
+#endif
diff --git a/src/include/exchange-database/insert_prewire.h b/src/include/exchange-database/insert_prewire.h
@@ -0,0 +1,43 @@
+/*
+ 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/exchange-database/insert_prewire.h
+ * @brief implementation of the insert_prewire function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_PREWIRE_H
+#define EXCHANGE_DATABASE_INSERT_PREWIRE_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to insert wire transfer commit data into the DB.
+ *
+ * @param pg the database context
+ * @param type type of the wire transfer (i.e. "iban")
+ * @param buf buffer with wire transfer preparation data
+ * @param buf_size number of bytes in @a buf
+ * @return query status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_prewire (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *type,
+ const char *buf,
+ size_t buf_size);
+
+#endif
diff --git a/src/include/exchange-database/insert_profit_drain.h b/src/include/exchange-database/insert_profit_drain.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/insert_profit_drain.h
+ * @brief implementation of the insert_profit_drain function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_PROFIT_DRAIN_H
+#define EXCHANGE_DATABASE_INSERT_PROFIT_DRAIN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to persist a request to drain profits.
+ *
+ * @param pg the database context
+ * @param wtid wire transfer ID to use
+ * @param account_section account to drain
+ * @param payto_uri account to wire funds to
+ * @param request_timestamp when was the request made
+ * @param amount amount to wire
+ * @param master_sig signature affirming the operation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_profit_drain (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_WireTransferIdentifierRawP *
+ wtid,
+ const char *account_section,
+ const struct TALER_FullPayto payto_uri,
+ struct GNUNET_TIME_Timestamp
+ request_timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_MasterSignatureP *
+ master_sig)
+;
+
+#endif
diff --git a/src/include/exchange-database/insert_records_by_table.h b/src/include/exchange-database/insert_records_by_table.h
@@ -22,7 +22,7 @@
#define EXCHANGE_DATABASE_INSERT_RECORDS_BY_TABLE_H
#include "exchangedb_lib.h"
-#include "exchange-database/lookup_records_by_table.h"
+#include "exchange-database/iterate_records_by_table.h"
/**
diff --git a/src/include/exchange-database/insert_signkey.h b/src/include/exchange-database/insert_signkey.h
@@ -0,0 +1,48 @@
+/*
+ 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/exchange-database/insert_signkey.h
+ * @brief implementation of the insert_signkey function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_SIGNKEY_H
+#define EXCHANGE_DATABASE_INSERT_SIGNKEY_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Add signing key.
+ *
+ * @param pg the database context
+ * @param exchange_pub the exchange online signing public key
+ * @param meta meta data about @a exchange_pub
+ * @param master_sig master signature to add
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_signkey (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct TALER_ExchangePublicKeyP *
+ exchange_pub,
+ const struct
+ TALER_EXCHANGEDB_SignkeyMetaData *
+ meta,
+ const struct TALER_MasterSignatureP *
+ master_sig
+ );
+
+#endif
diff --git a/src/include/exchange-database/insert_wad_in.h b/src/include/exchange-database/insert_wad_in.h
@@ -0,0 +1,52 @@
+/*
+ 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/exchange-database/insert_wad_in.h
+ * @brief implementation of the insert_wad_in function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_WAD_IN_H
+#define EXCHANGE_DATABASE_INSERT_WAD_IN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Insert an incoming WAD wire transfer into the database.
+ *
+ * @param pg the database context
+ * @param wad_id WAD identifier
+ * @param origin_exchange_url exchange base URL originating the transfer
+ * @param amount the amount that was transferred
+ * @param execution_date when was the transfer made
+ * @param debit_account_uri URI of the debit account
+ * @param section_name section of the exchange bank account that received the transfer
+ * @param serial_id bank-specific row identifying the transfer
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_wad_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_WadIdentifierP *wad_id,
+ const char *origin_exchange_url,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_FullPayto debit_account_uri,
+ const char *section_name,
+ uint64_t serial_id);
+
+
+#endif
diff --git a/src/include/exchange-database/insert_wire_fee.h b/src/include/exchange-database/insert_wire_fee.h
@@ -37,13 +37,13 @@
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_insert_wire_fee (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *type,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_WireFeeSet *fees,
- const struct TALER_MasterSignatureP *
- master_sig);
+TALER_EXCHANGEDB_insert_wire_fee (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *type,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_WireFeeSet *fees,
+ const struct TALER_MasterSignatureP *
+ master_sig);
#endif
diff --git a/src/include/exchange-database/insert_wire_out.h b/src/include/exchange-database/insert_wire_out.h
@@ -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/include/exchange-database/insert_wire_out.h
+ * @brief implementation of the insert_wire_out function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_INSERT_WIRE_OUT_H
+#define EXCHANGE_DATABASE_INSERT_WIRE_OUT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Store information about an outgoing wire transfer that was executed.
+ *
+ * @param pg the database context
+ * @param date time of the wire transfer
+ * @param wtid subject of the wire transfer
+ * @param h_payto identifies the receiver account of the wire transfer
+ * @param exchange_account_section configuration section of the exchange specifying the
+ * exchange's bank account being used
+ * @param amount amount that was transmitted
+ * @param extra_wire_subject_metadata additional meta data for the wire transfer subject, can be NULL
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_insert_wire_out (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ struct GNUNET_TIME_Timestamp date,
+ const struct
+ TALER_WireTransferIdentifierRawP *wtid
+ ,
+ const struct TALER_FullPaytoHashP *
+ h_payto,
+ const char *exchange_account_section,
+ const struct TALER_Amount *amount,
+ const char *
+ extra_wire_subject_metadata);
+
+#endif
diff --git a/src/include/exchange-database/iterate_account_merges_above_serial_id.h b/src/include/exchange-database/iterate_account_merges_above_serial_id.h
@@ -0,0 +1,89 @@
+/*
+ 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 iterate_account_merges_above_serial_id.h
+ * @brief implementation of the iterate_account_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_ACCOUNT_MERGES_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_ACCOUNT_MERGES_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Function called with details about
+ * account merge requests that have been made, with
+ * the goal of auditing the account merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param reserve_pub reserve affected by the merge
+ * @param purse_pub purse being merged
+ * @param h_contract_terms hash over contract of the purse
+ * @param purse_expiration when would the purse expire
+ * @param amount total amount in the purse
+ * @param min_age minimum age of all coins deposited into the purse
+ * @param flags how was the purse created
+ * @param purse_fee if a purse fee was paid, how high is it
+ * @param merge_timestamp when was the merge approved
+ * @param reserve_sig signature by reserve approving the merge
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AccountMergeCallback.
+ */
+#define TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_AccountMergeCallback)(
+ TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_Amount *amount,
+ uint32_t min_age,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+/**
+ * Select account merges above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_account_merges_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AccountMergeCallback
+ cb,
+ TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_aggregation_amounts_for_kyc_check.h b/src/include/exchange-database/iterate_aggregation_amounts_for_kyc_check.h
@@ -0,0 +1,48 @@
+/*
+ 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/exchange-database/iterate_aggregation_amounts_for_kyc_check.h
+ * @brief implementation of the iterate_aggregation_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AGGREGATION_AMOUNTS_FOR_KYC_CHECK_H
+#define EXCHANGE_DATABASE_ITERATE_AGGREGATION_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Call @a kac on deposited amounts after @a time_limit which are relevant for a
+ * KYC trigger for a the (credited) account identified by @a h_payto.
+ *
+ * @param pg the database context
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aggregation_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_aggregations_above_serial_id.h b/src/include/exchange-database/iterate_aggregations_above_serial_id.h
@@ -0,0 +1,92 @@
+/*
+ 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/exchange-database/iterate_aggregations_above_serial_id.h
+ * @brief implementation of the iterate_aggregations_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AGGREGATIONS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_AGGREGATIONS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called on aggregations that were done for
+ * a (batch) deposit.
+ *
+ * @param cls closure
+ * @param amount affected amount
+ * @param tracking_serial_id where in the table are we
+ * @param batch_deposit_serial_id which batch deposit was aggregated
+ */
+#ifndef TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AggregationCallback.
+ */
+#define TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AggregationCallback)(
+ TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE *cls,
+ const struct TALER_Amount *amount,
+ uint64_t tracking_serial_id,
+ uint64_t batch_deposit_serial_id);
+
+
+/* Callback typedefs */
+/**
+ * Function called on aggregations that were done for
+ * a (batch) deposit.
+ *
+ * @param cls closure
+ * @param amount affected amount
+ * @param tracking_serial_id where in the table are we
+ * @param batch_deposit_serial_id which batch deposit was aggregated
+ */
+typedef void
+(*TALER_EXCHANGEDB_AggregationCallback)(
+ TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE *cls,
+ const struct TALER_Amount *amount,
+ uint64_t tracking_serial_id,
+ uint64_t batch_deposit_serial_id);
+
+/**
+ * Select all aggregation tracking IDs in the database
+ * above a given @a min_tracking_serial_id.
+ *
+ * @param pg the database context
+ * @param min_tracking_serial_id only return entries strictly above this row (and in order)
+ * @param cb function to call on all such aggregations
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aggregations_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t
+ min_tracking_serial_id,
+ TALER_EXCHANGEDB_AggregationCallback
+ cb,
+ TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_all_kyc_attributes.h b/src/include/exchange-database/iterate_all_kyc_attributes.h
@@ -0,0 +1,109 @@
+/*
+ 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/exchange-database/iterate_all_kyc_attributes.h
+ * @brief implementation of the iterate_all_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_ALL_KYC_ATTRIBUTES_H
+#define EXCHANGE_DATABASE_ITERATE_ALL_KYC_ATTRIBUTES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Return KYC attribute information.
+ *
+ * @param cls closure
+ * @param row_id current row in kyc_attributes table
+ * @param h_payto account the attributes are about
+ * @param provider_name name of the provider that collected the attributes
+ * @param collection_time when were the attributes collected
+ * @param expiration_time when does the data expire
+ * @param properties properties that were set for @a h_payto
+ * @param enc_attributes_size size of @a enc_attributes
+ * @param enc_attributes the encrypted collected attributes
+ * @return true to continue to iterate
+ */
+#ifndef TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AllAttributesCallback.
+ */
+#define TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE void
+#endif
+typedef bool
+(*TALER_EXCHANGEDB_AllAttributesCallback)(
+ TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_name,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ const json_t *properties,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+
+/* Callback typedefs */
+/**
+ * Return KYC attribute information.
+ *
+ * @param cls closure
+ * @param row_id current row in kyc_attributes table
+ * @param h_payto account the attributes are about
+ * @param provider_name name of the provider that collected the attributes
+ * @param collection_time when were the attributes collected
+ * @param expiration_time when does the data expire
+ * @param properties properties that were set for @a h_payto
+ * @param enc_attributes_size size of @a enc_attributes
+ * @param enc_attributes the encrypted collected attributes
+ * @return true to continue to iterate
+ */
+typedef bool
+(*TALER_EXCHANGEDB_AllAttributesCallback)(
+ TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_name,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ const json_t *properties,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+/**
+ * Lookup all KYC attributes above @a min_row_id.
+ *
+ * @param pg the database context
+ * @param min_row_id minimum row ID to return (exclusive)
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_all_kyc_attributes (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg
+ ,
+ uint64_t min_row_id,
+ TALER_EXCHANGEDB_AllAttributesCallback
+ cb,
+ TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_all_purse_decisions_above_serial_id.h b/src/include/exchange-database/iterate_all_purse_decisions_above_serial_id.h
@@ -0,0 +1,93 @@
+/*
+ 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 iterate_all_purse_decisions_above_serial_id.h
+ * @brief implementation of the iterate_all_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_ALL_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_ALL_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about purse decisions that have been made, with
+ * the goal of auditing the purse's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub public key of the purse
+ * @param refunded true if decision was to refund
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AllPurseDecisionCallback.
+ */
+#define TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_AllPurseDecisionCallback)(
+ TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ bool refunded);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about purse decisions that have been made, with
+ * the goal of auditing the purse's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub public key of the purse
+ * @param refunded true if decision was to refund
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_AllPurseDecisionCallback)(
+ TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ bool refunded);
+
+/**
+ * Select purse decisions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_all_purse_decisions_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t serial_id
+ ,
+ TALER_EXCHANGEDB_AllPurseDecisionCallback
+ cb,
+ TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_all_purse_deletions_above_serial_id.h b/src/include/exchange-database/iterate_all_purse_deletions_above_serial_id.h
@@ -0,0 +1,92 @@
+/*
+ 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/exchange-database/iterate_all_purse_deletions_above_serial_id.h
+ * @brief implementation of the iterate_all_purse_deletions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_ALL_PURSE_DELETIONS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_ALL_PURSE_DELETIONS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about purse deletions that have been made, with
+ * the goal of auditing the purse's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub public key of the purse
+ * @param purse_sig signature affirming deletion of the purse
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AllPurseDeletionsCallback.
+ */
+#define TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_AllPurseDeletionsCallback)(
+ TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about purse deletions that have been made, with
+ * the goal of auditing the purse's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub public key of the purse
+ * @param purse_sig signature affirming deletion of the purse
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_AllPurseDeletionsCallback)(
+ TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig);
+
+/**
+ * Select all purse deletions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_all_purse_deletions_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t serial_id
+ ,
+ TALER_EXCHANGEDB_AllPurseDeletionsCallback
+ cb,
+ TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_aml_attributes.h b/src/include/exchange-database/iterate_aml_attributes.h
@@ -0,0 +1,106 @@
+/*
+ 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/exchange-database/iterate_aml_attributes.h
+ * @brief implementation of the iterate_aml_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AML_ATTRIBUTES_H
+#define EXCHANGE_DATABASE_ITERATE_AML_ATTRIBUTES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Return AML attribute information.
+ *
+ * @param cls closure
+ * @param row_id current row in kyc_attributes table
+ * @param collection_time when were the attributes collected
+ * @param by_aml_officer true if the data was filed by an AML officer
+ * @param officer_name name of the officer, NULL if not @a by_aml_officer
+ * @param enc_attributes_size size of @a enc_attributes
+ * @param enc_attributes the encrypted collected attributes
+ */
+#ifndef TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlAttributeCallback.
+ */
+#define TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlAttributeCallback)(
+ TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ struct GNUNET_TIME_Timestamp collection_time,
+ bool by_aml_officer,
+ const char *officer_name,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+
+/* Callback typedefs */
+/**
+ * Return AML attribute information.
+ *
+ * @param cls closure
+ * @param row_id current row in kyc_attributes table
+ * @param collection_time when were the attributes collected
+ * @param by_aml_officer true if the data was filed by an AML officer
+ * @param officer_name name of the officer, NULL if not @a by_aml_officer
+ * @param enc_attributes_size size of @a enc_attributes
+ * @param enc_attributes the encrypted collected attributes
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlAttributeCallback)(
+ TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ struct GNUNET_TIME_Timestamp collection_time,
+ bool by_aml_officer,
+ const char *officer_name,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+/**
+ * Lookup AML attributes of a particular account.
+ *
+ * @param pg the database context
+ * @param h_payto which account should we return attributes for
+ * @param offset row to start from
+ * @param limit how many records to return (negative
+ * to go back in time, positive to go forward)
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_attributes (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlAttributeCallback
+ cb
+ ,
+ TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_aml_decisions.h b/src/include/exchange-database/iterate_aml_decisions.h
@@ -0,0 +1,133 @@
+/*
+ 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/exchange-database/iterate_aml_decisions.h
+ * @brief implementation of the iterate_aml_decisions function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AML_DECISIONS_H
+#define EXCHANGE_DATABASE_ITERATE_AML_DECISIONS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Return AML decision information.
+ *
+ * @param cls closure
+ * @param row_id current row in legitimization outcomes table
+ * @param justification human-readable reason for the decision, NULL if none is available
+ * @param h_payto account for which the attribute data is stored
+ * @param decision_time when was the decision taken
+ * @param expiration_time when will the rules expire
+ * @param jproperties properties set for the account,
+ * NULL if no properties were set
+ * @param to_investigate true if AML staff should look at the account
+ * @param is_active true if this is the currently active decision about the account
+ * @param is_wallet true if the @a h_payto is for a Taler wallet
+ * @param payto payto URI of the account the decision is about
+ * @param account_rules current active rules for the account
+ */
+#ifndef TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlDecisionCallback.
+ */
+#define TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlDecisionCallback)(
+ TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const char *justification,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp decision_time,
+ struct GNUNET_TIME_Absolute expiration_time,
+ const json_t *jproperties,
+ bool to_investigate,
+ bool is_active,
+ bool is_wallet,
+ struct TALER_FullPayto payto,
+ const json_t *account_rules);
+
+
+/* Callback typedefs */
+/**
+ * Return AML decision information.
+ *
+ * @param cls closure
+ * @param row_id current row in legitimization outcomes table
+ * @param justification human-readable reason for the decision, NULL if none is available
+ * @param h_payto account for which the attribute data is stored
+ * @param decision_time when was the decision taken
+ * @param expiration_time when will the rules expire
+ * @param jproperties properties set for the account,
+ * NULL if no properties were set
+ * @param to_investigate true if AML staff should look at the account
+ * @param is_active true if this is the currently active decision about the account
+ * @param is_wallet true if the @a h_payto is for a Taler wallet
+ * @param payto payto URI of the account the decision is about
+ * @param account_rules current active rules for the account
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlDecisionCallback)(
+ TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const char *justification,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp decision_time,
+ struct GNUNET_TIME_Absolute expiration_time,
+ const json_t *jproperties,
+ bool to_investigate,
+ bool is_active,
+ bool is_wallet,
+ struct TALER_FullPayto payto,
+ const json_t *account_rules);
+
+/**
+ * Lookup AML decisions that have a particular state.
+ *
+ * @param pg the database context
+ * @param h_payto which account should we return the AML decision history for, NULL to return all accounts
+ * @param investigation_only filter by investigation state
+ * @param active_only filter for only active states
+ * @param offset row to start from
+ * @param limit how many records to return (negative
+ * to go back in time, positive to go forward)
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_decisions (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ enum TALER_EXCHANGE_YesNoAll
+ investigation_only
+ ,
+ enum TALER_EXCHANGE_YesNoAll active_only
+ ,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlDecisionCallback cb,
+ TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_aml_history.h b/src/include/exchange-database/iterate_aml_history.h
@@ -0,0 +1,116 @@
+/*
+ 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/exchange-database/iterate_aml_history.h
+ * @brief implementation of the iterate_aml_history function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AML_HISTORY_H
+#define EXCHANGE_DATABASE_ITERATE_AML_HISTORY_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with historic AML events of an
+ * account.
+ *
+ * @param cls closure
+ * @param outcome_serial_id row ID of the decision
+ * @param decision_time when was the decision taken
+ * @param justification what was the given justification
+ * @param decider_pub which key signed the decision
+ * @param jproperties what are the new account properties
+ * @param jnew_rules what are the new account rules
+ * @param to_investigate should AML staff investigate
+ * after the decision
+ * @param is_active is this the active decision
+ */
+#ifndef TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlHistoryCallback.
+ */
+#define TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlHistoryCallback) (
+ TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE *cls,
+ uint64_t outcome_serial_id,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const json_t *jproperties,
+ const json_t *jnew_rules,
+ bool to_investigate,
+ bool is_active);
+
+
+/* Callback typedefs */
+/**
+ * Function called with historic AML events of an
+ * account.
+ *
+ * @param cls closure
+ * @param outcome_serial_id row ID of the decision
+ * @param decision_time when was the decision taken
+ * @param justification what was the given justification
+ * @param decider_pub which key signed the decision
+ * @param jproperties what are the new account properties
+ * @param jnew_rules what are the new account rules
+ * @param to_investigate should AML staff investigate
+ * after the decision
+ * @param is_active is this the active decision
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlHistoryCallback) (
+ TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE *cls,
+ uint64_t outcome_serial_id,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const json_t *jproperties,
+ const json_t *jnew_rules,
+ bool to_investigate,
+ bool is_active);
+
+/**
+ * Lookup AML history for an account identified via
+ * @a h_payto.
+ *
+ * @param pg the database context
+ * @param h_payto hash of account to lookup history for
+ * @param offset row ID to start returning results from
+ * @param limit how many results to return, negative for descending order
+ * @param cb function to call on results
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_history (struct TALER_EXCHANGEDB_PostgresContext *
+ pg
+ ,
+ const struct TALER_NormalizedPaytoHashP *
+ h_payto,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlHistoryCallback cb,
+ TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_aml_measures.h b/src/include/exchange-database/iterate_aml_measures.h
@@ -0,0 +1,103 @@
+/*
+ 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/exchange-database/iterate_aml_measures.h
+ * @brief implementation of the iterate_aml_measures function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AML_MEASURES_H
+#define EXCHANGE_DATABASE_ITERATE_AML_MEASURES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with legitimization measures.
+ *
+ * @param cls closure
+ * @param h_payto hash of account the measure applies to
+ * @param start_time when was the process started
+ * @param jmeasures object of type ``LegitimizationMeasures``
+ * @param is_finished true if the measure was finished
+ * @param measure_serial_id row ID of the measure in the exchange table
+ */
+#ifndef TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_LegitimizationMeasureCallback.
+ */
+#define TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
+ TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE *cls,
+ struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute start_time,
+ const json_t *jmeasures,
+ bool is_finished,
+ uint64_t measure_serial_id);
+
+
+/* Callback typedefs */
+/**
+ * Function called with legitimization measures.
+ *
+ * @param cls closure
+ * @param h_payto hash of account the measure applies to
+ * @param start_time when was the process started
+ * @param jmeasures object of type ``LegitimizationMeasures``
+ * @param is_finished true if the measure was finished
+ * @param measure_serial_id row ID of the measure in the exchange table
+ */
+typedef void
+(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
+ TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE *cls,
+ struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute start_time,
+ const json_t *jmeasures,
+ bool is_finished,
+ uint64_t measure_serial_id);
+
+/**
+ * Lookup legitimization measures.
+ *
+ * @param pg the database context
+ * @param h_payto account for which the attribute data is stored,
+ * NULL to select for all accounts
+ * @param active_only select only measures that are active
+ * @param offset row offset to select from
+ * @param limit number of results to return, negative to
+ * return in descending order from @a offset
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_measures (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct TALER_NormalizedPaytoHashP *
+ h_payto
+ ,
+ enum TALER_EXCHANGE_YesNoAll active_only,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_LegitimizationMeasureCallback
+ cb,
+ TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_aml_statistics.h b/src/include/exchange-database/iterate_aml_statistics.h
@@ -0,0 +1,89 @@
+/*
+ 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/exchange-database/iterate_aml_statistics.h
+ * @brief implementation of the iterate_aml_statistics function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_AML_STATISTICS_H
+#define EXCHANGE_DATABASE_ITERATE_AML_STATISTICS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with AML statistics (counters).
+ *
+ * @param cls closure
+ * @param name name of the counter
+ * @param cnt number of events for @a name in the query range
+ */
+#ifndef TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlStatisticsCallback.
+ */
+#define TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlStatisticsCallback)(
+ TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE *cls,
+ const char *name,
+ uint64_t cnt);
+
+
+/* Callback typedefs */
+/**
+ * Function called with AML statistics (counters).
+ *
+ * @param cls closure
+ * @param name name of the counter
+ * @param cnt number of events for @a name in the query range
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlStatisticsCallback)(
+ TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE *cls,
+ const char *name,
+ uint64_t cnt);
+
+/**
+ * Obtain the AML statistics for a given set of @a names and
+ * timeframe.
+ *
+ * @param pg the database context
+ * @param num_names length of the @e names array
+ * @param names array of names of the statistics to fetch
+ * @param start_date start of time range
+ * @param end_date end of time range
+ * @param cb function to call on each statistic
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_aml_statistics (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ size_t num_names,
+ const char *names[static num_names],
+ struct GNUNET_TIME_Timestamp start_date
+ ,
+ struct GNUNET_TIME_Timestamp end_date,
+ TALER_EXCHANGEDB_AmlStatisticsCallback
+ cb,
+ TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_batch_deposits_missing_wire.h b/src/include/exchange-database/iterate_batch_deposits_missing_wire.h
@@ -0,0 +1,94 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-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/exchange-database/iterate_batch_deposits_missing_wire.h
+ * @brief implementation of the iterate_batch_deposits_missing_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_BATCH_DEPOSITS_MISSING_WIRE_H
+#define EXCHANGE_DATABASE_ITERATE_BATCH_DEPOSITS_MISSING_WIRE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called on (batch) deposits will need a wire
+ * transfer.
+ *
+ * @param cls closure
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
+ */
+#ifndef TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_WireMissingCallback.
+ */
+#define TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_WireMissingCallback)(
+ TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_FullPaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline);
+
+
+/* Callback typedefs */
+/**
+ * Function called on (batch) deposits will need a wire
+ * transfer.
+ *
+ * @param cls closure
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
+ */
+typedef void
+(*TALER_EXCHANGEDB_WireMissingCallback)(
+ TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_FullPaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline);
+
+/**
+ * Select all of those batch deposits in the database
+ * above the given serial ID.
+ *
+ * @param pg the database context
+ * @param min_batch_deposit_serial_id select all batch deposits above this ID
+ * @param cb function to call on all such deposits
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_batch_deposits_missing_wire (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t
+ min_batch_deposit_serial_id,
+ TALER_EXCHANGEDB_WireMissingCallback
+ cb,
+ TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_coin_deposits_above_serial_id.h b/src/include/exchange-database/iterate_coin_deposits_above_serial_id.h
@@ -0,0 +1,100 @@
+/*
+ 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/exchange-database/iterate_coin_deposits_above_serial_id.h
+ * @brief implementation of the iterate_coin_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_COIN_DEPOSITS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_COIN_DEPOSITS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about deposits that have been made,
+ * with the goal of auditing the deposit's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param exchange_timestamp when did the deposit happen
+ * @param deposit deposit details
+ * @param denom_pub denomination public key of @a coin_pub
+ * @param done flag set if the deposit was already executed (or not)
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_DepositCallback.
+ */
+#define TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_DepositCallback)(
+ TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp exchange_timestamp,
+ const struct TALER_EXCHANGEDB_Deposit *deposit,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ bool done);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about deposits that have been made,
+ * with the goal of auditing the deposit's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param exchange_timestamp when did the deposit happen
+ * @param deposit deposit details
+ * @param denom_pub denomination public key of @a coin_pub
+ * @param done flag set if the deposit was already executed (or not)
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_DepositCallback)(
+ TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp exchange_timestamp,
+ const struct TALER_EXCHANGEDB_Deposit *deposit,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ bool done);
+
+/**
+ * Select deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_coin_deposits_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_DepositCallback
+ cb,
+ TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_deposit_amounts_for_kyc_check.h b/src/include/exchange-database/iterate_deposit_amounts_for_kyc_check.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU 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/exchange-database/iterate_deposit_amounts_for_kyc_check.h
+ * @brief implementation of the iterate_deposit_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_DEPOSIT_AMOUNTS_FOR_KYC_CHECK_H
+#define EXCHANGE_DATABASE_ITERATE_DEPOSIT_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Call @a kac on deposited amounts after @a time_limit which are relevant for a
+ * KYC trigger for a merchant identified by @a h_payto.
+ *
+ * @param pg the database context
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount,
+ * in reverse chronological order (or until @a kac aborts
+ * by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_deposit_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_exchange_credit_transfers.h b/src/include/exchange-database/iterate_exchange_credit_transfers.h
@@ -0,0 +1,51 @@
+/*
+ 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/exchange-database/iterate_exchange_credit_transfers.h
+ * @brief implementation of the iterate_exchange_credit_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_EXCHANGE_CREDIT_TRANSFERS_H
+#define EXCHANGE_DATABASE_ITERATE_EXCHANGE_CREDIT_TRANSFERS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Return AML-relevant wire transfer credit data.
+ *
+ * @param pg the database context
+ * @param threshold minimum wire amount to return data for
+ * @param offset offset in table to filter by
+ * @param limit maximum number of entries to return, negative for descending
+ * @param h_payto account to filter transfer data by
+ * @param cb function to call on each result
+ * @param cb_cls closure to pass to @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_exchange_credit_transfers (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_exchange_debit_transfers.h b/src/include/exchange-database/iterate_exchange_debit_transfers.h
@@ -0,0 +1,76 @@
+/*
+ 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/exchange-database/iterate_exchange_debit_transfers.h
+ * @brief implementation of the iterate_exchange_debit_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_EXCHANGE_DEBIT_TRANSFERS_H
+#define EXCHANGE_DATABASE_ITERATE_EXCHANGE_DEBIT_TRANSFERS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Callback that is given AML-relevant transfer data.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param payto_uri account involved with the wire transfer
+ * @param execution_time when was the transfer made
+ * @param amount wire amount of the transfer
+ */
+#ifndef TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlTransferCallback.
+ */
+#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlTransferCallback)(
+ TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const char *payto_uri,
+ struct GNUNET_TIME_Absolute execution_time,
+ const struct TALER_Amount *amount);
+
+
+/**
+ * Return AML-relevant wire transfer debit data.
+ *
+ * @param pg the database context
+ * @param threshold minimum wire amount to return data for
+ * @param offset offset in table to filter by
+ * @param limit maximum number of entries to return, negative for descending
+ * @param h_payto account to filter transfer data by
+ * @param cb function to call on each result
+ * @param cb_cls closure to pass to @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_exchange_debit_transfers (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_exchange_kycauth_transfers.h b/src/include/exchange-database/iterate_exchange_kycauth_transfers.h
@@ -0,0 +1,82 @@
+/*
+ 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/exchange-database/iterate_exchange_kycauth_transfers.h
+ * @brief implementation of the iterate_exchange_kycauth_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_EXCHANGE_KYCAUTH_TRANSFERS_H
+#define EXCHANGE_DATABASE_ITERATE_EXCHANGE_KYCAUTH_TRANSFERS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Callback that is given AML-relevant transfer data.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param payto_uri account involved with the wire transfer
+ * @param execution_time when was the transfer made
+ * @param amount wire amount of the transfer
+ */
+#ifndef TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlTransferCallback.
+ */
+#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlTransferCallback)(
+ TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const char *payto_uri,
+ struct GNUNET_TIME_Absolute execution_time,
+ const struct TALER_Amount *amount);
+
+/**
+ * Return wire transfer kycauth data.
+ *
+ * @param pg the database context
+ * @param threshold minimum wire amount to return data for
+ * @param offset offset in table to filter by
+ * @param limit maximum number of entries to return, negative for descending
+ * @param h_payto account to filter transfer data by
+ * @param cb function to call on each result
+ * @param cb_cls closure to pass to @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_exchange_kycauth_transfers (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const struct TALER_Amount *
+ threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback
+ cb,
+ TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_expired_reserves.h b/src/include/exchange-database/iterate_expired_reserves.h
@@ -0,0 +1,79 @@
+/*
+ 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 iterate_expired_reserves.h
+ * @brief implementation of the get_expired_reserves function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_EXPIRED_RESERVES_H
+#define EXCHANGE_DATABASE_ITERATE_EXPIRED_RESERVES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about expired reserves.
+ *
+ * @param cls closure
+ * @param reserve_pub public key of the reserve
+ * @param left amount left in the reserve
+ * @param account_details information about the reserve's bank account, in payto://-format
+ * @param expiration_date when did the reserve expire
+ * @param close_request_row row that caused the reserve
+ * to be closed, 0 if it expired without request
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO to retry
+ * #GNUNET_SYSERR on hard failures (exit)
+ */
+#ifndef TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReserveExpiredCallback.
+ */
+#define TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveExpiredCallback)(
+ TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *left,
+ const struct TALER_FullPayto account_details,
+ struct GNUNET_TIME_Timestamp expiration_date,
+ uint64_t close_request_row);
+
+/**
+ * Obtain information about expired reserves and their
+ * remaining balances.
+ *
+ * @param pg the database context
+ * @param now timestamp based on which we decide expiration
+ * @param rec function to call on expired reserves
+ * @param rec_cls closure for @a rec
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_expired_reserves (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ struct GNUNET_TIME_Timestamp now,
+ TALER_EXCHANGEDB_ReserveExpiredCallback
+ rec,
+ TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
+ *rec_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_global_fees.h b/src/include/exchange-database/iterate_global_fees.h
@@ -0,0 +1,100 @@
+/*
+ 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/exchange-database/iterate_global_fees.h
+ * @brief implementation of the iterate_global_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_GLOBAL_FEES_H
+#define EXCHANGE_DATABASE_ITERATE_GLOBAL_FEES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Provide information about global fees.
+ *
+ * @param cls closure
+ * @param fees the global fees we charge
+ * @param purse_timeout when do purses time out
+ * @param history_expiration how long are account histories preserved
+ * @param purse_account_limit how many purses are free per account
+ * @param start_date from when are these fees valid (start date)
+ * @param end_date until when are these fees valid (end date, exclusive)
+ * @param master_sig master key signature affirming that this is the correct
+ * fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES)
+ */
+#ifndef TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_GlobalFeeCallback.
+ */
+#define TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_GlobalFeeCallback)(
+ TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE *cls,
+ const struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative purse_timeout,
+ struct GNUNET_TIME_Relative history_expiration,
+ uint32_t purse_account_limit,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_MasterSignatureP *master_sig);
+
+
+/* Callback typedefs */
+/**
+ * Provide information about global fees.
+ *
+ * @param cls closure
+ * @param fees the global fees we charge
+ * @param purse_timeout when do purses time out
+ * @param history_expiration how long are account histories preserved
+ * @param purse_account_limit how many purses are free per account
+ * @param start_date from when are these fees valid (start date)
+ * @param end_date until when are these fees valid (end date, exclusive)
+ * @param master_sig master key signature affirming that this is the correct
+ * fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES)
+ */
+typedef void
+(*TALER_EXCHANGEDB_GlobalFeeCallback)(
+ TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE *cls,
+ const struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative purse_timeout,
+ struct GNUNET_TIME_Relative history_expiration,
+ uint32_t purse_account_limit,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_MasterSignatureP *master_sig);
+
+/**
+ * Obtain global fees from database.
+ *
+ * @param pg the database context
+ * @param cb function to call on each fee entry
+ * @param cb_cls closure for @a cb
+ * @return status of the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_global_fees (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ TALER_EXCHANGEDB_GlobalFeeCallback cb,
+ TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_kyc_accounts.h b/src/include/exchange-database/iterate_kyc_accounts.h
@@ -0,0 +1,122 @@
+/*
+ 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/exchange-database/iterate_kyc_accounts.h
+ * @brief implementation of the iterate_kyc_accounts function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_KYC_ACCOUNTS_H
+#define EXCHANGE_DATABASE_ITERATE_KYC_ACCOUNTS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Return account summary information.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param h_payto account for which the attribute data is stored
+ * @param open_time when was the account opened formally,
+ * GNUNET_TIME_UNIT_FOREVER_TS if it was never opened
+ * @param close_time when was the account formally closed,
+ * GNUNET_TIME_UNIT_ZERO_TS if it was never closed
+ * @param comments comments on the account
+ * @param high_risk is this a high-risk business relationship
+ * @param to_investigate TRUE if this account should be investigated
+ * @param payto the payto URI of the account
+ */
+#ifndef TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlAccountListCallback.
+ */
+#define TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlAccountListCallback)(
+ TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp open_time,
+ struct GNUNET_TIME_Timestamp close_time,
+ const char *comments,
+ bool high_risk,
+ bool to_investigate,
+ struct TALER_FullPayto payto);
+
+
+/* Callback typedefs */
+/**
+ * Return account summary information.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param h_payto account for which the attribute data is stored
+ * @param open_time when was the account opened formally,
+ * GNUNET_TIME_UNIT_FOREVER_TS if it was never opened
+ * @param close_time when was the account formally closed,
+ * GNUNET_TIME_UNIT_ZERO_TS if it was never closed
+ * @param comments comments on the account
+ * @param high_risk is this a high-risk business relationship
+ * @param to_investigate TRUE if this account should be investigated
+ * @param payto the payto URI of the account
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlAccountListCallback)(
+ TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp open_time,
+ struct GNUNET_TIME_Timestamp close_time,
+ const char *comments,
+ bool high_risk,
+ bool to_investigate,
+ struct TALER_FullPayto payto);
+
+/**
+ * List accounts managed by the exchange (for AML/KYC).
+ *
+ * @param pg the database context
+ * @param investigation_only filter by investigation state
+ * @param open_only filter for only open accounts
+ * @param high_risk_only filter for only high-risk accounts
+ * @param offset row to start from
+ * @param limit how many records to return (negative
+ * to go back in time, positive to go forward)
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_accounts (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ enum TALER_EXCHANGE_YesNoAll
+ investigation_only,
+ enum TALER_EXCHANGE_YesNoAll open_only,
+ enum TALER_EXCHANGE_YesNoAll
+ high_risk_only,
+ uint64_t offset,
+ int64_t limit,
+ TALER_EXCHANGEDB_AmlAccountListCallback
+ cb
+ ,
+ TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_kyc_attributes.h b/src/include/exchange-database/iterate_kyc_attributes.h
@@ -0,0 +1,98 @@
+/*
+ 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/exchange-database/iterate_kyc_attributes.h
+ * @brief implementation of the iterate_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_KYC_ATTRIBUTES_H
+#define EXCHANGE_DATABASE_ITERATE_KYC_ATTRIBUTES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Callback with KYC attributes about a particular user.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_name provider that must be checked
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ */
+#ifndef TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AttributeCallback.
+ */
+#define TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AttributeCallback)(
+ TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE *cls,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_name,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+
+/* Callback typedefs */
+/**
+ * Callback with KYC attributes about a particular user.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_name provider that must be checked
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ */
+typedef void
+(*TALER_EXCHANGEDB_AttributeCallback)(
+ TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE *cls,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ const char *provider_name,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+/**
+ * Lookup KYC attribute data for a specific account.
+ *
+ * @param pg the database context
+ * @param h_payto account for which the attribute data is stored
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_attributes (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_kyc_history.h b/src/include/exchange-database/iterate_kyc_history.h
@@ -0,0 +1,123 @@
+/*
+ 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/exchange-database/iterate_kyc_history.h
+ * @brief implementation of the iterate_kyc_history function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_KYC_HISTORY_H
+#define EXCHANGE_DATABASE_ITERATE_KYC_HISTORY_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with historic KYC events of an
+ * account.
+ *
+ * @param cls closure
+ * @param provider_name name of the KYC provider
+ * @param finished did the KYC process finish
+ * @param error_code error code from the KYC process
+ * @param error_message error message from the KYC process,
+ * or NULL for none
+ * @param provider_user_id user ID at the provider
+ * or NULL for none
+ * @param provider_legitimization_id legitimization process ID at the provider
+ * or NULL for none
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the collected data expire
+ * @param encrypted_attributes_len number of bytes in @a encrypted_attributes
+ * @param encrypted_attributes encrypted KYC attributes
+ */
+#ifndef TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_KycHistoryCallback.
+ */
+#define TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_KycHistoryCallback) (
+ TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE *cls,
+ const char *provider_name,
+ bool finished,
+ enum TALER_ErrorCode error_code,
+ const char *error_message,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Absolute expiration_time,
+ size_t encrypted_attributes_len,
+ const void *encrypted_attributes);
+
+
+/* Callback typedefs */
+/**
+ * Function called with historic KYC events of an
+ * account.
+ *
+ * @param cls closure
+ * @param provider_name name of the KYC provider
+ * @param finished did the KYC process finish
+ * @param error_code error code from the KYC process
+ * @param error_message error message from the KYC process,
+ * or NULL for none
+ * @param provider_user_id user ID at the provider
+ * or NULL for none
+ * @param provider_legitimization_id legitimization process ID at the provider
+ * or NULL for none
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the collected data expire
+ * @param encrypted_attributes_len number of bytes in @a encrypted_attributes
+ * @param encrypted_attributes encrypted KYC attributes
+ */
+typedef void
+(*TALER_EXCHANGEDB_KycHistoryCallback) (
+ TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE *cls,
+ const char *provider_name,
+ bool finished,
+ enum TALER_ErrorCode error_code,
+ const char *error_message,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Absolute expiration_time,
+ size_t encrypted_attributes_len,
+ const void *encrypted_attributes);
+
+/**
+ * Lookup KYC history for an account identified via
+ * @a h_payto.
+ *
+ * @param pg the database context
+ * @param h_payto hash of account to lookup history for
+ * @param cb function to call on results
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_history (struct TALER_EXCHANGEDB_PostgresContext *
+ pg
+ ,
+ const struct TALER_NormalizedPaytoHashP *
+ h_payto,
+ TALER_EXCHANGEDB_KycHistoryCallback cb,
+ TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_kyc_reference.h b/src/include/exchange-database/iterate_kyc_reference.h
@@ -1,94 +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 iterate_kyc_reference.h
- * @brief implementation of the iterate_kyc_reference function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_ITERATE_KYC_REFERENCE_H
-#define EXCHANGE_DATABASE_ITERATE_KYC_REFERENCE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called on all legitimization operations
- * we have performed for the given account so far
- * (and that have not yet expired).
- *
- * @param cls closure
- * @param kyc_provider_name name of the provider
- * of the respective KYC process
- * @param provider_user_id UID at a provider (can be NULL)
- * @param legi_id legitimization process ID (can be NULL)
- */
-#ifndef TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_LegitimizationProcessCallback.
- */
-#define TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_LegitimizationProcessCallback)(
- TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE *cls,
- const char *kyc_provider_name,
- const char *provider_user_id,
- const char *legi_id);
-
-
-/* Callback typedefs */
-/**
- * Function called on all legitimization operations
- * we have performed for the given account so far
- * (and that have not yet expired).
- *
- * @param cls closure
- * @param kyc_provider_name name of the provider
- * of the respective KYC process
- * @param provider_user_id UID at a provider (can be NULL)
- * @param legi_id legitimization process ID (can be NULL)
- */
-typedef void
-(*TALER_EXCHANGEDB_LegitimizationProcessCallback)(
- TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE *cls,
- const char *kyc_provider_name,
- const char *provider_user_id,
- const char *legi_id);
-
-/**
- * Call us on KYC legitimization processes satisfied and not expired for the
- * given account.
- *
- * @param pg the database context
- * @param h_payto account identifier
- * @param lpc function to call for each satisfied KYC legitimization process
- * @param lpc_cls closure for @a lpc
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_iterate_kyc_reference (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- TALER_EXCHANGEDB_LegitimizationProcessCallback
- lpc,
- TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE
- *lpc_cls);
-
-#endif
diff --git a/src/include/exchange-database/iterate_kyc_references.h b/src/include/exchange-database/iterate_kyc_references.h
@@ -0,0 +1,94 @@
+/*
+ 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 iterate_kyc_references.h
+ * @brief implementation of the iterate_kyc_reference function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_KYC_REFERENCES_H
+#define EXCHANGE_DATABASE_ITERATE_KYC_REFERENCES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called on all legitimization operations
+ * we have performed for the given account so far
+ * (and that have not yet expired).
+ *
+ * @param cls closure
+ * @param kyc_provider_name name of the provider
+ * of the respective KYC process
+ * @param provider_user_id UID at a provider (can be NULL)
+ * @param legi_id legitimization process ID (can be NULL)
+ */
+#ifndef TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_LegitimizationProcessCallback.
+ */
+#define TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_LegitimizationProcessCallback)(
+ TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE *cls,
+ const char *kyc_provider_name,
+ const char *provider_user_id,
+ const char *legi_id);
+
+
+/* Callback typedefs */
+/**
+ * Function called on all legitimization operations
+ * we have performed for the given account so far
+ * (and that have not yet expired).
+ *
+ * @param cls closure
+ * @param kyc_provider_name name of the provider
+ * of the respective KYC process
+ * @param provider_user_id UID at a provider (can be NULL)
+ * @param legi_id legitimization process ID (can be NULL)
+ */
+typedef void
+(*TALER_EXCHANGEDB_LegitimizationProcessCallback)(
+ TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE *cls,
+ const char *kyc_provider_name,
+ const char *provider_user_id,
+ const char *legi_id);
+
+/**
+ * Call us on KYC legitimization processes satisfied and not expired for the
+ * given account.
+ *
+ * @param pg the database context
+ * @param h_payto account identifier
+ * @param lpc function to call for each satisfied KYC legitimization process
+ * @param lpc_cls closure for @a lpc
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_kyc_references (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto,
+ TALER_EXCHANGEDB_LegitimizationProcessCallback
+ lpc,
+ TALER_EXCHANGEDB_LEGITIMIZATION_PROCESS_RESULT_CLOSURE
+ *lpc_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_merge_amounts_for_kyc_check.h b/src/include/exchange-database/iterate_merge_amounts_for_kyc_check.h
@@ -0,0 +1,48 @@
+/*
+ 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/exchange-database/iterate_merge_amounts_for_kyc_check.h
+ * @brief implementation of the iterate_merge_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_MERGE_AMOUNTS_FOR_KYC_CHECK_H
+#define EXCHANGE_DATABASE_ITERATE_MERGE_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Call @a kac on merged reserve amounts after @a time_limit which are relevant for a
+ * KYC trigger for a the wallet identified by @a h_payto.
+ *
+ * @param pg the database context
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_merge_amounts_for_kyc_check (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_KYCLOGIC_KycAmountCallback kac,
+ void *kac_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_prewires.h b/src/include/exchange-database/iterate_prewires.h
@@ -0,0 +1,63 @@
+/*
+ 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/exchange-database/iterate_prewires.h
+ * @brief implementation of the iterate_prewires function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_PREWIRES_H
+#define EXCHANGE_DATABASE_ITERATE_PREWIRES_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Callback with data about a prepared wire transfer.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to mark prepared transaction as done
+ * @param wire_method which wire method is this preparation data for
+ * @param buf transaction data that was persisted, NULL on error
+ * @param buf_size number of bytes in @a buf, 0 on error
+ */
+typedef void
+(*TALER_EXCHANGEDB_WirePreparationIterator) (void *cls,
+ uint64_t rowid,
+ const char *wire_method,
+ const char *buf,
+ size_t buf_size);
+
+/**
+ * Function called to get an unfinished wire transfer
+ * preparation data. Fetches at most one item.
+ *
+ * @param pg the database context
+ * @param start_row offset to query table at
+ * @param limit maximum number of results to return
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_prewires (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ uint64_t start_row,
+ uint64_t limit,
+ TALER_EXCHANGEDB_WirePreparationIterator cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_purse_decisions_above_serial_id.h b/src/include/exchange-database/iterate_purse_decisions_above_serial_id.h
@@ -0,0 +1,99 @@
+/*
+ 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/exchange-database/iterate_purse_decisions_above_serial_id.h
+ * @brief implementation of the iterate_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about purse decisions that have been made, with
+ * the goal of auditing the purse's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub public key of the purse
+ * @param reserve_pub public key of the target reserve, NULL if not known / refunded
+ * @param purse_value what is the (target) value of the purse
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_PurseDecisionCallback.
+ */
+#define TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseDecisionCallback)(
+ TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *purse_value);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about purse decisions that have been made, with
+ * the goal of auditing the purse's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub public key of the purse
+ * @param reserve_pub public key of the target reserve, NULL if not known / refunded
+ * @param purse_value what is the (target) value of the purse
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseDecisionCallback)(
+ TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *purse_value);
+
+/**
+ * Select purse decisions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param refunded which refund status to select for
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_decisions_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t
+ serial_id,
+ bool refunded,
+ TALER_EXCHANGEDB_PurseDecisionCallback
+ cb,
+ TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_purse_deposits_above_serial_id.h b/src/include/exchange-database/iterate_purse_deposits_above_serial_id.h
@@ -0,0 +1,112 @@
+/*
+ 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 iterate_purse_deposits_above_serial_id.h
+ * @brief implementation of the iterate_purse_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_PURSE_DEPOSITS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_PURSE_DEPOSITS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about purse deposits that have been made, with
+ * the goal of auditing the deposit's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param deposit deposit details
+ * @param reserve_pub which reserve is the purse merged into, NULL if unknown
+ * @param flags purse flags
+ * @param auditor_balance purse balance (according to the
+ * auditor during auditing)
+ * @param purse_total target amount the purse should reach
+ * @param denom_pub denomination public key of @a coin_pub
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_PurseDepositCallback.
+ */
+#define TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseDepositCallback)(
+ TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *auditor_balance,
+ const struct TALER_Amount *purse_total,
+ const struct TALER_DenominationPublicKey *denom_pub);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about purse deposits that have been made, with
+ * the goal of auditing the deposit's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param deposit deposit details
+ * @param reserve_pub which reserve is the purse merged into, NULL if unknown
+ * @param flags purse flags
+ * @param auditor_balance purse balance (according to the
+ * auditor during auditing)
+ * @param purse_total target amount the purse should reach
+ * @param denom_pub denomination public key of @a coin_pub
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseDepositCallback)(
+ TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *auditor_balance,
+ const struct TALER_Amount *purse_total,
+ const struct TALER_DenominationPublicKey *denom_pub);
+
+/**
+ * Select deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_deposits_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id
+ ,
+ TALER_EXCHANGEDB_PurseDepositCallback
+ cb,
+ TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_purse_deposits_by_purse.h b/src/include/exchange-database/iterate_purse_deposits_by_purse.h
@@ -0,0 +1,98 @@
+/*
+ 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/exchange-database/iterate_purse_deposits_by_purse.h
+ * @brief implementation of the iterate_purse_deposits_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_PURSE_DEPOSITS_BY_PURSE_H
+#define EXCHANGE_DATABASE_ITERATE_PURSE_DEPOSITS_BY_PURSE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about purse refunds that have been made, with
+ * the goal of auditing the purse refund's execution.
+ *
+ * @param cls closure
+ * @param rowid row of the refund event
+ * @param amount_with_fee amount of the deposit into the purse
+ * @param coin_pub coin that is to be refunded the @a given amount_with_fee
+ * @param denom_pub denomination of @a coin_pub
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_PurseRefundCoinCallback.
+ */
+#define TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseRefundCoinCallback)(
+ TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_DenominationPublicKey *denom_pub);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about purse refunds that have been made, with
+ * the goal of auditing the purse refund's execution.
+ *
+ * @param cls closure
+ * @param rowid row of the refund event
+ * @param amount_with_fee amount of the deposit into the purse
+ * @param coin_pub coin that is to be refunded the @a given amount_with_fee
+ * @param denom_pub denomination of @a coin_pub
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseRefundCoinCallback)(
+ TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_DenominationPublicKey *denom_pub);
+
+/**
+ * Select coin affected by purse refund.
+ *
+ * @param pg the database context
+ * @param purse_pub purse that was refunded
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_deposits_by_purse (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ const struct
+ TALER_PurseContractPublicKeyP
+ *
+ purse_pub,
+ TALER_EXCHANGEDB_PurseRefundCoinCallback
+ cb,
+ TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_purse_merges_above_serial_id.h b/src/include/exchange-database/iterate_purse_merges_above_serial_id.h
@@ -0,0 +1,122 @@
+/*
+ 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 iterate_purse_merges_above_serial_id.h
+ * @brief implementation of the iterate_purse_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_PURSE_MERGES_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_PURSE_MERGES_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about purse
+ * merges that have been made, with
+ * the goal of auditing the purse merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param partner_base_url where is the reserve, NULL for this exchange
+ * @param amount total amount expected in the purse
+ * @param balance current balance in the purse (according to the auditor)
+ * @param flags purse flags
+ * @param merge_pub merge capability key
+ * @param reserve_pub reserve the merge affects
+ * @param merge_sig signature affirming the merge
+ * @param purse_pub purse key
+ * @param merge_timestamp when did the merge happen
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_PurseMergeCallback.
+ */
+#define TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseMergeCallback)(
+ TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const char *partner_base_url,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *balance,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp merge_timestamp);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about purse
+ * merges that have been made, with
+ * the goal of auditing the purse merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param partner_base_url where is the reserve, NULL for this exchange
+ * @param amount total amount expected in the purse
+ * @param balance current balance in the purse (according to the auditor)
+ * @param flags purse flags
+ * @param merge_pub merge capability key
+ * @param reserve_pub reserve the merge affects
+ * @param merge_sig signature affirming the merge
+ * @param purse_pub purse key
+ * @param merge_timestamp when did the merge happen
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseMergeCallback)(
+ TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const char *partner_base_url,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *balance,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp merge_timestamp);
+
+/**
+ * Select purse merges deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_merges_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t
+ serial_id,
+ TALER_EXCHANGEDB_PurseMergeCallback
+ cb,
+ TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_purse_requests_above_serial_id.h b/src/include/exchange-database/iterate_purse_requests_above_serial_id.h
@@ -0,0 +1,116 @@
+/*
+ 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 iterate_purse_requests_above_serial_id.h
+ * @brief implementation of the iterate_purse_requests_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_PURSE_REQUESTS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_PURSE_REQUESTS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called on purse requests.
+ *
+ * @param cls closure
+ * @param rowid purse request table row of the purse
+ * @param purse_pub public key of the purse
+ * @param merge_pub public key representing the merge capability
+ * @param purse_creation when was the purse created?
+ * @param purse_expiration when would an unmerged purse expire
+ * @param h_contract_terms contract associated with the purse
+ * @param age_limit the age limit for deposits into the purse
+ * @param target_amount amount to be put into the purse
+ * @param purse_sig signature of the purse over the initialization data
+ * @return #GNUNET_OK to continue to iterate
+ */
+#ifndef TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_PurseRequestCallback.
+ */
+#define TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseRequestCallback)(
+ TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp purse_creation,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t age_limit,
+ const struct TALER_Amount *target_amount,
+ const struct TALER_PurseContractSignatureP *purse_sig);
+
+
+/* Callback typedefs */
+/**
+ * Function called on purse requests.
+ *
+ * @param cls closure
+ * @param rowid purse request table row of the purse
+ * @param purse_pub public key of the purse
+ * @param merge_pub public key representing the merge capability
+ * @param purse_creation when was the purse created?
+ * @param purse_expiration when would an unmerged purse expire
+ * @param h_contract_terms contract associated with the purse
+ * @param age_limit the age limit for deposits into the purse
+ * @param target_amount amount to be put into the purse
+ * @param purse_sig signature of the purse over the initialization data
+ * @return #GNUNET_OK to continue to iterate
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseRequestCallback)(
+ TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp purse_creation,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t age_limit,
+ const struct TALER_Amount *target_amount,
+ const struct TALER_PurseContractSignatureP *purse_sig);
+
+/**
+ * Select purse requestss deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_purse_requests_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id
+ ,
+ TALER_EXCHANGEDB_PurseRequestCallback
+ cb,
+ TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_records_by_table.h b/src/include/exchange-database/iterate_records_by_table.h
@@ -0,0 +1,624 @@
+/*
+ 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 iterate_records_by_table.h
+ * @brief implementation of the lookup_records_by_table function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RECORDS_BY_TABLE_H
+#define EXCHANGE_DATABASE_ITERATE_RECORDS_BY_TABLE_H
+
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Enumeration of all of the tables replicated by exchange-auditor
+ * database replication.
+ *
+ * Note: wire_accounts is not replicated. So far not needed by the auditor.
+ */
+enum TALER_EXCHANGEDB_ReplicatedTable
+{
+ TALER_EXCHANGEDB_RT_DENOMINATIONS,
+ TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS,
+ TALER_EXCHANGEDB_RT_KYC_TARGETS,
+ TALER_EXCHANGEDB_RT_WIRE_TARGETS,
+ TALER_EXCHANGEDB_RT_RESERVES,
+ TALER_EXCHANGEDB_RT_RESERVES_IN,
+ TALER_EXCHANGEDB_RT_RESERVES_CLOSE,
+ TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS,
+ TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS,
+ TALER_EXCHANGEDB_RT_AUDITORS,
+ TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS,
+ TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS,
+ TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS,
+ TALER_EXCHANGEDB_RT_KNOWN_COINS,
+ TALER_EXCHANGEDB_RT_REFRESH,
+ TALER_EXCHANGEDB_RT_BATCH_DEPOSITS,
+ TALER_EXCHANGEDB_RT_COIN_DEPOSITS,
+ TALER_EXCHANGEDB_RT_REFUNDS,
+ TALER_EXCHANGEDB_RT_WIRE_OUT,
+ TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING,
+ TALER_EXCHANGEDB_RT_WIRE_FEE,
+ TALER_EXCHANGEDB_RT_GLOBAL_FEE,
+ TALER_EXCHANGEDB_RT_RECOUP,
+ TALER_EXCHANGEDB_RT_RECOUP_REFRESH,
+ TALER_EXCHANGEDB_RT_PURSE_REQUESTS,
+ TALER_EXCHANGEDB_RT_PURSE_DECISION,
+ TALER_EXCHANGEDB_RT_PURSE_MERGES,
+ TALER_EXCHANGEDB_RT_PURSE_DEPOSITS,
+ TALER_EXCHANGEDB_RT_ACCOUNT_MERGES,
+ TALER_EXCHANGEDB_RT_HISTORY_REQUESTS,
+ TALER_EXCHANGEDB_RT_CLOSE_REQUESTS,
+ TALER_EXCHANGEDB_RT_WADS_OUT,
+ TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES,
+ TALER_EXCHANGEDB_RT_WADS_IN,
+ TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES,
+ TALER_EXCHANGEDB_RT_PROFIT_DRAINS,
+ TALER_EXCHANGEDB_RT_AML_STAFF,
+ TALER_EXCHANGEDB_RT_PURSE_DELETION,
+ TALER_EXCHANGEDB_RT_WITHDRAW,
+ TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES,
+ TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES,
+ TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES,
+ TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES,
+ TALER_EXCHANGEDB_RT_AML_HISTORY,
+ TALER_EXCHANGEDB_RT_KYC_EVENTS,
+ TALER_EXCHANGEDB_RT_KYCAUTHS_IN
+};
+
+
+/**
+ * Record of a single entry in a replicated table.
+ */
+struct TALER_EXCHANGEDB_TableData
+{
+ /**
+ * Data of which table is returned here?
+ */
+ enum TALER_EXCHANGEDB_ReplicatedTable table;
+
+ /**
+ * Serial number of the record.
+ */
+ uint64_t serial;
+
+ /**
+ * Table-specific details.
+ */
+ union
+ {
+
+ /**
+ * Details from the 'denominations' table.
+ */
+ struct
+ {
+ uint32_t denom_type;
+ uint32_t age_mask;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_TIME_Timestamp valid_from;
+ struct GNUNET_TIME_Timestamp expire_withdraw;
+ struct GNUNET_TIME_Timestamp expire_deposit;
+ struct GNUNET_TIME_Timestamp expire_legal;
+ struct TALER_Amount coin;
+ struct TALER_DenomFeeSet fees;
+ } denominations;
+
+ struct
+ {
+ struct TALER_MasterSignatureP master_sig;
+ uint64_t denominations_serial;
+ } denomination_revocations;
+
+ struct
+ {
+ struct TALER_FullPayto full_payto_uri;
+ } wire_targets;
+
+ struct
+ {
+ struct TALER_NormalizedPaytoHashP h_normalized_payto;
+ struct TALER_AccountAccessTokenP access_token;
+ union TALER_AccountPublicKeyP target_pub;
+ bool no_account;
+ bool is_wallet;
+ } kyc_targets;
+
+ struct
+ {
+ struct TALER_AccountAccessTokenP target_token;
+ struct GNUNET_TIME_Timestamp start_time;
+ json_t *measures;
+ uint32_t display_priority;
+ } legitimization_measures;
+
+ struct
+ {
+ struct TALER_NormalizedPaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp decision_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ json_t *properties;
+ bool to_investigate;
+ json_t *new_rules;
+ } legitimization_outcomes;
+
+ struct
+ {
+ struct TALER_NormalizedPaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp start_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ uint64_t legitimization_measure_serial_id;
+ uint32_t measure_index;
+ char *provider_name;
+ char *provider_user_id;
+ char *provider_legitimization_id;
+ char *redirect_url;
+ } legitimization_processes;
+
+ struct
+ {
+ struct TALER_NormalizedPaytoHashP h_payto;
+ uint64_t legitimization_serial;
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ uint64_t trigger_outcome_serial;
+ void *encrypted_attributes;
+ size_t encrypted_attributes_size;
+ } kyc_attributes;
+
+ struct
+ {
+ struct TALER_NormalizedPaytoHashP h_payto;
+ uint64_t outcome_serial_id;
+ char *justification;
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+ struct TALER_AmlOfficerSignatureP decider_sig;
+ } aml_history;
+
+ struct
+ {
+ struct GNUNET_TIME_Timestamp event_timestamp;
+ char *event_type;
+ } kyc_events;
+
+ struct
+ {
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+ struct TALER_MasterSignatureP master_sig;
+ char *decider_name;
+ bool is_active;
+ bool read_only;
+ struct GNUNET_TIME_Timestamp last_change;
+ } aml_staff;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct GNUNET_TIME_Timestamp expiration_date;
+ struct GNUNET_TIME_Timestamp gc_date;
+ } reserves;
+
+ struct
+ {
+ uint64_t wire_reference;
+ struct TALER_Amount credit;
+ struct TALER_FullPaytoHashP sender_account_h_payto;
+ char *exchange_account_section;
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ } reserves_in;
+
+ struct
+ {
+ uint64_t wire_reference;
+ struct TALER_Amount credit;
+ struct TALER_FullPaytoHashP sender_account_h_payto;
+ char *exchange_account_section;
+ struct GNUNET_TIME_Timestamp execution_date;
+ union TALER_AccountPublicKeyP account_pub;
+ } kycauth_in;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct GNUNET_TIME_Timestamp expiration_date;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_Amount reserve_payment;
+ uint32_t requested_purse_limit;
+ } reserves_open_requests;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_Amount contribution;
+ } reserves_open_deposits;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_FullPaytoHashP sender_account_h_payto;
+ struct TALER_Amount amount;
+ struct TALER_Amount closing_fee;
+ } reserves_close;
+
+ struct
+ {
+ struct TALER_AuditorPublicKeyP auditor_pub;
+ char *auditor_url;
+ char *auditor_name;
+ bool is_active;
+ struct GNUNET_TIME_Timestamp last_change;
+ } auditors;
+
+ struct
+ {
+ uint64_t auditor_uuid;
+ uint64_t denominations_serial;
+ struct TALER_AuditorSignatureP auditor_sig;
+ } auditor_denom_sigs;
+
+ struct
+ {
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_MasterSignatureP master_sig;
+ struct TALER_EXCHANGEDB_SignkeyMetaData meta;
+ } exchange_sign_keys;
+
+ struct
+ {
+ uint64_t esk_serial;
+ struct TALER_MasterSignatureP master_sig;
+ } signkey_revocations;
+
+ struct
+ {
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_AgeCommitmentHashP age_hash;
+ uint64_t denominations_serial;
+ struct TALER_DenominationSignature denom_sig;
+ } known_coins;
+
+ struct
+ {
+ struct TALER_RefreshCommitmentP rc;
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_CoinSpendPublicKeyP old_coin_pub;
+ struct TALER_CoinSpendSignatureP old_coin_sig;
+ struct TALER_PublicRefreshMasterSeedP refresh_seed;
+ uint32_t noreveal_index;
+ struct TALER_HashBlindedPlanchetsP planchets_h;
+ struct TALER_HashBlindedPlanchetsP selected_h;
+ bool no_blinding_seed;
+ struct TALER_BlindingMasterSeedP blinding_seed;
+ size_t num_cs_r_values;
+ struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values;
+ uint64_t cs_r_choices;
+ size_t num_coins;
+ uint64_t *denom_serials;
+ struct TALER_BlindedDenominationSignature *denom_sigs;
+ } refresh;
+
+ struct
+ {
+ uint64_t shard;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Timestamp wallet_timestamp;
+ struct GNUNET_TIME_Timestamp exchange_timestamp;
+ struct GNUNET_TIME_Timestamp refund_deadline;
+ struct GNUNET_TIME_Timestamp wire_deadline;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ bool no_wallet_data_hash;
+ struct GNUNET_HashCode wallet_data_hash;
+ struct TALER_WireSaltP wire_salt;
+ struct TALER_FullPaytoHashP wire_target_h_payto;
+ struct TALER_Amount total_amount;
+ struct TALER_Amount total_without_fee;
+ struct TALER_MerchantSignatureP merchant_sig;
+ bool done;
+ } batch_deposits;
+
+ struct
+ {
+ uint64_t batch_deposit_serial_id;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct TALER_Amount amount_with_fee;
+ } coin_deposits;
+
+ struct
+ {
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ uint64_t batch_deposit_serial_id;
+ struct TALER_MerchantSignatureP merchant_sig;
+ uint64_t rtransaction_id;
+ struct TALER_Amount amount_with_fee;
+ } refunds;
+
+ struct
+ {
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_WireTransferIdentifierRawP wtid_raw;
+ struct TALER_FullPaytoHashP wire_target_h_payto;
+ char *exchange_account_section;
+ struct TALER_Amount amount;
+ } wire_out;
+
+ struct
+ {
+ uint64_t batch_deposit_serial_id;
+ struct TALER_WireTransferIdentifierRawP wtid_raw;
+ } aggregation_tracking;
+
+ struct
+ {
+ char *wire_method;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_WireFeeSet fees;
+ struct TALER_MasterSignatureP master_sig;
+ } wire_fee;
+
+ struct
+ {
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_GlobalFeeSet fees;
+ struct GNUNET_TIME_Relative purse_timeout;
+ struct GNUNET_TIME_Relative history_expiration;
+ uint32_t purse_account_limit;
+ struct TALER_MasterSignatureP master_sig;
+ } global_fee;
+
+ struct
+ {
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
+ struct TALER_Amount amount;
+ struct GNUNET_TIME_Timestamp timestamp;
+ uint64_t withdraw_serial_id;
+ } recoup;
+
+ struct
+ {
+ uint64_t known_coin_id;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
+ struct TALER_Amount amount;
+ struct GNUNET_TIME_Timestamp recoup_timestamp;
+ uint64_t refresh_id;
+ } recoup_refresh;
+
+ struct
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseMergePublicKeyP merge_pub;
+ struct GNUNET_TIME_Timestamp purse_creation;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ uint32_t age_limit;
+ uint32_t flags;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount purse_fee;
+ struct TALER_PurseContractSignatureP purse_sig;
+ } purse_requests;
+
+ struct
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct GNUNET_TIME_Timestamp action_timestamp;
+ bool refunded;
+ } purse_decision;
+
+ struct
+ {
+ uint64_t partner_serial_id;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseMergeSignatureP merge_sig;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ } purse_merges;
+
+ struct
+ {
+ uint64_t partner_serial_id;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ } purse_deposits;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_NormalizedPaytoHashP wallet_h_payto;
+ } account_merges;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct TALER_Amount history_fee;
+ } history_requests;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct GNUNET_TIME_Timestamp close_timestamp;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_Amount close;
+ struct TALER_Amount close_fee;
+ struct TALER_FullPayto payto_uri;
+ } close_requests;
+
+ struct
+ {
+ struct TALER_WadIdentifierP wad_id;
+ uint64_t partner_serial_id;
+ struct TALER_Amount amount;
+ struct GNUNET_TIME_Timestamp execution_time;
+ } wads_out;
+
+ struct
+ {
+ uint64_t wad_out_serial_id;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PrivateContractHashP h_contract;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount wad_fee;
+ struct TALER_Amount deposit_fees;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_PurseContractSignatureP purse_sig;
+ } wads_out_entries;
+
+ struct
+ {
+ struct TALER_WadIdentifierP wad_id;
+ char *origin_exchange_url;
+ struct TALER_Amount amount;
+ struct GNUNET_TIME_Timestamp arrival_time;
+ } wads_in;
+
+ struct
+ {
+ uint64_t wad_in_serial_id;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PrivateContractHashP h_contract;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount wad_fee;
+ struct TALER_Amount deposit_fees;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_PurseContractSignatureP purse_sig;
+ } wads_in_entries;
+
+ struct
+ {
+ struct TALER_WireTransferIdentifierRawP wtid;
+ char *account_section;
+ struct TALER_FullPayto payto_uri;
+ struct GNUNET_TIME_Timestamp trigger_date;
+ struct TALER_Amount amount;
+ struct TALER_MasterSignatureP master_sig;
+ } profit_drains;
+
+ struct
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseContractSignatureP purse_sig;
+ } purse_deletion;
+
+ struct
+ {
+ struct TALER_HashBlindedPlanchetsP planchets_h;
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ bool age_proof_required;
+ uint16_t max_age;
+ uint16_t noreveal_index;
+ struct TALER_HashBlindedPlanchetsP selected_h;
+ bool no_blinding_seed;
+ struct TALER_BlindingMasterSeedP blinding_seed;
+ size_t num_cs_r_values;
+ struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values;
+ uint64_t cs_r_choices;
+ size_t num_coins;
+ uint64_t *denom_serials;
+ struct TALER_BlindedDenominationSignature *denom_sigs;
+ } withdraw;
+
+ } details;
+
+};
+
+
+/**
+ * Function called on data to replicate in the auditor's database.
+ *
+ * @param cls closure
+ * @param td record from an exchange table
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_SYSERR to fail with an error
+ */
+#ifndef TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReplicationCallback.
+ */
+#define TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE void
+#endif
+typedef int
+(*TALER_EXCHANGEDB_ReplicationCallback)(
+ TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE *cls,
+ const struct TALER_EXCHANGEDB_TableData *td);
+
+
+/**
+ * Function called on data to replicate in the auditor's database.
+ *
+ * @param cls closure
+ * @param td record from an exchange table
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_SYSERR to fail with an error
+ */
+typedef int
+(*TALER_EXCHANGEDB_ReplicationCallback)(
+ TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE *cls,
+ const struct TALER_EXCHANGEDB_TableData *td);
+
+
+/**
+ * Lookup records above @a serial number in @a table. Used in
+ * exchange-auditor database replication.
+ *
+ * @param pg the database context
+ * @param table table for which we should return the serial
+ * @param serial largest serial number to exclude
+ * @param cb function to call on the records
+ * @param cb_cls closure for @a cb
+ * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
+ * @a table does not have a serial number
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_records_by_table (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t serial,
+ TALER_EXCHANGEDB_ReplicationCallback cb,
+ TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_recoup_refreshes_above_serial_id.h b/src/include/exchange-database/iterate_recoup_refreshes_above_serial_id.h
@@ -0,0 +1,116 @@
+/*
+ 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/exchange-database/iterate_recoup_refreshes_above_serial_id.h
+ * @brief implementation of the iterate_recoup_refreshes_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RECOUP_REFRESHES_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_RECOUP_REFRESHES_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called about recoups on refreshed coins the exchange has to
+ * perform.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the recoup operation
+ * @param timestamp when did we receive the recoup request
+ * @param amount how much should be added back to the old coin
+ * @param old_coin_pub original coin that was refreshed to create @a coin
+ * @param old_denom_pub_hash hash of public key of @a old_coin_pub
+ * @param coin public information about the fresh coin
+ * @param denom_pub denomination key of @a coin
+ * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
+ * @param coin_blind blinding factor used to blind the coin
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_RecoupRefreshCallback.
+ */
+#define TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RecoupRefreshCallback)(
+ TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ const struct TALER_DenominationHashP *old_denom_pub_hash,
+ const struct TALER_CoinPublicInfo *coin,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
+
+
+/* Callback typedefs */
+/**
+ * Function called about recoups on refreshed coins the exchange has to
+ * perform.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the recoup operation
+ * @param timestamp when did we receive the recoup request
+ * @param amount how much should be added back to the old coin
+ * @param old_coin_pub original coin that was refreshed to create @a coin
+ * @param old_denom_pub_hash hash of public key of @a old_coin_pub
+ * @param coin public information about the fresh coin
+ * @param denom_pub denomination key of @a coin
+ * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
+ * @param coin_blind blinding factor used to blind the coin
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RecoupRefreshCallback)(
+ TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ const struct TALER_DenominationHashP *old_denom_pub_hash,
+ const struct TALER_CoinPublicInfo *coin,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
+
+/**
+ * Function called to select recoup requests the exchange received for
+ * refreshed coins, ordered by serial ID (monotonically increasing).
+ *
+ * @param pg the database context
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_recoup_refreshes_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupRefreshCallback
+ cb,
+ TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_recoups_above_serial_id.h b/src/include/exchange-database/iterate_recoups_above_serial_id.h
@@ -0,0 +1,110 @@
+/*
+ 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/exchange-database/iterate_recoups_above_serial_id.h
+ * @brief implementation of the iterate_recoups_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RECOUPS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_RECOUPS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called about recoups the exchange has to perform.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the recoup operation
+ * @param timestamp when did we receive the recoup request
+ * @param amount how much should be added back to the reserve
+ * @param reserve_pub public key of the reserve
+ * @param coin public information about the coin
+ * @param denom_pub denomination key of @a coin
+ * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
+ * @param coin_blind blinding factor used to blind the coin
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_RecoupCallback.
+ */
+#define TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RecoupCallback)(
+ TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_CoinPublicInfo *coin,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
+
+
+/* Callback typedefs */
+/**
+ * Function called about recoups the exchange has to perform.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the recoup operation
+ * @param timestamp when did we receive the recoup request
+ * @param amount how much should be added back to the reserve
+ * @param reserve_pub public key of the reserve
+ * @param coin public information about the coin
+ * @param denom_pub denomination key of @a coin
+ * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
+ * @param coin_blind blinding factor used to blind the coin
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RecoupCallback)(
+ TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_CoinPublicInfo *coin,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
+
+/**
+ * Function called to select recoup requests the exchange
+ * received, ordered by serial ID (monotonically increasing).
+ *
+ * @param pg the database context
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_recoups_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupCallback
+ cb,
+ TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_refreshes_above_serial_id.h b/src/include/exchange-database/iterate_refreshes_above_serial_id.h
@@ -0,0 +1,116 @@
+/*
+ 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/exchange-database/iterate_refreshes_above_serial_id.h
+ * @brief implementation of the iterate_refreshes_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_REFRESHES_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_REFRESHES_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about coins that were melted,
+ * with the goal of auditing the refresh's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refresh session in our DB
+ * @param old_denom_pub denomination public key of @a coin_pub
+ * @param coin_pub public key of the coin
+ * @param coin_sig signature from the coin
+ * @param h_age_commitment hash of the age commitment for the coin
+ * @param amount_with_fee amount that was deposited including fee
+ * @param num_nds length of the @a new_denom_serials array
+ * @param new_denom_serials array of denomination serials of fresh coins
+ * @param rc what the refresh commitment
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_RefreshesCallback.
+ */
+#define TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RefreshesCallback)(
+ TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_DenominationPublicKey *old_denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const struct TALER_AgeCommitmentHashP *h_age_commitment,
+ const struct TALER_Amount *amount_with_fee,
+ size_t num_nds,
+ uint64_t new_denom_serials[static num_nds],
+ const struct TALER_RefreshCommitmentP *rc);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about coins that were melted,
+ * with the goal of auditing the refresh's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refresh session in our DB
+ * @param old_denom_pub denomination public key of @a coin_pub
+ * @param coin_pub public key of the coin
+ * @param coin_sig signature from the coin
+ * @param h_age_commitment hash of the age commitment for the coin
+ * @param amount_with_fee amount that was deposited including fee
+ * @param num_nds length of the @a new_denom_serials array
+ * @param new_denom_serials array of denomination serials of fresh coins
+ * @param rc what the refresh commitment
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RefreshesCallback)(
+ TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_DenominationPublicKey *old_denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const struct TALER_AgeCommitmentHashP *h_age_commitment,
+ const struct TALER_Amount *amount_with_fee,
+ size_t num_nds,
+ uint64_t new_denom_serials[static num_nds],
+ const struct TALER_RefreshCommitmentP *rc);
+
+/**
+ * Select refresh sessions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_refreshes_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefreshesCallback
+ cb,
+ TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_refunds_above_serial_id.h b/src/include/exchange-database/iterate_refunds_above_serial_id.h
@@ -0,0 +1,116 @@
+/*
+ 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/exchange-database/iterate_refunds_above_serial_id.h
+ * @brief implementation of the iterate_refunds_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_REFUNDS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_REFUNDS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+#include "exchange-database/do_refund.h"
+
+
+/**
+ * Function called with details about coins that were refunding,
+ * with the goal of auditing the refund's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refund in our DB
+ * @param denom_pub denomination public key of @a coin_pub
+ * @param coin_pub public key of the coin
+ * @param merchant_pub public key of the merchant
+ * @param merchant_sig signature of the merchant
+ * @param h_contract_terms hash of the proposal data known to merchant and customer
+ * @param rtransaction_id refund transaction ID chosen by the merchant
+ * @param full_refund true if the refunds total up to the entire value of the deposit
+ * @param amount_with_fee amount that was deposited including fee
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_RefundCallback.
+ */
+#define TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RefundCallback)(
+ TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_MerchantSignatureP *merchant_sig,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint64_t rtransaction_id,
+ bool full_refund,
+ const struct TALER_Amount *amount_with_fee);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about coins that were refunding,
+ * with the goal of auditing the refund's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refund in our DB
+ * @param denom_pub denomination public key of @a coin_pub
+ * @param coin_pub public key of the coin
+ * @param merchant_pub public key of the merchant
+ * @param merchant_sig signature of the merchant
+ * @param h_contract_terms hash of the proposal data known to merchant and customer
+ * @param rtransaction_id refund transaction ID chosen by the merchant
+ * @param full_refund true if the refunds total up to the entire value of the deposit
+ * @param amount_with_fee amount that was deposited including fee
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RefundCallback)(
+ TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_MerchantSignatureP *merchant_sig,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint64_t rtransaction_id,
+ bool full_refund,
+ const struct TALER_Amount *amount_with_fee);
+
+/**
+ * Select refunds above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_refunds_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefundCallback
+ cb,
+ TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_refunds_by_coin.h b/src/include/exchange-database/iterate_refunds_by_coin.h
@@ -0,0 +1,91 @@
+/*
+ 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/exchange-database/iterate_refunds_by_coin.h
+ * @brief implementation of the iterate_refunds_by_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_REFUNDS_BY_COIN_H
+#define EXCHANGE_DATABASE_ITERATE_REFUNDS_BY_COIN_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Callback invoked with information about refunds applicable
+ * to a particular coin and contract.
+ *
+ * @param cls closure
+ * @param amount_with_fee amount being refunded
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_RefundCoinCallback.
+ */
+#define TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RefundCoinCallback)(
+ TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE *cls,
+ const struct TALER_Amount *amount_with_fee);
+
+
+/* Callback typedefs */
+/**
+ * Callback invoked with information about refunds applicable
+ * to a particular coin and contract.
+ *
+ * @param cls closure
+ * @param amount_with_fee amount being refunded
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_RefundCoinCallback)(
+ TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE *cls,
+ const struct TALER_Amount *amount_with_fee);
+
+/**
+ * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract.
+ *
+ * @param pg the database context
+ * @param coin_pub coin to get refunds for
+ * @param merchant_pub merchant to get refunds for
+ * @param h_contract contract (hash) to get refunds for
+ * @param cb function to call for each refund found
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_refunds_by_coin (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_CoinSpendPublicKeyP *
+ coin_pub,
+ const struct
+ TALER_MerchantPublicKeyP *
+ merchant_pub,
+ const struct
+ TALER_PrivateContractHashP *
+ h_contract,
+ TALER_EXCHANGEDB_RefundCoinCallback cb
+ ,
+ TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_reserve_closed_above_serial_id.h b/src/include/exchange-database/iterate_reserve_closed_above_serial_id.h
@@ -0,0 +1,115 @@
+/*
+ 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 iterate_reserve_closed_above_serial_id.h
+ * @brief implementation of the select_reserve_closed_above_serial_id function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RESERVE_CLOSED_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_RESERVE_CLOSED_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called about reserve closing operations
+ * the aggregator triggered.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param execution_date when did we execute the close operation
+ * @param amount_with_fee how much did we debit the reserve
+ * @param closing_fee how much did we charge for closing the reserve
+ * @param reserve_pub public key of the reserve
+ * @param receiver_account where did we send the funds, in payto://-format
+ * @param wtid identifier used for the wire transfer
+ * @param close_request_row row with the responsible close
+ * request, 0 if regular expiration triggered close
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReserveClosedCallback.
+ */
+#define TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveClosedCallback)(
+ TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *closing_fee,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_FullPayto receiver_account,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t close_request_row);
+
+
+/* Callback typedefs */
+/**
+ * Function called about reserve closing operations
+ * the aggregator triggered.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param execution_date when did we execute the close operation
+ * @param amount_with_fee how much did we debit the reserve
+ * @param closing_fee how much did we charge for closing the reserve
+ * @param reserve_pub public key of the reserve
+ * @param receiver_account where did we send the funds, in payto://-format
+ * @param wtid identifier used for the wire transfer
+ * @param close_request_row row with the responsible close
+ * request, 0 if regular expiration triggered close
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveClosedCallback)(
+ TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *closing_fee,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_FullPayto receiver_account,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t close_request_row);
+
+/**
+ * Function called to select reserve close operations the aggregator
+ * triggered, ordered by serial ID (monotonically increasing).
+ *
+ * @param pg the database context
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserve_closed_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveClosedCallback
+ cb,
+ TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_reserve_open_above_serial_id.h b/src/include/exchange-database/iterate_reserve_open_above_serial_id.h
@@ -0,0 +1,110 @@
+/*
+ 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 iterate_reserve_open_above_serial_id.h
+ * @brief implementation of the select_reserve_open_above_serial_id function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RESERVE_OPEN_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_RESERVE_OPEN_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called about reserve opening operations.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature affirming the operation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReserveOpenCallback.
+ */
+#define TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveOpenCallback)(
+ TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/* Callback typedefs */
+/**
+ * Function called about reserve opening operations.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature affirming the operation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveOpenCallback)(
+ TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+/**
+ * Function called to select reserve open operations, ordered by serial ID
+ * (monotonically increasing).
+ *
+ * @param pg the database context
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserve_open_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveOpenCallback
+ cb,
+ TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE
+ *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_reserves_in_above_serial_id.h b/src/include/exchange-database/iterate_reserves_in_above_serial_id.h
@@ -0,0 +1,78 @@
+/*
+ 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/exchange-database/iterate_reserves_in_above_serial_id.h
+ * @brief implementation of the iterate_reserves_in_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RESERVES_IN_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_RESERVES_IN_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about incoming wire transfers.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refresh session in our DB
+ * @param reserve_pub public key of the reserve (also the wire subject)
+ * @param credit amount that was received
+ * @param sender_account_details information about the sender's bank account, in payto://-format
+ * @param wire_reference unique identifier for the wire transfer
+ * @param execution_date when did we receive the funds
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReserveInCallback.
+ */
+#define TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveInCallback)(
+ TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *credit,
+ const struct TALER_FullPayto sender_account_details,
+ uint64_t wire_reference,
+ struct GNUNET_TIME_Timestamp execution_date);
+
+/**
+ * Select inbound wire transfers into reserves_in above @a serial_id
+ * in monotonically increasing order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserves_in_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback
+ cb,
+ TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_reserves_in_above_serial_id_by_account.h b/src/include/exchange-database/iterate_reserves_in_above_serial_id_by_account.h
@@ -0,0 +1,84 @@
+/*
+ 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/exchange-database/iterate_reserves_in_above_serial_id_by_account.h
+ * @brief implementation of the iterate_reserves_in_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_RESERVES_IN_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+#define EXCHANGE_DATABASE_ITERATE_RESERVES_IN_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about incoming wire transfers.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refresh session in our DB
+ * @param reserve_pub public key of the reserve (also the wire subject)
+ * @param credit amount that was received
+ * @param sender_account_details information about the sender's bank account, in payto://-format
+ * @param wire_reference unique identifier for the wire transfer
+ * @param execution_date when did we receive the funds
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReserveInCallback.
+ */
+#define TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveInCallback)(
+ TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *credit,
+ const struct TALER_FullPayto sender_account_details,
+ uint64_t wire_reference,
+ struct GNUNET_TIME_Timestamp execution_date);
+
+/**
+ * Select inbound wire transfers into reserves_in above @a serial_id
+ * in monotonically increasing order by account.
+ *
+ * @param pg the database context
+ * @param account_name name of the account to select by
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_reserves_in_above_serial_id_by_account (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const char
+ *
+ account_name,
+ uint64_t
+ serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback
+ cb,
+ TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
+ *
+ cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_unfinished_close_requests.h b/src/include/exchange-database/iterate_unfinished_close_requests.h
@@ -0,0 +1,80 @@
+/*
+ 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 iterate_unfinished_close_requests.h
+ * @brief implementation of the get_unfinished_close_requests function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_UNFINISHED_CLOSE_REQUESTS_H
+#define EXCHANGE_DATABASE_ITERATE_UNFINISHED_CLOSE_REQUESTS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about expired reserves.
+ *
+ * @param cls closure
+ * @param reserve_pub public key of the reserve
+ * @param left amount left in the reserve
+ * @param account_details information about the reserve's bank account, in payto://-format
+ * @param expiration_date when did the reserve expire
+ * @param close_request_row row that caused the reserve
+ * to be closed, 0 if it expired without request
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO to retry
+ * #GNUNET_SYSERR on hard failures (exit)
+ */
+#ifndef TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_ReserveExpiredCallback.
+ */
+#define TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveExpiredCallback)(
+ TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *left,
+ const struct TALER_FullPayto account_details,
+ struct GNUNET_TIME_Timestamp expiration_date,
+ uint64_t close_request_row);
+
+/**
+ * Obtain information about force-closed reserves
+ * where the close was not yet done (and their remaining
+ * balances). Updates the returned reserve's close
+ * status to "done".
+ *
+ * @param pg the database context
+ * @param rec function to call on expired reserves
+ * @param rec_cls closure for @a rec
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_unfinished_close_requests (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ TALER_EXCHANGEDB_ReserveExpiredCallback
+ rec,
+ TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
+ *rec_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_wallet_merges.h b/src/include/exchange-database/iterate_wallet_merges.h
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2026 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/exchange-database/iterate_wallet_merges.h
+ * @brief implementation of the select_wallet_merges function
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WALLET_MERGES_H
+#define EXCHANGE_DATABASE_ITERATE_WALLET_MERGES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Callback that is given AML-relevant transfer data.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param payto_uri account involved with the wire transfer
+ * @param execution_time when was the transfer made
+ * @param amount wire amount of the transfer
+ */
+#ifndef TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AmlTransferCallback.
+ */
+#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AmlTransferCallback)(
+ TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cls,
+ uint64_t row_id,
+ const char *payto_uri,
+ struct GNUNET_TIME_Absolute execution_time,
+ const struct TALER_Amount *amount);
+
+
+/**
+ * Return AML-relevant merges (credits) into a wallet.
+ *
+ * @param pg the database context
+ * @param threshold minimum wire amount to return data for
+ * @param offset offset in table to filter by
+ * @param limit maximum number of entries to return, negative for descending
+ * @param h_payto account to filter transfer data by
+ * @param cb function to call on each result
+ * @param cb_cls closure to pass to @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wallet_merges (
+ struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_Amount *threshold,
+ uint64_t offset,
+ int64_t limit,
+ const struct TALER_NormalizedPaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlTransferCallback cb,
+ TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cb_cls);
+
+
+#endif
diff --git a/src/include/exchange-database/iterate_wire_accounts.h b/src/include/exchange-database/iterate_wire_accounts.h
@@ -0,0 +1,108 @@
+/*
+ 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/exchange-database/iterate_wire_accounts.h
+ * @brief implementation of the iterate_wire_accounts function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WIRE_ACCOUNTS_H
+#define EXCHANGE_DATABASE_ITERATE_WIRE_ACCOUNTS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Provide information about a wire account.
+ *
+ * @param cls closure
+ * @param payto_uri the exchange bank account URI
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param open_banking_gateway open banking gateway service, NULL if unavailable
+ * @param prepared_transfer_url prepared transfer service, NULL if unavailable
+ * @param debit_restrictions JSON array with debit restrictions on the account
+ * @param credit_restrictions JSON array with credit restrictions on the account
+ * @param master_sig master key signature affirming that this is a bank
+ * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
+ * @param bank_label label the wallet should use to display the account, can be NULL
+ * @param priority priority for ordering bank account labels
+ */
+#ifndef TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_WireAccountCallback.
+ */
+#define TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_WireAccountCallback)(
+ TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE *cls,
+ const struct TALER_FullPayto payto_uri,
+ const char *conversion_url,
+ const char *open_banking_gateway,
+ const char *prepared_transfer_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority);
+
+
+/* Callback typedefs */
+/**
+ * Provide information about a wire account.
+ *
+ * @param cls closure
+ * @param payto_uri the exchange bank account URI
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param open_banking_gateway open banking gateway service, NULL if unavailable
+ * @param prepared_transfer_url prepared transfer service, NULL if unavailable
+ * @param debit_restrictions JSON array with debit restrictions on the account
+ * @param credit_restrictions JSON array with credit restrictions on the account
+ * @param master_sig master key signature affirming that this is a bank
+ * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
+ * @param bank_label label the wallet should use to display the account, can be NULL
+ * @param priority priority for ordering bank account labels
+ */
+typedef void
+(*TALER_EXCHANGEDB_WireAccountCallback)(
+ TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE *cls,
+ const struct TALER_FullPayto payto_uri,
+ const char *conversion_url,
+ const char *open_banking_gateway,
+ const char *prepared_transfer_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority);
+
+/**
+ * Obtain information about the enabled wire accounts of the exchange.
+ *
+ * @param pg the database context
+ * @param cb function to call on each account
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_accounts (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ TALER_EXCHANGEDB_WireAccountCallback cb,
+ TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_wire_fees.h b/src/include/exchange-database/iterate_wire_fees.h
@@ -0,0 +1,91 @@
+/*
+ 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/exchange-database/iterate_wire_fees.h
+ * @brief implementation of the iterate_wire_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WIRE_FEES_H
+#define EXCHANGE_DATABASE_ITERATE_WIRE_FEES_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Provide information about wire fees.
+ *
+ * @param cls closure
+ * @param fees the wire fees we charge
+ * @param start_date from when are these fees valid (start date)
+ * @param end_date until when are these fees valid (end date, exclusive)
+ * @param master_sig master key signature affirming that this is the correct
+ * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES)
+ */
+#ifndef TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_WireFeeCallback.
+ */
+#define TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_WireFeeCallback)(
+ TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE *cls,
+ const struct TALER_WireFeeSet *fees,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_MasterSignatureP *master_sig);
+
+
+/* Callback typedefs */
+/**
+ * Provide information about wire fees.
+ *
+ * @param cls closure
+ * @param fees the wire fees we charge
+ * @param start_date from when are these fees valid (start date)
+ * @param end_date until when are these fees valid (end date, exclusive)
+ * @param master_sig master key signature affirming that this is the correct
+ * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES)
+ */
+typedef void
+(*TALER_EXCHANGEDB_WireFeeCallback)(
+ TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE *cls,
+ const struct TALER_WireFeeSet *fees,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_MasterSignatureP *master_sig);
+
+/**
+ * Obtain information about the fee structure of the exchange for
+ * a given @a wire_method
+ *
+ * @param pg the database context
+ * @param wire_method which wire method to obtain fees for
+ * @param cb function to call on each account
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_fees (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const char *wire_method,
+ TALER_EXCHANGEDB_WireFeeCallback cb,
+ TALER_EXCHANGEDB_WIRE_FEE_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_wire_outs_above_serial_id.h b/src/include/exchange-database/iterate_wire_outs_above_serial_id.h
@@ -0,0 +1,78 @@
+/*
+ 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/exchange-database/iterate_wire_outs_above_serial_id.h
+ * @brief implementation of the iterate_wire_outs_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WIRE_OUTS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_WIRE_OUTS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Function called with the results of the lookup of the
+ * wire transfer data of the exchange.
+ *
+ * @param cls closure
+ * @param rowid identifier of the respective row in the database
+ * @param date timestamp of the wire transfer (roughly)
+ * @param wtid wire transfer subject
+ * @param payto_uri details of the receiver, URI in payto://-format
+ * @param amount amount that was wired
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration
+ */
+#ifndef TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_WireTransferOutCallback.
+ */
+#define TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_WireTransferOutCallback)(
+ TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_FullPayto payto_uri,
+ const struct TALER_Amount *amount);
+
+/**
+ * Function called to select all wire transfers the exchange
+ * executed.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_outs_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback
+ cb,
+ TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_wire_outs_above_serial_id_by_account.h b/src/include/exchange-database/iterate_wire_outs_above_serial_id_by_account.h
@@ -0,0 +1,82 @@
+/*
+ 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/exchange-database/iterate_wire_outs_above_serial_id_by_account.h
+ * @brief implementation of the iterate_wire_outs_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WIRE_OUTS_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+#define EXCHANGE_DATABASE_ITERATE_WIRE_OUTS_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/* Callback typedefs */
+/**
+ * Function called with the results of the lookup of the
+ * wire transfer data of the exchange.
+ *
+ * @param cls closure
+ * @param rowid identifier of the respective row in the database
+ * @param date timestamp of the wire transfer (roughly)
+ * @param wtid wire transfer subject
+ * @param payto_uri details of the receiver, URI in payto://-format
+ * @param amount amount that was wired
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration
+ */
+#ifndef TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_WireTransferOutCallback.
+ */
+#define TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_WireTransferOutCallback)(
+ TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_FullPayto payto_uri,
+ const struct TALER_Amount *amount);
+
+/**
+ * Function called to select all wire transfers the exchange
+ * executed by account.
+ *
+ * @param pg the database context
+ * @param account_name account to select
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_outs_above_serial_id_by_account (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ const char *
+ account_name,
+ uint64_t
+ serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback
+ cb,
+ TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
+ *cb_cls)
+;
+
+#endif
diff --git a/src/include/exchange-database/iterate_wire_transfers.h b/src/include/exchange-database/iterate_wire_transfers.h
@@ -0,0 +1,119 @@
+/*
+ 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/exchange-database/iterate_wire_transfers.h
+ * @brief implementation of the iterate_wire_transfers function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WIRE_TRANSFERS_H
+#define EXCHANGE_DATABASE_ITERATE_WIRE_TRANSFERS_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with the results of the lookup of the
+ * transaction data associated with a wire transfer identifier.
+ *
+ * @param cls closure
+ * @param rowid which row in the table is the information from (for diagnostics)
+ * @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls)
+ * @param account_payto_uri which account did the transfer go to?
+ * @param h_payto hash over @a account_payto_uri as it is in the DB
+ * @param exec_time execution time of the wire transfer (should be same for all callbacks with the same @e cls)
+ * @param h_contract_terms which proposal was this payment about
+ * @param denom_pub denomination of @a coin_pub
+ * @param coin_pub which public key was this payment about
+ * @param coin_value amount contributed by this coin in total (with fee)
+ * @param coin_fee applicable fee for this coin
+ */
+#ifndef TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_AggregationDataCallback.
+ */
+#define TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE void
+#endif
+typedef void
+(*TALER_EXCHANGEDB_AggregationDataCallback)(
+ TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_FullPayto account_payto_uri,
+ const struct TALER_FullPaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp exec_time,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *coin_value,
+ const struct TALER_Amount *coin_fee);
+
+
+/* Callback typedefs */
+/**
+ * Function called with the results of the lookup of the
+ * transaction data associated with a wire transfer identifier.
+ *
+ * @param cls closure
+ * @param rowid which row in the table is the information from (for diagnostics)
+ * @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls)
+ * @param account_payto_uri which account did the transfer go to?
+ * @param h_payto hash over @a account_payto_uri as it is in the DB
+ * @param exec_time execution time of the wire transfer (should be same for all callbacks with the same @e cls)
+ * @param h_contract_terms which proposal was this payment about
+ * @param denom_pub denomination of @a coin_pub
+ * @param coin_pub which public key was this payment about
+ * @param coin_value amount contributed by this coin in total (with fee)
+ * @param coin_fee applicable fee for this coin
+ */
+typedef void
+(*TALER_EXCHANGEDB_AggregationDataCallback)(
+ TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_FullPayto account_payto_uri,
+ const struct TALER_FullPaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp exec_time,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *coin_value,
+ const struct TALER_Amount *coin_fee);
+
+/**
+ * Lookup the list of Taler transactions that were aggregated
+ * into a wire transfer by the respective @a wtid.
+ *
+ * @param pg the database context
+ * @param wtid the raw wire transfer identifier we used
+ * @param cb function to call on each transaction found
+ * @param cb_cls closure for @a cb
+ * @return query status of the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_wire_transfers (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_WireTransferIdentifierRawP *
+ wtid,
+ TALER_EXCHANGEDB_AggregationDataCallback
+ cb,
+ TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_withdraw_amounts_for_kyc_check.h b/src/include/exchange-database/iterate_withdraw_amounts_for_kyc_check.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/iterate_withdraw_amounts_for_kyc_check.h
+ * @brief implementation of the iterate_withdraw_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WITHDRAW_AMOUNTS_FOR_KYC_CHECK_H
+#define EXCHANGE_DATABASE_ITERATE_WITHDRAW_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Call @a kac on withdrawn amounts after @a time_limit which are relevant
+ * for a KYC trigger for a the (debited) account identified by @a h_payto.
+ *
+ * @param pg the database context
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_withdraw_amounts_for_kyc_check (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ struct
+ GNUNET_TIME_Absolute
+ time_limit,
+ TALER_KYCLOGIC_KycAmountCallback
+ kac,
+ void *kac_cls);
+
+#endif
diff --git a/src/include/exchange-database/iterate_withdrawals_above_serial_id.h b/src/include/exchange-database/iterate_withdrawals_above_serial_id.h
@@ -0,0 +1,129 @@
+/*
+ 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/exchange-database/iterate_withdrawals_above_serial_id.h
+ * @brief implementation of the iterate_withdrawals_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_ITERATE_WITHDRAWALS_ABOVE_SERIAL_ID_H
+#define EXCHANGE_DATABASE_ITERATE_WITHDRAWALS_ABOVE_SERIAL_ID_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called with details about withdraw operations.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refresh session in our DB
+ * @param num_denom_serials number of elements in @e denom_serials array
+ * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB
+ * @param selected_h hash over the gamma-selected planchets
+ * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request
+ * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL
+ * @param age_proof_required true if the withdraw request required an age proof.
+ * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins.
+ * @param noreveal_index if @e age_proof_required is true, the index that was returned by the exchange for the reveal phase.
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature over the withdraw operation
+ * @param execution_date when did the wallet withdraw the coin
+ * @param amount_with_fee amount that was withdrawn
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+#ifndef TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE
+/**
+ * Type of the closure for #TALER_EXCHANGEDB_WithdrawCallback.
+ */
+#define TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE void
+#endif
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_WithdrawCallback)(
+ TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ size_t num_denom_serials,
+ const uint64_t *denom_serials,
+ const struct TALER_HashBlindedPlanchetsP *selected_h,
+ const struct TALER_HashBlindedPlanchetsP *h_planchets,
+ const struct TALER_BlindingMasterSeedP *blinding_seed,
+ bool age_proof_required,
+ uint8_t max_age,
+ uint8_t noreveal_index,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_Amount *amount_with_fee);
+
+
+/* Callback typedefs */
+/**
+ * Function called with details about withdraw operations.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refresh session in our DB
+ * @param num_denom_serials number of elements in @e denom_serials array
+ * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB
+ * @param selected_h hash over the gamma-selected planchets
+ * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request
+ * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL
+ * @param age_proof_required true if the withdraw request required an age proof.
+ * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins.
+ * @param noreveal_index if @e age_proof_required is true, the index that was returned by the exchange for the reveal phase.
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature over the withdraw operation
+ * @param execution_date when did the wallet withdraw the coin
+ * @param amount_with_fee amount that was withdrawn
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_WithdrawCallback)(
+ TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE *cls,
+ uint64_t rowid,
+ size_t num_denom_serials,
+ const uint64_t *denom_serials,
+ const struct TALER_HashBlindedPlanchetsP *selected_h,
+ const struct TALER_HashBlindedPlanchetsP *h_planchets,
+ const struct TALER_BlindingMasterSeedP *blinding_seed,
+ bool age_proof_required,
+ uint8_t max_age,
+ uint8_t noreveal_index,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const struct TALER_Amount *amount_with_fee);
+
+/**
+ * Select withdraw operations from reserves_out above @a serial_id
+ * in monotonically increasing order.
+ *
+ * @param pg the database context
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_iterate_withdrawals_above_serial_id (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WithdrawCallback
+ cb,
+ TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE
+ *cb_cls);
+
+#endif
diff --git a/src/include/exchange-database/kyc_provider_account_lookup.h b/src/include/exchange-database/kyc_provider_account_lookup.h
@@ -1,53 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/kyc_provider_account_lookup.h
- * @brief implementation of the kyc_provider_account_lookup function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_KYC_PROVIDER_ACCOUNT_LOOKUP_H
-#define EXCHANGE_DATABASE_KYC_PROVIDER_ACCOUNT_LOOKUP_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup an
- * @a h_payto by @a provider_legitimization_id.
- *
- * @param pg the database context
- * @param provider_name
- * @param provider_legitimization_id legi to look up
- * @param[out] h_payto where to write the result
- * @param[out] is_wallet set to true if @a h_payto is for a wallet
- * @param[out] process_row where to write the row of the entry
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_kyc_provider_account_lookup (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const char *provider_name,
- const char *
- provider_legitimization_id,
- struct TALER_NormalizedPaytoHashP
- *
- h_payto,
- bool *is_wallet,
- uint64_t *process_row);
-
-#endif
diff --git a/src/include/exchange-database/kycauth_in_insert.h b/src/include/exchange-database/kycauth_in_insert.h
@@ -1,54 +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/exchange-database/kycauth_in_insert.h
- * @brief implementation of the kycauth_in_insert function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_KYCAUTH_IN_INSERT_H
-#define EXCHANGE_DATABASE_KYCAUTH_IN_INSERT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Insert an incoming KCYAUTH wire transfer into
- * the database and update the authentication key
- * for the origin account.
- *
- * @param pg the database context
- * @param account_pub public key of the account
- * @param credit_amount amount we were credited
- * @param execution_date when was the transfer made
- * @param debit_account_uri URI of the debit account
- * @param section_name section of the exchange bank account that received the transfer
- * @param serial_id bank-specific row identifying the transfer
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_kycauth_in_insert (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const union TALER_AccountPublicKeyP *
- account_pub,
- const struct TALER_Amount *credit_amount,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_FullPayto
- debit_account_uri,
- const char *section_name,
- uint64_t serial_id);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_active_legitimization.h b/src/include/exchange-database/lookup_active_legitimization.h
@@ -1,49 +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/exchange-database/lookup_active_legitimization.h
- * @brief implementation of the lookup_active_legitimization function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_ACTIVE_LEGITIMIZATION_H
-#define EXCHANGE_DATABASE_LOOKUP_ACTIVE_LEGITIMIZATION_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup measure data for an active legitimization process.
- *
- * @param pg the database context
- * @param legitimization_process_serial_id
- * row in legitimization_processes table to access
- * @param[out] measure_index set to the measure the
- * process is trying to satisfy
- * @param[out] jmeasures set to the legitimization
- * measures that were put on the account
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_active_legitimization (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t
- legitimization_process_serial_id,
- uint32_t *measure_index,
- json_t **jmeasures);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_aml_file_number.h b/src/include/exchange-database/lookup_aml_file_number.h
@@ -1,47 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2025 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_aml_file_number.h
- * @brief implementation of the lookup_aml_file_number function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_AML_FILE_NUMBER_H
-#define EXCHANGE_DATABASE_LOOKUP_AML_FILE_NUMBER_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup AML file number by the payto address.
- *
- * @param pg the database context
- * @param h_payto account for which to find the row ID
- * @param[out] kyc_target_row set to row in the kyc_targets table for @a h_payto
- * @param[out] is_wallet set to true if this account is for a wallet
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_aml_file_number (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- uint64_t *kyc_target_row,
- bool *is_wallet);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_aml_history.h b/src/include/exchange-database/lookup_aml_history.h
@@ -1,115 +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/exchange-database/lookup_aml_history.h
- * @brief implementation of the lookup_aml_history function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_AML_HISTORY_H
-#define EXCHANGE_DATABASE_LOOKUP_AML_HISTORY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with historic AML events of an
- * account.
- *
- * @param cls closure
- * @param outcome_serial_id row ID of the decision
- * @param decision_time when was the decision taken
- * @param justification what was the given justification
- * @param decider_pub which key signed the decision
- * @param jproperties what are the new account properties
- * @param jnew_rules what are the new account rules
- * @param to_investigate should AML staff investigate
- * after the decision
- * @param is_active is this the active decision
- */
-#ifndef TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlHistoryCallback.
- */
-#define TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlHistoryCallback) (
- TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE *cls,
- uint64_t outcome_serial_id,
- struct GNUNET_TIME_Timestamp decision_time,
- const char *justification,
- const struct TALER_AmlOfficerPublicKeyP *decider_pub,
- const json_t *jproperties,
- const json_t *jnew_rules,
- bool to_investigate,
- bool is_active);
-
-
-/* Callback typedefs */
-/**
- * Function called with historic AML events of an
- * account.
- *
- * @param cls closure
- * @param outcome_serial_id row ID of the decision
- * @param decision_time when was the decision taken
- * @param justification what was the given justification
- * @param decider_pub which key signed the decision
- * @param jproperties what are the new account properties
- * @param jnew_rules what are the new account rules
- * @param to_investigate should AML staff investigate
- * after the decision
- * @param is_active is this the active decision
- */
-typedef void
-(*TALER_EXCHANGEDB_AmlHistoryCallback) (
- TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE *cls,
- uint64_t outcome_serial_id,
- struct GNUNET_TIME_Timestamp decision_time,
- const char *justification,
- const struct TALER_AmlOfficerPublicKeyP *decider_pub,
- const json_t *jproperties,
- const json_t *jnew_rules,
- bool to_investigate,
- bool is_active);
-
-/**
- * Lookup AML history for an account identified via
- * @a h_payto.
- *
- * @param pg the database context
- * @param h_payto hash of account to lookup history for
- * @param offset row ID to start returning results from
- * @param limit how many results to return, negative for descending order
- * @param cb function to call on results
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_aml_history (struct TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct TALER_NormalizedPaytoHashP *
- h_payto,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlHistoryCallback cb,
- TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_aml_officer.h b/src/include/exchange-database/lookup_aml_officer.h
@@ -1,51 +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/exchange-database/lookup_aml_officer.h
- * @brief implementation of the lookup_aml_officer function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_AML_OFFICER_H
-#define EXCHANGE_DATABASE_LOOKUP_AML_OFFICER_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Fetch AML staff record.
- *
- * @param pg the database context
- * @param decider_pub public key of the staff member
- * @param[out] master_sig offline signature affirming the AML officer
- * @param[out] decider_name full name of the staff member
- * @param[out] is_active true to enable, false to set as inactive
- * @param[out] read_only true to set read-only access
- * @param[out] last_change when was the change made effective
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_aml_officer (struct TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct TALER_AmlOfficerPublicKeyP *
- decider_pub,
- struct TALER_MasterSignatureP *master_sig,
- char **decider_name,
- bool *is_active,
- bool *read_only,
- struct GNUNET_TIME_Absolute *last_change);
-
-#endif
diff --git a/src/include/exchange-database/lookup_auditor_status.h b/src/include/exchange-database/lookup_auditor_status.h
@@ -1,44 +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/exchange-database/lookup_auditor_status.h
- * @brief implementation of the lookup_auditor_status function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_AUDITOR_STATUS_H
-#define EXCHANGE_DATABASE_LOOKUP_AUDITOR_STATUS_H
-
-#include "exchangedb_lib.h"
-
-/**
- * Lookup current state of an auditor.
- *
- * @param pg the database context
- * @param auditor_pub key to look up information for
- * @param[out] auditor_url set to the base URL of the auditor's REST API; memory to be
- * released by the caller!
- * @param[out] enabled set if the auditor is currently in use
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_auditor_status (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AuditorPublicKeyP *
- auditor_pub,
- char **auditor_url,
- bool *enabled);
-
-#endif
diff --git a/src/include/exchange-database/lookup_auditor_timestamp.h b/src/include/exchange-database/lookup_auditor_timestamp.h
@@ -1,45 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_auditor_timestamp.h
- * @brief implementation of the lookup_auditor_timestamp function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_AUDITOR_TIMESTAMP_H
-#define EXCHANGE_DATABASE_LOOKUP_AUDITOR_TIMESTAMP_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Check the last date an auditor was modified.
- *
- * @param pg the database context
- * @param auditor_pub key to look up information for
- * @param[out] last_date last modification date to auditor status
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_auditor_timestamp (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_AuditorPublicKeyP *
- auditor_pub,
- struct GNUNET_TIME_Timestamp *
- last_date);
-
-#endif
diff --git a/src/include/exchange-database/lookup_completed_legitimization.h b/src/include/exchange-database/lookup_completed_legitimization.h
@@ -1,74 +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 lookup_completed_legitimization.h
- * @brief implementation of the lookup_pending_legitimization function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_COMPLETED_LEGITIMIZATION_H
-#define EXCHANGE_DATABASE_LOOKUP_COMPLETED_LEGITIMIZATION_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup measure data for a legitimization process.
- *
- * @param pg the database context
- * @param legitimization_measure_serial_id
- * row in legitimization_measures table to access
- * @param measure_index index of the measure to return
- * attribute data for
- * @param[out] access_token
- * set to token for access control that must match
- * @param[out] h_payto set to the the hash of the
- * payto URI of the account undergoing legitimization
- * @param[out] is_wallet set to true if @a h_payto is for a wallet
- * @param[out] jmeasures set to the legitimization
- * measures that were put on the account
- * @param[out] is_finished set to true if the legitimization was
- * already finished
- * @param[out] encrypted_attributes_len set to length of
- * @a encrypted_attributes
- * @param[out] encrypted_attributes set to the attributes
- * obtained for the legitimization process, if it
- * succeeded, otherwise set to NULL
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_completed_legitimization (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t
- legitimization_measure_serial_id,
- uint32_t measure_index,
- struct
- TALER_AccountAccessTokenP *
- access_token,
- struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- bool *is_wallet,
- json_t **jmeasures,
- bool *is_finished,
- size_t *
- encrypted_attributes_len,
- void **encrypted_attributes);
-
-#endif
diff --git a/src/include/exchange-database/lookup_denomination_key.h b/src/include/exchange-database/lookup_denomination_key.h
@@ -1,45 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_denomination_key.h
- * @brief implementation of the lookup_denomination_key function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_DENOMINATION_KEY_H
-#define EXCHANGE_DATABASE_LOOKUP_DENOMINATION_KEY_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Lookup information about current denomination key.
- *
- * @param pg the database context
- * @param h_denom_pub hash of the denomination public key
- * @param[out] meta set to various meta data about the key
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_denomination_key (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_DenominationHashP *
- h_denom_pub,
- struct
- TALER_EXCHANGEDB_DenominationKeyMetaData
- *
- meta);
-
-#endif
diff --git a/src/include/exchange-database/lookup_global_fee_by_time.h b/src/include/exchange-database/lookup_global_fee_by_time.h
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_global_fee_by_time.h
- * @brief implementation of the lookup_global_fee_by_time function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_GLOBAL_FEE_BY_TIME_H
-#define EXCHANGE_DATABASE_LOOKUP_GLOBAL_FEE_BY_TIME_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup information about known global fees.
- *
- * @param pg the database context
- * @param start_time starting time of fee
- * @param end_time end time of fee
- * @param[out] fees set to wire fees for that time period; if
- * different global fee exists within this time
- * period, an 'invalid' amount is returned.
- * @param[out] purse_timeout set to when unmerged purses expire
- * @param[out] history_expiration set to when we expire reserve histories
- * @param[out] purse_account_limit set to number of free purses
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_global_fee_by_time (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- struct GNUNET_TIME_Timestamp
- start_time,
- struct GNUNET_TIME_Timestamp
- end_time,
- struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative *
- purse_timeout
- ,
- struct GNUNET_TIME_Relative *
- history_expiration,
- uint32_t *purse_account_limit);
-
-#endif
diff --git a/src/include/exchange-database/lookup_h_payto_by_access_token.h b/src/include/exchange-database/lookup_h_payto_by_access_token.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/exchange-database/lookup_h_payto_by_access_token.h
- * @brief implementation of the lookup_h_payto_by_access_token function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_H_PAYTO_BY_ACCESS_TOKEN_H
-#define EXCHANGE_DATABASE_LOOKUP_H_PAYTO_BY_ACCESS_TOKEN_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup @a h_payto based on an @a access_token.
- *
- * @param pg the database context
- * @param access_token
- * set to token for access control
- * @param[out] h_payto set to the the hash of the
- * payto URI of the account (if found)
- * @param[out] is_wallet set to true if @a h_payto
- * is for a wallet
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_h_payto_by_access_token (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- const struct
- TALER_AccountAccessTokenP *
- access_token,
- struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- bool *is_wallet);
-
-#endif
diff --git a/src/include/exchange-database/lookup_kyc_history.h b/src/include/exchange-database/lookup_kyc_history.h
@@ -1,122 +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/exchange-database/lookup_kyc_history.h
- * @brief implementation of the lookup_kyc_history function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_KYC_HISTORY_H
-#define EXCHANGE_DATABASE_LOOKUP_KYC_HISTORY_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with historic KYC events of an
- * account.
- *
- * @param cls closure
- * @param provider_name name of the KYC provider
- * @param finished did the KYC process finish
- * @param error_code error code from the KYC process
- * @param error_message error message from the KYC process,
- * or NULL for none
- * @param provider_user_id user ID at the provider
- * or NULL for none
- * @param provider_legitimization_id legitimization process ID at the provider
- * or NULL for none
- * @param collection_time when was the data collected
- * @param expiration_time when does the collected data expire
- * @param encrypted_attributes_len number of bytes in @a encrypted_attributes
- * @param encrypted_attributes encrypted KYC attributes
- */
-#ifndef TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_KycHistoryCallback.
- */
-#define TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_KycHistoryCallback) (
- TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE *cls,
- const char *provider_name,
- bool finished,
- enum TALER_ErrorCode error_code,
- const char *error_message,
- const char *provider_user_id,
- const char *provider_legitimization_id,
- struct GNUNET_TIME_Timestamp collection_time,
- struct GNUNET_TIME_Absolute expiration_time,
- size_t encrypted_attributes_len,
- const void *encrypted_attributes);
-
-
-/* Callback typedefs */
-/**
- * Function called with historic KYC events of an
- * account.
- *
- * @param cls closure
- * @param provider_name name of the KYC provider
- * @param finished did the KYC process finish
- * @param error_code error code from the KYC process
- * @param error_message error message from the KYC process,
- * or NULL for none
- * @param provider_user_id user ID at the provider
- * or NULL for none
- * @param provider_legitimization_id legitimization process ID at the provider
- * or NULL for none
- * @param collection_time when was the data collected
- * @param expiration_time when does the collected data expire
- * @param encrypted_attributes_len number of bytes in @a encrypted_attributes
- * @param encrypted_attributes encrypted KYC attributes
- */
-typedef void
-(*TALER_EXCHANGEDB_KycHistoryCallback) (
- TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE *cls,
- const char *provider_name,
- bool finished,
- enum TALER_ErrorCode error_code,
- const char *error_message,
- const char *provider_user_id,
- const char *provider_legitimization_id,
- struct GNUNET_TIME_Timestamp collection_time,
- struct GNUNET_TIME_Absolute expiration_time,
- size_t encrypted_attributes_len,
- const void *encrypted_attributes);
-
-/**
- * Lookup KYC history for an account identified via
- * @a h_payto.
- *
- * @param pg the database context
- * @param h_payto hash of account to lookup history for
- * @param cb function to call on results
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_history (struct TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct TALER_NormalizedPaytoHashP *
- h_payto,
- TALER_EXCHANGEDB_KycHistoryCallback cb,
- TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/lookup_kyc_process_by_account.h b/src/include/exchange-database/lookup_kyc_process_by_account.h
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_kyc_process_by_account.h
- * @brief implementation of the lookup_kyc_process_by_account function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_KYC_PROCESS_BY_ACCOUNT_H
-#define EXCHANGE_DATABASE_LOOKUP_KYC_PROCESS_BY_ACCOUNT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup KYC provider meta data.
- *
- * @param pg the database context
- * @param provider_name provider that must be checked
- * @param h_payto account that must be KYC'ed
- * @param[out] process_row row with the legitimization data
- * @param[out] expiration how long is this KYC check set to be valid (in the past if invalid)
- * @param[out] provider_account_id provider account ID
- * @param[out] provider_legitimization_id provider legitimization ID
- * @param[out] is_wallet set to true if @a h_payto is for a wallet
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_process_by_account (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- const char *provider_name,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- uint64_t *process_row,
- struct GNUNET_TIME_Absolute *
- expiration,
- char **provider_account_id,
- char **
- provider_legitimization_id,
- bool *is_wallet);
-
-#endif
diff --git a/src/include/exchange-database/lookup_kyc_requirement_by_row.h b/src/include/exchange-database/lookup_kyc_requirement_by_row.h
@@ -1,72 +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/exchange-database/lookup_kyc_requirement_by_row.h
- * @brief implementation of the lookup_kyc_requirement_by_row function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_KYC_REQUIREMENT_BY_ROW_H
-#define EXCHANGE_DATABASE_LOOKUP_KYC_REQUIREMENT_BY_ROW_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup KYC requirement.
- *
- * @param pg the database context
- * @param h_payto identifies account to look up requirement for
- * @param account_pub set to public key of the account
- * needed to authorize access
- * @param[out] is_wallet set to #GNUNET_YES if the account is
- * that of a wallet (#GNUNET_SYSERR is used if unknown)
- * @param[out] access_token set to the access token to begin
- * work on KYC processes for this account
- * @param[out] rule_gen row ID of the last decision this
- * response is based on (for long-polling by clients)
- * @param[out] jrules set to active ``LegitimizationRuleSet``
- * of the account impacted by the requirement
- * @param[out] aml_review set to true if the account is under
- * active review by AML staff
- * @param[out] kyc_required set to true if the user must pass
- * some KYC check before some previous operation may continue
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_requirement_by_row (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- const union
- TALER_AccountPublicKeyP *
- account_pub,
- enum GNUNET_GenericReturnValue *
- is_wallet,
- struct TALER_AccountAccessTokenP
- *
- access_token,
- uint64_t *rule_gen,
- json_t **jrules,
- bool *aml_review,
- bool *kyc_required);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_kyc_status_by_token.h b/src/include/exchange-database/lookup_kyc_status_by_token.h
@@ -1,47 +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/exchange-database/lookup_kyc_status_by_token.h
- * @brief implementation of the lookup_kyc_status_by_token function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_KYC_STATUS_BY_TOKEN_H
-#define EXCHANGE_DATABASE_LOOKUP_KYC_STATUS_BY_TOKEN_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup KYC status by account access token.
- *
- * @param pg the database context
- * @param access_token key to look under
- * @param[out] row set to requirement row that matches
- * @param[out] jmeasures set to the LegitimizationMeasures for the @a access_token; must be freed by caller!
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_kyc_status_by_token (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct
- TALER_AccountAccessTokenP *
- access_token,
- uint64_t *row,
- json_t **jmeasures);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_pending_legitimization.h b/src/include/exchange-database/lookup_pending_legitimization.h
@@ -1,62 +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/exchange-database/lookup_pending_legitimization.h
- * @brief implementation of the lookup_pending_legitimization function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_PENDING_LEGITIMIZATION_H
-#define EXCHANGE_DATABASE_LOOKUP_PENDING_LEGITIMIZATION_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup measure data for a legitimization process.
- *
- * @param pg the database context
- * @param legitimization_measure_serial_id
- * row in legitimization_measures table to access
- * @param[out] access_token
- * set to token for access control that must match
- * @param[out] h_payto set to the the hash of the
- * payto URI of the account undergoing legitimization
- * @param[out] jmeasures set to the legitimization
- * measures that were put on the account
- * @param[out] is_finished set to true if the legitimization was
- * already finished
- * @param[out] is_wallet set to true if @a h_payto is for a wallet
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_pending_legitimization (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- uint64_t
- legitimization_measure_serial_id,
- struct TALER_AccountAccessTokenP
- *
- access_token,
- struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- json_t **jmeasures,
- bool *is_finished,
- bool *is_wallet);
-
-#endif
diff --git a/src/include/exchange-database/lookup_records_by_table.h b/src/include/exchange-database/lookup_records_by_table.h
@@ -1,624 +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 lookup_records_by_table.h
- * @brief implementation of the lookup_records_by_table function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_RECORDS_BY_TABLE_H
-#define EXCHANGE_DATABASE_LOOKUP_RECORDS_BY_TABLE_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Enumeration of all of the tables replicated by exchange-auditor
- * database replication.
- *
- * Note: wire_accounts is not replicated. So far not needed by the auditor.
- */
-enum TALER_EXCHANGEDB_ReplicatedTable
-{
- TALER_EXCHANGEDB_RT_DENOMINATIONS,
- TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS,
- TALER_EXCHANGEDB_RT_KYC_TARGETS,
- TALER_EXCHANGEDB_RT_WIRE_TARGETS,
- TALER_EXCHANGEDB_RT_RESERVES,
- TALER_EXCHANGEDB_RT_RESERVES_IN,
- TALER_EXCHANGEDB_RT_RESERVES_CLOSE,
- TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS,
- TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS,
- TALER_EXCHANGEDB_RT_AUDITORS,
- TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS,
- TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS,
- TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS,
- TALER_EXCHANGEDB_RT_KNOWN_COINS,
- TALER_EXCHANGEDB_RT_REFRESH,
- TALER_EXCHANGEDB_RT_BATCH_DEPOSITS,
- TALER_EXCHANGEDB_RT_COIN_DEPOSITS,
- TALER_EXCHANGEDB_RT_REFUNDS,
- TALER_EXCHANGEDB_RT_WIRE_OUT,
- TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING,
- TALER_EXCHANGEDB_RT_WIRE_FEE,
- TALER_EXCHANGEDB_RT_GLOBAL_FEE,
- TALER_EXCHANGEDB_RT_RECOUP,
- TALER_EXCHANGEDB_RT_RECOUP_REFRESH,
- TALER_EXCHANGEDB_RT_PURSE_REQUESTS,
- TALER_EXCHANGEDB_RT_PURSE_DECISION,
- TALER_EXCHANGEDB_RT_PURSE_MERGES,
- TALER_EXCHANGEDB_RT_PURSE_DEPOSITS,
- TALER_EXCHANGEDB_RT_ACCOUNT_MERGES,
- TALER_EXCHANGEDB_RT_HISTORY_REQUESTS,
- TALER_EXCHANGEDB_RT_CLOSE_REQUESTS,
- TALER_EXCHANGEDB_RT_WADS_OUT,
- TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES,
- TALER_EXCHANGEDB_RT_WADS_IN,
- TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES,
- TALER_EXCHANGEDB_RT_PROFIT_DRAINS,
- TALER_EXCHANGEDB_RT_AML_STAFF,
- TALER_EXCHANGEDB_RT_PURSE_DELETION,
- TALER_EXCHANGEDB_RT_WITHDRAW,
- TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES,
- TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES,
- TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES,
- TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES,
- TALER_EXCHANGEDB_RT_AML_HISTORY,
- TALER_EXCHANGEDB_RT_KYC_EVENTS,
- TALER_EXCHANGEDB_RT_KYCAUTHS_IN
-};
-
-
-/**
- * Record of a single entry in a replicated table.
- */
-struct TALER_EXCHANGEDB_TableData
-{
- /**
- * Data of which table is returned here?
- */
- enum TALER_EXCHANGEDB_ReplicatedTable table;
-
- /**
- * Serial number of the record.
- */
- uint64_t serial;
-
- /**
- * Table-specific details.
- */
- union
- {
-
- /**
- * Details from the 'denominations' table.
- */
- struct
- {
- uint32_t denom_type;
- uint32_t age_mask;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_TIME_Timestamp valid_from;
- struct GNUNET_TIME_Timestamp expire_withdraw;
- struct GNUNET_TIME_Timestamp expire_deposit;
- struct GNUNET_TIME_Timestamp expire_legal;
- struct TALER_Amount coin;
- struct TALER_DenomFeeSet fees;
- } denominations;
-
- struct
- {
- struct TALER_MasterSignatureP master_sig;
- uint64_t denominations_serial;
- } denomination_revocations;
-
- struct
- {
- struct TALER_FullPayto full_payto_uri;
- } wire_targets;
-
- struct
- {
- struct TALER_NormalizedPaytoHashP h_normalized_payto;
- struct TALER_AccountAccessTokenP access_token;
- union TALER_AccountPublicKeyP target_pub;
- bool no_account;
- bool is_wallet;
- } kyc_targets;
-
- struct
- {
- struct TALER_AccountAccessTokenP target_token;
- struct GNUNET_TIME_Timestamp start_time;
- json_t *measures;
- uint32_t display_priority;
- } legitimization_measures;
-
- struct
- {
- struct TALER_NormalizedPaytoHashP h_payto;
- struct GNUNET_TIME_Timestamp decision_time;
- struct GNUNET_TIME_Timestamp expiration_time;
- json_t *properties;
- bool to_investigate;
- json_t *new_rules;
- } legitimization_outcomes;
-
- struct
- {
- struct TALER_NormalizedPaytoHashP h_payto;
- struct GNUNET_TIME_Timestamp start_time;
- struct GNUNET_TIME_Timestamp expiration_time;
- uint64_t legitimization_measure_serial_id;
- uint32_t measure_index;
- char *provider_name;
- char *provider_user_id;
- char *provider_legitimization_id;
- char *redirect_url;
- } legitimization_processes;
-
- struct
- {
- struct TALER_NormalizedPaytoHashP h_payto;
- uint64_t legitimization_serial;
- struct GNUNET_TIME_Timestamp collection_time;
- struct GNUNET_TIME_Timestamp expiration_time;
- uint64_t trigger_outcome_serial;
- void *encrypted_attributes;
- size_t encrypted_attributes_size;
- } kyc_attributes;
-
- struct
- {
- struct TALER_NormalizedPaytoHashP h_payto;
- uint64_t outcome_serial_id;
- char *justification;
- struct TALER_AmlOfficerPublicKeyP decider_pub;
- struct TALER_AmlOfficerSignatureP decider_sig;
- } aml_history;
-
- struct
- {
- struct GNUNET_TIME_Timestamp event_timestamp;
- char *event_type;
- } kyc_events;
-
- struct
- {
- struct TALER_AmlOfficerPublicKeyP decider_pub;
- struct TALER_MasterSignatureP master_sig;
- char *decider_name;
- bool is_active;
- bool read_only;
- struct GNUNET_TIME_Timestamp last_change;
- } aml_staff;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct GNUNET_TIME_Timestamp expiration_date;
- struct GNUNET_TIME_Timestamp gc_date;
- } reserves;
-
- struct
- {
- uint64_t wire_reference;
- struct TALER_Amount credit;
- struct TALER_FullPaytoHashP sender_account_h_payto;
- char *exchange_account_section;
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_ReservePublicKeyP reserve_pub;
- } reserves_in;
-
- struct
- {
- uint64_t wire_reference;
- struct TALER_Amount credit;
- struct TALER_FullPaytoHashP sender_account_h_payto;
- char *exchange_account_section;
- struct GNUNET_TIME_Timestamp execution_date;
- union TALER_AccountPublicKeyP account_pub;
- } kycauth_in;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct GNUNET_TIME_Timestamp request_timestamp;
- struct GNUNET_TIME_Timestamp expiration_date;
- struct TALER_ReserveSignatureP reserve_sig;
- struct TALER_Amount reserve_payment;
- uint32_t requested_purse_limit;
- } reserves_open_requests;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct TALER_ReserveSignatureP reserve_sig;
- struct TALER_Amount contribution;
- } reserves_open_deposits;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_WireTransferIdentifierRawP wtid;
- struct TALER_FullPaytoHashP sender_account_h_payto;
- struct TALER_Amount amount;
- struct TALER_Amount closing_fee;
- } reserves_close;
-
- struct
- {
- struct TALER_AuditorPublicKeyP auditor_pub;
- char *auditor_url;
- char *auditor_name;
- bool is_active;
- struct GNUNET_TIME_Timestamp last_change;
- } auditors;
-
- struct
- {
- uint64_t auditor_uuid;
- uint64_t denominations_serial;
- struct TALER_AuditorSignatureP auditor_sig;
- } auditor_denom_sigs;
-
- struct
- {
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_MasterSignatureP master_sig;
- struct TALER_EXCHANGEDB_SignkeyMetaData meta;
- } exchange_sign_keys;
-
- struct
- {
- uint64_t esk_serial;
- struct TALER_MasterSignatureP master_sig;
- } signkey_revocations;
-
- struct
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_AgeCommitmentHashP age_hash;
- uint64_t denominations_serial;
- struct TALER_DenominationSignature denom_sig;
- } known_coins;
-
- struct
- {
- struct TALER_RefreshCommitmentP rc;
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_Amount amount_with_fee;
- struct TALER_CoinSpendPublicKeyP old_coin_pub;
- struct TALER_CoinSpendSignatureP old_coin_sig;
- struct TALER_PublicRefreshMasterSeedP refresh_seed;
- uint32_t noreveal_index;
- struct TALER_HashBlindedPlanchetsP planchets_h;
- struct TALER_HashBlindedPlanchetsP selected_h;
- bool no_blinding_seed;
- struct TALER_BlindingMasterSeedP blinding_seed;
- size_t num_cs_r_values;
- struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values;
- uint64_t cs_r_choices;
- size_t num_coins;
- uint64_t *denom_serials;
- struct TALER_BlindedDenominationSignature *denom_sigs;
- } refresh;
-
- struct
- {
- uint64_t shard;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct GNUNET_TIME_Timestamp wallet_timestamp;
- struct GNUNET_TIME_Timestamp exchange_timestamp;
- struct GNUNET_TIME_Timestamp refund_deadline;
- struct GNUNET_TIME_Timestamp wire_deadline;
- struct TALER_PrivateContractHashP h_contract_terms;
- bool no_wallet_data_hash;
- struct GNUNET_HashCode wallet_data_hash;
- struct TALER_WireSaltP wire_salt;
- struct TALER_FullPaytoHashP wire_target_h_payto;
- struct TALER_Amount total_amount;
- struct TALER_Amount total_without_fee;
- struct TALER_MerchantSignatureP merchant_sig;
- bool done;
- } batch_deposits;
-
- struct
- {
- uint64_t batch_deposit_serial_id;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct TALER_Amount amount_with_fee;
- } coin_deposits;
-
- struct
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- uint64_t batch_deposit_serial_id;
- struct TALER_MerchantSignatureP merchant_sig;
- uint64_t rtransaction_id;
- struct TALER_Amount amount_with_fee;
- } refunds;
-
- struct
- {
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_WireTransferIdentifierRawP wtid_raw;
- struct TALER_FullPaytoHashP wire_target_h_payto;
- char *exchange_account_section;
- struct TALER_Amount amount;
- } wire_out;
-
- struct
- {
- uint64_t batch_deposit_serial_id;
- struct TALER_WireTransferIdentifierRawP wtid_raw;
- } aggregation_tracking;
-
- struct
- {
- char *wire_method;
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct TALER_WireFeeSet fees;
- struct TALER_MasterSignatureP master_sig;
- } wire_fee;
-
- struct
- {
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct TALER_GlobalFeeSet fees;
- struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative history_expiration;
- uint32_t purse_account_limit;
- struct TALER_MasterSignatureP master_sig;
- } global_fee;
-
- struct
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- union GNUNET_CRYPTO_BlindingSecretP coin_blind;
- struct TALER_Amount amount;
- struct GNUNET_TIME_Timestamp timestamp;
- uint64_t withdraw_serial_id;
- } recoup;
-
- struct
- {
- uint64_t known_coin_id;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- union GNUNET_CRYPTO_BlindingSecretP coin_blind;
- struct TALER_Amount amount;
- struct GNUNET_TIME_Timestamp recoup_timestamp;
- uint64_t refresh_id;
- } recoup_refresh;
-
- struct
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PurseMergePublicKeyP merge_pub;
- struct GNUNET_TIME_Timestamp purse_creation;
- struct GNUNET_TIME_Timestamp purse_expiration;
- struct TALER_PrivateContractHashP h_contract_terms;
- uint32_t age_limit;
- uint32_t flags;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount purse_fee;
- struct TALER_PurseContractSignatureP purse_sig;
- } purse_requests;
-
- struct
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct GNUNET_TIME_Timestamp action_timestamp;
- bool refunded;
- } purse_decision;
-
- struct
- {
- uint64_t partner_serial_id;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PurseMergeSignatureP merge_sig;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- } purse_merges;
-
- struct
- {
- uint64_t partner_serial_id;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount amount_with_fee;
- struct TALER_CoinSpendSignatureP coin_sig;
- } purse_deposits;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_NormalizedPaytoHashP wallet_h_payto;
- } account_merges;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- struct GNUNET_TIME_Timestamp request_timestamp;
- struct TALER_Amount history_fee;
- } history_requests;
-
- struct
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct GNUNET_TIME_Timestamp close_timestamp;
- struct TALER_ReserveSignatureP reserve_sig;
- struct TALER_Amount close;
- struct TALER_Amount close_fee;
- struct TALER_FullPayto payto_uri;
- } close_requests;
-
- struct
- {
- struct TALER_WadIdentifierP wad_id;
- uint64_t partner_serial_id;
- struct TALER_Amount amount;
- struct GNUNET_TIME_Timestamp execution_time;
- } wads_out;
-
- struct
- {
- uint64_t wad_out_serial_id;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PrivateContractHashP h_contract;
- struct GNUNET_TIME_Timestamp purse_expiration;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount wad_fee;
- struct TALER_Amount deposit_fees;
- struct TALER_ReserveSignatureP reserve_sig;
- struct TALER_PurseContractSignatureP purse_sig;
- } wads_out_entries;
-
- struct
- {
- struct TALER_WadIdentifierP wad_id;
- char *origin_exchange_url;
- struct TALER_Amount amount;
- struct GNUNET_TIME_Timestamp arrival_time;
- } wads_in;
-
- struct
- {
- uint64_t wad_in_serial_id;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PrivateContractHashP h_contract;
- struct GNUNET_TIME_Timestamp purse_expiration;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount wad_fee;
- struct TALER_Amount deposit_fees;
- struct TALER_ReserveSignatureP reserve_sig;
- struct TALER_PurseContractSignatureP purse_sig;
- } wads_in_entries;
-
- struct
- {
- struct TALER_WireTransferIdentifierRawP wtid;
- char *account_section;
- struct TALER_FullPayto payto_uri;
- struct GNUNET_TIME_Timestamp trigger_date;
- struct TALER_Amount amount;
- struct TALER_MasterSignatureP master_sig;
- } profit_drains;
-
- struct
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PurseContractSignatureP purse_sig;
- } purse_deletion;
-
- struct
- {
- struct TALER_HashBlindedPlanchetsP planchets_h;
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_Amount amount_with_fee;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- bool age_proof_required;
- uint16_t max_age;
- uint16_t noreveal_index;
- struct TALER_HashBlindedPlanchetsP selected_h;
- bool no_blinding_seed;
- struct TALER_BlindingMasterSeedP blinding_seed;
- size_t num_cs_r_values;
- struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values;
- uint64_t cs_r_choices;
- size_t num_coins;
- uint64_t *denom_serials;
- struct TALER_BlindedDenominationSignature *denom_sigs;
- } withdraw;
-
- } details;
-
-};
-
-
-/**
- * Function called on data to replicate in the auditor's database.
- *
- * @param cls closure
- * @param td record from an exchange table
- * @return #GNUNET_OK to continue to iterate,
- * #GNUNET_SYSERR to fail with an error
- */
-#ifndef TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReplicationCallback.
- */
-#define TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE void
-#endif
-typedef int
-(*TALER_EXCHANGEDB_ReplicationCallback)(
- TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE *cls,
- const struct TALER_EXCHANGEDB_TableData *td);
-
-
-/**
- * Function called on data to replicate in the auditor's database.
- *
- * @param cls closure
- * @param td record from an exchange table
- * @return #GNUNET_OK to continue to iterate,
- * #GNUNET_SYSERR to fail with an error
- */
-typedef int
-(*TALER_EXCHANGEDB_ReplicationCallback)(
- TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE *cls,
- const struct TALER_EXCHANGEDB_TableData *td);
-
-
-/**
- * Lookup records above @a serial number in @a table. Used in
- * exchange-auditor database replication.
- *
- * @param pg the database context
- * @param table table for which we should return the serial
- * @param serial largest serial number to exclude
- * @param cb function to call on the records
- * @param cb_cls closure for @a cb
- * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
- * @a table does not have a serial number
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_records_by_table (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- enum TALER_EXCHANGEDB_ReplicatedTable table,
- uint64_t serial,
- TALER_EXCHANGEDB_ReplicationCallback cb,
- TALER_EXCHANGEDB_REPLICATION_RESULT_CLOSURE *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_rules_by_access_token.h b/src/include/exchange-database/lookup_rules_by_access_token.h
@@ -1,47 +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/exchange-database/lookup_rules_by_access_token.h
- * @brief implementation of the lookup_rules_by_access_token function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_RULES_BY_ACCESS_TOKEN_H
-#define EXCHANGE_DATABASE_LOOKUP_RULES_BY_ACCESS_TOKEN_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup KYC rules by account access token.
- *
- * @param pg the database context
- * @param h_payto account hash to look under
- * @param[out] jnew_rules set to active LegitimizationRuleSet
- * @param[out] rowid set to outcome_serial_id of the row
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_rules_by_access_token (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- json_t **jnew_rules,
- uint64_t *rowid);
-
-#endif
diff --git a/src/include/exchange-database/lookup_serial_by_table.h b/src/include/exchange-database/lookup_serial_by_table.h
@@ -1,44 +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 lookup_serial_by_table.h
- * @brief implementation of the lookup_serial_by_table function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_SERIAL_BY_TABLE_H
-#define EXCHANGE_DATABASE_LOOKUP_SERIAL_BY_TABLE_H
-
-#include "exchangedb_lib.h"
-#include "exchange-database/lookup_records_by_table.h"
-
-/**
- * Lookup the latest serial number of @a table. Used in
- * exchange-auditor database replication.
- *
- * @param pg the database context
- * @param table table for which we should return the serial
- * @param[out] serial latest serial number in use
- * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
- * @a table does not have a serial number
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_serial_by_table (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- enum TALER_EXCHANGEDB_ReplicatedTable table,
- uint64_t *serial);
-
-
-#endif
diff --git a/src/include/exchange-database/lookup_signing_key.h b/src/include/exchange-database/lookup_signing_key.h
@@ -1,43 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_signing_key.h
- * @brief implementation of the lookup_signing_key function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_SIGNING_KEY_H
-#define EXCHANGE_DATABASE_LOOKUP_SIGNING_KEY_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup signing key meta data.
- *
- * @param pg the database context
- * @param exchange_pub the exchange online signing public key
- * @param[out] meta meta data about @a exchange_pub
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_signing_key (struct TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct TALER_ExchangePublicKeyP *
- exchange_pub,
- struct TALER_EXCHANGEDB_SignkeyMetaData *
- meta);
-
-#endif
diff --git a/src/include/exchange-database/lookup_signkey_revocation.h b/src/include/exchange-database/lookup_signkey_revocation.h
@@ -1,46 +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/exchange-database/lookup_signkey_revocation.h
- * @brief implementation of the lookup_signkey_revocation function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_SIGNKEY_REVOCATION_H
-#define EXCHANGE_DATABASE_LOOKUP_SIGNKEY_REVOCATION_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Obtain information about a revoked online signing key.
- *
- * @param pg the database context
- * @param exchange_pub exchange online signing key
- * @param[out] master_sig set to signature affirming the revocation (if revoked)
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_signkey_revocation (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct
- TALER_ExchangePublicKeyP *
- exchange_pub,
- struct TALER_MasterSignatureP *
- master_sig)
-;
-
-#endif
diff --git a/src/include/exchange-database/lookup_transfer_by_deposit.h b/src/include/exchange-database/lookup_transfer_by_deposit.h
@@ -1,79 +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/exchange-database/lookup_transfer_by_deposit.h
- * @brief implementation of the lookup_transfer_by_deposit function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_TRANSFER_BY_DEPOSIT_H
-#define EXCHANGE_DATABASE_LOOKUP_TRANSFER_BY_DEPOSIT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Try to find the wire transfer details for a deposit operation.
- * If we did not execute the deposit yet, return when it is supposed
- * to be executed.
- *
- * @param pg the database context
- * @param h_contract_terms hash of the proposal data
- * @param h_wire hash of merchant wire details
- * @param coin_pub public key of deposited coin
- * @param merchant_pub merchant public key
- * @param[out] pending set to true if the transaction is still pending
- * @param[out] wtid wire transfer identifier, only set if @a pending is false
- * @param[out] exec_time when was the transaction done, or
- * when we expect it to be done (if @a pending is false)
- * @param[out] amount_with_fee set to the total deposited amount
- * @param[out] deposit_fee set to how much the exchange did charge for the deposit
- * @param[out] kyc set to the kyc status of the receiver (if @a pending)
- * @param[out] account_pub set to public key that is authorized to start the KYC process; unchanged if no such key is known
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_transfer_by_deposit (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct
- TALER_PrivateContractHashP *
- h_contract_terms,
- const struct
- TALER_MerchantWireHashP *
- h_wire,
- const struct
- TALER_CoinSpendPublicKeyP *
- coin_pub,
- const struct
- TALER_MerchantPublicKeyP *
- merchant_pub,
- bool *pending,
- struct
- TALER_WireTransferIdentifierRawP *
- wtid,
- struct GNUNET_TIME_Timestamp *
- exec_time,
- struct TALER_Amount *
- amount_with_fee,
- struct TALER_Amount *deposit_fee,
- struct TALER_EXCHANGEDB_KycStatus *
- kyc,
- union TALER_AccountPublicKeyP *
- account_pub);
-
-#endif
diff --git a/src/include/exchange-database/lookup_wire_fee_by_time.h b/src/include/exchange-database/lookup_wire_fee_by_time.h
@@ -1,53 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/lookup_wire_fee_by_time.h
- * @brief implementation of the lookup_wire_fee_by_time function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_WIRE_FEE_BY_TIME_H
-#define EXCHANGE_DATABASE_LOOKUP_WIRE_FEE_BY_TIME_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Lookup information about known wire fees. Finds all applicable
- * fees in the given range. If they are identical, returns the
- * respective @a fees. If any of the fees
- * differ between @a start_time and @a end_time, the transaction
- * succeeds BUT returns an invalid amount for both fees.
- *
- * @param pg the database context
- * @param wire_method the wire method to lookup fees for
- * @param start_time starting time of fee
- * @param end_time end time of fee
- * @param[out] fees wire fees for that time period; if
- * different fees exists within this time
- * period, an 'invalid' amount is returned.
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_wire_fee_by_time (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *wire_method,
- struct GNUNET_TIME_Timestamp
- start_time,
- struct GNUNET_TIME_Timestamp end_time,
- struct TALER_WireFeeSet *fees);
-
-#endif
diff --git a/src/include/exchange-database/lookup_wire_timestamp.h b/src/include/exchange-database/lookup_wire_timestamp.h
@@ -1,44 +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/exchange-database/lookup_wire_timestamp.h
- * @brief implementation of the lookup_wire_timestamp function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_WIRE_TIMESTAMP_H
-#define EXCHANGE_DATABASE_LOOKUP_WIRE_TIMESTAMP_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Check the last date an exchange wire account was modified.
- *
- * @param pg the database context
- * @param payto_uri key to look up information for
- * @param[out] last_date last modification date to auditor status
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_wire_timestamp (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_FullPayto payto_uri,
- struct GNUNET_TIME_Timestamp *last_date)
-;
-
-#endif
diff --git a/src/include/exchange-database/lookup_wire_transfer.h b/src/include/exchange-database/lookup_wire_transfer.h
@@ -1,118 +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/exchange-database/lookup_wire_transfer.h
- * @brief implementation of the lookup_wire_transfer function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_LOOKUP_WIRE_TRANSFER_H
-#define EXCHANGE_DATABASE_LOOKUP_WIRE_TRANSFER_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with the results of the lookup of the
- * transaction data associated with a wire transfer identifier.
- *
- * @param cls closure
- * @param rowid which row in the table is the information from (for diagnostics)
- * @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls)
- * @param account_payto_uri which account did the transfer go to?
- * @param h_payto hash over @a account_payto_uri as it is in the DB
- * @param exec_time execution time of the wire transfer (should be same for all callbacks with the same @e cls)
- * @param h_contract_terms which proposal was this payment about
- * @param denom_pub denomination of @a coin_pub
- * @param coin_pub which public key was this payment about
- * @param coin_value amount contributed by this coin in total (with fee)
- * @param coin_fee applicable fee for this coin
- */
-#ifndef TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AggregationDataCallback.
- */
-#define TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AggregationDataCallback)(
- TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_FullPayto account_payto_uri,
- const struct TALER_FullPaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp exec_time,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *coin_value,
- const struct TALER_Amount *coin_fee);
-
-
-/* Callback typedefs */
-/**
- * Function called with the results of the lookup of the
- * transaction data associated with a wire transfer identifier.
- *
- * @param cls closure
- * @param rowid which row in the table is the information from (for diagnostics)
- * @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls)
- * @param account_payto_uri which account did the transfer go to?
- * @param h_payto hash over @a account_payto_uri as it is in the DB
- * @param exec_time execution time of the wire transfer (should be same for all callbacks with the same @e cls)
- * @param h_contract_terms which proposal was this payment about
- * @param denom_pub denomination of @a coin_pub
- * @param coin_pub which public key was this payment about
- * @param coin_value amount contributed by this coin in total (with fee)
- * @param coin_fee applicable fee for this coin
- */
-typedef void
-(*TALER_EXCHANGEDB_AggregationDataCallback)(
- TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_FullPayto account_payto_uri,
- const struct TALER_FullPaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp exec_time,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *coin_value,
- const struct TALER_Amount *coin_fee);
-
-/**
- * Lookup the list of Taler transactions that were aggregated
- * into a wire transfer by the respective @a wtid.
- *
- * @param pg the database context
- * @param wtid the raw wire transfer identifier we used
- * @param cb function to call on each transaction found
- * @param cb_cls closure for @a cb
- * @return query status of the transaction
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_lookup_wire_transfer (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct
- TALER_WireTransferIdentifierRawP *
- wtid,
- TALER_EXCHANGEDB_AggregationDataCallback
- cb,
- TALER_EXCHANGEDB_AGGREGATION_DATA_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/mark_refresh_reveal_success.h b/src/include/exchange-database/mark_refresh_reveal_success.h
@@ -1,42 +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/exchange-database/mark_refresh_reveal_success.h
- * @brief Mark the successful reveal of a refresh in the database
- * @author Özgür Kesim
- */
-#ifndef EXCHANGE_DATABASE_MARK_REFRESH_REVEAL_SUCCESS_H
-#define EXCHANGE_DATABASE_MARK_REFRESH_REVEAL_SUCCESS_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Mark a refresh, given by the commitment, as successfully revealed.
- *
- * @param pg the database context
- * @param rc commitment for the refresh
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_mark_refresh_reveal_success (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct
- TALER_RefreshCommitmentP *
- rc);
-
-#endif
diff --git a/src/include/exchange-database/persist_aml_program_result.h b/src/include/exchange-database/persist_aml_program_result.h
@@ -1,53 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file persist_aml_program_result.h
- * @brief implementation of the persist_aml_program_result function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_PERSIST_AML_PROGRAM_RESULT_H
-#define EXCHANGE_DATABASE_PERSIST_AML_PROGRAM_RESULT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-#include "exchange-database/set_aml_lock.h"
-#include "exchange-database/clear_aml_lock.h"
-
-
-/**
- * Persist the given @a apr for the given process and account
- * into the database via @a pg. Called within an open
- * database transaction.
- *
- * @param pg database API handle
- * @param process_row row identifying the legitimization process that was run,
- * 0 if there was no legi process (for example, due to rule
- * expiration triggering something) and we should simply
- * create a new row
- * @param account_id hash of account the result is about
- * @param ret_pprs
- * @param apr AML program result to persist
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_persist_aml_program_result (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t process_row,
- const struct TALER_NormalizedPaytoHashP *account_id,
- const struct TALER_KYCLOGIC_AmlProgramResult *apr,
- enum TALER_EXCHANGEDB_PersistProgramResultStatus *ret_pprs);
-
-#endif
diff --git a/src/include/exchange-database/persist_kyc_attributes.h b/src/include/exchange-database/persist_kyc_attributes.h
@@ -1,63 +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/exchange-database/persist_kyc_attributes.h
- * @brief implementation of the persist_kyc_attributes function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_PERSIST_KYC_ATTRIBUTES_H
-#define EXCHANGE_DATABASE_PERSIST_KYC_ATTRIBUTES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Store KYC attribute data.
- *
- * @param pg the database context
- * @param process_row KYC process row to update
- * @param h_payto account for which the attribute data is stored
- * @param provider_name name of the provider that provided the attributes
- * @param provider_account_id provider account ID
- * @param provider_legitimization_id provider legitimization ID
- * @param birthday birthdate of user, in days after 1990, or 0 if unknown or definitively adult
- * @param expiration_time when does the data expire
- * @param form_name name of the form from which the @a enc_attributes originate, can be NULL
- * @param enc_attributes_size number of bytes in @a enc_attributes
- * @param enc_attributes encrypted attribute data
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_persist_kyc_attributes (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t process_row,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- const char *provider_name,
- const char *provider_account_id,
- const char *provider_legitimization_id,
- uint32_t birthday,
- struct GNUNET_TIME_Absolute
- expiration_time,
- const char *form_name,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-
-#endif
diff --git a/src/include/exchange-database/profit_drains_get_pending.h b/src/include/exchange-database/profit_drains_get_pending.h
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/profit_drains_get_pending.h
- * @brief implementation of the profit_drains_get_pending function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_PROFIT_DRAINS_GET_PENDING_H
-#define EXCHANGE_DATABASE_PROFIT_DRAINS_GET_PENDING_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Get profit drain operation ready to execute.
- *
- * @param pg the database context
- * @param[out] serial set to serial ID of the entry
- * @param[out] wtid set set to wire transfer ID to use
- * @param[out] account_section set to account to drain
- * @param[out] payto_uri set to account to wire funds to
- * @param[out] request_timestamp set to time of the signature
- * @param[out] amount set to amount to wire
- * @param[out] master_sig set to signature affirming the operation
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_profit_drains_get_pending (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- uint64_t *serial,
- struct
- TALER_WireTransferIdentifierRawP *
- wtid,
- char **account_section,
- struct TALER_FullPayto *payto_uri,
- struct GNUNET_TIME_Timestamp *
- request_timestamp,
- struct TALER_Amount *amount,
- struct TALER_MasterSignatureP *
- master_sig)
-;
-
-#endif
diff --git a/src/include/exchange-database/profit_drains_set_finished.h b/src/include/exchange-database/profit_drains_set_finished.h
@@ -1,40 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/profit_drains_set_finished.h
- * @brief implementation of the profit_drains_set_finished function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_PROFIT_DRAINS_SET_FINISHED_H
-#define EXCHANGE_DATABASE_PROFIT_DRAINS_SET_FINISHED_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Set profit drain operation to finished.
- *
- * @param pg the database context
- * @param serial serial ID of the entry to mark finished
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_profit_drains_set_finished (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- uint64_t serial);
-
-#endif
diff --git a/src/include/exchange-database/reserves_get.h b/src/include/exchange-database/reserves_get.h
@@ -1,40 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/reserves_get.h
- * @brief implementation of the reserves_get function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_RESERVES_GET_H
-#define EXCHANGE_DATABASE_RESERVES_GET_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-/**
- * Get the summary of a reserve.
- *
- * @param pg the database context
- * @param[in,out] reserve the reserve data. The public key of the reserve should be
- * set in this structure; it is used to query the database. The balance
- * and expiration are then filled accordingly.
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_reserves_get (struct TALER_EXCHANGEDB_PostgresContext *pg,
- struct TALER_EXCHANGEDB_Reserve *reserve);
-
-#endif
diff --git a/src/include/exchange-database/reserves_get_origin.h b/src/include/exchange-database/reserves_get_origin.h
@@ -1,48 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/reserves_get_origin.h
- * @brief implementation of the reserves_get_origin function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_RESERVES_GET_ORIGIN_H
-#define EXCHANGE_DATABASE_RESERVES_GET_ORIGIN_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Get the origin of funds of a reserve.
- *
- * @param pg the database context
- * @param reserve_pub public key of the reserve
- * @param[out] h_payto set to hash of the wire source payto://-URI
- * @param[out] payto_uri set to the wire source payto://-URI
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_reserves_get_origin (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct
- TALER_ReservePublicKeyP *
- reserve_pub,
- struct TALER_FullPaytoHashP *h_payto
- ,
- struct TALER_FullPayto *payto_uri);
-
-#endif
diff --git a/src/include/exchange-database/reserves_in_insert.h b/src/include/exchange-database/reserves_in_insert.h
@@ -1,58 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/reserves_in_insert.h
- * @brief implementation of the reserves_in_insert function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_RESERVES_IN_INSERT_H
-#define EXCHANGE_DATABASE_RESERVES_IN_INSERT_H
-
-#include "exchangedb_lib.h"
-
-
-struct TALER_EXCHANGEDB_ReserveInInfo
-{
- const struct TALER_ReservePublicKeyP *reserve_pub;
- const struct TALER_Amount *balance;
- struct GNUNET_TIME_Timestamp execution_time;
- struct TALER_FullPayto sender_account_details;
- const char *exchange_account_name;
- uint64_t wire_reference;
-};
-
-
-/**
- * Insert an incoming transaction into reserves. New reserves are also
- * created through this function. Runs its own transaction(s).
- *
- * @param pg the database context
- * @param reserves array of reserves to insert
- * @param reserves_length length of the @a reserves array
- * @param[out] results set to query status per reserve, must be of length @a reserves_length
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_reserves_in_insert (struct TALER_EXCHANGEDB_PostgresContext *pg
- ,
- const struct
- TALER_EXCHANGEDB_ReserveInInfo *
- reserves,
- unsigned int reserves_length,
- enum GNUNET_DB_QueryStatus *results);
-
-
-#endif
diff --git a/src/include/exchange-database/reserves_update.h b/src/include/exchange-database/reserves_update.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/exchange-database/reserves_update.h
- * @brief implementation of the reserves_update function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_RESERVES_UPDATE_H
-#define EXCHANGE_DATABASE_RESERVES_UPDATE_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Updates a reserve with the data from the given reserve structure.
- *
- * @param pg the database context
- * @param reserve the reserve structure whose data will be used to update the
- * corresponding record in the database.
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_reserves_update (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_EXCHANGEDB_Reserve *reserve
- );
-
-#endif
diff --git a/src/include/exchange-database/select_account_merges_above_serial_id.h b/src/include/exchange-database/select_account_merges_above_serial_id.h
@@ -1,89 +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 select_account_merges_above_serial_id.h
- * @brief implementation of the select_account_merges_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_ACCOUNT_MERGES_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_ACCOUNT_MERGES_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Function called with details about
- * account merge requests that have been made, with
- * the goal of auditing the account merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param reserve_pub reserve affected by the merge
- * @param purse_pub purse being merged
- * @param h_contract_terms hash over contract of the purse
- * @param purse_expiration when would the purse expire
- * @param amount total amount in the purse
- * @param min_age minimum age of all coins deposited into the purse
- * @param flags how was the purse created
- * @param purse_fee if a purse fee was paid, how high is it
- * @param merge_timestamp when was the merge approved
- * @param reserve_sig signature by reserve approving the merge
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AccountMergeCallback.
- */
-#define TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_AccountMergeCallback)(
- TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_Amount *amount,
- uint32_t min_age,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *purse_fee,
- struct GNUNET_TIME_Timestamp merge_timestamp,
- const struct TALER_ReserveSignatureP *reserve_sig);
-
-/**
- * Select account merges above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_account_merges_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AccountMergeCallback
- cb,
- TALER_EXCHANGEDB_ACCOUNT_MERGE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_aggregation_amounts_for_kyc_check.h b/src/include/exchange-database/select_aggregation_amounts_for_kyc_check.h
@@ -1,48 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_aggregation_amounts_for_kyc_check.h
- * @brief implementation of the select_aggregation_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AGGREGATION_AMOUNTS_FOR_KYC_CHECK_H
-#define EXCHANGE_DATABASE_SELECT_AGGREGATION_AMOUNTS_FOR_KYC_CHECK_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Call @a kac on deposited amounts after @a time_limit which are relevant for a
- * KYC trigger for a the (credited) account identified by @a h_payto.
- *
- * @param pg the database context
- * @param h_payto account identifier
- * @param time_limit oldest transaction that could be relevant
- * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
- * @param kac_cls closure for @a kac
- * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aggregation_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_aggregation_transient.h b/src/include/exchange-database/select_aggregation_transient.h
@@ -1,58 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_aggregation_transient.h
- * @brief implementation of the select_aggregation_transient function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AGGREGATION_TRANSIENT_H
-#define EXCHANGE_DATABASE_SELECT_AGGREGATION_TRANSIENT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Find existing entry in the transient aggregation table.
- *
- * @param pg the database context
- * @param h_payto destination of the wire transfer
- * @param merchant_pub public key of the merchant receiving the transfer
- * @param exchange_account_section exchange account to use
- * @param[out] wtid set to the raw wire transfer identifier to be used
- * @param[out] total existing amount to be wired in the future
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aggregation_transient (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_FullPaytoHashP *
- h_payto,
- const struct
- TALER_MerchantPublicKeyP *
- merchant_pub,
- const char *
- exchange_account_section,
- struct
- TALER_WireTransferIdentifierRawP
- *wtid,
- struct TALER_Amount *total);
-
-
-#endif
diff --git a/src/include/exchange-database/select_aggregations_above_serial.h b/src/include/exchange-database/select_aggregations_above_serial.h
@@ -1,92 +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/exchange-database/select_aggregations_above_serial.h
- * @brief implementation of the select_aggregations_above_serial function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AGGREGATIONS_ABOVE_SERIAL_H
-#define EXCHANGE_DATABASE_SELECT_AGGREGATIONS_ABOVE_SERIAL_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called on aggregations that were done for
- * a (batch) deposit.
- *
- * @param cls closure
- * @param amount affected amount
- * @param tracking_serial_id where in the table are we
- * @param batch_deposit_serial_id which batch deposit was aggregated
- */
-#ifndef TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AggregationCallback.
- */
-#define TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AggregationCallback)(
- TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE *cls,
- const struct TALER_Amount *amount,
- uint64_t tracking_serial_id,
- uint64_t batch_deposit_serial_id);
-
-
-/* Callback typedefs */
-/**
- * Function called on aggregations that were done for
- * a (batch) deposit.
- *
- * @param cls closure
- * @param amount affected amount
- * @param tracking_serial_id where in the table are we
- * @param batch_deposit_serial_id which batch deposit was aggregated
- */
-typedef void
-(*TALER_EXCHANGEDB_AggregationCallback)(
- TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE *cls,
- const struct TALER_Amount *amount,
- uint64_t tracking_serial_id,
- uint64_t batch_deposit_serial_id);
-
-/**
- * Select all aggregation tracking IDs in the database
- * above a given @a min_tracking_serial_id.
- *
- * @param pg the database context
- * @param min_tracking_serial_id only return entries strictly above this row (and in order)
- * @param cb function to call on all such aggregations
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aggregations_above_serial (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t
- min_tracking_serial_id,
- TALER_EXCHANGEDB_AggregationCallback
- cb,
- TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_all_kyc_attributes.h b/src/include/exchange-database/select_all_kyc_attributes.h
@@ -1,108 +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/exchange-database/select_all_kyc_attributes.h
- * @brief implementation of the select_all_kyc_attributes function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_ALL_KYC_ATTRIBUTES_H
-#define EXCHANGE_DATABASE_SELECT_ALL_KYC_ATTRIBUTES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Return KYC attribute information.
- *
- * @param cls closure
- * @param row_id current row in kyc_attributes table
- * @param h_payto account the attributes are about
- * @param provider_name name of the provider that collected the attributes
- * @param collection_time when were the attributes collected
- * @param expiration_time when does the data expire
- * @param properties properties that were set for @a h_payto
- * @param enc_attributes_size size of @a enc_attributes
- * @param enc_attributes the encrypted collected attributes
- * @return true to continue to iterate
- */
-#ifndef TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AllAttributesCallback.
- */
-#define TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE void
-#endif
-typedef bool
-(*TALER_EXCHANGEDB_AllAttributesCallback)(
- TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_name,
- struct GNUNET_TIME_Timestamp collection_time,
- struct GNUNET_TIME_Timestamp expiration_time,
- const json_t *properties,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-
-/* Callback typedefs */
-/**
- * Return KYC attribute information.
- *
- * @param cls closure
- * @param row_id current row in kyc_attributes table
- * @param h_payto account the attributes are about
- * @param provider_name name of the provider that collected the attributes
- * @param collection_time when were the attributes collected
- * @param expiration_time when does the data expire
- * @param properties properties that were set for @a h_payto
- * @param enc_attributes_size size of @a enc_attributes
- * @param enc_attributes the encrypted collected attributes
- * @return true to continue to iterate
- */
-typedef bool
-(*TALER_EXCHANGEDB_AllAttributesCallback)(
- TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_name,
- struct GNUNET_TIME_Timestamp collection_time,
- struct GNUNET_TIME_Timestamp expiration_time,
- const json_t *properties,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-/**
- * Lookup all KYC attributes above @a min_row_id.
- *
- * @param pg the database context
- * @param min_row_id minimum row ID to return (exclusive)
- * @param cb callback to invoke on each match
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_all_kyc_attributes (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- uint64_t min_row_id,
- TALER_EXCHANGEDB_AllAttributesCallback
- cb,
- TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_all_purse_decisions_above_serial_id.h b/src/include/exchange-database/select_all_purse_decisions_above_serial_id.h
@@ -1,92 +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 select_all_purse_decisions_above_serial_id.h
- * @brief implementation of the select_all_purse_decisions_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_ALL_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_ALL_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about purse decisions that have been made, with
- * the goal of auditing the purse's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the purse
- * @param refunded true if decision was to refund
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AllPurseDecisionCallback.
- */
-#define TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_AllPurseDecisionCallback)(
- TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- bool refunded);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about purse decisions that have been made, with
- * the goal of auditing the purse's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the purse
- * @param refunded true if decision was to refund
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_AllPurseDecisionCallback)(
- TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- bool refunded);
-
-/**
- * Select purse decisions above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_all_purse_decisions_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AllPurseDecisionCallback
- cb,
- TALER_EXCHANGEDB_ALL_PURSE_DECISION_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_all_purse_deletions_above_serial_id.h b/src/include/exchange-database/select_all_purse_deletions_above_serial_id.h
@@ -1,91 +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/exchange-database/select_all_purse_deletions_above_serial_id.h
- * @brief implementation of the select_all_purse_deletions_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_ALL_PURSE_DELETIONS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_ALL_PURSE_DELETIONS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about purse deletions that have been made, with
- * the goal of auditing the purse's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the purse
- * @param purse_sig signature affirming deletion of the purse
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AllPurseDeletionsCallback.
- */
-#define TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_AllPurseDeletionsCallback)(
- TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseContractSignatureP *purse_sig);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about purse deletions that have been made, with
- * the goal of auditing the purse's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the purse
- * @param purse_sig signature affirming deletion of the purse
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_AllPurseDeletionsCallback)(
- TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseContractSignatureP *purse_sig);
-
-/**
- * Select all purse deletions above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_all_purse_deletions_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AllPurseDeletionsCallback
- cb,
- TALER_EXCHANGEDB_ALL_PURSE_DELETIONS_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_aml_attributes.h b/src/include/exchange-database/select_aml_attributes.h
@@ -1,105 +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/exchange-database/select_aml_attributes.h
- * @brief implementation of the select_aml_attributes function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AML_ATTRIBUTES_H
-#define EXCHANGE_DATABASE_SELECT_AML_ATTRIBUTES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Return AML attribute information.
- *
- * @param cls closure
- * @param row_id current row in kyc_attributes table
- * @param collection_time when were the attributes collected
- * @param by_aml_officer true if the data was filed by an AML officer
- * @param officer_name name of the officer, NULL if not @a by_aml_officer
- * @param enc_attributes_size size of @a enc_attributes
- * @param enc_attributes the encrypted collected attributes
- */
-#ifndef TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlAttributeCallback.
- */
-#define TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlAttributeCallback)(
- TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE *cls,
- uint64_t row_id,
- struct GNUNET_TIME_Timestamp collection_time,
- bool by_aml_officer,
- const char *officer_name,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-
-/* Callback typedefs */
-/**
- * Return AML attribute information.
- *
- * @param cls closure
- * @param row_id current row in kyc_attributes table
- * @param collection_time when were the attributes collected
- * @param by_aml_officer true if the data was filed by an AML officer
- * @param officer_name name of the officer, NULL if not @a by_aml_officer
- * @param enc_attributes_size size of @a enc_attributes
- * @param enc_attributes the encrypted collected attributes
- */
-typedef void
-(*TALER_EXCHANGEDB_AmlAttributeCallback)(
- TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE *cls,
- uint64_t row_id,
- struct GNUNET_TIME_Timestamp collection_time,
- bool by_aml_officer,
- const char *officer_name,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-/**
- * Lookup AML attributes of a particular account.
- *
- * @param pg the database context
- * @param h_payto which account should we return attributes for
- * @param offset row to start from
- * @param limit how many records to return (negative
- * to go back in time, positive to go forward)
- * @param cb callback to invoke on each match
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_attributes (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlAttributeCallback cb
- ,
- TALER_EXCHANGEDB_AML_ATTRIBUTE_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_aml_decisions.h b/src/include/exchange-database/select_aml_decisions.h
@@ -1,130 +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/exchange-database/select_aml_decisions.h
- * @brief implementation of the select_aml_decisions function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AML_DECISIONS_H
-#define EXCHANGE_DATABASE_SELECT_AML_DECISIONS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Return AML decision information.
- *
- * @param cls closure
- * @param row_id current row in legitimization outcomes table
- * @param justification human-readable reason for the decision, NULL if none is available
- * @param h_payto account for which the attribute data is stored
- * @param decision_time when was the decision taken
- * @param expiration_time when will the rules expire
- * @param jproperties properties set for the account,
- * NULL if no properties were set
- * @param to_investigate true if AML staff should look at the account
- * @param is_active true if this is the currently active decision about the account
- * @param is_wallet true if the @a h_payto is for a Taler wallet
- * @param payto payto URI of the account the decision is about
- * @param account_rules current active rules for the account
- */
-#ifndef TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlDecisionCallback.
- */
-#define TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlDecisionCallback)(
- TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const char *justification,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp decision_time,
- struct GNUNET_TIME_Absolute expiration_time,
- const json_t *jproperties,
- bool to_investigate,
- bool is_active,
- bool is_wallet,
- struct TALER_FullPayto payto,
- const json_t *account_rules);
-
-
-/* Callback typedefs */
-/**
- * Return AML decision information.
- *
- * @param cls closure
- * @param row_id current row in legitimization outcomes table
- * @param justification human-readable reason for the decision, NULL if none is available
- * @param h_payto account for which the attribute data is stored
- * @param decision_time when was the decision taken
- * @param expiration_time when will the rules expire
- * @param jproperties properties set for the account,
- * NULL if no properties were set
- * @param to_investigate true if AML staff should look at the account
- * @param is_active true if this is the currently active decision about the account
- * @param is_wallet true if the @a h_payto is for a Taler wallet
- * @param payto payto URI of the account the decision is about
- * @param account_rules current active rules for the account
- */
-typedef void
-(*TALER_EXCHANGEDB_AmlDecisionCallback)(
- TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const char *justification,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp decision_time,
- struct GNUNET_TIME_Absolute expiration_time,
- const json_t *jproperties,
- bool to_investigate,
- bool is_active,
- bool is_wallet,
- struct TALER_FullPayto payto,
- const json_t *account_rules);
-
-/**
- * Lookup AML decisions that have a particular state.
- *
- * @param pg the database context
- * @param h_payto which account should we return the AML decision history for, NULL to return all accounts
- * @param investigation_only filter by investigation state
- * @param active_only filter for only active states
- * @param offset row to start from
- * @param limit how many records to return (negative
- * to go back in time, positive to go forward)
- * @param cb callback to invoke on each match
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_decisions (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct TALER_NormalizedPaytoHashP *
- h_payto,
- enum TALER_EXCHANGE_YesNoAll
- investigation_only
- ,
- enum TALER_EXCHANGE_YesNoAll active_only,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlDecisionCallback cb,
- TALER_EXCHANGEDB_AML_DECISION_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_aml_measures.h b/src/include/exchange-database/select_aml_measures.h
@@ -1,103 +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/exchange-database/select_aml_measures.h
- * @brief implementation of the select_aml_measures function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AML_MEASURES_H
-#define EXCHANGE_DATABASE_SELECT_AML_MEASURES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with legitimization measures.
- *
- * @param cls closure
- * @param h_payto hash of account the measure applies to
- * @param start_time when was the process started
- * @param jmeasures object of type ``LegitimizationMeasures``
- * @param is_finished true if the measure was finished
- * @param measure_serial_id row ID of the measure in the exchange table
- */
-#ifndef TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_LegitimizationMeasureCallback.
- */
-#define TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
- TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE *cls,
- struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute start_time,
- const json_t *jmeasures,
- bool is_finished,
- uint64_t measure_serial_id);
-
-
-/* Callback typedefs */
-/**
- * Function called with legitimization measures.
- *
- * @param cls closure
- * @param h_payto hash of account the measure applies to
- * @param start_time when was the process started
- * @param jmeasures object of type ``LegitimizationMeasures``
- * @param is_finished true if the measure was finished
- * @param measure_serial_id row ID of the measure in the exchange table
- */
-typedef void
-(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
- TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE *cls,
- struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute start_time,
- const json_t *jmeasures,
- bool is_finished,
- uint64_t measure_serial_id);
-
-/**
- * Lookup legitimization measures.
- *
- * @param pg the database context
- * @param h_payto account for which the attribute data is stored,
- * NULL to select for all accounts
- * @param active_only select only measures that are active
- * @param offset row offset to select from
- * @param limit number of results to return, negative to
- * return in descending order from @a offset
- * @param cb callback to invoke on each match
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_measures (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- const struct TALER_NormalizedPaytoHashP *
- h_payto
- ,
- enum TALER_EXCHANGE_YesNoAll active_only,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_LegitimizationMeasureCallback
- cb,
- TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_aml_statistics.h b/src/include/exchange-database/select_aml_statistics.h
@@ -1,88 +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/exchange-database/select_aml_statistics.h
- * @brief implementation of the select_aml_statistics function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AML_STATISTICS_H
-#define EXCHANGE_DATABASE_SELECT_AML_STATISTICS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with AML statistics (counters).
- *
- * @param cls closure
- * @param name name of the counter
- * @param cnt number of events for @a name in the query range
- */
-#ifndef TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlStatisticsCallback.
- */
-#define TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlStatisticsCallback)(
- TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE *cls,
- const char *name,
- uint64_t cnt);
-
-
-/* Callback typedefs */
-/**
- * Function called with AML statistics (counters).
- *
- * @param cls closure
- * @param name name of the counter
- * @param cnt number of events for @a name in the query range
- */
-typedef void
-(*TALER_EXCHANGEDB_AmlStatisticsCallback)(
- TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE *cls,
- const char *name,
- uint64_t cnt);
-
-/**
- * Obtain the AML statistics for a given set of @a names and
- * timeframe.
- *
- * @param pg the database context
- * @param num_names length of the @e names array
- * @param names array of names of the statistics to fetch
- * @param start_date start of time range
- * @param end_date end of time range
- * @param cb function to call on each statistic
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_aml_statistics (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- size_t num_names,
- const char *names[static num_names],
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- TALER_EXCHANGEDB_AmlStatisticsCallback
- cb,
- TALER_EXCHANGEDB_AML_STATISTICS_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_auditor_denom_sig.h b/src/include/exchange-database/select_auditor_denom_sig.h
@@ -1,49 +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/exchange-database/select_auditor_denom_sig.h
- * @brief implementation of the select_auditor_denom_sig function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_AUDITOR_DENOM_SIG_H
-#define EXCHANGE_DATABASE_SELECT_AUDITOR_DENOM_SIG_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Select information about an auditor auditing a denomination key.
- *
- * @param pg the database context
- * @param h_denom_pub the audited denomination
- * @param auditor_pub the auditor's key
- * @param[out] auditor_sig set to signature affirming the auditor's audit activity
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_auditor_denom_sig (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_DenominationHashP *
- h_denom_pub,
- const struct
- TALER_AuditorPublicKeyP *
- auditor_pub,
- struct TALER_AuditorSignatureP *
- auditor_sig
- );
-
-#endif
diff --git a/src/include/exchange-database/select_batch_deposits_missing_wire.h b/src/include/exchange-database/select_batch_deposits_missing_wire.h
@@ -1,94 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022-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/exchange-database/select_batch_deposits_missing_wire.h
- * @brief implementation of the select_batch_deposits_missing_wire function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_BATCH_DEPOSITS_MISSING_WIRE_H
-#define EXCHANGE_DATABASE_SELECT_BATCH_DEPOSITS_MISSING_WIRE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called on (batch) deposits will need a wire
- * transfer.
- *
- * @param cls closure
- * @param batch_deposit_serial_id where in the table are we
- * @param total_amount value of all missing deposits, including fees
- * @param wire_target_h_payto hash of the recipient account's payto URI
- * @param deadline what was the earliest requested wire transfer deadline
- */
-#ifndef TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_WireMissingCallback.
- */
-#define TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_WireMissingCallback)(
- TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE *cls,
- uint64_t batch_deposit_serial_id,
- const struct TALER_Amount *total_amount,
- const struct TALER_FullPaytoHashP *wire_target_h_payto,
- struct GNUNET_TIME_Timestamp deadline);
-
-
-/* Callback typedefs */
-/**
- * Function called on (batch) deposits will need a wire
- * transfer.
- *
- * @param cls closure
- * @param batch_deposit_serial_id where in the table are we
- * @param total_amount value of all missing deposits, including fees
- * @param wire_target_h_payto hash of the recipient account's payto URI
- * @param deadline what was the earliest requested wire transfer deadline
- */
-typedef void
-(*TALER_EXCHANGEDB_WireMissingCallback)(
- TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE *cls,
- uint64_t batch_deposit_serial_id,
- const struct TALER_Amount *total_amount,
- const struct TALER_FullPaytoHashP *wire_target_h_payto,
- struct GNUNET_TIME_Timestamp deadline);
-
-/**
- * Select all of those batch deposits in the database
- * above the given serial ID.
- *
- * @param pg the database context
- * @param min_batch_deposit_serial_id select all batch deposits above this ID
- * @param cb function to call on all such deposits
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_batch_deposits_missing_wire (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t
- min_batch_deposit_serial_id,
- TALER_EXCHANGEDB_WireMissingCallback
- cb,
- TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_coin_deposits_above_serial_id.h b/src/include/exchange-database/select_coin_deposits_above_serial_id.h
@@ -1,100 +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/exchange-database/select_coin_deposits_above_serial_id.h
- * @brief implementation of the select_coin_deposits_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_COIN_DEPOSITS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_COIN_DEPOSITS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about deposits that have been made,
- * with the goal of auditing the deposit's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param exchange_timestamp when did the deposit happen
- * @param deposit deposit details
- * @param denom_pub denomination public key of @a coin_pub
- * @param done flag set if the deposit was already executed (or not)
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_DepositCallback.
- */
-#define TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_DepositCallback)(
- TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp exchange_timestamp,
- const struct TALER_EXCHANGEDB_Deposit *deposit,
- const struct TALER_DenominationPublicKey *denom_pub,
- bool done);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about deposits that have been made,
- * with the goal of auditing the deposit's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param exchange_timestamp when did the deposit happen
- * @param deposit deposit details
- * @param denom_pub denomination public key of @a coin_pub
- * @param done flag set if the deposit was already executed (or not)
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_DepositCallback)(
- TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp exchange_timestamp,
- const struct TALER_EXCHANGEDB_Deposit *deposit,
- const struct TALER_DenominationPublicKey *denom_pub,
- bool done);
-
-/**
- * Select deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_coin_deposits_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- uint64_t serial_id,
- TALER_EXCHANGEDB_DepositCallback
- cb,
- TALER_EXCHANGEDB_DEPOSIT_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_contract.h b/src/include/exchange-database/select_contract.h
@@ -1,50 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_contract.h
- * @brief implementation of the select_contract function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_CONTRACT_H
-#define EXCHANGE_DATABASE_SELECT_CONTRACT_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to retrieve an encrypted contract.
- *
- * @param pg the database context
- * @param purse_pub key to lookup the contract by
- * @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract
- * @param[out] econtract_sig set to the signature over the encrypted contract
- * @param[out] econtract_size set to the number of bytes in @a econtract
- * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_contract (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ContractDiffiePublicP *
- pub_ckey,
- struct TALER_PurseContractPublicKeyP *
- purse_pub,
- struct TALER_PurseContractSignatureP *
- econtract_sig,
- size_t *econtract_size,
- void **econtract);
-
-#endif
diff --git a/src/include/exchange-database/select_contract_by_purse.h b/src/include/exchange-database/select_contract_by_purse.h
@@ -1,46 +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/exchange-database/select_contract_by_purse.h
- * @brief implementation of the select_contract_by_purse function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_CONTRACT_BY_PURSE_H
-#define EXCHANGE_DATABASE_SELECT_CONTRACT_BY_PURSE_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to retrieve an encrypted contract.
- *
- * @param pg the database context
- * @param purse_pub key to lookup the contract by
- * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_contract_by_purse (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_PurseContractPublicKeyP *
- purse_pub,
- struct TALER_EncryptedContract
- *econtract);
-
-#endif
diff --git a/src/include/exchange-database/select_deposit_amounts_for_kyc_check.h b/src/include/exchange-database/select_deposit_amounts_for_kyc_check.h
@@ -1,51 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_deposit_amounts_for_kyc_check.h
- * @brief implementation of the select_deposit_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_DEPOSIT_AMOUNTS_FOR_KYC_CHECK_H
-#define EXCHANGE_DATABASE_SELECT_DEPOSIT_AMOUNTS_FOR_KYC_CHECK_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Call @a kac on deposited amounts after @a time_limit which are relevant for a
- * KYC trigger for a merchant identified by @a h_payto.
- *
- * @param pg the database context
- * @param h_payto account identifier
- * @param time_limit oldest transaction that could be relevant
- * @param kac function to call for each applicable amount,
- * in reverse chronological order (or until @a kac aborts
- * by returning anything except #GNUNET_OK).
- * @param kac_cls closure for @a kac
- * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_deposit_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_exchange_credit_transfers.h b/src/include/exchange-database/select_exchange_credit_transfers.h
@@ -1,51 +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/exchange-database/select_exchange_credit_transfers.h
- * @brief implementation of the select_exchange_credit_transfers function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_EXCHANGE_CREDIT_TRANSFERS_H
-#define EXCHANGE_DATABASE_SELECT_EXCHANGE_CREDIT_TRANSFERS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Return AML-relevant wire transfer credit data.
- *
- * @param pg the database context
- * @param threshold minimum wire amount to return data for
- * @param offset offset in table to filter by
- * @param limit maximum number of entries to return, negative for descending
- * @param h_payto account to filter transfer data by
- * @param cb function to call on each result
- * @param cb_cls closure to pass to @a cb
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_exchange_credit_transfers (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- void *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_exchange_debit_transfers.h b/src/include/exchange-database/select_exchange_debit_transfers.h
@@ -1,76 +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/exchange-database/select_exchange_debit_transfers.h
- * @brief implementation of the select_exchange_debit_transfers function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_EXCHANGE_DEBIT_TRANSFERS_H
-#define EXCHANGE_DATABASE_SELECT_EXCHANGE_DEBIT_TRANSFERS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Callback that is given AML-relevant transfer data.
- *
- * @param cls closure
- * @param row_id current row in AML status table
- * @param payto_uri account involved with the wire transfer
- * @param execution_time when was the transfer made
- * @param amount wire amount of the transfer
- */
-#ifndef TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlTransferCallback.
- */
-#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlTransferCallback)(
- TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const char *payto_uri,
- struct GNUNET_TIME_Absolute execution_time,
- const struct TALER_Amount *amount);
-
-
-/**
- * Return AML-relevant wire transfer debit data.
- *
- * @param pg the database context
- * @param threshold minimum wire amount to return data for
- * @param offset offset in table to filter by
- * @param limit maximum number of entries to return, negative for descending
- * @param h_payto account to filter transfer data by
- * @param cb function to call on each result
- * @param cb_cls closure to pass to @a cb
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_exchange_debit_transfers (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_exchange_kycauth_transfers.h b/src/include/exchange-database/select_exchange_kycauth_transfers.h
@@ -1,81 +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/exchange-database/select_exchange_kycauth_transfers.h
- * @brief implementation of the select_exchange_kycauth_transfers function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_EXCHANGE_KYCAUTH_TRANSFERS_H
-#define EXCHANGE_DATABASE_SELECT_EXCHANGE_KYCAUTH_TRANSFERS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Callback that is given AML-relevant transfer data.
- *
- * @param cls closure
- * @param row_id current row in AML status table
- * @param payto_uri account involved with the wire transfer
- * @param execution_time when was the transfer made
- * @param amount wire amount of the transfer
- */
-#ifndef TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlTransferCallback.
- */
-#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlTransferCallback)(
- TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const char *payto_uri,
- struct GNUNET_TIME_Absolute execution_time,
- const struct TALER_Amount *amount);
-
-/**
- * Return wire transfer kycauth data.
- *
- * @param pg the database context
- * @param threshold minimum wire amount to return data for
- * @param offset offset in table to filter by
- * @param limit maximum number of entries to return, negative for descending
- * @param h_payto account to filter transfer data by
- * @param cb function to call on each result
- * @param cb_cls closure to pass to @a cb
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_exchange_kycauth_transfers (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct TALER_Amount *
- threshold,
- uint64_t offset,
- int64_t limit,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback
- cb,
- TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_kyc_accounts.h b/src/include/exchange-database/select_kyc_accounts.h
@@ -1,121 +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/exchange-database/select_kyc_accounts.h
- * @brief implementation of the select_kyc_accounts function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_KYC_ACCOUNTS_H
-#define EXCHANGE_DATABASE_SELECT_KYC_ACCOUNTS_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Return account summary information.
- *
- * @param cls closure
- * @param row_id current row in AML status table
- * @param h_payto account for which the attribute data is stored
- * @param open_time when was the account opened formally,
- * GNUNET_TIME_UNIT_FOREVER_TS if it was never opened
- * @param close_time when was the account formally closed,
- * GNUNET_TIME_UNIT_ZERO_TS if it was never closed
- * @param comments comments on the account
- * @param high_risk is this a high-risk business relationship
- * @param to_investigate TRUE if this account should be investigated
- * @param payto the payto URI of the account
- */
-#ifndef TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlAccountListCallback.
- */
-#define TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlAccountListCallback)(
- TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp open_time,
- struct GNUNET_TIME_Timestamp close_time,
- const char *comments,
- bool high_risk,
- bool to_investigate,
- struct TALER_FullPayto payto);
-
-
-/* Callback typedefs */
-/**
- * Return account summary information.
- *
- * @param cls closure
- * @param row_id current row in AML status table
- * @param h_payto account for which the attribute data is stored
- * @param open_time when was the account opened formally,
- * GNUNET_TIME_UNIT_FOREVER_TS if it was never opened
- * @param close_time when was the account formally closed,
- * GNUNET_TIME_UNIT_ZERO_TS if it was never closed
- * @param comments comments on the account
- * @param high_risk is this a high-risk business relationship
- * @param to_investigate TRUE if this account should be investigated
- * @param payto the payto URI of the account
- */
-typedef void
-(*TALER_EXCHANGEDB_AmlAccountListCallback)(
- TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp open_time,
- struct GNUNET_TIME_Timestamp close_time,
- const char *comments,
- bool high_risk,
- bool to_investigate,
- struct TALER_FullPayto payto);
-
-/**
- * List accounts managed by the exchange (for AML/KYC).
- *
- * @param pg the database context
- * @param investigation_only filter by investigation state
- * @param open_only filter for only open accounts
- * @param high_risk_only filter for only high-risk accounts
- * @param offset row to start from
- * @param limit how many records to return (negative
- * to go back in time, positive to go forward)
- * @param cb callback to invoke on each match
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_kyc_accounts (struct TALER_EXCHANGEDB_PostgresContext *
- pg,
- enum TALER_EXCHANGE_YesNoAll
- investigation_only,
- enum TALER_EXCHANGE_YesNoAll open_only,
- enum TALER_EXCHANGE_YesNoAll
- high_risk_only,
- uint64_t offset,
- int64_t limit,
- TALER_EXCHANGEDB_AmlAccountListCallback cb
- ,
- TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_kyc_attributes.h b/src/include/exchange-database/select_kyc_attributes.h
@@ -1,98 +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/exchange-database/select_kyc_attributes.h
- * @brief implementation of the select_kyc_attributes function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_KYC_ATTRIBUTES_H
-#define EXCHANGE_DATABASE_SELECT_KYC_ATTRIBUTES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Callback with KYC attributes about a particular user.
- *
- * @param cls closure
- * @param h_payto account for which the attribute data is stored
- * @param provider_name provider that must be checked
- * @param collection_time when was the data collected
- * @param expiration_time when does the data expire
- * @param enc_attributes_size number of bytes in @a enc_attributes
- * @param enc_attributes encrypted attribute data
- */
-#ifndef TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AttributeCallback.
- */
-#define TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AttributeCallback)(
- TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE *cls,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_name,
- struct GNUNET_TIME_Timestamp collection_time,
- struct GNUNET_TIME_Timestamp expiration_time,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-
-/* Callback typedefs */
-/**
- * Callback with KYC attributes about a particular user.
- *
- * @param cls closure
- * @param h_payto account for which the attribute data is stored
- * @param provider_name provider that must be checked
- * @param collection_time when was the data collected
- * @param expiration_time when does the data expire
- * @param enc_attributes_size number of bytes in @a enc_attributes
- * @param enc_attributes encrypted attribute data
- */
-typedef void
-(*TALER_EXCHANGEDB_AttributeCallback)(
- TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE *cls,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- const char *provider_name,
- struct GNUNET_TIME_Timestamp collection_time,
- struct GNUNET_TIME_Timestamp expiration_time,
- size_t enc_attributes_size,
- const void *enc_attributes);
-
-/**
- * Lookup KYC attribute data for a specific account.
- *
- * @param pg the database context
- * @param h_payto account for which the attribute data is stored
- * @param cb callback to invoke on each match
- * @param cb_cls closure for @a cb
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_kyc_attributes (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- TALER_EXCHANGEDB_AttributeCallback cb,
- TALER_EXCHANGEDB_ATTRIBUTE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_merge_amounts_for_kyc_check.h b/src/include/exchange-database/select_merge_amounts_for_kyc_check.h
@@ -1,48 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_merge_amounts_for_kyc_check.h
- * @brief implementation of the select_merge_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_MERGE_AMOUNTS_FOR_KYC_CHECK_H
-#define EXCHANGE_DATABASE_SELECT_MERGE_AMOUNTS_FOR_KYC_CHECK_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Call @a kac on merged reserve amounts after @a time_limit which are relevant for a
- * KYC trigger for a the wallet identified by @a h_payto.
- *
- * @param pg the database context
- * @param h_payto account identifier
- * @param time_limit oldest transaction that could be relevant
- * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
- * @param kac_cls closure for @a kac
- * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_merge_amounts_for_kyc_check (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Absolute time_limit,
- TALER_KYCLOGIC_KycAmountCallback kac,
- void *kac_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_purse.h b/src/include/exchange-database/select_purse.h
@@ -1,57 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file select_purse.h
- * @brief implementation of the select_purse function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to obtain information about a purse.
- *
- * @param pg the database context
- * @param purse_pub public key of the new purse
- * @param[out] purse_creation set to time when the purse was created
- * @param[out] purse_expiration set to time when the purse will expire
- * @param[out] amount set to target amount (with fees) to be put into the purse
- * @param[out] deposited set to actual amount put into the purse so far
- * @param[out] h_contract_terms set to hash of the contract for the purse
- * @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
- * @param[out] purse_deleted set to true if purse was deleted
- * @param[out] purse_refunded set to true if purse was refunded
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_purse (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp *purse_creation,
- struct GNUNET_TIME_Timestamp *purse_expiration,
- struct TALER_Amount *amount,
- struct TALER_Amount *deposited,
- struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp *merge_timestamp,
- bool *purse_deleted,
- bool *purse_refunded);
-
-#endif
diff --git a/src/include/exchange-database/select_purse_by_merge_pub.h b/src/include/exchange-database/select_purse_by_merge_pub.h
@@ -1,69 +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/exchange-database/select_purse_by_merge_pub.h
- * @brief implementation of the select_purse_by_merge_pub function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_BY_MERGE_PUB_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_BY_MERGE_PUB_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to return meta data about a purse by the
- * merge capability key.
- *
- * @param pg the database context
- * @param merge_pub public key representing the merge capability
- * @param[out] purse_pub public key of the purse
- * @param[out] purse_expiration when would an unmerged purse expire
- * @param[out] h_contract_terms contract associated with the purse
- * @param[out] age_limit the age limit for deposits into the purse
- * @param[out] target_amount amount to be put into the purse
- * @param[out] balance amount put so far into the purse
- * @param[out] purse_sig signature of the purse over the initialization data
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_by_merge_pub (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct
- TALER_PurseMergePublicKeyP *
- merge_pub,
- struct
- TALER_PurseContractPublicKeyP
- *
- purse_pub,
- struct GNUNET_TIME_Timestamp *
- purse_expiration,
- struct
- TALER_PrivateContractHashP *
- h_contract_terms,
- uint32_t *age_limit,
- struct TALER_Amount *
- target_amount,
- struct TALER_Amount *balance,
- struct
- TALER_PurseContractSignatureP
- *
- purse_sig);
-
-#endif
diff --git a/src/include/exchange-database/select_purse_decisions_above_serial_id.h b/src/include/exchange-database/select_purse_decisions_above_serial_id.h
@@ -1,99 +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/exchange-database/select_purse_decisions_above_serial_id.h
- * @brief implementation of the select_purse_decisions_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about purse decisions that have been made, with
- * the goal of auditing the purse's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the purse
- * @param reserve_pub public key of the target reserve, NULL if not known / refunded
- * @param purse_value what is the (target) value of the purse
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_PurseDecisionCallback.
- */
-#define TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseDecisionCallback)(
- TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *purse_value);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about purse decisions that have been made, with
- * the goal of auditing the purse's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the purse
- * @param reserve_pub public key of the target reserve, NULL if not known / refunded
- * @param purse_value what is the (target) value of the purse
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseDecisionCallback)(
- TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *purse_value);
-
-/**
- * Select purse decisions above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param refunded which refund status to select for
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_decisions_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t
- serial_id,
- bool refunded,
- TALER_EXCHANGEDB_PurseDecisionCallback
- cb,
- TALER_EXCHANGEDB_PURSE_DECISION_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_purse_deposits_above_serial_id.h b/src/include/exchange-database/select_purse_deposits_above_serial_id.h
@@ -1,112 +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 select_purse_deposits_above_serial_id.h
- * @brief implementation of the select_purse_deposits_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_DEPOSITS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_DEPOSITS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about purse deposits that have been made, with
- * the goal of auditing the deposit's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param deposit deposit details
- * @param reserve_pub which reserve is the purse merged into, NULL if unknown
- * @param flags purse flags
- * @param auditor_balance purse balance (according to the
- * auditor during auditing)
- * @param purse_total target amount the purse should reach
- * @param denom_pub denomination public key of @a coin_pub
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_PurseDepositCallback.
- */
-#define TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseDepositCallback)(
- TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *auditor_balance,
- const struct TALER_Amount *purse_total,
- const struct TALER_DenominationPublicKey *denom_pub);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about purse deposits that have been made, with
- * the goal of auditing the deposit's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param deposit deposit details
- * @param reserve_pub which reserve is the purse merged into, NULL if unknown
- * @param flags purse flags
- * @param auditor_balance purse balance (according to the
- * auditor during auditing)
- * @param purse_total target amount the purse should reach
- * @param denom_pub denomination public key of @a coin_pub
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseDepositCallback)(
- TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *auditor_balance,
- const struct TALER_Amount *purse_total,
- const struct TALER_DenominationPublicKey *denom_pub);
-
-/**
- * Select deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_deposits_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id
- ,
- TALER_EXCHANGEDB_PurseDepositCallback
- cb,
- TALER_EXCHANGEDB_PURSE_DEPOSIT_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_purse_deposits_by_purse.h b/src/include/exchange-database/select_purse_deposits_by_purse.h
@@ -1,98 +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/exchange-database/select_purse_deposits_by_purse.h
- * @brief implementation of the select_purse_deposits_by_purse function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_DEPOSITS_BY_PURSE_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_DEPOSITS_BY_PURSE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about purse refunds that have been made, with
- * the goal of auditing the purse refund's execution.
- *
- * @param cls closure
- * @param rowid row of the refund event
- * @param amount_with_fee amount of the deposit into the purse
- * @param coin_pub coin that is to be refunded the @a given amount_with_fee
- * @param denom_pub denomination of @a coin_pub
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_PurseRefundCoinCallback.
- */
-#define TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseRefundCoinCallback)(
- TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_Amount *amount_with_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_DenominationPublicKey *denom_pub);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about purse refunds that have been made, with
- * the goal of auditing the purse refund's execution.
- *
- * @param cls closure
- * @param rowid row of the refund event
- * @param amount_with_fee amount of the deposit into the purse
- * @param coin_pub coin that is to be refunded the @a given amount_with_fee
- * @param denom_pub denomination of @a coin_pub
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseRefundCoinCallback)(
- TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_Amount *amount_with_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_DenominationPublicKey *denom_pub);
-
-/**
- * Select coin affected by purse refund.
- *
- * @param pg the database context
- * @param purse_pub purse that was refunded
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_deposits_by_purse (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- const struct
- TALER_PurseContractPublicKeyP
- *
- purse_pub,
- TALER_EXCHANGEDB_PurseRefundCoinCallback
- cb,
- TALER_EXCHANGEDB_PURSE_REFUND_COIN_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_purse_merge.h b/src/include/exchange-database/select_purse_merge.h
@@ -1,56 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_purse_merge.h
- * @brief implementation of the select_purse_merge function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_MERGE_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_MERGE_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to approve merging of a purse with
- * an account, made by the receiving account.
- *
- * @param pg the database context
- * @param purse_pub public key of the purse
- * @param[out] merge_sig set to the signature confirming the merge
- * @param[out] merge_timestamp set to the time of the merge
- * @param[out] partner_url set to the URL of the target exchange, or NULL if the target exchange is us. To be freed by the caller.
- * @param[out] reserve_pub set to the public key of the reserve/account being credited
- * @param[out] refunded set to true if purse was refunded
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_merge (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_PurseContractPublicKeyP *
- purse_pub,
- struct TALER_PurseMergeSignatureP *
- merge_sig,
- struct GNUNET_TIME_Timestamp *
- merge_timestamp,
- char **partner_url,
- struct TALER_ReservePublicKeyP *
- reserve_pub,
- bool *refunded);
-
-#endif
diff --git a/src/include/exchange-database/select_purse_merges_above_serial_id.h b/src/include/exchange-database/select_purse_merges_above_serial_id.h
@@ -1,122 +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 select_purse_merges_above_serial_id.h
- * @brief implementation of the select_purse_merges_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_MERGES_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_MERGES_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about purse
- * merges that have been made, with
- * the goal of auditing the purse merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param partner_base_url where is the reserve, NULL for this exchange
- * @param amount total amount expected in the purse
- * @param balance current balance in the purse (according to the auditor)
- * @param flags purse flags
- * @param merge_pub merge capability key
- * @param reserve_pub reserve the merge affects
- * @param merge_sig signature affirming the merge
- * @param purse_pub purse key
- * @param merge_timestamp when did the merge happen
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_PurseMergeCallback.
- */
-#define TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseMergeCallback)(
- TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const char *partner_base_url,
- const struct TALER_Amount *amount,
- const struct TALER_Amount *balance,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseMergeSignatureP *merge_sig,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp merge_timestamp);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about purse
- * merges that have been made, with
- * the goal of auditing the purse merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param partner_base_url where is the reserve, NULL for this exchange
- * @param amount total amount expected in the purse
- * @param balance current balance in the purse (according to the auditor)
- * @param flags purse flags
- * @param merge_pub merge capability key
- * @param reserve_pub reserve the merge affects
- * @param merge_sig signature affirming the merge
- * @param purse_pub purse key
- * @param merge_timestamp when did the merge happen
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseMergeCallback)(
- TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const char *partner_base_url,
- const struct TALER_Amount *amount,
- const struct TALER_Amount *balance,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseMergeSignatureP *merge_sig,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp merge_timestamp);
-
-/**
- * Select purse merges deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_TALER_EXCHANGEDB_select_purse_merges_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t
- serial_id,
- TALER_EXCHANGEDB_PurseMergeCallback
- cb,
- TALER_EXCHANGEDB_PURSE_MERGE_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_purse_requests_above_serial_id.h b/src/include/exchange-database/select_purse_requests_above_serial_id.h
@@ -1,116 +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 select_purse_requests_above_serial_id.h
- * @brief implementation of the select_purse_requests_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_PURSE_REQUESTS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_PURSE_REQUESTS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called on purse requests.
- *
- * @param cls closure
- * @param rowid purse request table row of the purse
- * @param purse_pub public key of the purse
- * @param merge_pub public key representing the merge capability
- * @param purse_creation when was the purse created?
- * @param purse_expiration when would an unmerged purse expire
- * @param h_contract_terms contract associated with the purse
- * @param age_limit the age limit for deposits into the purse
- * @param target_amount amount to be put into the purse
- * @param purse_sig signature of the purse over the initialization data
- * @return #GNUNET_OK to continue to iterate
- */
-#ifndef TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_PurseRequestCallback.
- */
-#define TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseRequestCallback)(
- TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- struct GNUNET_TIME_Timestamp purse_creation,
- struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- uint32_t age_limit,
- const struct TALER_Amount *target_amount,
- const struct TALER_PurseContractSignatureP *purse_sig);
-
-
-/* Callback typedefs */
-/**
- * Function called on purse requests.
- *
- * @param cls closure
- * @param rowid purse request table row of the purse
- * @param purse_pub public key of the purse
- * @param merge_pub public key representing the merge capability
- * @param purse_creation when was the purse created?
- * @param purse_expiration when would an unmerged purse expire
- * @param h_contract_terms contract associated with the purse
- * @param age_limit the age limit for deposits into the purse
- * @param target_amount amount to be put into the purse
- * @param purse_sig signature of the purse over the initialization data
- * @return #GNUNET_OK to continue to iterate
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseRequestCallback)(
- TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- struct GNUNET_TIME_Timestamp purse_creation,
- struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- uint32_t age_limit,
- const struct TALER_Amount *target_amount,
- const struct TALER_PurseContractSignatureP *purse_sig);
-
-/**
- * Select purse requestss deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_purse_requests_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id
- ,
- TALER_EXCHANGEDB_PurseRequestCallback
- cb,
- TALER_EXCHANGEDB_PURSE_REQUEST_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_recoup_above_serial_id.h b/src/include/exchange-database/select_recoup_above_serial_id.h
@@ -1,110 +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/exchange-database/select_recoup_above_serial_id.h
- * @brief implementation of the select_recoup_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RECOUP_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_RECOUP_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called about recoups the exchange has to perform.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the recoup operation
- * @param timestamp when did we receive the recoup request
- * @param amount how much should be added back to the reserve
- * @param reserve_pub public key of the reserve
- * @param coin public information about the coin
- * @param denom_pub denomination key of @a coin
- * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
- * @param coin_blind blinding factor used to blind the coin
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_RecoupCallback.
- */
-#define TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RecoupCallback)(
- TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp timestamp,
- const struct TALER_Amount *amount,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_CoinPublicInfo *coin,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
-
-
-/* Callback typedefs */
-/**
- * Function called about recoups the exchange has to perform.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the recoup operation
- * @param timestamp when did we receive the recoup request
- * @param amount how much should be added back to the reserve
- * @param reserve_pub public key of the reserve
- * @param coin public information about the coin
- * @param denom_pub denomination key of @a coin
- * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
- * @param coin_blind blinding factor used to blind the coin
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RecoupCallback)(
- TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp timestamp,
- const struct TALER_Amount *amount,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_CoinPublicInfo *coin,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
-
-/**
- * Function called to select recoup requests the exchange
- * received, ordered by serial ID (monotonically increasing).
- *
- * @param pg the database context
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_recoup_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RecoupCallback
- cb,
- TALER_EXCHANGEDB_RECOUP_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_recoup_refresh_above_serial_id.h b/src/include/exchange-database/select_recoup_refresh_above_serial_id.h
@@ -1,116 +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/exchange-database/select_recoup_refresh_above_serial_id.h
- * @brief implementation of the select_recoup_refresh_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RECOUP_REFRESH_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_RECOUP_REFRESH_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called about recoups on refreshed coins the exchange has to
- * perform.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the recoup operation
- * @param timestamp when did we receive the recoup request
- * @param amount how much should be added back to the old coin
- * @param old_coin_pub original coin that was refreshed to create @a coin
- * @param old_denom_pub_hash hash of public key of @a old_coin_pub
- * @param coin public information about the fresh coin
- * @param denom_pub denomination key of @a coin
- * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
- * @param coin_blind blinding factor used to blind the coin
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_RecoupRefreshCallback.
- */
-#define TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RecoupRefreshCallback)(
- TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp timestamp,
- const struct TALER_Amount *amount,
- const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
- const struct TALER_DenominationHashP *old_denom_pub_hash,
- const struct TALER_CoinPublicInfo *coin,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
-
-
-/* Callback typedefs */
-/**
- * Function called about recoups on refreshed coins the exchange has to
- * perform.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the recoup operation
- * @param timestamp when did we receive the recoup request
- * @param amount how much should be added back to the old coin
- * @param old_coin_pub original coin that was refreshed to create @a coin
- * @param old_denom_pub_hash hash of public key of @a old_coin_pub
- * @param coin public information about the fresh coin
- * @param denom_pub denomination key of @a coin
- * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP
- * @param coin_blind blinding factor used to blind the coin
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RecoupRefreshCallback)(
- TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp timestamp,
- const struct TALER_Amount *amount,
- const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
- const struct TALER_DenominationHashP *old_denom_pub_hash,
- const struct TALER_CoinPublicInfo *coin,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
-
-/**
- * Function called to select recoup requests the exchange received for
- * refreshed coins, ordered by serial ID (monotonically increasing).
- *
- * @param pg the database context
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_recoup_refresh_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RecoupRefreshCallback
- cb,
- TALER_EXCHANGEDB_RECOUP_REFRESH_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_refreshes_above_serial_id.h b/src/include/exchange-database/select_refreshes_above_serial_id.h
@@ -1,116 +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/exchange-database/select_refreshes_above_serial_id.h
- * @brief implementation of the select_refreshes_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_REFRESHES_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_REFRESHES_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about coins that were melted,
- * with the goal of auditing the refresh's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refresh session in our DB
- * @param old_denom_pub denomination public key of @a coin_pub
- * @param coin_pub public key of the coin
- * @param coin_sig signature from the coin
- * @param h_age_commitment hash of the age commitment for the coin
- * @param amount_with_fee amount that was deposited including fee
- * @param num_nds length of the @a new_denom_serials array
- * @param new_denom_serials array of denomination serials of fresh coins
- * @param rc what the refresh commitment
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_RefreshesCallback.
- */
-#define TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RefreshesCallback)(
- TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_DenominationPublicKey *old_denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const struct TALER_AgeCommitmentHashP *h_age_commitment,
- const struct TALER_Amount *amount_with_fee,
- size_t num_nds,
- uint64_t new_denom_serials[static num_nds],
- const struct TALER_RefreshCommitmentP *rc);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about coins that were melted,
- * with the goal of auditing the refresh's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refresh session in our DB
- * @param old_denom_pub denomination public key of @a coin_pub
- * @param coin_pub public key of the coin
- * @param coin_sig signature from the coin
- * @param h_age_commitment hash of the age commitment for the coin
- * @param amount_with_fee amount that was deposited including fee
- * @param num_nds length of the @a new_denom_serials array
- * @param new_denom_serials array of denomination serials of fresh coins
- * @param rc what the refresh commitment
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RefreshesCallback)(
- TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_DenominationPublicKey *old_denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const struct TALER_AgeCommitmentHashP *h_age_commitment,
- const struct TALER_Amount *amount_with_fee,
- size_t num_nds,
- uint64_t new_denom_serials[static num_nds],
- const struct TALER_RefreshCommitmentP *rc);
-
-/**
- * Select refresh sessions above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_refreshes_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RefreshesCallback
- cb,
- TALER_EXCHANGEDB_REFRESHES_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_refunds_above_serial_id.h b/src/include/exchange-database/select_refunds_above_serial_id.h
@@ -1,116 +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/exchange-database/select_refunds_above_serial_id.h
- * @brief implementation of the select_refunds_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_REFUNDS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_REFUNDS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "exchangedb_lib.h"
-#include "exchange-database/do_refund.h"
-
-
-/**
- * Function called with details about coins that were refunding,
- * with the goal of auditing the refund's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refund in our DB
- * @param denom_pub denomination public key of @a coin_pub
- * @param coin_pub public key of the coin
- * @param merchant_pub public key of the merchant
- * @param merchant_sig signature of the merchant
- * @param h_contract_terms hash of the proposal data known to merchant and customer
- * @param rtransaction_id refund transaction ID chosen by the merchant
- * @param full_refund true if the refunds total up to the entire value of the deposit
- * @param amount_with_fee amount that was deposited including fee
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_RefundCallback.
- */
-#define TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RefundCallback)(
- TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_MerchantSignatureP *merchant_sig,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- uint64_t rtransaction_id,
- bool full_refund,
- const struct TALER_Amount *amount_with_fee);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about coins that were refunding,
- * with the goal of auditing the refund's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refund in our DB
- * @param denom_pub denomination public key of @a coin_pub
- * @param coin_pub public key of the coin
- * @param merchant_pub public key of the merchant
- * @param merchant_sig signature of the merchant
- * @param h_contract_terms hash of the proposal data known to merchant and customer
- * @param rtransaction_id refund transaction ID chosen by the merchant
- * @param full_refund true if the refunds total up to the entire value of the deposit
- * @param amount_with_fee amount that was deposited including fee
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RefundCallback)(
- TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_MerchantSignatureP *merchant_sig,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- uint64_t rtransaction_id,
- bool full_refund,
- const struct TALER_Amount *amount_with_fee);
-
-/**
- * Select refunds above @a serial_id in monotonically increasing
- * order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_refunds_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RefundCallback
- cb,
- TALER_EXCHANGEDB_REFUND_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_refunds_by_coin.h b/src/include/exchange-database/select_refunds_by_coin.h
@@ -1,89 +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/exchange-database/select_refunds_by_coin.h
- * @brief implementation of the select_refunds_by_coin function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_REFUNDS_BY_COIN_H
-#define EXCHANGE_DATABASE_SELECT_REFUNDS_BY_COIN_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Callback invoked with information about refunds applicable
- * to a particular coin and contract.
- *
- * @param cls closure
- * @param amount_with_fee amount being refunded
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_RefundCoinCallback.
- */
-#define TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RefundCoinCallback)(
- TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE *cls,
- const struct TALER_Amount *amount_with_fee);
-
-
-/* Callback typedefs */
-/**
- * Callback invoked with information about refunds applicable
- * to a particular coin and contract.
- *
- * @param cls closure
- * @param amount_with_fee amount being refunded
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_RefundCoinCallback)(
- TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE *cls,
- const struct TALER_Amount *amount_with_fee);
-
-/**
- * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract.
- *
- * @param pg the database context
- * @param coin_pub coin to get refunds for
- * @param merchant_pub merchant to get refunds for
- * @param h_contract contract (hash) to get refunds for
- * @param cb function to call for each refund found
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_refunds_by_coin (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const struct
- TALER_CoinSpendPublicKeyP *
- coin_pub,
- const struct TALER_MerchantPublicKeyP *
- merchant_pub,
- const struct
- TALER_PrivateContractHashP *
- h_contract,
- TALER_EXCHANGEDB_RefundCoinCallback cb,
- TALER_EXCHANGEDB_REFUND_COIN_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_reserve_close_info.h b/src/include/exchange-database/select_reserve_close_info.h
@@ -1,49 +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 select_reserve_close_info.h
- * @brief implementation of the select_reserve_close_info function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RESERVE_CLOSE_INFO_H
-#define EXCHANGE_DATABASE_SELECT_RESERVE_CLOSE_INFO_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Select information needed to see if we can close
- * a reserve.
- *
- * @param pg the database context
- * @param reserve_pub which reserve is this about?
- * @param[out] balance current reserve balance
- * @param[out] payto_uri set to URL of account that
- * originally funded the reserve;
- * could be set to NULL if not known
- * @return transaction status code, 0 if reserve unknown
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_close_info (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_Amount *balance,
- struct TALER_FullPayto *payto_uri);
-
-
-#endif
diff --git a/src/include/exchange-database/select_reserve_close_request_info.h b/src/include/exchange-database/select_reserve_close_request_info.h
@@ -1,55 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022, 2026 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 select_reserve_close_request_info.h
- * @brief implementation of the select_reserve_close_request_info function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RESERVE_CLOSE_REQUEST_INFO_H
-#define EXCHANGE_DATABASE_SELECT_RESERVE_CLOSE_REQUEST_INFO_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Select information about reserve close requests.
- *
- * @param pg the database context
- * @param reserve_pub which reserve is this about?
- * @param rowid row ID of the close request
- * @param[out] reserve_sig reserve signature affirming
- * @param[out] request_timestamp when was the request made
- * @param[out] close_balance reserve balance at close time
- * @param[out] close_fee closing fee to be charged
- * @param[out] payto_uri set to URL of account that
- * should receive the money;
- * could be set to NULL for origin
- * @return transaction status code, 0 if reserve unknown
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_close_request_info (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- uint64_t rowid,
- struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp *request_timestamp,
- struct TALER_Amount *close_balance,
- struct TALER_Amount *close_fee,
- struct TALER_FullPayto *payto_uri);
-
-#endif
diff --git a/src/include/exchange-database/select_reserve_closed_above_serial_id.h b/src/include/exchange-database/select_reserve_closed_above_serial_id.h
@@ -1,115 +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 select_reserve_closed_above_serial_id.h
- * @brief implementation of the select_reserve_closed_above_serial_id function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RESERVE_CLOSED_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_RESERVE_CLOSED_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called about reserve closing operations
- * the aggregator triggered.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the reserve closing operation
- * @param execution_date when did we execute the close operation
- * @param amount_with_fee how much did we debit the reserve
- * @param closing_fee how much did we charge for closing the reserve
- * @param reserve_pub public key of the reserve
- * @param receiver_account where did we send the funds, in payto://-format
- * @param wtid identifier used for the wire transfer
- * @param close_request_row row with the responsible close
- * request, 0 if regular expiration triggered close
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReserveClosedCallback.
- */
-#define TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveClosedCallback)(
- TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_Amount *amount_with_fee,
- const struct TALER_Amount *closing_fee,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_FullPayto receiver_account,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- uint64_t close_request_row);
-
-
-/* Callback typedefs */
-/**
- * Function called about reserve closing operations
- * the aggregator triggered.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the reserve closing operation
- * @param execution_date when did we execute the close operation
- * @param amount_with_fee how much did we debit the reserve
- * @param closing_fee how much did we charge for closing the reserve
- * @param reserve_pub public key of the reserve
- * @param receiver_account where did we send the funds, in payto://-format
- * @param wtid identifier used for the wire transfer
- * @param close_request_row row with the responsible close
- * request, 0 if regular expiration triggered close
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveClosedCallback)(
- TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_Amount *amount_with_fee,
- const struct TALER_Amount *closing_fee,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_FullPayto receiver_account,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- uint64_t close_request_row);
-
-/**
- * Function called to select reserve close operations the aggregator
- * triggered, ordered by serial ID (monotonically increasing).
- *
- * @param pg the database context
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_closed_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveClosedCallback
- cb,
- TALER_EXCHANGEDB_RESERVE_CLOSED_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_reserve_open_above_serial_id.h b/src/include/exchange-database/select_reserve_open_above_serial_id.h
@@ -1,110 +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 select_reserve_open_above_serial_id.h
- * @brief implementation of the select_reserve_open_above_serial_id function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RESERVE_OPEN_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_RESERVE_OPEN_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called about reserve opening operations.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the reserve closing operation
- * @param reserve_payment how much to pay from the
- * reserve's own balance for opening the reserve
- * @param request_timestamp when was the request created
- * @param reserve_expiration desired expiration time for the reserve
- * @param purse_limit minimum number of purses the client
- * wants to have concurrently open for this reserve
- * @param reserve_pub public key of the reserve
- * @param reserve_sig signature affirming the operation
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReserveOpenCallback.
- */
-#define TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveOpenCallback)(
- TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_Amount *reserve_payment,
- struct GNUNET_TIME_Timestamp request_timestamp,
- struct GNUNET_TIME_Timestamp reserve_expiration,
- uint32_t purse_limit,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig);
-
-
-/* Callback typedefs */
-/**
- * Function called about reserve opening operations.
- *
- * @param cls closure
- * @param rowid row identifier used to uniquely identify the reserve closing operation
- * @param reserve_payment how much to pay from the
- * reserve's own balance for opening the reserve
- * @param request_timestamp when was the request created
- * @param reserve_expiration desired expiration time for the reserve
- * @param purse_limit minimum number of purses the client
- * wants to have concurrently open for this reserve
- * @param reserve_pub public key of the reserve
- * @param reserve_sig signature affirming the operation
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveOpenCallback)(
- TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_Amount *reserve_payment,
- struct GNUNET_TIME_Timestamp request_timestamp,
- struct GNUNET_TIME_Timestamp reserve_expiration,
- uint32_t purse_limit,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig);
-
-/**
- * Function called to select reserve open operations, ordered by serial ID
- * (monotonically increasing).
- *
- * @param pg the database context
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserve_open_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveOpenCallback
- cb,
- TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE
- *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_reserves_in_above_serial_id.h b/src/include/exchange-database/select_reserves_in_above_serial_id.h
@@ -1,78 +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/exchange-database/select_reserves_in_above_serial_id.h
- * @brief implementation of the select_reserves_in_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Function called with details about incoming wire transfers.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refresh session in our DB
- * @param reserve_pub public key of the reserve (also the wire subject)
- * @param credit amount that was received
- * @param sender_account_details information about the sender's bank account, in payto://-format
- * @param wire_reference unique identifier for the wire transfer
- * @param execution_date when did we receive the funds
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReserveInCallback.
- */
-#define TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveInCallback)(
- TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *credit,
- const struct TALER_FullPayto sender_account_details,
- uint64_t wire_reference,
- struct GNUNET_TIME_Timestamp execution_date);
-
-/**
- * Select inbound wire transfers into reserves_in above @a serial_id
- * in monotonically increasing order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_reserves_in_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveInCallback
- cb,
- TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_reserves_in_above_serial_id_by_account.h b/src/include/exchange-database/select_reserves_in_above_serial_id_by_account.h
@@ -1,84 +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/exchange-database/select_reserves_in_above_serial_id_by_account.h
- * @brief implementation of the select_reserves_in_above_serial_id_by_account function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_BY_ACCOUNT_H
-#define EXCHANGE_DATABASE_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_BY_ACCOUNT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Function called with details about incoming wire transfers.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refresh session in our DB
- * @param reserve_pub public key of the reserve (also the wire subject)
- * @param credit amount that was received
- * @param sender_account_details information about the sender's bank account, in payto://-format
- * @param wire_reference unique identifier for the wire transfer
- * @param execution_date when did we receive the funds
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_ReserveInCallback.
- */
-#define TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_ReserveInCallback)(
- TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE *cls,
- uint64_t rowid,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *credit,
- const struct TALER_FullPayto sender_account_details,
- uint64_t wire_reference,
- struct GNUNET_TIME_Timestamp execution_date);
-
-/**
- * Select inbound wire transfers into reserves_in above @a serial_id
- * in monotonically increasing order by account.
- *
- * @param pg the database context
- * @param account_name name of the account to select by
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_reserves_in_above_serial_id_by_account (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const char
- *
- account_name,
- uint64_t
- serial_id,
- TALER_EXCHANGEDB_ReserveInCallback
- cb,
- TALER_EXCHANGEDB_RESERVE_IN_RESULT_CLOSURE
- *
- cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_wallet_merges.h b/src/include/exchange-database/select_wallet_merges.h
@@ -1,76 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2026 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/exchange-database/select_wallet_merges.h
- * @brief implementation of the select_wallet_merges function
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_WALLET_MERGES_H
-#define EXCHANGE_DATABASE_SELECT_WALLET_MERGES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Callback that is given AML-relevant transfer data.
- *
- * @param cls closure
- * @param row_id current row in AML status table
- * @param payto_uri account involved with the wire transfer
- * @param execution_time when was the transfer made
- * @param amount wire amount of the transfer
- */
-#ifndef TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_AmlTransferCallback.
- */
-#define TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_AmlTransferCallback)(
- TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cls,
- uint64_t row_id,
- const char *payto_uri,
- struct GNUNET_TIME_Absolute execution_time,
- const struct TALER_Amount *amount);
-
-
-/**
- * Return AML-relevant merges (credits) into a wallet.
- *
- * @param pg the database context
- * @param threshold minimum wire amount to return data for
- * @param offset offset in table to filter by
- * @param limit maximum number of entries to return, negative for descending
- * @param h_payto account to filter transfer data by
- * @param cb function to call on each result
- * @param cb_cls closure to pass to @a cb
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_wallet_merges (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_Amount *threshold,
- uint64_t offset,
- int64_t limit,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- TALER_EXCHANGEDB_AmlTransferCallback cb,
- TALER_EXCHANGEDB_AML_TRANSFER_RESULT_CLOSURE *cb_cls);
-
-
-#endif
diff --git a/src/include/exchange-database/select_wire_out_above_serial_id.h b/src/include/exchange-database/select_wire_out_above_serial_id.h
@@ -1,78 +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/exchange-database/select_wire_out_above_serial_id.h
- * @brief implementation of the select_wire_out_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Function called with the results of the lookup of the
- * wire transfer data of the exchange.
- *
- * @param cls closure
- * @param rowid identifier of the respective row in the database
- * @param date timestamp of the wire transfer (roughly)
- * @param wtid wire transfer subject
- * @param payto_uri details of the receiver, URI in payto://-format
- * @param amount amount that was wired
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration
- */
-#ifndef TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_WireTransferOutCallback.
- */
-#define TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_WireTransferOutCallback)(
- TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp date,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_FullPayto payto_uri,
- const struct TALER_Amount *amount);
-
-/**
- * Function called to select all wire transfers the exchange
- * executed.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_wire_out_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback
- cb,
- TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_wire_out_above_serial_id_by_account.h b/src/include/exchange-database/select_wire_out_above_serial_id_by_account.h
@@ -1,82 +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/exchange-database/select_wire_out_above_serial_id_by_account.h
- * @brief implementation of the select_wire_out_above_serial_id_by_account function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_BY_ACCOUNT_H
-#define EXCHANGE_DATABASE_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_BY_ACCOUNT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/* Callback typedefs */
-/**
- * Function called with the results of the lookup of the
- * wire transfer data of the exchange.
- *
- * @param cls closure
- * @param rowid identifier of the respective row in the database
- * @param date timestamp of the wire transfer (roughly)
- * @param wtid wire transfer subject
- * @param payto_uri details of the receiver, URI in payto://-format
- * @param amount amount that was wired
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration
- */
-#ifndef TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_WireTransferOutCallback.
- */
-#define TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_WireTransferOutCallback)(
- TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE *cls,
- uint64_t rowid,
- struct GNUNET_TIME_Timestamp date,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_FullPayto payto_uri,
- const struct TALER_Amount *amount);
-
-/**
- * Function called to select all wire transfers the exchange
- * executed by account.
- *
- * @param pg the database context
- * @param account_name account to select
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_TALER_EXCHANGEDB_select_wire_out_above_serial_id_by_account (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const char *
- account_name,
- uint64_t
- serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback
- cb,
- TALER_EXCHANGEDB_WIRE_TRANSFER_OUT_RESULT_CLOSURE
- *cb_cls)
-;
-
-#endif
diff --git a/src/include/exchange-database/select_withdraw_amounts_for_kyc_check.h b/src/include/exchange-database/select_withdraw_amounts_for_kyc_check.h
@@ -1,56 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/select_withdraw_amounts_for_kyc_check.h
- * @brief implementation of the select_withdraw_amounts_for_kyc_check function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_WITHDRAW_AMOUNTS_FOR_KYC_CHECK_H
-#define EXCHANGE_DATABASE_SELECT_WITHDRAW_AMOUNTS_FOR_KYC_CHECK_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Call @a kac on withdrawn amounts after @a time_limit which are relevant
- * for a KYC trigger for a the (debited) account identified by @a h_payto.
- *
- * @param pg the database context
- * @param h_payto account identifier
- * @param time_limit oldest transaction that could be relevant
- * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
- * @param kac_cls closure for @a kac
- * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_withdraw_amounts_for_kyc_check (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- const struct
- TALER_NormalizedPaytoHashP
- *
- h_payto,
- struct
- GNUNET_TIME_Absolute
- time_limit,
- TALER_KYCLOGIC_KycAmountCallback
- kac,
- void *kac_cls);
-
-#endif
diff --git a/src/include/exchange-database/select_withdrawals_above_serial_id.h b/src/include/exchange-database/select_withdrawals_above_serial_id.h
@@ -1,129 +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/exchange-database/select_withdrawals_above_serial_id.h
- * @brief implementation of the select_withdrawals_above_serial_id function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SELECT_WITHDRAWALS_ABOVE_SERIAL_ID_H
-#define EXCHANGE_DATABASE_SELECT_WITHDRAWALS_ABOVE_SERIAL_ID_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called with details about withdraw operations.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refresh session in our DB
- * @param num_denom_serials number of elements in @e denom_serials array
- * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB
- * @param selected_h hash over the gamma-selected planchets
- * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request
- * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL
- * @param age_proof_required true if the withdraw request required an age proof.
- * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins.
- * @param noreveal_index if @e age_proof_required is true, the index that was returned by the exchange for the reveal phase.
- * @param reserve_pub public key of the reserve
- * @param reserve_sig signature over the withdraw operation
- * @param execution_date when did the wallet withdraw the coin
- * @param amount_with_fee amount that was withdrawn
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-#ifndef TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_WithdrawCallback.
- */
-#define TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE void
-#endif
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_WithdrawCallback)(
- TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE *cls,
- uint64_t rowid,
- size_t num_denom_serials,
- const uint64_t *denom_serials,
- const struct TALER_HashBlindedPlanchetsP *selected_h,
- const struct TALER_HashBlindedPlanchetsP *h_planchets,
- const struct TALER_BlindingMasterSeedP *blinding_seed,
- bool age_proof_required,
- uint8_t max_age,
- uint8_t noreveal_index,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_Amount *amount_with_fee);
-
-
-/* Callback typedefs */
-/**
- * Function called with details about withdraw operations.
- *
- * @param cls closure
- * @param rowid unique serial ID for the refresh session in our DB
- * @param num_denom_serials number of elements in @e denom_serials array
- * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB
- * @param selected_h hash over the gamma-selected planchets
- * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request
- * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL
- * @param age_proof_required true if the withdraw request required an age proof.
- * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins.
- * @param noreveal_index if @e age_proof_required is true, the index that was returned by the exchange for the reveal phase.
- * @param reserve_pub public key of the reserve
- * @param reserve_sig signature over the withdraw operation
- * @param execution_date when did the wallet withdraw the coin
- * @param amount_with_fee amount that was withdrawn
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_WithdrawCallback)(
- TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE *cls,
- uint64_t rowid,
- size_t num_denom_serials,
- const uint64_t *denom_serials,
- const struct TALER_HashBlindedPlanchetsP *selected_h,
- const struct TALER_HashBlindedPlanchetsP *h_planchets,
- const struct TALER_BlindingMasterSeedP *blinding_seed,
- bool age_proof_required,
- uint8_t max_age,
- uint8_t noreveal_index,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_Amount *amount_with_fee);
-
-/**
- * Select withdraw operations from reserves_out above @a serial_id
- * in monotonically increasing order.
- *
- * @param pg the database context
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_select_withdrawals_above_serial_id (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WithdrawCallback
- cb,
- TALER_EXCHANGEDB_WITHDRAW_RESULT_CLOSURE
- *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/set_aml_lock.h b/src/include/exchange-database/set_aml_lock.h
@@ -1,48 +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/exchange-database/set_aml_lock.h
- * @brief implementation of the set_aml_lock function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SET_AML_LOCK_H
-#define EXCHANGE_DATABASE_SET_AML_LOCK_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Set a lock for @a lock_duration on running AML programs for the @a h_payto
- * account. If a lock already exists, returns the timeout of the
- * @a existing_lock. Returns 0 if @a h_payto is not known.
- *
- * @param pg the database context
- * @param h_payto account to lock
- * @param lock_duration how long to lock the account
- * @param[out] existing_lock set to timeout of existing lock, or
- * to zero if there is no existing lock
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_set_aml_lock (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_NormalizedPaytoHashP *h_payto,
- struct GNUNET_TIME_Relative lock_duration,
- struct GNUNET_TIME_Absolute *existing_lock);
-
-
-#endif
diff --git a/src/include/exchange-database/set_purse_balance.h b/src/include/exchange-database/set_purse_balance.h
@@ -1,44 +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/exchange-database/set_purse_balance.h
- * @brief implementation of the set_purse_balance function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_SET_PURSE_BALANCE_H
-#define EXCHANGE_DATABASE_SET_PURSE_BALANCE_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Set the current @a balance in the purse
- * identified by @a purse_pub. Used by the auditor
- * to update the balance as calculated by the auditor.
- *
- * @param pg the database context
- * @param purse_pub public key of a purse
- * @param balance new balance to store under the purse
- * @return transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_set_purse_balance (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_PurseContractPublicKeyP *
- purse_pub,
- const struct TALER_Amount *balance);
-
-#endif
diff --git a/src/include/exchange-database/start_deferred_wire_out.h b/src/include/exchange-database/start_deferred_wire_out.h
@@ -35,8 +35,8 @@
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
-TALER_TALER_EXCHANGEDB_start_deferred_wire_out (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg);
+TALER_EXCHANGEDB_start_deferred_wire_out (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg);
#endif
diff --git a/src/include/exchange-database/start_read_committed.h b/src/include/exchange-database/start_read_committed.h
@@ -34,9 +34,9 @@
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
-TALER_TALER_EXCHANGEDB_start_read_committed (struct
- TALER_EXCHANGEDB_PostgresContext *
- pg,
- const char *name);
+TALER_EXCHANGEDB_start_read_committed (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const char *name);
#endif
diff --git a/src/include/exchange-database/start_read_only.h b/src/include/exchange-database/start_read_only.h
@@ -35,8 +35,8 @@
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
-TALER_TALER_EXCHANGEDB_start_read_only (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *name);
+TALER_EXCHANGEDB_start_read_only (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const char *name);
#endif
diff --git a/src/include/exchange-database/store_wire_transfer_out.h b/src/include/exchange-database/store_wire_transfer_out.h
@@ -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/include/exchange-database/store_wire_transfer_out.h
- * @brief implementation of the store_wire_transfer_out function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_STORE_WIRE_TRANSFER_OUT_H
-#define EXCHANGE_DATABASE_STORE_WIRE_TRANSFER_OUT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-/**
- * Store information about an outgoing wire transfer that was executed.
- *
- * @param pg the database context
- * @param date time of the wire transfer
- * @param wtid subject of the wire transfer
- * @param h_payto identifies the receiver account of the wire transfer
- * @param exchange_account_section configuration section of the exchange specifying the
- * exchange's bank account being used
- * @param amount amount that was transmitted
- * @param extra_wire_subject_metadata additional meta data for the wire transfer subject, can be NULL
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_store_wire_transfer_out (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- struct GNUNET_TIME_Timestamp date,
- const struct
- TALER_WireTransferIdentifierRawP *wtid
- ,
- const struct TALER_FullPaytoHashP *
- h_payto,
- const char *exchange_account_section,
- const struct TALER_Amount *amount,
- const char *
- extra_wire_subject_metadata);
-
-#endif
diff --git a/src/include/exchange-database/test_aml_officer.h b/src/include/exchange-database/test_aml_officer.h
@@ -1,43 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/test_aml_officer.h
- * @brief implementation of the test_aml_officer function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_TEST_AML_OFFICER_H
-#define EXCHANGE_DATABASE_TEST_AML_OFFICER_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Test if the given AML staff member is active
- * (at least read-only).
- *
- * @param pg the database context
- * @param decider_pub public key of the staff member
- * @param[out] read_only set to true if the member is read-only
- * @return database transaction status, if member is unknown or not active, 1 if member is active
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_test_aml_officer (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AmlOfficerPublicKeyP *
- decider_pub,
- bool *read_only);
-
-
-#endif
diff --git a/src/include/exchange-database/trigger_kyc_rule_for_account.h b/src/include/exchange-database/trigger_kyc_rule_for_account.h
@@ -1,69 +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/exchange-database/trigger_kyc_rule_for_account.h
- * @brief implementation of the trigger_kyc_rule_for_account function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_TRIGGER_KYC_RULE_FOR_ACCOUNT_H
-#define EXCHANGE_DATABASE_TRIGGER_KYC_RULE_FOR_ACCOUNT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Insert KYC requirement for @a h_payto account into table.
- *
- * @param pg the database context
- * @param payto_uri account that must be KYC'ed,
- * can be NULL if @a h_payto is already
- * guaranteed to be in wire_targets
- * @param h_payto hash of @a payto_uri
- * @param set_account_pub public key to enable for the
- * KYC authorization, NULL if not known
- * @param check_merchant_pub public key that must already
- * be enabled for a KYC authorzation for it to be
- * valid, NULL if not known
- * @param jmeasures serialized MeasureSet to put in place
- * @param display_priority priority of the rule
- * @param[out] requirement_row set to legitimization requirement row for this check
- * @param[out] bad_kyc_auth set if @a check_account_pub
- * did not match the existing KYC auth
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_trigger_kyc_rule_for_account (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg,
- const struct TALER_FullPayto
- payto_uri,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- const union
- TALER_AccountPublicKeyP *
- set_account_pub,
- const struct
- TALER_MerchantPublicKeyP *
- check_merchant_pub,
- const json_t *jmeasures,
- uint32_t display_priority,
- uint64_t *requirement_row,
- bool *bad_kyc_auth);
-
-#endif
diff --git a/src/include/exchange-database/update_kyc_process_by_row.h b/src/include/exchange-database/update_kyc_process_by_row.h
@@ -1,65 +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/exchange-database/update_kyc_process_by_row.h
- * @brief implementation of the update_kyc_process_by_row function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_UPDATE_KYC_PROCESS_BY_ROW_H
-#define EXCHANGE_DATABASE_UPDATE_KYC_PROCESS_BY_ROW_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Update KYC requirement check with provider-linkage and/or
- * expiration data.
- *
- * @param pg the database context
- * @param process_row row to select by
- * @param provider_name provider that must be checked (technically redundant)
- * @param h_payto account that must be KYC'ed (helps access by shard, otherwise also redundant)
- * @param provider_account_id provider account ID
- * @param provider_legitimization_id provider legitimization ID
- * @param redirect_url where the user should be redirected to start the KYC process
- * @param expiration how long is this KYC check set to be valid (in the past if invalid)
- * @param ec error code, #TALER_EC_NONE on success
- * @param error_message_hint human-readable error message details (in addition to @a ec, NULL on success)
- * @param finished true to mark the process as done
- * @return database transaction status
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_update_kyc_process_by_row (struct
- TALER_EXCHANGEDB_PostgresContext *pg
- ,
- uint64_t process_row,
- const char *provider_name,
- const struct
- TALER_NormalizedPaytoHashP *
- h_payto,
- const char *provider_account_id,
- const char *
- provider_legitimization_id,
- const char *redirect_url,
- struct GNUNET_TIME_Absolute
- expiration,
- enum TALER_ErrorCode ec,
- const char *error_message_hint,
- bool finished);
-
-#endif
diff --git a/src/include/exchange-database/update_legitimization_process_by_row.h b/src/include/exchange-database/update_legitimization_process_by_row.h
@@ -0,0 +1,71 @@
+/*
+ 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/exchange-database/update_legitimization_process_by_row.h
+ * @brief implementation of the update_legitimization_process_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_LEGITIMIZATION_PROCESS_BY_ROW_H
+#define EXCHANGE_DATABASE_UPDATE_LEGITIMIZATION_PROCESS_BY_ROW_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Update KYC requirement check with provider-linkage and/or
+ * expiration data.
+ *
+ * @param pg the database context
+ * @param process_row row to select by
+ * @param provider_name provider that must be checked (technically redundant)
+ * @param h_payto account that must be KYC'ed (helps access by shard, otherwise also redundant)
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param redirect_url where the user should be redirected to start the KYC process
+ * @param expiration how long is this KYC check set to be valid (in the past if invalid)
+ * @param ec error code, #TALER_EC_NONE on success
+ * @param error_message_hint human-readable error message details (in addition to @a ec, NULL on success)
+ * @param finished true to mark the process as done
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_legitimization_process_by_row (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ uint64_t process_row,
+ const char *provider_name
+ ,
+ const struct
+ TALER_NormalizedPaytoHashP
+ *
+ h_payto,
+ const char *
+ provider_account_id,
+ const char *
+ provider_legitimization_id,
+ const char *redirect_url,
+ struct
+ GNUNET_TIME_Absolute
+ expiration,
+ enum TALER_ErrorCode ec,
+ const char *
+ error_message_hint,
+ bool finished);
+
+#endif
diff --git a/src/include/exchange-database/update_purse_balance.h b/src/include/exchange-database/update_purse_balance.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file src/include/exchange-database/update_purse_balance.h
+ * @brief implementation of the update_purse_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_PURSE_BALANCE_H
+#define EXCHANGE_DATABASE_UPDATE_PURSE_BALANCE_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+/**
+ * Set the current @a balance in the purse
+ * identified by @a purse_pub. Used by the auditor
+ * to update the balance as calculated by the auditor.
+ *
+ * @param pg the database context
+ * @param purse_pub public key of a purse
+ * @param balance new balance to store under the purse
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_purse_balance (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_PurseContractPublicKeyP *
+ purse_pub,
+ const struct TALER_Amount *balance);
+
+#endif
diff --git a/src/include/exchange-database/update_reserve.h b/src/include/exchange-database/update_reserve.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/exchange-database/update_reserve.h
+ * @brief implementation of the update_reserve function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_RESERVE_H
+#define EXCHANGE_DATABASE_UPDATE_RESERVE_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Updates a reserve with the data from the given reserve structure.
+ *
+ * @param pg the database context
+ * @param reserve the reserve structure whose data will be used to update the
+ * corresponding record in the database.
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_reserve (struct TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct TALER_EXCHANGEDB_Reserve *reserve
+ );
+
+#endif
diff --git a/src/include/exchange-database/update_rules.h b/src/include/exchange-database/update_rules.h
@@ -1,127 +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 update_rules.h
- * @brief implementation to update rules for an account
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_UPDATE_RULES_H
-#define EXCHANGE_DATABASE_UPDATE_RULES_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Handle for helper logic that advances rules to the currently
- * valid rule set.
- */
-struct TALER_EXCHANGEDB_RuleUpdater;
-
-/**
- * Main result returned in the
- * #TALER_EXCHANGEDB_CurrentRulesCallback
- */
-struct TALER_EXCHANGEDB_RuleUpdaterResult
-{
- /**
- * Row the rule set is based on.
- */
- uint64_t legitimization_outcome_last_row;
-
- /**
- * Current legitimization rule set, owned by callee. Will be NULL on error
- * or for default rules. Will not contain skip rules and not be expired.
- */
- struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs;
-
- /**
- * Hint to return, if @e ec is not #TALER_EC_NONE. Can be NULL.
- */
- const char *hint;
-
- /**
- * Error code in case a problem was encountered
- * when fetching or updating the legitimization rules.
- */
- enum TALER_ErrorCode ec;
-};
-
-
-/**
- * Function called with the current rule set.
- *
- * @param cls closure
- * @param rur includes legitimziation rule set that applies to the account
- * (owned by callee, callee must free the lrs!)
- */
-#ifndef TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE
-/**
- * Type of the closure for #TALER_EXCHANGEDB_CurrentRulesCallback.
- */
-#define TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE void
-#endif
-typedef void
-(*TALER_EXCHANGEDB_CurrentRulesCallback)(
- TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE *cls,
- struct TALER_EXCHANGEDB_RuleUpdaterResult *rur);
-
-
-/**
- * Obtains the current rule set for an account and advances it
- * to the rule set that should apply right now. Considers
- * expiration of rules as well as "skip" measures. Runs
- * AML programs as needed to advance the rule book to the currently
- * valid state.
- *
- * On success, the result is returned in a (fresh) transaction
- * that must be committed for the result to be valid. This should
- * be used to ensure transactionality of the AML program result.
- *
- * This function should be called *outside* of any other transaction.
- * Calling it while a transaction is already running risks aborting
- * that transaction.
- *
- * @param pg database plugin to use
- * @param attribute_key key to use to decrypt attributes
- * @param account account to get the rule set for
- * @param is_wallet true if @a account is a wallet
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle to cancel the operation
- */
-struct TALER_EXCHANGEDB_RuleUpdater *
-TALER_EXCHANGEDB_update_rules (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_AttributeEncryptionKeyP *attribute_key,
- const struct TALER_NormalizedPaytoHashP *account,
- bool is_wallet,
- TALER_EXCHANGEDB_CurrentRulesCallback cb,
- TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE *cb_cls);
-
-
-/**
- * Cancel operation to get the current legitimization rule set.
- *
- * @param[in] ru operation to cancel
- */
-void
-TALER_EXCHANGEDB_update_rules_cancel (
- struct TALER_EXCHANGEDB_RuleUpdater *ru);
-
-
-#endif
diff --git a/src/include/exchange-database/update_to_aml_locked.h b/src/include/exchange-database/update_to_aml_locked.h
@@ -0,0 +1,52 @@
+/*
+ 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/exchange-database/update_to_aml_locked.h
+ * @brief implementation of the update_to_aml_locked function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_TO_AML_LOCKED_H
+#define EXCHANGE_DATABASE_UPDATE_TO_AML_LOCKED_H
+
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Set a lock for @a lock_duration on running AML programs for the @a h_payto
+ * account. If a lock already exists, returns the timeout of the
+ * @a existing_lock. Returns 0 if @a h_payto is not known.
+ *
+ * @param pg the database context
+ * @param h_payto account to lock
+ * @param lock_duration how long to lock the account
+ * @param[out] existing_lock set to timeout of existing lock, or
+ * to zero if there is no existing lock
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_aml_locked (struct TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct TALER_NormalizedPaytoHashP *
+ h_payto,
+ struct GNUNET_TIME_Relative lock_duration
+ ,
+ struct GNUNET_TIME_Absolute *
+ existing_lock);
+
+
+#endif
diff --git a/src/include/exchange-database/update_to_aml_unlocked.h b/src/include/exchange-database/update_to_aml_unlocked.h
@@ -0,0 +1,47 @@
+/*
+ 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/exchange-database/update_to_aml_unlocked.h
+ * @brief implementation of the update_to_aml_unlocked function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_TO_AML_UNLOCKED_H
+#define EXCHANGE_DATABASE_UPDATE_TO_AML_UNLOCKED_H
+
+#include "taler/taler_util.h"
+#include "exchangedb_lib.h"
+
+
+/**
+ * Clear a lock on running AML programs for the @a h_payto
+ * account. Returns 0 if @a h_payto is not known; does not
+ * actually care if there was a lock. Also does not by
+ * itself notify clients waiting for the lock, that
+ * notification the caller must do separately after finishing
+ * the database update.
+ *
+ * @param pg the database context
+ * @param h_payto account to clear the lock for
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_aml_unlocked (struct
+ TALER_EXCHANGEDB_PostgresContext *pg,
+ const struct
+ TALER_NormalizedPaytoHashP *
+ h_payto);
+
+#endif
diff --git a/src/include/exchange-database/update_to_prewire_failed.h b/src/include/exchange-database/update_to_prewire_failed.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/exchange-database/update_to_prewire_failed.h
+ * @brief implementation of the update_to_prewire_failed function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_TO_PREWIRE_FAILED_H
+#define EXCHANGE_DATABASE_UPDATE_TO_PREWIRE_FAILED_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to mark wire transfer commit data as failed.
+ *
+ * @param pg the database context
+ * @param rowid which entry to mark as failed
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_prewire_failed (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *pg
+ ,
+ uint64_t rowid);
+
+#endif
diff --git a/src/include/exchange-database/update_to_prewire_finished.h b/src/include/exchange-database/update_to_prewire_finished.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/exchange-database/update_to_prewire_finished.h
+ * @brief implementation of the update_to_prewire_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_TO_PREWIRE_FINISHED_H
+#define EXCHANGE_DATABASE_UPDATE_TO_PREWIRE_FINISHED_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Function called to mark wire transfer commit data as finished.
+ *
+ * @param pg the database context
+ * @param rowid which entry to mark as finished
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_prewire_finished (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t rowid);
+
+#endif
diff --git a/src/include/exchange-database/update_to_profit_drain_finished.h b/src/include/exchange-database/update_to_profit_drain_finished.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/exchange-database/update_to_profit_drain_finished.h
+ * @brief implementation of the update_to_profit_drain_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_TO_PROFIT_DRAIN_FINISHED_H
+#define EXCHANGE_DATABASE_UPDATE_TO_PROFIT_DRAIN_FINISHED_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Set profit drain operation to finished.
+ *
+ * @param pg the database context
+ * @param serial serial ID of the entry to mark finished
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_profit_drain_finished (struct
+ TALER_EXCHANGEDB_PostgresContext
+ *
+ pg,
+ uint64_t serial);
+
+#endif
diff --git a/src/include/exchange-database/update_to_refresh_revealed.h b/src/include/exchange-database/update_to_refresh_revealed.h
@@ -0,0 +1,42 @@
+/*
+ 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/exchange-database/update_to_refresh_revealed.h
+ * @brief Mark the successful reveal of a refresh in the database
+ * @author Özgür Kesim
+ */
+#ifndef EXCHANGE_DATABASE_UPDATE_TO_REFRESH_REVEALED_H
+#define EXCHANGE_DATABASE_UPDATE_TO_REFRESH_REVEALED_H
+
+#include "exchangedb_lib.h"
+
+
+/**
+ * Mark a refresh, given by the commitment, as successfully revealed.
+ *
+ * @param pg the database context
+ * @param rc commitment for the refresh
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TALER_EXCHANGEDB_update_to_refresh_revealed (struct
+ TALER_EXCHANGEDB_PostgresContext *
+ pg,
+ const struct
+ TALER_RefreshCommitmentP *
+ rc);
+
+#endif
diff --git a/src/include/exchange-database/wad_in_insert.h b/src/include/exchange-database/wad_in_insert.h
@@ -1,52 +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/exchange-database/wad_in_insert.h
- * @brief implementation of the wad_in_insert function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_WAD_IN_INSERT_H
-#define EXCHANGE_DATABASE_WAD_IN_INSERT_H
-
-#include "taler/taler_util.h"
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Insert an incoming WAD wire transfer into the database.
- *
- * @param pg the database context
- * @param wad_id WAD identifier
- * @param origin_exchange_url exchange base URL originating the transfer
- * @param amount the amount that was transferred
- * @param execution_date when was the transfer made
- * @param debit_account_uri URI of the debit account
- * @param section_name section of the exchange bank account that received the transfer
- * @param serial_id bank-specific row identifying the transfer
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wad_in_insert (struct TALER_EXCHANGEDB_PostgresContext *pg,
- const struct TALER_WadIdentifierP *wad_id,
- const char *origin_exchange_url,
- const struct TALER_Amount *amount,
- struct GNUNET_TIME_Timestamp execution_date,
- const struct TALER_FullPayto debit_account_uri,
- const char *section_name,
- uint64_t serial_id);
-
-
-#endif
diff --git a/src/include/exchange-database/wire_prepare_data_get.h b/src/include/exchange-database/wire_prepare_data_get.h
@@ -1,63 +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/exchange-database/wire_prepare_data_get.h
- * @brief implementation of the wire_prepare_data_get function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_WIRE_PREPARE_DATA_GET_H
-#define EXCHANGE_DATABASE_WIRE_PREPARE_DATA_GET_H
-
-#include "taler/taler_json_lib.h"
-#include "exchangedb_lib.h"
-
-
-/**
- * Callback with data about a prepared wire transfer.
- *
- * @param cls closure
- * @param rowid row identifier used to mark prepared transaction as done
- * @param wire_method which wire method is this preparation data for
- * @param buf transaction data that was persisted, NULL on error
- * @param buf_size number of bytes in @a buf, 0 on error
- */
-typedef void
-(*TALER_EXCHANGEDB_WirePreparationIterator) (void *cls,
- uint64_t rowid,
- const char *wire_method,
- const char *buf,
- size_t buf_size);
-
-/**
- * Function called to get an unfinished wire transfer
- * preparation data. Fetches at most one item.
- *
- * @param pg the database context
- * @param start_row offset to query table at
- * @param limit maximum number of results to return
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_get (
- struct TALER_EXCHANGEDB_PostgresContext *pg,
- uint64_t start_row,
- uint64_t limit,
- TALER_EXCHANGEDB_WirePreparationIterator cb,
- void *cb_cls);
-
-#endif
diff --git a/src/include/exchange-database/wire_prepare_data_insert.h b/src/include/exchange-database/wire_prepare_data_insert.h
@@ -1,43 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file src/include/exchange-database/wire_prepare_data_insert.h
- * @brief implementation of the wire_prepare_data_insert function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_WIRE_PREPARE_DATA_INSERT_H
-#define EXCHANGE_DATABASE_WIRE_PREPARE_DATA_INSERT_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to insert wire transfer commit data into the DB.
- *
- * @param pg the database context
- * @param type type of the wire transfer (i.e. "iban")
- * @param buf buffer with wire transfer preparation data
- * @param buf_size number of bytes in @a buf
- * @return query status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_insert (struct
- TALER_EXCHANGEDB_PostgresContext *pg,
- const char *type,
- const char *buf,
- size_t buf_size);
-
-#endif
diff --git a/src/include/exchange-database/wire_prepare_data_mark_failed.h b/src/include/exchange-database/wire_prepare_data_mark_failed.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/exchange-database/wire_prepare_data_mark_failed.h
- * @brief implementation of the wire_prepare_data_mark_failed function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_WIRE_PREPARE_DATA_MARK_FAILED_H
-#define EXCHANGE_DATABASE_WIRE_PREPARE_DATA_MARK_FAILED_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to mark wire transfer commit data as failed.
- *
- * @param pg the database context
- * @param rowid which entry to mark as failed
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_mark_failed (struct
- TALER_EXCHANGEDB_PostgresContext
- *pg
- ,
- uint64_t rowid);
-
-#endif
diff --git a/src/include/exchange-database/wire_prepare_data_mark_finished.h b/src/include/exchange-database/wire_prepare_data_mark_finished.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/exchange-database/wire_prepare_data_mark_finished.h
- * @brief implementation of the wire_prepare_data_mark_finished function for Postgres
- * @author Christian Grothoff
- */
-#ifndef EXCHANGE_DATABASE_WIRE_PREPARE_DATA_MARK_FINISHED_H
-#define EXCHANGE_DATABASE_WIRE_PREPARE_DATA_MARK_FINISHED_H
-
-#include "exchangedb_lib.h"
-
-
-/**
- * Function called to mark wire transfer commit data as finished.
- *
- * @param pg the database context
- * @param rowid which entry to mark as finished
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TALER_EXCHANGEDB_wire_prepare_data_mark_finished (struct
- TALER_EXCHANGEDB_PostgresContext
- *
- pg,
- uint64_t rowid);
-
-#endif
diff --git a/src/testing/testing_api_cmd_insert_deposit.c b/src/testing/testing_api_cmd_insert_deposit.c
@@ -36,7 +36,7 @@
#include "exchange-database/preflight.h"
#include "exchange-database/do_deposit.h"
#include "exchange-database/insert_denomination_info.h"
-#include "exchange-database/ensure_coin_known.h"
+#include "exchange-database/do_insert_known_coin.h"
/**
* State for a "insert-deposit" CMD.
@@ -294,11 +294,11 @@ insert_deposit_run (void *cls,
TALER_EXCHANGEDB_start (ids->plugin,
"libtalertesting: insert deposit")) ||
(0 >
- TALER_EXCHANGEDB_ensure_coin_known (ids->plugin,
- &deposit.coin,
- &known_coin_id,
- &dph,
- &agh)) ||
+ TALER_EXCHANGEDB_do_insert_known_coin (ids->plugin,
+ &deposit.coin,
+ &known_coin_id,
+ &dph,
+ &agh)) ||
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
TALER_EXCHANGEDB_do_deposit (ids->plugin,
&bd,