summaryrefslogtreecommitdiff
path: root/src/auditordb
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditordb')
-rw-r--r--src/auditordb/.gitignore4
-rw-r--r--src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_bad_sig_losses.sql26
-rw-r--r--src/auditordb/0002-auditor_balances.sql30
-rw-r--r--src/auditordb/0002-auditor_closure_lags.sql27
-rw-r--r--src/auditordb/0002-auditor_coin_inconsistency.sql28
-rw-r--r--src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_denomination_pending.sql34
-rw-r--r--src/auditordb/0002-auditor_denominations_without_sigs.sql27
-rw-r--r--src/auditordb/0002-auditor_deposit_confirmations.sql58
-rw-r--r--src/auditordb/0002-auditor_emergency.sql29
-rw-r--r--src/auditordb/0002-auditor_emergency_by_count.sql30
-rw-r--r--src/auditordb/0002-auditor_exchange_signkeys.sql35
-rw-r--r--src/auditordb/0002-auditor_fee_time_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_historic_denomination_revenue.sql32
-rw-r--r--src/auditordb/0002-auditor_historic_reserve_summary.sql30
-rw-r--r--src/auditordb/0002-auditor_misattribution_in_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_progress.sql26
-rw-r--r--src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql26
-rw-r--r--src/auditordb/0002-auditor_purses.sql25
-rw-r--r--src/auditordb/0002-auditor_refreshes_hanging.sql25
-rw-r--r--src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_reserve_in_inconsistency.sql29
-rw-r--r--src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql27
-rw-r--r--src/auditordb/0002-auditor_reserves.sql31
-rw-r--r--src/auditordb/0002-auditor_row_inconsistency.sql25
-rw-r--r--src/auditordb/0002-auditor_row_minor_inconsistencies.sql25
-rw-r--r--src/auditordb/0002-auditor_wire_format_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_wire_out_inconsistency.sql26
-rw-r--r--src/auditordb/Makefile.am139
-rw-r--r--src/auditordb/auditor-0001.sql579
-rw-r--r--src/auditordb/auditor-0002.sql.in46
-rw-r--r--src/auditordb/auditor_do_get_auditor_progress.sql38
-rw-r--r--src/auditordb/auditor_do_get_balance.sql47
-rw-r--r--src/auditordb/drop.sql9
-rw-r--r--src/auditordb/pg_del_denomination_balance.c (renamed from src/auditordb/pg_insert_exchange.c)28
-rw-r--r--src/auditordb/pg_del_denomination_balance.h (renamed from src/auditordb/pg_get_wire_auditor_progress.h)22
-rw-r--r--src/auditordb/pg_del_reserve_info.c11
-rw-r--r--src/auditordb/pg_del_reserve_info.h4
-rw-r--r--src/auditordb/pg_delete_deposit_confirmations.c (renamed from src/auditordb/pg_insert_wire_fee_summary.c)99
-rw-r--r--src/auditordb/pg_delete_deposit_confirmations.h (renamed from src/auditordb/pg_list_exchanges.h)26
-rw-r--r--src/auditordb/pg_delete_exchange.h43
-rw-r--r--src/auditordb/pg_delete_pending_deposit.c (renamed from src/auditordb/pg_delete_exchange.c)23
-rw-r--r--src/auditordb/pg_delete_pending_deposit.h (renamed from src/auditordb/pg_get_balance_summary.h)23
-rw-r--r--src/auditordb/pg_delete_purse_info.c7
-rw-r--r--src/auditordb/pg_delete_purse_info.h4
-rw-r--r--src/auditordb/pg_get_auditor_progress.c178
-rw-r--r--src/auditordb/pg_get_auditor_progress.h (renamed from src/auditordb/pg_get_auditor_progress_deposit_confirmation.h)23
-rw-r--r--src/auditordb/pg_get_auditor_progress_aggregation.c56
-rw-r--r--src/auditordb/pg_get_auditor_progress_aggregation.h43
-rw-r--r--src/auditordb/pg_get_auditor_progress_coin.c77
-rw-r--r--src/auditordb/pg_get_auditor_progress_coin.h43
-rw-r--r--src/auditordb/pg_get_auditor_progress_deposit_confirmation.c56
-rw-r--r--src/auditordb/pg_get_auditor_progress_purse.c68
-rw-r--r--src/auditordb/pg_get_auditor_progress_reserve.c77
-rw-r--r--src/auditordb/pg_get_balance.c183
-rw-r--r--src/auditordb/pg_get_balance.h (renamed from src/auditordb/pg_get_purse_summary.h)25
-rw-r--r--src/auditordb/pg_get_balance_summary.c89
-rw-r--r--src/auditordb/pg_get_denomination_balance.c12
-rw-r--r--src/auditordb/pg_get_deposit_confirmations.c70
-rw-r--r--src/auditordb/pg_get_deposit_confirmations.h4
-rw-r--r--src/auditordb/pg_get_predicted_balance.c61
-rw-r--r--src/auditordb/pg_get_predicted_balance.h44
-rw-r--r--src/auditordb/pg_get_purse_info.c8
-rw-r--r--src/auditordb/pg_get_purse_info.h2
-rw-r--r--src/auditordb/pg_get_purse_summary.c59
-rw-r--r--src/auditordb/pg_get_reserve_info.c29
-rw-r--r--src/auditordb/pg_get_reserve_info.h2
-rw-r--r--src/auditordb/pg_get_reserve_summary.c88
-rw-r--r--src/auditordb/pg_get_reserve_summary.h43
-rw-r--r--src/auditordb/pg_get_wire_auditor_account_progress.c68
-rw-r--r--src/auditordb/pg_get_wire_auditor_account_progress.h48
-rw-r--r--src/auditordb/pg_get_wire_auditor_progress.c59
-rw-r--r--src/auditordb/pg_get_wire_fee_summary.c9
-rw-r--r--src/auditordb/pg_get_wire_fee_summary.h2
-rw-r--r--src/auditordb/pg_helper.h15
-rw-r--r--src/auditordb/pg_insert_auditor_progress.c97
-rw-r--r--src/auditordb/pg_insert_auditor_progress.h (renamed from src/auditordb/pg_insert_wire_auditor_progress.h)21
-rw-r--r--src/auditordb/pg_insert_auditor_progress_aggregation.c51
-rw-r--r--src/auditordb/pg_insert_auditor_progress_coin.c65
-rw-r--r--src/auditordb/pg_insert_auditor_progress_coin.h44
-rw-r--r--src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c51
-rw-r--r--src/auditordb/pg_insert_auditor_progress_deposit_confirmation.h44
-rw-r--r--src/auditordb/pg_insert_auditor_progress_purse.c59
-rw-r--r--src/auditordb/pg_insert_auditor_progress_purse.h44
-rw-r--r--src/auditordb/pg_insert_auditor_progress_reserve.c65
-rw-r--r--src/auditordb/pg_insert_auditor_progress_reserve.h43
-rw-r--r--src/auditordb/pg_insert_balance.c97
-rw-r--r--src/auditordb/pg_insert_balance.h (renamed from src/auditordb/pg_get_auditor_progress_purse.h)27
-rw-r--r--src/auditordb/pg_insert_balance_summary.c77
-rw-r--r--src/auditordb/pg_insert_balance_summary.h44
-rw-r--r--src/auditordb/pg_insert_denomination_balance.c26
-rw-r--r--src/auditordb/pg_insert_deposit_confirmation.c24
-rw-r--r--src/auditordb/pg_insert_exchange.h43
-rw-r--r--src/auditordb/pg_insert_exchange_signkey.c6
-rw-r--r--src/auditordb/pg_insert_historic_denom_revenue.c19
-rw-r--r--src/auditordb/pg_insert_historic_denom_revenue.h2
-rw-r--r--src/auditordb/pg_insert_historic_reserve_revenue.c13
-rw-r--r--src/auditordb/pg_insert_historic_reserve_revenue.h2
-rw-r--r--src/auditordb/pg_insert_pending_deposit.c (renamed from src/auditordb/pg_insert_purse_summary.c)38
-rw-r--r--src/auditordb/pg_insert_pending_deposit.h (renamed from src/auditordb/pg_insert_auditor_progress_aggregation.h)27
-rw-r--r--src/auditordb/pg_insert_predicted_result.c56
-rw-r--r--src/auditordb/pg_insert_predicted_result.h46
-rw-r--r--src/auditordb/pg_insert_purse_info.c11
-rw-r--r--src/auditordb/pg_insert_purse_info.h2
-rw-r--r--src/auditordb/pg_insert_purse_summary.h45
-rw-r--r--src/auditordb/pg_insert_reserve_info.c53
-rw-r--r--src/auditordb/pg_insert_reserve_info.h2
-rw-r--r--src/auditordb/pg_insert_reserve_summary.c75
-rw-r--r--src/auditordb/pg_insert_reserve_summary.h45
-rw-r--r--src/auditordb/pg_insert_wire_auditor_account_progress.c61
-rw-r--r--src/auditordb/pg_insert_wire_auditor_account_progress.h48
-rw-r--r--src/auditordb/pg_insert_wire_auditor_progress.c53
-rw-r--r--src/auditordb/pg_insert_wire_fee_summary.h44
-rw-r--r--src/auditordb/pg_list_exchanges.c126
-rw-r--r--src/auditordb/pg_select_historic_denom_revenue.c11
-rw-r--r--src/auditordb/pg_select_historic_denom_revenue.h3
-rw-r--r--src/auditordb/pg_select_historic_reserve_revenue.c8
-rw-r--r--src/auditordb/pg_select_historic_reserve_revenue.h2
-rw-r--r--src/auditordb/pg_select_pending_deposits.c149
-rw-r--r--src/auditordb/pg_select_pending_deposits.h (renamed from src/auditordb/pg_get_auditor_progress_reserve.h)27
-rw-r--r--src/auditordb/pg_select_purse_expired.c8
-rw-r--r--src/auditordb/pg_select_purse_expired.h2
-rw-r--r--src/auditordb/pg_template.c2
-rw-r--r--src/auditordb/pg_template.h2
-rw-r--r--src/auditordb/pg_update_auditor_progress.c99
-rw-r--r--src/auditordb/pg_update_auditor_progress.h (renamed from src/auditordb/pg_update_wire_auditor_progress.h)21
-rw-r--r--src/auditordb/pg_update_auditor_progress_aggregation.c50
-rw-r--r--src/auditordb/pg_update_auditor_progress_aggregation.h44
-rw-r--r--src/auditordb/pg_update_auditor_progress_coin.c64
-rw-r--r--src/auditordb/pg_update_auditor_progress_coin.h44
-rw-r--r--src/auditordb/pg_update_auditor_progress_deposit_confirmation.c50
-rw-r--r--src/auditordb/pg_update_auditor_progress_deposit_confirmation.h45
-rw-r--r--src/auditordb/pg_update_auditor_progress_purse.c58
-rw-r--r--src/auditordb/pg_update_auditor_progress_purse.h44
-rw-r--r--src/auditordb/pg_update_auditor_progress_reserve.c64
-rw-r--r--src/auditordb/pg_update_auditor_progress_reserve.h43
-rw-r--r--src/auditordb/pg_update_balance.c100
-rw-r--r--src/auditordb/pg_update_balance.h (renamed from src/auditordb/pg_update_purse_summary.h)24
-rw-r--r--src/auditordb/pg_update_balance_summary.c75
-rw-r--r--src/auditordb/pg_update_balance_summary.h44
-rw-r--r--src/auditordb/pg_update_denomination_balance.c28
-rw-r--r--src/auditordb/pg_update_predicted_result.c55
-rw-r--r--src/auditordb/pg_update_predicted_result.h46
-rw-r--r--src/auditordb/pg_update_purse_info.c13
-rw-r--r--src/auditordb/pg_update_purse_info.h2
-rw-r--r--src/auditordb/pg_update_purse_summary.c53
-rw-r--r--src/auditordb/pg_update_reserve_info.c47
-rw-r--r--src/auditordb/pg_update_reserve_info.h2
-rw-r--r--src/auditordb/pg_update_reserve_summary.c69
-rw-r--r--src/auditordb/pg_update_reserve_summary.h45
-rw-r--r--src/auditordb/pg_update_wire_auditor_account_progress.c59
-rw-r--r--src/auditordb/pg_update_wire_auditor_account_progress.h49
-rw-r--r--src/auditordb/pg_update_wire_auditor_progress.c52
-rw-r--r--src/auditordb/pg_update_wire_fee_summary.c9
-rw-r--r--src/auditordb/pg_update_wire_fee_summary.h2
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c367
-rw-r--r--src/auditordb/procedures.sql.in24
-rw-r--r--src/auditordb/restart.sql18
-rw-r--r--src/auditordb/test_auditordb.c282
-rw-r--r--src/auditordb/test_auditordb_checkpoints.c386
-rw-r--r--src/auditordb/versioning.sql3
163 files changed, 3261 insertions, 4655 deletions
diff --git a/src/auditordb/.gitignore b/src/auditordb/.gitignore
index 56c08312b..e1c7a648b 100644
--- a/src/auditordb/.gitignore
+++ b/src/auditordb/.gitignore
@@ -1 +1,5 @@
test-auditordb-postgres
+auditor-0002.sql
+procedures.sql
+test_auditordb_checkpoints_postgres
+test_auditordb-postgres
diff --git a/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql b/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql
new file mode 100644
index 000000000..19dfa682c
--- /dev/null
+++ b/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_amount_arithmetic_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ operation BYTEA,
+ exchange_amount taler_amount,
+ auditor_amount taler_amount,
+ profitable BOOLEAN
+);
+COMMENT ON TABLE auditor_amount_arithmetic_inconsistency
+ IS 'Report a (serious) inconsistency in the exchange''s database with respect to calculations involving amounts';
diff --git a/src/auditordb/0002-auditor_bad_sig_losses.sql b/src/auditordb/0002-auditor_bad_sig_losses.sql
new file mode 100644
index 000000000..ac17a5120
--- /dev/null
+++ b/src/auditordb/0002-auditor_bad_sig_losses.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_bad_sig_losses
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ operation BYTEA,
+ loss taler_amount,
+ operation_specific_pub BYTEA
+);
+COMMENT ON TABLE auditor_bad_sig_losses
+ IS 'Report a (serious) inconsistency with losses due to bad signatures'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_balances.sql b/src/auditordb/0002-auditor_balances.sql
new file mode 100644
index 000000000..8014b9c41
--- /dev/null
+++ b/src/auditordb/0002-auditor_balances.sql
@@ -0,0 +1,30 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE IF NOT EXISTS auditor_balances
+(
+ balance_key TEXT PRIMARY KEY NOT NULL
+ ,balance_value taler_amount
+);
+COMMENT
+ON TABLE auditor_balances
+ IS 'table storing various global balances of the auditor';
+COMMENT
+ON COLUMN auditor_balances.balance_key
+ IS 'unique name for the balance value';
+COMMENT
+ON COLUMN auditor_balances.balance_value
+ IS 'balance amount';
diff --git a/src/auditordb/0002-auditor_closure_lags.sql b/src/auditordb/0002-auditor_closure_lags.sql
new file mode 100644
index 000000000..8473b25f9
--- /dev/null
+++ b/src/auditordb/0002-auditor_closure_lags.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_closure_lags
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ deadline BIGINT,
+ wtid integer,
+ account BYTEA
+);
+COMMENT ON TABLE auditor_closure_lags
+ IS 'Report closure lags.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_coin_inconsistency.sql b/src/auditordb/0002-auditor_coin_inconsistency.sql
new file mode 100644
index 000000000..91f954a68
--- /dev/null
+++ b/src/auditordb/0002-auditor_coin_inconsistency.sql
@@ -0,0 +1,28 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_coin_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ operation BYTEA,
+ exchange_amount taler_amount,
+ auditor_amount taler_amount,
+ coin_pub BYTEA,
+ profitable BOOLEAN
+);
+COMMENT ON TABLE auditor_coin_inconsistency
+ IS 'Report a (serious) inconsistency in the exchange''s database with respect to calculations involving amounts'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql b/src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql
new file mode 100644
index 000000000..fd18f35fb
--- /dev/null
+++ b/src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_denomination_key_validity_withdraw_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ execution_date BIGINT,
+ reserve_pub BYTEA,
+ denompub_h BYTEA
+);
+COMMENT ON TABLE auditor_denomination_key_validity_withdraw_inconsistency
+ IS 'Report a (serious) denomination key validity withdraw inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_denomination_pending.sql b/src/auditordb/0002-auditor_denomination_pending.sql
new file mode 100644
index 000000000..f9ba535b4
--- /dev/null
+++ b/src/auditordb/0002-auditor_denomination_pending.sql
@@ -0,0 +1,34 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_denomination_pending
+ (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
+ ,denom_balance taler_amount NOT NULL
+ ,denom_loss taler_amount NOT NULL
+ ,num_issued INT8 NOT NULL
+ ,denom_risk taler_amount NOT NULL
+ ,recoup_loss taler_amount NOT NULL
+);
+COMMENT ON TABLE auditor_denomination_pending
+ IS 'outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the maximum value at risk).';
+COMMENT ON COLUMN auditor_denomination_pending.num_issued
+ IS 'counts the number of coins issued (withdraw, refresh) of this denomination';
+COMMENT ON COLUMN auditor_denomination_pending.denom_risk
+ IS 'amount that could theoretically be lost in the future due to recoup operations';
+COMMENT ON COLUMN auditor_denomination_pending.denom_loss
+ IS 'amount that was lost due to failures by the exchange';
+COMMENT ON COLUMN auditor_denomination_pending.recoup_loss
+ IS 'amount actually lost due to recoup operations after a revocation';
diff --git a/src/auditordb/0002-auditor_denominations_without_sigs.sql b/src/auditordb/0002-auditor_denominations_without_sigs.sql
new file mode 100644
index 000000000..86c83e94f
--- /dev/null
+++ b/src/auditordb/0002-auditor_denominations_without_sigs.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_denominations_without_sigs
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ denompub_h BYTEA,
+ value taler_amount,
+ start_time BIGINT,
+ end_time BIGINT
+);
+COMMENT ON TABLE auditor_denominations_without_sigs
+ IS 'Report encountered denomination that auditor is not auditing.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_deposit_confirmations.sql b/src/auditordb/0002-auditor_deposit_confirmations.sql
new file mode 100644
index 000000000..1b7fec185
--- /dev/null
+++ b/src/auditordb/0002-auditor_deposit_confirmations.sql
@@ -0,0 +1,58 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_deposit_confirmations
+(deposit_confirmation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
+ ,h_policy BYTEA NOT NULL CHECK (LENGTH(h_policy)=64)
+ ,h_wire BYTEA NOT NULL CHECK (LENGTH(h_wire)=64)
+ ,exchange_timestamp INT8 NOT NULL
+ ,refund_deadline INT8 NOT NULL
+ ,wire_deadline INT8 NOT NULL
+ ,total_without_fee taler_amount NOT NULL
+ ,coin_pubs BYTEA[] NOT NULL CHECK (CARDINALITY(coin_pubs)>0)
+ ,coin_sigs BYTEA[] NOT NULL CHECK (CARDINALITY(coin_sigs)=CARDINALITY(coin_pubs))
+ ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
+ ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
+ ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,suppressed BOOLEAN NOT NULL DEFAULT FALSE
+ ,ancient BOOLEAN NOT NULL DEFAULT FALSE
+ ,PRIMARY KEY (h_contract_terms,h_wire,merchant_pub,exchange_sig,exchange_pub,master_sig)
+ );
+COMMENT ON TABLE auditor_deposit_confirmations
+ IS 'deposit confirmation sent to us by merchants; we must check that the exchange reported these properly.';
+
+CREATE INDEX IF NOT EXISTS auditor_deposit_confirmations_not_ancient
+ ON auditor_deposit_confirmations
+ (exchange_timestamp ASC)
+ WHERE NOT ancient;
+
+CREATE OR REPLACE FUNCTION auditor_new_transactions_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $$
+BEGIN
+ NOTIFY XX81AFHF88YGN6ESNH39KR5VQE9MHD7GSSNMTCXB82SZ6T99ARHE0;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION auditor_new_transactions_trigger()
+ IS 'Call auditor_call_db_notify on new entry';
+
+CREATE TRIGGER auditor_notify_helper_deposits
+ AFTER INSERT
+ ON auditor.auditor_deposit_confirmations
+EXECUTE PROCEDURE auditor_new_transactions_trigger();
diff --git a/src/auditordb/0002-auditor_emergency.sql b/src/auditordb/0002-auditor_emergency.sql
new file mode 100644
index 000000000..2bb13d7e5
--- /dev/null
+++ b/src/auditordb/0002-auditor_emergency.sql
@@ -0,0 +1,29 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_emergency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ denompub_h BYTEA,
+ denom_risk taler_amount,
+ denom_loss taler_amount,
+ deposit_start BIGINT,
+ deposit_end BIGINT,
+ value taler_amount
+);
+COMMENT ON TABLE auditor_emergency
+ IS 'Report an emergency denomination.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_emergency_by_count.sql b/src/auditordb/0002-auditor_emergency_by_count.sql
new file mode 100644
index 000000000..4daa994a7
--- /dev/null
+++ b/src/auditordb/0002-auditor_emergency_by_count.sql
@@ -0,0 +1,30 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_emergency_by_count
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ denompub_h BYTEA,
+ num_issued integer,
+ num_known integer,
+ risk taler_amount,
+ start BIGINT,
+ deposit_end BIGINT,
+ value taler_amount
+);
+COMMENT ON TABLE auditor_emergency_by_count
+ IS 'Report an emergency denomination.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_exchange_signkeys.sql b/src/auditordb/0002-auditor_exchange_signkeys.sql
new file mode 100644
index 000000000..64349a2ff
--- /dev/null
+++ b/src/auditordb/0002-auditor_exchange_signkeys.sql
@@ -0,0 +1,35 @@
+ --
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_exchange_signkeys
+ (exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32)
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,ep_valid_from INT8 NOT NULL
+ ,ep_expire_sign INT8 NOT NULL
+ ,ep_expire_legal INT8 NOT NULL
+ );
+COMMENT ON TABLE auditor_exchange_signkeys
+ IS 'list of the online signing keys of exchanges we are auditing';
+COMMENT ON COLUMN auditor_exchange_signkeys.exchange_pub
+ IS 'Public online signing key of the exchange.';
+COMMENT ON COLUMN auditor_exchange_signkeys.master_sig
+ IS 'Signature affirming the validity of the signing key of purpose TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY.';
+COMMENT ON COLUMN auditor_exchange_signkeys.ep_valid_from
+ IS 'Time when this online signing key will first be used to sign messages.';
+COMMENT ON COLUMN auditor_exchange_signkeys.ep_expire_sign
+ IS 'Time when this online signing key will no longer be used to sign.';
+COMMENT ON COLUMN auditor_exchange_signkeys.ep_expire_legal
+ IS 'Time when this online signing key legally expires.';
diff --git a/src/auditordb/0002-auditor_fee_time_inconsistency.sql b/src/auditordb/0002-auditor_fee_time_inconsistency.sql
new file mode 100644
index 000000000..b89cc59c7
--- /dev/null
+++ b/src/auditordb/0002-auditor_fee_time_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_fee_time_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ type BYTEA,
+ time BIGINT,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_fee_time_inconsistency
+ IS 'Report a (serious) fee time inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_historic_denomination_revenue.sql b/src/auditordb/0002-auditor_historic_denomination_revenue.sql
new file mode 100644
index 000000000..bf7e4c07e
--- /dev/null
+++ b/src/auditordb/0002-auditor_historic_denomination_revenue.sql
@@ -0,0 +1,32 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_historic_denomination_revenue
+ (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
+ ,revenue_timestamp INT8 NOT NULL
+ ,revenue_balance taler_amount NOT NULL
+ ,loss_balance taler_amount NOT NULL
+ );
+COMMENT ON TABLE auditor_historic_denomination_revenue
+ IS 'Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the denom_pub here is not a foreign key, we just keep it as a reference point.';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.denom_pub_hash
+ IS 'hash of the denomination public key that created this revenue';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.revenue_timestamp
+ IS 'when was this revenue realized (by the denomination public key expiring)';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.revenue_balance
+ IS 'the sum of all of the profits we made on the denomination except for withdraw fees (which are in historic_reserve_revenue); so this includes the deposit, melt and refund fees';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.loss_balance
+ IS 'the sum of all of the losses we made on the denomination (for example, because the signing key was compromised and thus we redeemed coins we never issued); of course should be zero in practice in most cases';
diff --git a/src/auditordb/0002-auditor_historic_reserve_summary.sql b/src/auditordb/0002-auditor_historic_reserve_summary.sql
new file mode 100644
index 000000000..819c4e160
--- /dev/null
+++ b/src/auditordb/0002-auditor_historic_reserve_summary.sql
@@ -0,0 +1,30 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary
+ (start_date INT8 PRIMARY KEY
+ ,end_date INT8 NOT NULL
+ ,reserve_profits taler_amount NOT NULL
+ );
+COMMENT ON TABLE auditor_historic_reserve_summary
+ IS 'historic profits from reserves; we eventually GC auditor_historic_reserve_revenue, and then store the totals in here (by time intervals).';
+COMMENT ON COLUMN auditor_historic_reserve_summary.start_date
+ IS 'start date of the time interval over which we made these profits from reserves';
+COMMENT ON COLUMN auditor_historic_reserve_summary.end_date
+ IS 'end date (exclusive) of the time interval over which we made these profits from reserves';
+COMMENT ON COLUMN auditor_historic_reserve_summary.reserve_profits
+ IS 'total amount in profits made';
diff --git a/src/auditordb/0002-auditor_misattribution_in_inconsistency.sql b/src/auditordb/0002-auditor_misattribution_in_inconsistency.sql
new file mode 100644
index 000000000..f786d0fdf
--- /dev/null
+++ b/src/auditordb/0002-auditor_misattribution_in_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_misattribution_in_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ bank_row BIGINT,
+ reserve_pub BYTEA
+);
+COMMENT ON TABLE auditor_misattribution_in_inconsistency
+ IS 'Report wire transfer that was smaller than it should have been.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_progress.sql b/src/auditordb/0002-auditor_progress.sql
new file mode 100644
index 000000000..288a08ae9
--- /dev/null
+++ b/src/auditordb/0002-auditor_progress.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE IF NOT EXISTS auditor_progress
+ (progress_key TEXT PRIMARY KEY NOT NULL
+ ,progress_offset INT8 NOT NULL
+ );
+COMMENT ON TABLE auditor_progress
+ IS 'Information about to the point until which the audit has progressed. Used for SELECTing the statements to process.';
+COMMENT ON COLUMN auditor_progress.progress_key
+ IS 'Name of the progress indicator';
+COMMENT ON COLUMN auditor_progress.progress_offset
+ IS 'Table offset or timestamp or counter until which the audit has progressed';
diff --git a/src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql b/src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql
new file mode 100644
index 000000000..5ffb6e85a
--- /dev/null
+++ b/src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_purse_not_closed_inconsistencies
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ purse_pub BYTEA,
+ amount taler_amount,
+ expiration_date BIGINT
+);
+COMMENT ON TABLE auditor_purse_not_closed_inconsistencies
+ IS 'Report expired purses'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_purses.sql b/src/auditordb/0002-auditor_purses.sql
new file mode 100644
index 000000000..86b6494d1
--- /dev/null
+++ b/src/auditordb/0002-auditor_purses.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_purses
+ (auditor_purses_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)
+ ,balance taler_amount NOT NULL DEFAULT(0,0)
+ ,target taler_amount NOT NULL
+ ,expiration_date INT8 NOT NULL
+ );
+COMMENT ON TABLE auditor_purses
+ IS 'all of the purses and their respective balances that the auditor is aware of';
diff --git a/src/auditordb/0002-auditor_refreshes_hanging.sql b/src/auditordb/0002-auditor_refreshes_hanging.sql
new file mode 100644
index 000000000..5544bc0d8
--- /dev/null
+++ b/src/auditordb/0002-auditor_refreshes_hanging.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_refreshes_hanging
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ coin_pub BYTEA
+);
+COMMENT ON TABLE auditor_refreshes_hanging
+ IS 'Report a hanging refresh.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql b/src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql
new file mode 100644
index 000000000..bbc0c8118
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_balance_insufficient_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ reserve_pub BYTEA,
+ inconsistency_gain BOOLEAN,
+ inconsistency_amount taler_amount
+);
+COMMENT ON TABLE auditor_reserve_balance_insufficient_inconsistency
+ IS 'Report a (serious) balance insufficiency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql b/src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql
new file mode 100644
index 000000000..26d872132
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_balance_summary_wrong_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ reserve_pub BYTEA,
+ exchange_amount taler_amount,
+ auditor_amount taler_amount
+);
+COMMENT ON TABLE auditor_reserve_balance_summary_wrong_inconsistency
+ IS 'Report a (serious) reserve balance insufficiency.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_in_inconsistency.sql b/src/auditordb/0002-auditor_reserve_in_inconsistency.sql
new file mode 100644
index 000000000..bb90c4018
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_in_inconsistency.sql
@@ -0,0 +1,29 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_in_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount_exchange_expected taler_amount,
+ amount_wired taler_amount,
+ reserve_pub BYTEA,
+ timestamp BIGINT,
+ account BYTEA,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_reserve_in_inconsistency
+ IS 'Report an incoming wire transfer claimed by exchange not found.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql b/src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql
new file mode 100644
index 000000000..1147b4ae8
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_not_closed_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ reserve_pub BYTEA,
+ balance taler_amount,
+ expiration_time BIGINT,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_reserve_not_closed_inconsistency
+ IS 'Report a (serious) reserve balance insufficiency.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserves.sql b/src/auditordb/0002-auditor_reserves.sql
new file mode 100644
index 000000000..808524b28
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserves.sql
@@ -0,0 +1,31 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_reserves
+ (auditor_reserves_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)
+ ,reserve_balance taler_amount NOT NULL
+ ,reserve_loss taler_amount NOT NULL
+ ,withdraw_fee_balance taler_amount NOT NULL
+ ,close_fee_balance taler_amount NOT NULL
+ ,purse_fee_balance taler_amount NOT NULL
+ ,open_fee_balance taler_amount NOT NULL
+ ,history_fee_balance taler_amount NOT NULL
+ ,expiration_date INT8 NOT NULL
+ ,origin_account TEXT
+ );
+COMMENT ON TABLE auditor_reserves
+ IS 'all of the customer reserves and their respective balances that the auditor is aware of';
diff --git a/src/auditordb/0002-auditor_row_inconsistency.sql b/src/auditordb/0002-auditor_row_inconsistency.sql
new file mode 100644
index 000000000..ece2e5661
--- /dev/null
+++ b/src/auditordb/0002-auditor_row_inconsistency.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_row_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ table BYTEA,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_row_inconsistency
+ IS 'Report a (serious) row inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_row_minor_inconsistencies.sql b/src/auditordb/0002-auditor_row_minor_inconsistencies.sql
new file mode 100644
index 000000000..7836037c7
--- /dev/null
+++ b/src/auditordb/0002-auditor_row_minor_inconsistencies.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_row_minor_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ table BYTEA,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_row_minor_inconsistency
+ IS 'Report a (serious) row inconsistency in the exchange''s database.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_wire_format_inconsistency.sql b/src/auditordb/0002-auditor_wire_format_inconsistency.sql
new file mode 100644
index 000000000..1bc9af89d
--- /dev/null
+++ b/src/auditordb/0002-auditor_wire_format_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_wire_format_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ wire_offset BIGINT,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_wire_format_inconsistency
+ IS 'Report a (serious) format inconsistency.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_wire_out_inconsistency.sql b/src/auditordb/0002-auditor_wire_out_inconsistency.sql
new file mode 100644
index 000000000..6a49c24a0
--- /dev/null
+++ b/src/auditordb/0002-auditor_wire_out_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_wire_out_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ destination_account BYTEA,
+ expected taler_amount,
+ claimed taler_amount
+);
+COMMENT ON TABLE auditor_wire_out_inconsistency
+ IS 'Report a (serious) wire inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am
index 98b19f894..c0282e9c9 100644
--- a/src/auditordb/Makefile.am
+++ b/src/auditordb/Makefile.am
@@ -13,15 +13,38 @@ pkgcfg_DATA = \
sqldir = $(prefix)/share/taler/sql/auditor/
+sqlinputs = \
+ 0002-*.sql \
+ auditor-0002.sql.in \
+ auditor_do_*.sql \
+ procedures.sql.in
+
sql_DATA = \
versioning.sql \
auditor-0001.sql \
+ auditor-0002.sql \
drop.sql \
- restart.sql
+ restart.sql \
+ procedures.sql
+
+CLEANFILES = \
+ auditor-0002.sql
+
+procedures.sql: procedures.sql.in auditor_do_*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < procedures.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
+ chmod ugo-w $@
+
+auditor-0002.sql: auditor-0002.sql.in 0002-*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < auditor-0002.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
+ chmod ugo-w $@
+
EXTRA_DIST = \
auditordb-postgres.conf \
test-auditor-db-postgres.conf \
+ $(sqlinputs) \
$(sql_DATA) \
pg_template.h pg_template.c \
pg_template.sh
@@ -35,74 +58,47 @@ endif
libtaler_plugin_auditordb_postgres_la_SOURCES = \
plugin_auditordb_postgres.c pg_helper.h \
- pg_insert_auditor_progress_reserve.h pg_insert_auditor_progress_reserve.c \
- pg_update_auditor_progress_reserve.h pg_update_auditor_progress_reserve.c \
- pg_get_auditor_progress_reserve.h pg_get_auditor_progress_reserve.c \
- pg_insert_auditor_progress_purse.h pg_insert_auditor_progress_purse.c \
- pg_update_auditor_progress_purse.h pg_update_auditor_progress_purse.c \
- pg_get_auditor_progress_purse.h pg_get_auditor_progress_purse.c \
- pg_insert_auditor_progress_aggregation.h pg_insert_auditor_progress_aggregation.c \
- pg_update_auditor_progress_aggregation.h pg_update_auditor_progress_aggregation.c \
- pg_get_auditor_progress_aggregation.h pg_get_auditor_progress_aggregation.c \
- pg_insert_auditor_progress_deposit_confirmation.h pg_insert_auditor_progress_deposit_confirmation.c \
- pg_update_auditor_progress_deposit_confirmation.h pg_update_auditor_progress_deposit_confirmation.c \
- pg_get_auditor_progress_deposit_confirmation.h pg_get_auditor_progress_deposit_confirmation.c \
- pg_insert_auditor_progress_coin.h pg_insert_auditor_progress_coin.c \
- pg_update_auditor_progress_coin.h pg_update_auditor_progress_coin.c \
- pg_get_auditor_progress_coin.h pg_get_auditor_progress_coin.c \
- pg_insert_wire_auditor_account_progress.h pg_insert_wire_auditor_account_progress.c \
- pg_update_wire_auditor_account_progress.h pg_update_wire_auditor_account_progress.c \
- pg_get_wire_auditor_account_progress.h pg_get_wire_auditor_account_progress.c \
- pg_insert_wire_auditor_progress.h pg_insert_wire_auditor_progress.c \
- pg_update_wire_auditor_progress.h pg_update_wire_auditor_progress.c \
- pg_get_wire_auditor_progress.h pg_get_wire_auditor_progress.c \
- pg_insert_reserve_info.h pg_insert_reserve_info.c \
- pg_update_reserve_info.h pg_update_reserve_info.c \
- pg_del_reserve_info.h pg_del_reserve_info.c \
- pg_get_reserve_info.h pg_get_reserve_info.c \
- pg_insert_reserve_summary.h pg_insert_reserve_summary.c \
- pg_update_reserve_summary.h pg_update_reserve_summary.c \
- pg_get_reserve_summary.h pg_get_reserve_summary.c \
- pg_insert_wire_fee_summary.h pg_insert_wire_fee_summary.c \
- pg_update_wire_fee_summary.h pg_update_wire_fee_summary.c \
- pg_get_wire_fee_summary.h pg_get_wire_fee_summary.c \
- pg_insert_denomination_balance.h pg_insert_denomination_balance.c \
- pg_update_denomination_balance.h pg_update_denomination_balance.c \
- pg_get_denomination_balance.h pg_get_denomination_balance.c \
- pg_insert_balance_summary.h pg_insert_balance_summary.c \
- pg_update_balance_summary.h pg_update_balance_summary.c \
- pg_get_balance_summary.h pg_get_balance_summary.c \
- pg_insert_historic_denom_revenue.h pg_insert_historic_denom_revenue.c \
- pg_select_historic_denom_revenue.h pg_select_historic_denom_revenue.c \
- pg_insert_historic_reserve_revenue.h pg_insert_historic_reserve_revenue.c \
- pg_select_historic_reserve_revenue.h pg_select_historic_reserve_revenue.c \
- pg_insert_predicted_result.h pg_insert_predicted_result.c \
- pg_update_predicted_result.h pg_update_predicted_result.c \
- pg_get_predicted_balance.h pg_get_predicted_balance.c \
- pg_insert_exchange.h pg_insert_exchange.c \
- pg_list_exchanges.h pg_list_exchanges.c \
- pg_delete_exchange.h pg_delete_exchange.c \
- pg_insert_exchange_signkey.h pg_insert_exchange_signkey.c \
- pg_insert_deposit_confirmation.h pg_insert_deposit_confirmation.c \
- pg_get_purse_info.h pg_get_purse_info.c \
- pg_delete_purse_info.h pg_delete_purse_info.c \
- pg_update_purse_info.h pg_update_purse_info.c \
- pg_insert_purse_info.h pg_insert_purse_info.c \
- pg_get_purse_summary.h pg_get_purse_summary.c \
- pg_select_purse_expired.h pg_select_purse_expired.c \
- pg_insert_purse_summary.h pg_insert_purse_summary.c \
- pg_update_purse_summary.h pg_update_purse_summary.c \
- pg_get_deposit_confirmations.h pg_get_deposit_confirmations.c
-libtaler_plugin_auditordb_postgres_la_LIBADD = \
- $(LTLIBINTL)
+ pg_delete_deposit_confirmations.c pg_delete_deposit_confirmations.h \
+ pg_delete_pending_deposit.c pg_delete_pending_deposit.h \
+ pg_delete_purse_info.c pg_delete_purse_info.h \
+ pg_del_denomination_balance.h pg_del_denomination_balance.c \
+ pg_del_reserve_info.c pg_del_reserve_info.h \
+ pg_get_auditor_progress.c pg_get_auditor_progress.h \
+ pg_get_balance.c pg_get_balance.h \
+ pg_get_denomination_balance.c pg_get_denomination_balance.h \
+ pg_get_deposit_confirmations.c pg_get_deposit_confirmations.h \
+ pg_get_purse_info.c pg_get_purse_info.h \
+ pg_get_reserve_info.c pg_get_reserve_info.h \
+ pg_get_wire_fee_summary.c pg_get_wire_fee_summary.h \
+ pg_insert_auditor_progress.c pg_insert_auditor_progress.h \
+ pg_insert_balance.c pg_insert_balance.h \
+ pg_insert_denomination_balance.c pg_insert_denomination_balance.h \
+ pg_insert_deposit_confirmation.c pg_insert_deposit_confirmation.h \
+ pg_insert_exchange_signkey.c pg_insert_exchange_signkey.h \
+ pg_insert_historic_denom_revenue.c pg_insert_historic_denom_revenue.h \
+ pg_insert_historic_reserve_revenue.c pg_insert_historic_reserve_revenue.h \
+ pg_insert_pending_deposit.c pg_insert_pending_deposit.h \
+ pg_insert_purse_info.c pg_insert_purse_info.h \
+ pg_insert_reserve_info.c pg_insert_reserve_info.h \
+ pg_select_historic_denom_revenue.c pg_select_historic_denom_revenue.h \
+ pg_select_historic_reserve_revenue.c pg_select_historic_reserve_revenue.h \
+ pg_select_pending_deposits.c pg_select_pending_deposits.h \
+ pg_select_purse_expired.c pg_select_purse_expired.h \
+ pg_update_auditor_progress.c pg_update_auditor_progress.h \
+ pg_update_balance.c pg_update_balance.h \
+ pg_update_denomination_balance.c pg_update_denomination_balance.h \
+ pg_update_purse_info.c pg_update_purse_info.h \
+ pg_update_reserve_info.c pg_update_reserve_info.h \
+ pg_update_wire_fee_summary.c pg_update_wire_fee_summary.h
libtaler_plugin_auditordb_postgres_la_LDFLAGS = \
- $(TALER_PLUGIN_LDFLAGS) \
+ $(TALER_PLUGIN_LDFLAGS)
+libtaler_plugin_auditordb_postgres_la_LIBADD = \
+ $(LTLIBINTL) \
$(top_builddir)/src/pq/libtalerpq.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lpq \
-lgnunetpq \
-lgnunetutil \
- -lpthread \
+ -lpq \
$(XLIB)
lib_LTLIBRARIES = \
@@ -124,11 +120,22 @@ libtalerauditordb_la_LDFLAGS = \
check_PROGRAMS = \
- test-auditordb-postgres
+ test_auditordb_checkpoints-postgres \
+ test_auditordb-postgres
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = \
- test-auditordb-postgres
+ test_auditordb_checkpoints-postgres \
+ test_auditordb-postgres
+
+test_auditordb_checkpoints_postgres_SOURCES = \
+ test_auditordb_checkpoints.c
+test_auditordb_checkpoints_postgres_LDADD = \
+ libtalerauditordb.la \
+ $(top_srcdir)/src/pq/libtalerpq.la \
+ $(top_srcdir)/src/util/libtalerutil.la \
+ -lgnunetutil \
+ $(XLIB)
test_auditordb_postgres_SOURCES = \
test_auditordb.c
diff --git a/src/auditordb/auditor-0001.sql b/src/auditordb/auditor-0001.sql
index 01214d53e..0b7823cec 100644
--- a/src/auditordb/auditor-0001.sql
+++ b/src/auditordb/auditor-0001.sql
@@ -1,6 +1,6 @@
--
-- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
+-- Copyright (C) 2014--2024 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
@@ -14,330 +14,283 @@
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
--- Everything in one big transaction
BEGIN;
--- Check patch versioning is in place.
SELECT _v.register_patch('auditor-0001', NULL, NULL);
-
CREATE SCHEMA auditor;
COMMENT ON SCHEMA auditor IS 'taler-auditor data';
SET search_path TO auditor;
-
-CREATE TABLE IF NOT EXISTS auditor_exchanges
- (master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)
- ,exchange_url VARCHAR NOT NULL
- );
-COMMENT ON TABLE auditor_exchanges
- IS 'list of the exchanges we are auditing';
-
-
-CREATE TABLE IF NOT EXISTS auditor_exchange_signkeys
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,ep_start INT8 NOT NULL
- ,ep_expire INT8 NOT NULL
- ,ep_end INT8 NOT NULL
- ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- );
-COMMENT ON TABLE auditor_exchange_signkeys
- IS 'list of the online signing keys of exchanges we are auditing';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_reserve
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_recoup_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_open_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_decision_serial_id INT8 NOT NULL DEFAULT 0
- ,last_account_merges_serial_id INT8 NOT NULL DEFAULT 0
- ,last_history_requests_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_reserve
- IS 'information as to which transactions the reserve auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_purse
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_purse_request_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_decision_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_merges_serial_id INT8 NOT NULL DEFAULT 0
- ,last_account_merges_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_deposits_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_purse
- IS 'information as to which purses the purse auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_aggregation
- (master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_wire_out_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_aggregation
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_deposit_confirmation
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_deposit_confirmation_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_deposit_confirmation
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_coin
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_withdraw_serial_id INT8 NOT NULL DEFAULT 0
- ,last_deposit_serial_id INT8 NOT NULL DEFAULT 0
- ,last_melt_serial_id INT8 NOT NULL DEFAULT 0
- ,last_refund_serial_id INT8 NOT NULL DEFAULT 0
- ,last_recoup_serial_id INT8 NOT NULL DEFAULT 0
- ,last_recoup_refresh_serial_id INT8 NOT NULL DEFAULT 0
- ,last_open_deposits_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_deposits_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_decision_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
+---------------------------------------------------------------------------
+-- General procedures for DB setup
+---------------------------------------------------------------------------
+
+CREATE TABLE auditor_tables
+ (table_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY
+ ,name TEXT NOT NULL
+ ,version TEXT NOT NULL
+ ,action TEXT NOT NULL
+ ,partitioned BOOL NOT NULL
+ ,by_range BOOL NOT NULL
+ ,finished BOOL NOT NULL DEFAULT(FALSE));
+COMMENT ON TABLE auditor_tables
+ IS 'Tables of the auditor and their status';
+COMMENT ON COLUMN auditor_tables.name
+ IS 'Base name of the table (without partition/shard)';
+COMMENT ON COLUMN auditor_tables.version
+ IS 'Version of the DB in which the given action happened';
+COMMENT ON COLUMN auditor_tables.action
+ IS 'Action to take on the table (e.g. create, constrain, or foreign). Create is done for the master table and each partition; constrain is only for partitions or for master if there are no partitions; master only on master (takes no argument); foreign only on master if there are no partitions.';
+COMMENT ON COLUMN auditor_tables.partitioned
+ IS 'TRUE if the table is partitioned';
+COMMENT ON COLUMN auditor_tables.by_range
+ IS 'TRUE if the table is partitioned by range';
+COMMENT ON COLUMN auditor_tables.finished
+ IS 'TRUE if the respective migration has been run';
+
+
+CREATE FUNCTION create_partitioned_table(
+ IN table_definition TEXT -- SQL template for table creation
+ ,IN table_name TEXT -- base name of the table
+ ,IN main_table_partition_str TEXT -- declaration for how to partition the table
+ ,IN partition_suffix TEXT DEFAULT NULL -- NULL: no partitioning, 0: yes partitioning, no sharding, >0: sharding
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF (partition_suffix IS NULL)
+ THEN
+ -- no partitioning, disable option
+ main_table_partition_str = '';
+ ELSE
+ IF (partition_suffix::int > 0)
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ END IF;
+ EXECUTE FORMAT(
+ table_definition,
+ table_name,
+ main_table_partition_str
);
-COMMENT ON TABLE auditor_progress_coin
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS wire_auditor_account_progress
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,account_name TEXT NOT NULL
- ,last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0
- ,last_wire_wire_out_serial_id INT8 NOT NULL DEFAULT 0
- ,wire_in_off INT8 NOT NULL
- ,wire_out_off INT8 NOT NULL
- ,PRIMARY KEY (master_pub,account_name)
+END $$;
+
+COMMENT ON FUNCTION create_partitioned_table
+ IS 'Generic function to create a table that is partitioned or sharded.';
+
+
+CREATE FUNCTION comment_partitioned_table(
+ IN table_comment TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON TABLE %s IS %s'
+ ,table_name
+ ,quote_literal(table_comment)
);
-COMMENT ON TABLE wire_auditor_account_progress
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS wire_auditor_progress
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_timestamp INT8 NOT NULL
- ,last_reserve_close_uuid INT8 NOT NULL
- ,PRIMARY KEY (master_pub)
- );
-
-
-CREATE TABLE IF NOT EXISTS auditor_reserves
- (reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)
- ,master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,reserve_balance_val INT8 NOT NULL
- ,reserve_balance_frac INT4 NOT NULL
- ,reserve_loss_val INT8 NOT NULL
- ,reserve_loss_frac INT4 NOT NULL
- ,withdraw_fee_balance_val INT8 NOT NULL
- ,withdraw_fee_balance_frac INT4 NOT NULL
- ,close_fee_balance_val INT8 NOT NULL
- ,close_fee_balance_frac INT4 NOT NULL
- ,purse_fee_balance_val INT8 NOT NULL
- ,purse_fee_balance_frac INT4 NOT NULL
- ,open_fee_balance_val INT8 NOT NULL
- ,open_fee_balance_frac INT4 NOT NULL
- ,history_fee_balance_val INT8 NOT NULL
- ,history_fee_balance_frac INT4 NOT NULL
- ,expiration_date INT8 NOT NULL
- ,auditor_reserves_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,origin_account TEXT
- );
-COMMENT ON TABLE auditor_reserves
- IS 'all of the customer reserves and their respective balances that the auditor is aware of';
-
-CREATE INDEX IF NOT EXISTS auditor_reserves_by_reserve_pub
- ON auditor_reserves
- (reserve_pub);
-
-
-CREATE TABLE IF NOT EXISTS auditor_purses
- (purse_pub BYTEA NOT NULL CHECK(LENGTH(purse_pub)=32)
- ,master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,balance_val INT8 NOT NULL DEFAULT(0)
- ,balance_frac INT4 NOT NULL DEFAULT(0)
- ,target_val INT8 NOT NULL
- ,target_frac INT4 NOT NULL
- ,expiration_date INT8 NOT NULL
- ,auditor_purses_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- );
-COMMENT ON TABLE auditor_purses
- IS 'all of the purses and their respective balances that the auditor is aware of';
-
-CREATE INDEX IF NOT EXISTS auditor_purses_by_purse_pub
- ON auditor_purses
- (purse_pub);
-
-
-CREATE TABLE IF NOT EXISTS auditor_purse_summary
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,balance_val INT8 NOT NULL
- ,balance_frac INT4 NOT NULL
- ,open_purses INT8 NOT NULL
- );
-COMMENT ON TABLE auditor_purse_summary
- IS 'sum of the balances in open purses';
-
-CREATE TABLE IF NOT EXISTS auditor_reserve_balance
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,reserve_balance_val INT8 NOT NULL
- ,reserve_balance_frac INT4 NOT NULL
- ,reserve_loss_val INT8 NOT NULL
- ,reserve_loss_frac INT4 NOT NULL
- ,withdraw_fee_balance_val INT8 NOT NULL
- ,withdraw_fee_balance_frac INT4 NOT NULL
- ,close_fee_balance_val INT8 NOT NULL
- ,close_fee_balance_frac INT4 NOT NULL
- ,purse_fee_balance_val INT8 NOT NULL
- ,purse_fee_balance_frac INT4 NOT NULL
- ,open_fee_balance_val INT8 NOT NULL
- ,open_fee_balance_frac INT4 NOT NULL
- ,history_fee_balance_val INT8 NOT NULL
- ,history_fee_balance_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_reserve_balance
- IS 'sum of the balances of all customer reserves (by exchange master public key)';
-
-
-CREATE TABLE IF NOT EXISTS auditor_wire_fee_balance
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,wire_fee_balance_val INT8 NOT NULL
- ,wire_fee_balance_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_wire_fee_balance
- IS 'sum of the balances of all wire fees (by exchange master public key)';
-
-
-CREATE TABLE IF NOT EXISTS auditor_denomination_pending
- (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
- ,denom_balance_val INT8 NOT NULL
- ,denom_balance_frac INT4 NOT NULL
- ,denom_loss_val INT8 NOT NULL
- ,denom_loss_frac INT4 NOT NULL
- ,num_issued INT8 NOT NULL
- ,denom_risk_val INT8 NOT NULL
- ,denom_risk_frac INT4 NOT NULL
- ,recoup_loss_val INT8 NOT NULL
- ,recoup_loss_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_denomination_pending
- IS 'outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the maximum value at risk).';
-COMMENT ON COLUMN auditor_denomination_pending.num_issued
- IS 'counts the number of coins issued (withdraw, refresh) of this denomination';
-COMMENT ON COLUMN auditor_denomination_pending.denom_risk_val
- IS 'amount that could theoretically be lost in the future due to recoup operations';
-COMMENT ON COLUMN auditor_denomination_pending.denom_loss_val
- IS 'amount that was lost due to failures by the exchange';
-COMMENT ON COLUMN auditor_denomination_pending.recoup_loss_val
- IS 'amount actually lost due to recoup operations after a revocation';
-
-
-CREATE TABLE IF NOT EXISTS auditor_balance_summary
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,denom_balance_val INT8 NOT NULL
- ,denom_balance_frac INT4 NOT NULL
- ,deposit_fee_balance_val INT8 NOT NULL
- ,deposit_fee_balance_frac INT4 NOT NULL
- ,melt_fee_balance_val INT8 NOT NULL
- ,melt_fee_balance_frac INT4 NOT NULL
- ,refund_fee_balance_val INT8 NOT NULL
- ,refund_fee_balance_frac INT4 NOT NULL
- ,purse_fee_balance_val INT8 NOT NULL
- ,purse_fee_balance_frac INT4 NOT NULL
- ,open_deposit_fee_balance_val INT8 NOT NULL
- ,open_deposit_fee_balance_frac INT4 NOT NULL
- ,risk_val INT8 NOT NULL
- ,risk_frac INT4 NOT NULL
- ,loss_val INT8 NOT NULL
- ,loss_frac INT4 NOT NULL
- ,irregular_loss_val INT8 NOT NULL
- ,irregular_loss_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_balance_summary
- IS 'the sum of the outstanding coins from auditor_denomination_pending (denom_pubs must belong to the respectives exchange master public key); it represents the auditor_balance_summary of the exchange at this point (modulo unexpected historic_loss-style events where denomination keys are compromised)';
-COMMENT ON COLUMN auditor_balance_summary.denom_balance_frac
- IS 'total amount we should have in escrow for all denominations';
-
-
-CREATE TABLE IF NOT EXISTS auditor_historic_denomination_revenue
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
- ,revenue_timestamp INT8 NOT NULL
- ,revenue_balance_val INT8 NOT NULL
- ,revenue_balance_frac INT4 NOT NULL
- ,loss_balance_val INT8 NOT NULL
- ,loss_balance_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_historic_denomination_revenue
- IS 'Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the denom_pub here is not a foreign key, we just keep it as a reference point.';
-COMMENT ON COLUMN auditor_historic_denomination_revenue.revenue_balance_val
- IS 'the sum of all of the profits we made on the coin except for withdraw fees (which are in historic_reserve_revenue); so this includes the deposit, melt and refund fees';
-
-
-CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,start_date INT8 NOT NULL
- ,end_date INT8 NOT NULL
- ,reserve_profits_val INT8 NOT NULL
- ,reserve_profits_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_historic_reserve_summary
- IS 'historic profits from reserves; we eventually GC auditor_historic_reserve_revenue, and then store the totals in here (by time intervals).';
-
-CREATE INDEX IF NOT EXISTS auditor_historic_reserve_summary_by_master_pub_start_date
- ON auditor_historic_reserve_summary
- (master_pub
- ,start_date);
-
-
-CREATE TABLE IF NOT EXISTS deposit_confirmations
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
- ,h_policy BYTEA NOT NULL CHECK (LENGTH(h_policy)=64)
- ,h_wire BYTEA NOT NULL CHECK (LENGTH(h_wire)=64)
- ,exchange_timestamp INT8 NOT NULL
- ,refund_deadline INT8 NOT NULL
- ,wire_deadline INT8 NOT NULL
- ,amount_without_fee_val INT8 NOT NULL
- ,amount_without_fee_frac INT4 NOT NULL
- ,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)
- ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
- ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
- ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,PRIMARY KEY (h_contract_terms,h_wire,coin_pub,merchant_pub,exchange_sig,exchange_pub,master_sig)
- );
-COMMENT ON TABLE deposit_confirmations
- IS 'deposit confirmation sent to us by merchants; we must check that the exchange reported these properly.';
-
-
-CREATE TABLE IF NOT EXISTS auditor_predicted_result
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,balance_val INT8 NOT NULL
- ,balance_frac INT4 NOT NULL
- ,drained_val INT8 NOT NULL
- ,drained_frac INT4 NOT NULL
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_table
+ IS 'Generic function to create a comment on table that is partitioned.';
+
+
+CREATE FUNCTION comment_partitioned_column(
+ IN table_comment TEXT
+ ,IN column_name TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON COLUMN %s.%s IS %s'
+ ,table_name
+ ,column_name
+ ,quote_literal(table_comment)
);
-COMMENT ON TABLE auditor_predicted_result
- IS 'Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance and the drained profits. This is the final amount that the exchange should have in its bank account right now (and the total amount drained as profits to non-escrow accounts).';
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_column
+ IS 'Generic function to create a comment on column of a table that is partitioned.';
+
+
+---------------------------------------------------------------------------
+-- Main DB setup loop
+---------------------------------------------------------------------------
+
+CREATE FUNCTION do_create_tables(
+ num_partitions INTEGER
+-- NULL: no partitions, add foreign constraints
+-- 0: no partitions, no foreign constraints
+-- 1: only 1 default partition
+-- > 1: normal partitions
+)
+ RETURNS VOID
+ LANGUAGE plpgsql
+AS $$
+DECLARE
+ tc CURSOR FOR
+ SELECT table_serial_id
+ ,name
+ ,action
+ ,partitioned
+ ,by_range
+ FROM auditor.auditor_tables
+ WHERE NOT finished
+ ORDER BY table_serial_id ASC;
+BEGIN
+ FOR rec IN tc
+ LOOP
+ CASE rec.action
+ -- "create" actions apply to master and partitions
+ WHEN 'create'
+ THEN
+ IF (rec.partitioned AND
+ (num_partitions IS NOT NULL))
+ THEN
+ -- Create master table with partitioning.
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal('0')
+ );
+ IF (rec.by_range OR
+ (num_partitions = 0))
+ THEN
+ -- Create default partition.
+ IF (rec.by_range)
+ THEN
+ -- Range partition
+ EXECUTE FORMAT(
+ 'CREATE TABLE auditor.%s_default'
+ ' PARTITION OF %s'
+ ' DEFAULT'
+ ,rec.name
+ ,rec.name
+ );
+ ELSE
+ -- Hash partition
+ EXECUTE FORMAT(
+ 'CREATE TABLE auditor.%s_default'
+ ' PARTITION OF %s'
+ ' FOR VALUES WITH (MODULUS 1, REMAINDER 0)'
+ ,rec.name
+ ,rec.name
+ );
+ END IF;
+ ELSE
+ FOR i IN 1..num_partitions LOOP
+ -- Create num_partitions
+ EXECUTE FORMAT(
+ 'CREATE TABLE auditor.%I'
+ ' PARTITION OF %I'
+ ' FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
+ ,rec.name || '_' || i
+ ,rec.name
+ ,num_partitions
+ ,i-1
+ );
+ END LOOP;
+ END IF;
+ ELSE
+ -- Only create master table. No partitions.
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
+ END IF;
+ -- Constrain action apply to master OR each partition
+ WHEN 'constrain'
+ THEN
+ ASSERT rec.partitioned, 'constrain action only applies to partitioned tables';
+ IF (num_partitions IS NULL)
+ THEN
+ -- Constrain master table
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (NULL)'::text
+ ,rec.action
+ ,rec.name
+ );
+ ELSE
+ IF ( (num_partitions = 0) OR
+ (rec.by_range) )
+ THEN
+ -- Constrain default table
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal('default')
+ );
+ ELSE
+ -- Constrain each partition
+ FOR i IN 1..num_partitions LOOP
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal(i)
+ );
+ END LOOP;
+ END IF;
+ END IF;
+ -- Foreign actions only apply if partitioning is off
+ WHEN 'foreign'
+ THEN
+ IF (num_partitions IS NULL)
+ THEN
+ -- Add foreign constraints
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,NULL
+ );
+ END IF;
+ WHEN 'master'
+ THEN
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
+ ELSE
+ ASSERT FALSE, 'unsupported action type: ' || rec.action;
+ END CASE; -- END CASE (rec.action)
+ -- Mark as finished
+ UPDATE auditor.auditor_tables
+ SET finished=TRUE
+ WHERE table_serial_id=rec.table_serial_id;
+ END LOOP; -- create/alter/drop actions
+END $$;
+
+COMMENT ON FUNCTION do_create_tables
+ IS 'Creates all tables for the given number of partitions that need creating. Does NOT support sharding.';
--- Finally, commit everything
COMMIT;
diff --git a/src/auditordb/auditor-0002.sql.in b/src/auditordb/auditor-0002.sql.in
new file mode 100644
index 000000000..ad459b472
--- /dev/null
+++ b/src/auditordb/auditor-0002.sql.in
@@ -0,0 +1,46 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('auditor-0002', NULL, NULL);
+
+SET search_path TO auditor;
+
+DO $$ BEGIN
+ CREATE TYPE taler_amount
+ AS
+ (val INT8
+ ,frac INT4
+ );
+ COMMENT ON TYPE taler_amount
+ IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
+EXCEPTION
+ WHEN duplicate_object THEN null;
+END $$;
+
+#include "0002-auditor_amount_arithmetic_inconsistency.sql"
+#include "0002-auditor_balances.sql"
+#include "0002-auditor_denomination_pending.sql"
+#include "0002-auditor_exchange_signkeys.sql"
+#include "0002-auditor_historic_denomination_revenue.sql"
+#include "0002-auditor_historic_reserve_summary.sql"
+#include "0002-auditor_progress.sql"
+#include "0002-auditor_purses.sql"
+#include "0002-auditor_reserves.sql"
+#include "0002-auditor_deposit_confirmations.sql"
+
+COMMIT;
diff --git a/src/auditordb/auditor_do_get_auditor_progress.sql b/src/auditordb/auditor_do_get_auditor_progress.sql
new file mode 100644
index 000000000..9371cf67b
--- /dev/null
+++ b/src/auditordb/auditor_do_get_auditor_progress.sql
@@ -0,0 +1,38 @@
+--
+-- 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/>
+--
+-- @author Christian Grothoff
+
+CREATE OR REPLACE FUNCTION auditor_do_get_auditor_progress(
+ IN in_keys TEXT[])
+RETURNS INT8
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_key TEXT;
+ my_off INT8;
+BEGIN
+ FOREACH my_key IN ARRAY in_keys
+ LOOP
+ SELECT progress_offset
+ INTO my_off
+ FROM auditor_progress
+ WHERE progress_key=my_key;
+ RETURN my_off;
+ END LOOP;
+END $$;
+
+COMMENT ON FUNCTION auditor_do_get_auditor_progress(TEXT[])
+ IS 'Finds all progress offsets associated with the array of keys given as the argument and returns them in order';
diff --git a/src/auditordb/auditor_do_get_balance.sql b/src/auditordb/auditor_do_get_balance.sql
new file mode 100644
index 000000000..782a31f89
--- /dev/null
+++ b/src/auditordb/auditor_do_get_balance.sql
@@ -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/>
+--
+-- @author Christian Grothoff
+
+CREATE OR REPLACE FUNCTION auditor_do_get_balance(
+ IN in_keys TEXT[])
+RETURNS taler_amount
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_key TEXT;
+ my_rec RECORD;
+ my_val taler_amount;
+BEGIN
+ FOREACH my_key IN ARRAY in_keys
+ LOOP
+ SELECT (ab.balance_value).val
+ ,(ab.balance_value).frac
+ INTO my_rec
+ FROM auditor_balances ab
+ WHERE balance_key=my_key;
+ IF FOUND
+ THEN
+ my_val.val = my_rec.val;
+ my_val.frac = my_rec.frac;
+ RETURN my_val;
+ ELSE
+ RETURN NULL;
+ END IF;
+ END LOOP;
+END $$;
+
+COMMENT ON FUNCTION auditor_do_get_balance(TEXT[])
+ IS 'Finds all balances associated with the array of keys given as the argument and returns them in order';
diff --git a/src/auditordb/drop.sql b/src/auditordb/drop.sql
index 37a50ee68..4bae66103 100644
--- a/src/auditordb/drop.sql
+++ b/src/auditordb/drop.sql
@@ -17,9 +17,14 @@
-- Everything in one big transaction
BEGIN;
+WITH xpatches AS (
+ SELECT patch_name
+ FROM _v.patches
+ WHERE starts_with(patch_name,'auditor-')
+)
+ SELECT _v.unregister_patch(xpatches.patch_name)
+ FROM xpatches;
--- Drop versioning (auditor-0001.sql)
-SELECT _v.unregister_patch('auditor-0001');
DROP SCHEMA auditor CASCADE;
-- And we're out of here...
diff --git a/src/auditordb/pg_insert_exchange.c b/src/auditordb/pg_del_denomination_balance.c
index bc84ad77c..154dc50bb 100644
--- a/src/auditordb/pg_insert_exchange.c
+++ b/src/auditordb/pg_del_denomination_balance.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,36 +14,34 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_insert_exchange.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @file auditordb/pg_del_denomination_balance.c
+ * @brief Implementation of the del_denomination_balance function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
-#include "pg_insert_exchange.h"
+#include "pg_del_denomination_balance.h"
#include "pg_helper.h"
enum GNUNET_DB_QueryStatus
-TAH_PG_insert_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *exchange_url)
+TAH_PG_del_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (exchange_url),
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
- "auditor_insert_exchange",
- "INSERT INTO auditor_exchanges "
- "(master_pub"
- ",exchange_url"
- ") VALUES ($1,$2);");
+ "auditor_del_denomination_balance",
+ "DELETE"
+ " FROM auditor_denomination_pending"
+ " WHERE denom_pub_hash=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_insert_exchange",
+ "auditor_del_denomination_balance",
params);
}
diff --git a/src/auditordb/pg_get_wire_auditor_progress.h b/src/auditordb/pg_del_denomination_balance.h
index dec554acc..56e9232b0 100644
--- a/src/auditordb/pg_get_wire_auditor_progress.h
+++ b/src/auditordb/pg_del_denomination_balance.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,31 +14,27 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_get_wire_auditor_progress.h
- * @brief implementation of the get_wire_auditor_progress function
+ * @file auditordb/pg_del_denomination_balance.h
+ * @brief implementation of the del_denomination_balance function for Postgres
* @author Christian Grothoff
*/
-#ifndef PG_GET_WIRE_AUDITOR_PROGRESS_H
-#define PG_GET_WIRE_AUDITOR_PROGRESS_H
+#ifndef PG_DEL_DENOMINATION_BALANCE_H
+#define PG_DEL_DENOMINATION_BALANCE_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_auditordb_plugin.h"
-
/**
- * Get information about the progress of the auditor.
+ * Delete information about a denomination key's balances.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] pp set to where the auditor is in processing
+ * @param denom_pub_hash hash of the denomination public key
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_get_wire_auditor_progress (
+TAH_PG_del_denomination_balance (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_WireProgressPoint *pp);
-
+ const struct TALER_DenominationHashP *denom_pub_hash);
#endif
diff --git a/src/auditordb/pg_del_reserve_info.c b/src/auditordb/pg_del_reserve_info.c
index 81db98df9..619bd0afa 100644
--- a/src/auditordb/pg_del_reserve_info.c
+++ b/src/auditordb/pg_del_reserve_info.c
@@ -28,23 +28,20 @@
enum GNUNET_DB_QueryStatus
TAH_PG_del_reserve_info (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub)
+ const struct TALER_ReservePublicKeyP *reserve_pub)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
- "auditor_reserves_delete",
+ "auditor_del_reserve_info",
"DELETE"
" FROM auditor_reserves"
- " WHERE reserve_pub=$1"
- " AND master_pub=$2;");
+ " WHERE reserve_pub=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserves_delete",
+ "auditor_del_reserve_info",
params);
}
diff --git a/src/auditordb/pg_del_reserve_info.h b/src/auditordb/pg_del_reserve_info.h
index 1bed879d9..88a10bcfd 100644
--- a/src/auditordb/pg_del_reserve_info.h
+++ b/src/auditordb/pg_del_reserve_info.h
@@ -31,13 +31,11 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
TAH_PG_del_reserve_info (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub);
+ const struct TALER_ReservePublicKeyP *reserve_pub);
#endif
diff --git a/src/auditordb/pg_insert_wire_fee_summary.c b/src/auditordb/pg_delete_deposit_confirmations.c
index 2de51a7c8..6cb76d4e9 100644
--- a/src/auditordb/pg_insert_wire_fee_summary.c
+++ b/src/auditordb/pg_delete_deposit_confirmations.c
@@ -1,52 +1,47 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file pg_insert_wire_fee_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_wire_fee_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_wire_fee_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *wire_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (wire_fee_balance),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_wire_fee_balance_insert",
- "INSERT INTO auditor_wire_fee_balance"
- "(master_pub"
- ",wire_fee_balance_val"
- ",wire_fee_balance_frac"
- ") VALUES ($1,$2,$3)");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_wire_fee_balance_insert",
- params);
-}
+/*
+ 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 auditordb/pg_delete_deposit_confirmations.c
+ * @brief Implementation of the delete_deposit_confirmations function for Postgres
+ * @author Nicola Eigel
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_deposit_confirmations.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_deposit_confirmation (
+ void *cls,
+ uint64_t row_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&row_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_delete_deposit_confirmation",
+ "DELETE"
+ " FROM deposit_confirmations"
+ " WHERE deposit_confirmation_serial_id=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_delete_deposit_confirmation",
+ params);
+}
diff --git a/src/auditordb/pg_list_exchanges.h b/src/auditordb/pg_delete_deposit_confirmations.h
index 4396603ee..5f7700ba1 100644
--- a/src/auditordb/pg_list_exchanges.h
+++ b/src/auditordb/pg_delete_deposit_confirmations.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,30 +14,28 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_list_exchanges.h
- * @brief implementation of the list_exchanges function
- * @author Christian Grothoff
+ * @file auditordb/pg_delete_deposit_confirmations.h
+ * @brief implementation of the delete_deposit_confirmation function for Postgres
+ * @author Nicola Eigel
*/
-#ifndef PG_LIST_EXCHANGES_H
-#define PG_LIST_EXCHANGES_H
+#ifndef PG_DELETE_DEPOSIT_CONFIRMATIONS_H
+#define PG_DELETE_DEPOSIT_CONFIRMATIONS_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_auditordb_plugin.h"
-
/**
- * Obtain information about exchanges this auditor is auditing.
+ * Delete a row from the deposit confirmations table.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call with the results
- * @param cb_cls closure for @a cb
- * @return query result status
+ * @param row_id row to delete
+ * @return query transaction status
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_list_exchanges (void *cls,
- TALER_AUDITORDB_ExchangeCallback cb,
- void *cb_cls);
+TAH_PG_delete_deposit_confirmation (
+ void *cls,
+ uint64_t row_id);
#endif
diff --git a/src/auditordb/pg_delete_exchange.h b/src/auditordb/pg_delete_exchange.h
deleted file mode 100644
index 4b639a62b..000000000
--- a/src/auditordb/pg_delete_exchange.h
+++ /dev/null
@@ -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 pg_delete_exchange.h
- * @brief implementation of the delete_exchange function
- * @author Christian Grothoff
- */
-#ifndef PG_DELETE_EXCHANGE_H
-#define PG_DELETE_EXCHANGE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Delete an exchange from the list of exchanges this auditor is auditing.
- * Warning: this will cascade and delete all knowledge of this auditor related
- * to this exchange!
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_delete_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub);
-
-
-#endif
diff --git a/src/auditordb/pg_delete_exchange.c b/src/auditordb/pg_delete_pending_deposit.c
index 9415335c2..29814e84b 100644
--- a/src/auditordb/pg_delete_exchange.c
+++ b/src/auditordb/pg_delete_pending_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,34 +14,35 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_delete_exchange.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @file auditordb/pg_delete_pending_deposit.c
+ * @brief Implementation of the delete_pending_deposit function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
-#include "pg_delete_exchange.h"
+#include "pg_delete_pending_deposit.h"
#include "pg_helper.h"
enum GNUNET_DB_QueryStatus
-TAH_PG_delete_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub)
+TAH_PG_delete_pending_deposit (
+ void *cls,
+ uint64_t batch_deposit_serial_id)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
+ GNUNET_PQ_query_param_uint64 (&batch_deposit_serial_id),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
- "auditor_delete_exchange",
+ "auditor_delete_pending_deposit",
"DELETE"
- " FROM auditor_exchanges"
- " WHERE master_pub=$1;");
+ " FROM auditor_pending_deposits"
+ " WHERE batch_deposit_serial_id=$1;");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_delete_exchange",
+ "auditor_delete_pending_deposit",
params);
}
diff --git a/src/auditordb/pg_get_balance_summary.h b/src/auditordb/pg_delete_pending_deposit.h
index 1fc31109f..8e7159eac 100644
--- a/src/auditordb/pg_get_balance_summary.h
+++ b/src/auditordb/pg_delete_pending_deposit.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_get_balance_summary.h
- * @brief implementation of the get_balance_summary function
+ * @file auditordb/pg_delete_pending_deposit.h
+ * @brief implementation of the delete_pending_deposit function for Postgres
* @author Christian Grothoff
*/
-#ifndef PG_GET_BALANCE_SUMMARY_H
-#define PG_GET_BALANCE_SUMMARY_H
+#ifndef PG_DELETE_PENDING_DEPOSIT_H
+#define PG_DELETE_PENDING_DEPOSIT_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -27,17 +27,18 @@
/**
- * Get information about an exchange's denomination balances.
+ * Delete a row from the pending deposit table.
+ * Usually done when the respective wire transfer
+ * was finally detected.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] dfb where to return the denomination balances
+ * @param batch_deposit_serial_id which entry to delete
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_get_balance_summary (
+TAH_PG_delete_pending_deposit (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_GlobalCoinBalance *dfb);
+ uint64_t batch_deposit_serial_id);
+
#endif
diff --git a/src/auditordb/pg_delete_purse_info.c b/src/auditordb/pg_delete_purse_info.c
index cd390d0ca..8fa77ba46 100644
--- a/src/auditordb/pg_delete_purse_info.c
+++ b/src/auditordb/pg_delete_purse_info.c
@@ -29,21 +29,18 @@
enum GNUNET_DB_QueryStatus
TAH_PG_delete_purse_info (
void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub)
+ const struct TALER_PurseContractPublicKeyP *purse_pub)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
"auditor_purses_delete",
"DELETE FROM auditor_purses "
- " WHERE purse_pub=$1"
- " AND master_pub=$2;");
+ " WHERE purse_pub=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_purses_delete",
params);
diff --git a/src/auditordb/pg_delete_purse_info.h b/src/auditordb/pg_delete_purse_info.h
index 88b59fde2..88393f9b8 100644
--- a/src/auditordb/pg_delete_purse_info.h
+++ b/src/auditordb/pg_delete_purse_info.h
@@ -31,14 +31,12 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
TAH_PG_delete_purse_info (
void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub);
+ const struct TALER_PurseContractPublicKeyP *purse_pub);
#endif
diff --git a/src/auditordb/pg_get_auditor_progress.c b/src/auditordb/pg_get_auditor_progress.c
new file mode 100644
index 000000000..3742d2eb6
--- /dev/null
+++ b/src/auditordb/pg_get_auditor_progress.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/>
+ */
+/**
+ * @file pg_get_auditor_progress.c
+ * @brief Implementation of get_auditor_progress function
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_auditor_progress.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #auditor_progress_cb().
+ */
+struct AuditorProgressContext
+{
+
+ /**
+ * Where to store results.
+ */
+ uint64_t **dst;
+
+ /**
+ * Offset in @e dst.
+ */
+ unsigned int off;
+
+ /**
+ * Length of array at @e dst.
+ */
+ unsigned int len;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to true on failure.
+ */
+ bool failure;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_auditor_progress().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AuditorProgressContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+auditor_progress_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AuditorProgressContext *ctx = cls;
+
+ GNUNET_assert (num_results <= ctx->len);
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ bool is_missing = false;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("progress_offset",
+ ctx->dst[i]),
+ &is_missing),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->failure = true;
+ return;
+ }
+ if (is_missing)
+ *ctx->dst[i] = 0;
+ ctx->off++;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_auditor_progress (void *cls,
+ const char *progress_key,
+ uint64_t *progress_offset,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ progress_offset);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ uint64_t *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ uint64_t *dsts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct AuditorProgressContext ctx = {
+ .dst = dsts,
+ .len = cnt,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = progress_key;
+ dsts[0] = progress_offset;
+
+ va_start (ap,
+ progress_offset);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ dsts[off] = va_arg (ap,
+ uint64_t *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "get_auditor_progress",
+ "SELECT"
+ " auditor_do_get_auditor_progress AS progress_offset"
+ " FROM auditor_do_get_auditor_progress "
+ "($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_auditor_progress",
+ params,
+ &auditor_progress_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if (ctx.failure)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ if (qs < 0)
+ return qs;
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_get_auditor_progress_deposit_confirmation.h b/src/auditordb/pg_get_auditor_progress.h
index 3b558d0c6..fee7a4424 100644
--- a/src/auditordb/pg_get_auditor_progress_deposit_confirmation.h
+++ b/src/auditordb/pg_get_auditor_progress.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_get_auditor_progress_deposit_confirmation.h
- * @brief implementation of the get_auditor_progress_deposit_confirmation function
+ * @file pg_get_auditor_progress.h
+ * @brief implementation of the get_auditor_progress function
* @author Christian Grothoff
*/
-#ifndef PG_GET_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H
-#define PG_GET_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H
+#ifndef PG_GET_AUDITOR_PROGRESS_H
+#define PG_GET_AUDITOR_PROGRESS_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -30,14 +30,15 @@
* Get information about the progress of the auditor.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppdc set to where the auditor is in processing
+ * @param progress_key name of the progress indicator
+ * @param[out] progress_offset set to offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to fetch
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc);
+TAH_PG_get_auditor_progress (void *cls,
+ const char *progress_key,
+ uint64_t *progress_offset,
+ ...);
#endif
diff --git a/src/auditordb/pg_get_auditor_progress_aggregation.c b/src/auditordb/pg_get_auditor_progress_aggregation.c
deleted file mode 100644
index a9f89d07a..000000000
--- a/src/auditordb/pg_get_auditor_progress_aggregation.c
+++ /dev/null
@@ -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 pg_get_auditor_progress_aggregation.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_auditor_progress_aggregation.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointAggregation *ppa)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_wire_out_serial_id",
- &ppa->last_wire_out_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_progress_select_aggregation",
- "SELECT"
- " last_wire_out_serial_id"
- " FROM auditor_progress_aggregation"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_aggregation",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_auditor_progress_aggregation.h b/src/auditordb/pg_get_auditor_progress_aggregation.h
deleted file mode 100644
index b20a00adf..000000000
--- a/src/auditordb/pg_get_auditor_progress_aggregation.h
+++ /dev/null
@@ -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 pg_get_auditor_progress_aggregation.h
- * @brief implementation of the get_auditor_progress_aggregation function
- * @author Christian Grothoff
- */
-#ifndef PG_GET_AUDITOR_PROGRESS_AGGREGATION_H
-#define PG_GET_AUDITOR_PROGRESS_AGGREGATION_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppa set to where the auditor is in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointAggregation *ppa);
-
-#endif
diff --git a/src/auditordb/pg_get_auditor_progress_coin.c b/src/auditordb/pg_get_auditor_progress_coin.c
deleted file mode 100644
index a160f1ccc..000000000
--- a/src/auditordb/pg_get_auditor_progress_coin.c
+++ /dev/null
@@ -1,77 +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 pg_get_auditor_progress_coin.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_auditor_progress_coin.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointCoin *ppc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_withdraw_serial_id",
- &ppc->last_withdraw_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_deposit_serial_id",
- &ppc->last_deposit_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_melt_serial_id",
- &ppc->last_melt_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_refund_serial_id",
- &ppc->last_refund_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_recoup_serial_id",
- &ppc->last_recoup_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_recoup_refresh_serial_id",
- &ppc->last_recoup_refresh_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_deposits_serial_id",
- &ppc->last_purse_deposits_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_decision_serial_id",
- &ppc->last_purse_refunds_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_progress_select_coin",
- "SELECT"
- " last_withdraw_serial_id"
- ",last_deposit_serial_id"
- ",last_melt_serial_id"
- ",last_refund_serial_id"
- ",last_recoup_serial_id"
- ",last_recoup_refresh_serial_id"
- ",last_purse_deposits_serial_id"
- ",last_purse_decision_serial_id"
- " FROM auditor_progress_coin"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_coin",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_auditor_progress_coin.h b/src/auditordb/pg_get_auditor_progress_coin.h
deleted file mode 100644
index 46f997b36..000000000
--- a/src/auditordb/pg_get_auditor_progress_coin.h
+++ /dev/null
@@ -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 pg_get_auditor_progress_coin.h
- * @brief implementation of the get_auditor_progress_coin function
- * @author Christian Grothoff
- */
-#ifndef PG_GET_AUDITOR_PROGRESS_COIN_H
-#define PG_GET_AUDITOR_PROGRESS_COIN_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppc set to where the auditor is in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointCoin *ppc);
-
-#endif
diff --git a/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c b/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c
deleted file mode 100644
index f69f4a692..000000000
--- a/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c
+++ /dev/null
@@ -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 pg_get_auditor_progress_deposit_confirmation.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_auditor_progress_deposit_confirmation.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_deposit_confirmation_serial_id",
- &ppdc->last_deposit_confirmation_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_progress_select_deposit_confirmation",
- "SELECT"
- " last_deposit_confirmation_serial_id"
- " FROM auditor_progress_deposit_confirmation"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_deposit_confirmation",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_auditor_progress_purse.c b/src/auditordb/pg_get_auditor_progress_purse.c
deleted file mode 100644
index de8628ce7..000000000
--- a/src/auditordb/pg_get_auditor_progress_purse.c
+++ /dev/null
@@ -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 pg_get_auditor_progress_purse.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_auditor_progress_purse.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_purse (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointPurse *ppp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_purse_request_serial_id",
- &ppp->last_purse_request_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_decision_serial_id",
- &ppp->last_purse_decision_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_merges_serial_id",
- &ppp->last_purse_merge_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_account_merges_serial_id",
- &ppp->last_account_merge_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_deposits_serial_id",
- &ppp->last_purse_deposits_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_progress_select_purse",
- "SELECT"
- " last_purse_request_serial_id"
- ",last_purse_decision_serial_id"
- ",last_purse_merges_serial_id"
- ",last_account_merges_serial_id"
- ",last_purse_deposits_serial_id"
- " FROM auditor_progress_purse"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_purse",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_auditor_progress_reserve.c b/src/auditordb/pg_get_auditor_progress_reserve.c
deleted file mode 100644
index 90923a0f7..000000000
--- a/src/auditordb/pg_get_auditor_progress_reserve.c
+++ /dev/null
@@ -1,77 +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 pg_get_auditor_progress_reserve.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_auditor_progress_reserve.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointReserve *ppr)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_reserve_in_serial_id",
- &ppr->last_reserve_in_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id",
- &ppr->last_reserve_out_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_recoup_serial_id",
- &ppr->last_reserve_recoup_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_open_serial_id",
- &ppr->last_reserve_open_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_close_serial_id",
- &ppr->last_reserve_close_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_decision_serial_id",
- &ppr->last_purse_decisions_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_account_merges_serial_id",
- &ppr->last_account_merges_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_history_requests_serial_id",
- &ppr->last_history_requests_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_progress_select_reserve",
- "SELECT"
- " last_reserve_in_serial_id"
- ",last_reserve_out_serial_id"
- ",last_reserve_recoup_serial_id"
- ",last_reserve_close_serial_id"
- ",last_purse_decision_serial_id"
- ",last_account_merges_serial_id"
- ",last_history_requests_serial_id"
- ",last_reserve_open_serial_id"
- " FROM auditor_progress_reserve"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_reserve",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_balance.c b/src/auditordb/pg_get_balance.c
new file mode 100644
index 000000000..4edc1c89f
--- /dev/null
+++ b/src/auditordb/pg_get_balance.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/>
+ */
+/**
+ * @file auditordb/pg_get_balance.c
+ * @brief Implementation of the get_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_balance.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #balance_cb().
+ */
+struct BalanceContext
+{
+
+ /**
+ * Where to store results.
+ */
+ struct TALER_Amount **dst;
+
+ /**
+ * Offset in @e dst.
+ */
+ unsigned int off;
+
+ /**
+ * Length of array at @e dst.
+ */
+ unsigned int len;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to true on failure.
+ */
+ bool failure;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_balance().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct BalanceContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+balance_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct BalanceContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ GNUNET_assert (num_results <= ctx->len);
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ bool is_missing = false;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_amount ("balance",
+ pg->currency,
+ ctx->dst[i]),
+ &is_missing),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->failure = true;
+ return;
+ }
+ if (is_missing)
+ memset (ctx->dst[i],
+ 0,
+ sizeof (struct TALER_Amount));
+ ctx->off++;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_balance (void *cls,
+ const char *balance_key,
+ struct TALER_Amount *balance_value,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ balance_value);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ struct TALER_Amount *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ struct TALER_Amount *dsts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct BalanceContext ctx = {
+ .dst = dsts,
+ .len = cnt,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = balance_key;
+ dsts[0] = balance_value;
+
+ va_start (ap,
+ balance_value);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ dsts[off] = va_arg (ap,
+ struct TALER_Amount *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "get_balance",
+ "SELECT "
+ " auditor_do_get_balance AS balance"
+ " FROM auditor_do_get_balance "
+ "($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_balance",
+ params,
+ &balance_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if (ctx.failure)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ if (qs < 0)
+ return qs;
+ GNUNET_assert (qs == ctx.off);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_get_purse_summary.h b/src/auditordb/pg_get_balance.h
index e3c5d92f7..59d2af0ae 100644
--- a/src/auditordb/pg_get_purse_summary.h
+++ b/src/auditordb/pg_get_balance.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file auditordb/pg_get_purse_summary.h
- * @brief implementation of the get_purse_summary function for Postgres
+ * @file auditordb/pg_get_balance.h
+ * @brief implementation of the get_balance function for Postgres
* @author Christian Grothoff
*/
-#ifndef PG_GET_PURSE_SUMMARY_H
-#define PG_GET_PURSE_SUMMARY_H
+#ifndef PG_GET_BALANCE_H
+#define PG_GET_BALANCE_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -27,17 +27,18 @@
/**
- * Get summary information about all purses.
+ * Get summary information about balance tracked by the auditor.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] sum purse balances summary to initialize
+ * @param balance_key key of the balance to store
+ * @param[out] balance_value set to amount stored under @a balance_key
+ * @param ... NULL terminated list of additional key-value pairs to fetch
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_get_purse_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_PurseBalance *sum);
-
+TAH_PG_get_balance (void *cls,
+ const char *balance_key,
+ struct TALER_Amount *balance_value,
+ ...);
#endif
diff --git a/src/auditordb/pg_get_balance_summary.c b/src/auditordb/pg_get_balance_summary.c
deleted file mode 100644
index a8ba733bb..000000000
--- a/src/auditordb/pg_get_balance_summary.c
+++ /dev/null
@@ -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 pg_get_balance_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_balance_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_GlobalCoinBalance *dfb)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance",
- &dfb->total_escrowed),
- TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee_balance",
- &dfb->deposit_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("melt_fee_balance",
- &dfb->melt_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("refund_fee_balance",
- &dfb->refund_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee_balance",
- &dfb->purse_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("open_deposit_fee_balance",
- &dfb->open_deposit_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("risk",
- &dfb->risk),
- TALER_PQ_RESULT_SPEC_AMOUNT ("loss",
- &dfb->loss),
- TALER_PQ_RESULT_SPEC_AMOUNT ("irregular_loss",
- &dfb->irregular_loss),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_balance_summary_select",
- "SELECT"
- " denom_balance_val"
- ",denom_balance_frac"
- ",deposit_fee_balance_val"
- ",deposit_fee_balance_frac"
- ",melt_fee_balance_val"
- ",melt_fee_balance_frac"
- ",refund_fee_balance_val"
- ",refund_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",open_deposit_fee_balance_val"
- ",open_deposit_fee_balance_frac"
- ",risk_val"
- ",risk_frac"
- ",loss_val"
- ",loss_frac"
- ",irregular_loss_val"
- ",irregular_loss_frac"
- " FROM auditor_balance_summary"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_balance_summary_select",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_denomination_balance.c b/src/auditordb/pg_get_denomination_balance.c
index 10d5a4be7..40af766cd 100644
--- a/src/auditordb/pg_get_denomination_balance.c
+++ b/src/auditordb/pg_get_denomination_balance.c
@@ -54,15 +54,11 @@ TAH_PG_get_denomination_balance (
PREPARE (pg,
"auditor_denomination_pending_select",
"SELECT"
- " denom_balance_val"
- ",denom_balance_frac"
- ",denom_loss_val"
- ",denom_loss_frac"
+ " denom_balance"
+ ",denom_loss"
",num_issued"
- ",denom_risk_val"
- ",denom_risk_frac"
- ",recoup_loss_val"
- ",recoup_loss_frac"
+ ",denom_risk"
+ ",recoup_loss"
" FROM auditor_denomination_pending"
" WHERE denom_pub_hash=$1");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
diff --git a/src/auditordb/pg_get_deposit_confirmations.c b/src/auditordb/pg_get_deposit_confirmations.c
index 3f0bd1e2f..b8055a296 100644
--- a/src/auditordb/pg_get_deposit_confirmations.c
+++ b/src/auditordb/pg_get_deposit_confirmations.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -33,11 +33,6 @@ struct DepositConfirmationContext
{
/**
- * Master public key that is being used.
- */
- const struct TALER_MasterPublicKeyP *master_pub;
-
- /**
* Function to call for each deposit confirmation.
*/
TALER_AUDITORDB_DepositConfirmationCallback cb;
@@ -79,9 +74,11 @@ deposit_confirmation_cb (void *cls,
for (unsigned int i = 0; i < num_results; i++)
{
uint64_t serial_id;
- struct TALER_AUDITORDB_DepositConfirmation dc = {
- .master_public_key = *dcc->master_pub
- };
+ 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 ("serial_id",
&serial_id),
@@ -97,10 +94,16 @@ deposit_confirmation_cb (void *cls,
&dc.refund_deadline),
GNUNET_PQ_result_spec_timestamp ("wire_deadline",
&dc.wire_deadline),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_without_fee",
- &dc.amount_without_fee),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &dc.coin_pub),
+ 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",
@@ -111,6 +114,7 @@ deposit_confirmation_cb (void *cls,
&dc.master_sig),
GNUNET_PQ_result_spec_end
};
+ enum GNUNET_GenericReturnValue rval;
if (GNUNET_OK !=
GNUNET_PQ_extract_result (result,
@@ -121,11 +125,22 @@ deposit_confirmation_cb (void *cls,
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;
- if (GNUNET_OK !=
- dcc->cb (dcc->cb_cls,
- serial_id,
- &dc))
+ dc.coin_pubs = coin_pubs;
+ dc.coin_sigs = coin_sigs;
+ dc.num_coins = num_sigs;
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
break;
}
}
@@ -134,19 +149,18 @@ deposit_confirmation_cb (void *cls,
enum GNUNET_DB_QueryStatus
TAH_PG_get_deposit_confirmations (
void *cls,
- const struct TALER_MasterPublicKeyP *master_public_key,
uint64_t start_id,
+ bool return_suppressed,
TALER_AUDITORDB_DepositConfirmationCallback cb,
void *cb_cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_public_key),
GNUNET_PQ_query_param_uint64 (&start_id),
+ GNUNET_PQ_query_param_bool (return_suppressed),
GNUNET_PQ_query_param_end
};
struct DepositConfirmationContext dcc = {
- .master_pub = master_public_key,
.cb = cb,
.cb_cls = cb_cls,
.pg = pg
@@ -156,23 +170,23 @@ TAH_PG_get_deposit_confirmations (
PREPARE (pg,
"auditor_deposit_confirmation_select",
"SELECT"
- " serial_id"
+ " deposit_confirmation_serial_id"
",h_contract_terms"
",h_policy"
",h_wire"
",exchange_timestamp"
",wire_deadline"
",refund_deadline"
- ",amount_without_fee_val"
- ",amount_without_fee_frac"
- ",coin_pub"
+ ",total_without_fee"
+ ",coin_pubs"
+ ",coin_sigs"
",merchant_pub"
",exchange_sig"
",exchange_pub"
- ",master_sig" /* master_sig could be normalized... */
- " FROM deposit_confirmations"
- " WHERE master_pub=$1"
- " AND serial_id>$2");
+ ",master_sig"
+ " FROM auditor_deposit_confirmations"
+ " WHERE deposit_confirmation_serial_id>$1"
+ " AND ($2 OR NOT suppressed);");
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
"auditor_deposit_confirmation_select",
params,
diff --git a/src/auditordb/pg_get_deposit_confirmations.h b/src/auditordb/pg_get_deposit_confirmations.h
index 48ee70634..6b33e9e6f 100644
--- a/src/auditordb/pg_get_deposit_confirmations.h
+++ b/src/auditordb/pg_get_deposit_confirmations.h
@@ -30,9 +30,9 @@
* Get information about deposit confirmations from the database.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_public_key for which exchange do we want to get deposit confirmations
* @param start_id row/serial ID where to start the iteration (0 from
* the start, exclusive, i.e. serial_ids must start from 1)
+ * @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
@@ -40,8 +40,8 @@
enum GNUNET_DB_QueryStatus
TAH_PG_get_deposit_confirmations (
void *cls,
- const struct TALER_MasterPublicKeyP *master_public_key,
uint64_t start_id,
+ bool return_suppressed,
TALER_AUDITORDB_DepositConfirmationCallback cb,
void *cb_cls);
diff --git a/src/auditordb/pg_get_predicted_balance.c b/src/auditordb/pg_get_predicted_balance.c
deleted file mode 100644
index 07d1faae4..000000000
--- a/src/auditordb/pg_get_predicted_balance.c
+++ /dev/null
@@ -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 pg_get_predicted_balance.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_predicted_balance.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_predicted_balance (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *balance,
- struct TALER_Amount *drained)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("drained",
- drained),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_predicted_result_select",
- "SELECT"
- " balance_val"
- ",balance_frac"
- ",drained_val"
- ",drained_frac"
- " FROM auditor_predicted_result"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_predicted_result_select",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_predicted_balance.h b/src/auditordb/pg_get_predicted_balance.h
deleted file mode 100644
index 925e6a85b..000000000
--- a/src/auditordb/pg_get_predicted_balance.h
+++ /dev/null
@@ -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 pg_get_predicted_balance.h
- * @brief implementation of the get_predicted_balance function
- * @author Christian Grothoff
- */
-#ifndef PG_GET_PREDICTED_BALANCE_H
-#define PG_GET_PREDICTED_BALANCE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Get an exchange's predicted balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] balance expected bank account balance of the exchange
- * @param[out] drained amount drained so far
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_predicted_balance (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *balance,
- struct TALER_Amount *drained);
-
-#endif
diff --git a/src/auditordb/pg_get_purse_info.c b/src/auditordb/pg_get_purse_info.c
index aa0f3027d..6a0faf616 100644
--- a/src/auditordb/pg_get_purse_info.c
+++ b/src/auditordb/pg_get_purse_info.c
@@ -29,7 +29,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_get_purse_info (
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
uint64_t *rowid,
struct TALER_Amount *balance,
struct GNUNET_TIME_Timestamp *expiration_date)
@@ -37,7 +36,6 @@ TAH_PG_get_purse_info (
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -54,11 +52,9 @@ TAH_PG_get_purse_info (
"auditor_get_purse_info",
"SELECT"
" expiration_date"
- ",balance_val"
- ",balance_frac"
+ ",balance"
" FROM auditor_purses"
- " WHERE purse_pub=$1"
- " AND master_pub=$2;");
+ " WHERE purse_pub=$1");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"auditor_get_purse_info",
params,
diff --git a/src/auditordb/pg_get_purse_info.h b/src/auditordb/pg_get_purse_info.h
index 2b2e77415..e8268282e 100644
--- a/src/auditordb/pg_get_purse_info.h
+++ b/src/auditordb/pg_get_purse_info.h
@@ -31,7 +31,6 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub public key of the purse
- * @param master_pub master public key of the exchange
* @param[out] rowid which row did we get the information from
* @param[out] balance set to balance of the purse
* @param[out] expiration_date expiration date of the purse
@@ -41,7 +40,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_get_purse_info (
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
uint64_t *rowid,
struct TALER_Amount *balance,
struct GNUNET_TIME_Timestamp *expiration_date);
diff --git a/src/auditordb/pg_get_purse_summary.c b/src/auditordb/pg_get_purse_summary.c
deleted file mode 100644
index 1c5e8a36f..000000000
--- a/src/auditordb/pg_get_purse_summary.c
+++ /dev/null
@@ -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 auditordb/pg_get_purse_summary.c
- * @brief Implementation of the get_purse_summary function for Postgres
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_purse_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_purse_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_PurseBalance *sum)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &sum->balance),
- GNUNET_PQ_result_spec_uint64 ("open_purses",
- &sum->open_purses),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_get_purse_summary",
- "SELECT"
- " open_purses"
- ",balance_val"
- ",balance_frac"
- " FROM auditor_purse_summary"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_get_purse_summary",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_reserve_info.c b/src/auditordb/pg_get_reserve_info.c
index 6beb0c8de..f16c6d995 100644
--- a/src/auditordb/pg_get_reserve_info.c
+++ b/src/auditordb/pg_get_reserve_info.c
@@ -29,7 +29,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_get_reserve_info (void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
uint64_t *rowid,
struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
struct GNUNET_TIME_Timestamp *expiration_date,
@@ -38,7 +37,6 @@ TAH_PG_get_reserve_info (void *cls,
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -69,29 +67,22 @@ TAH_PG_get_reserve_info (void *cls,
*sender_account = NULL;
PREPARE (pg,
- "auditor_reserves_select",
+ "auditor_get_reserve_info",
"SELECT"
- " reserve_balance_val"
- ",reserve_balance_frac"
- ",reserve_loss_val"
- ",reserve_loss_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",close_fee_balance_val"
- ",close_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",open_fee_balance_val"
- ",open_fee_balance_frac"
- ",history_fee_balance_val"
- ",history_fee_balance_frac"
+ " reserve_balance"
+ ",reserve_loss"
+ ",withdraw_fee_balance"
+ ",close_fee_balance"
+ ",purse_fee_balance"
+ ",open_fee_balance"
+ ",history_fee_balance"
",expiration_date"
",auditor_reserves_rowid"
",origin_account"
" FROM auditor_reserves"
- " WHERE reserve_pub=$1 AND master_pub=$2;");
+ " WHERE reserve_pub=$1;");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_reserves_select",
+ "auditor_get_reserve_info",
params,
rs);
}
diff --git a/src/auditordb/pg_get_reserve_info.h b/src/auditordb/pg_get_reserve_info.h
index a04d23c27..3eba035fc 100644
--- a/src/auditordb/pg_get_reserve_info.h
+++ b/src/auditordb/pg_get_reserve_info.h
@@ -31,7 +31,6 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @param[out] rowid which row did we get the information from
* @param[out] rfb where to store the reserve balance summary
* @param[out] expiration_date expiration date of the reserve
@@ -41,7 +40,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_get_reserve_info (void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
uint64_t *rowid,
struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
struct GNUNET_TIME_Timestamp *expiration_date,
diff --git a/src/auditordb/pg_get_reserve_summary.c b/src/auditordb/pg_get_reserve_summary.c
deleted file mode 100644
index 225d7e6a8..000000000
--- a/src/auditordb/pg_get_reserve_summary.c
+++ /dev/null
@@ -1,88 +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 pg_get_reserve_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_reserve_summary.h"
-#include "pg_helper.h"
-
-
-/**
- * Get summary information about all reserves.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] rfb balances are returned here
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_reserve_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ReserveFeeBalance *rfb)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
- &rfb->reserve_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_loss",
- &rfb->reserve_loss),
- TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance",
- &rfb->withdraw_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("close_fee_balance",
- &rfb->close_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee_balance",
- &rfb->purse_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("open_fee_balance",
- &rfb->open_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee_balance",
- &rfb->history_fee_balance),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "auditor_reserve_balance_select",
- "SELECT"
- " reserve_balance_val"
- ",reserve_balance_frac"
- ",reserve_loss_val"
- ",reserve_loss_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",close_fee_balance_val"
- ",close_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",open_fee_balance_val"
- ",open_fee_balance_frac"
- ",history_fee_balance_val"
- ",history_fee_balance_frac"
- " FROM auditor_reserve_balance"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_reserve_balance_select",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_reserve_summary.h b/src/auditordb/pg_get_reserve_summary.h
deleted file mode 100644
index d9a3ea5aa..000000000
--- a/src/auditordb/pg_get_reserve_summary.h
+++ /dev/null
@@ -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 pg_get_reserve_summary.h
- * @brief implementation of the get_reserve_summary function
- * @author Christian Grothoff
- */
-#ifndef PG_GET_RESERVE_SUMMARY_H
-#define PG_GET_RESERVE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Get summary information about all reserves.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] rfb balances are returned here
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_reserve_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ReserveFeeBalance *rfb);
-
-
-#endif
diff --git a/src/auditordb/pg_get_wire_auditor_account_progress.c b/src/auditordb/pg_get_wire_auditor_account_progress.c
deleted file mode 100644
index 147fffa7c..000000000
--- a/src/auditordb/pg_get_wire_auditor_account_progress.c
+++ /dev/null
@@ -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 pg_get_wire_auditor_account_progress.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_wire_auditor_account_progress.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- struct TALER_AUDITORDB_BankAccountProgressPoint *bapp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_wire_reserve_in_serial_id",
- &pp->last_reserve_in_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_wire_wire_out_serial_id",
- &pp->last_wire_out_serial_id),
- GNUNET_PQ_result_spec_uint64 ("wire_in_off",
- &bapp->in_wire_off),
- GNUNET_PQ_result_spec_uint64 ("wire_out_off",
- &bapp->out_wire_off),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "wire_auditor_account_progress_select",
- "SELECT"
- " last_wire_reserve_in_serial_id"
- ",last_wire_wire_out_serial_id"
- ",wire_in_off"
- ",wire_out_off"
- " FROM wire_auditor_account_progress"
- " WHERE master_pub=$1 AND account_name=$2;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "wire_auditor_account_progress_select",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_wire_auditor_account_progress.h b/src/auditordb/pg_get_wire_auditor_account_progress.h
deleted file mode 100644
index ab1d2bb96..000000000
--- a/src/auditordb/pg_get_wire_auditor_account_progress.h
+++ /dev/null
@@ -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 pg_get_wire_auditor_account_progress.h
- * @brief implementation of the get_wire_auditor_account_progress function
- * @author Christian Grothoff
- */
-#ifndef PG_GET_WIRE_AUDITOR_ACCOUNT_PROGRESS_H
-#define PG_GET_WIRE_AUDITOR_ACCOUNT_PROGRESS_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param[out] pp where is the auditor in processing
- * @param[out] bapp how far are we in the wire transaction histories
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- struct TALER_AUDITORDB_BankAccountProgressPoint *bapp);
-
-
-#endif
diff --git a/src/auditordb/pg_get_wire_auditor_progress.c b/src/auditordb/pg_get_wire_auditor_progress.c
deleted file mode 100644
index c5caf3f01..000000000
--- a/src/auditordb/pg_get_wire_auditor_progress.c
+++ /dev/null
@@ -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 pg_get_wire_auditor_progress.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_get_wire_auditor_progress.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_get_wire_auditor_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_WireProgressPoint *pp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("last_timestamp",
- &pp->last_timestamp),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_close_uuid",
- &pp->last_reserve_close_uuid),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "wire_auditor_progress_select",
- "SELECT"
- " last_timestamp"
- ",last_reserve_close_uuid"
- " FROM wire_auditor_progress"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "wire_auditor_progress_select",
- params,
- rs);
-}
diff --git a/src/auditordb/pg_get_wire_fee_summary.c b/src/auditordb/pg_get_wire_fee_summary.c
index 8b48a4d47..b0eb9ba50 100644
--- a/src/auditordb/pg_get_wire_fee_summary.c
+++ b/src/auditordb/pg_get_wire_fee_summary.c
@@ -30,18 +30,15 @@
* Get summary information about an exchanges wire fee balance.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
* @param[out] wire_fee_balance set amount the exchange gained in wire fees
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
TAH_PG_get_wire_fee_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_Amount *wire_fee_balance)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -53,10 +50,8 @@ TAH_PG_get_wire_fee_summary (void *cls,
PREPARE (pg,
"auditor_wire_fee_balance_select",
"SELECT"
- " wire_fee_balance_val"
- ",wire_fee_balance_frac"
- " FROM auditor_wire_fee_balance"
- " WHERE master_pub=$1;");
+ " wire_fee_balance"
+ " FROM auditor_wire_fee_balance");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"auditor_wire_fee_balance_select",
params,
diff --git a/src/auditordb/pg_get_wire_fee_summary.h b/src/auditordb/pg_get_wire_fee_summary.h
index c6e5bacde..4c7f1aebd 100644
--- a/src/auditordb/pg_get_wire_fee_summary.h
+++ b/src/auditordb/pg_get_wire_fee_summary.h
@@ -30,13 +30,11 @@
* Get summary information about an exchanges wire fee balance.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
* @param[out] wire_fee_balance set amount the exchange gained in wire fees
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
TAH_PG_get_wire_fee_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_Amount *wire_fee_balance);
diff --git a/src/auditordb/pg_helper.h b/src/auditordb/pg_helper.h
index 7ebe5a179..54ccd5978 100644
--- a/src/auditordb/pg_helper.h
+++ b/src/auditordb/pg_helper.h
@@ -111,19 +111,8 @@ struct PostgresClosure
* @param field name of the database field to fetch amount from
* @param[out] amountp pointer to amount to set
*/
-#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount ( \
- field,pg->currency,amountp)
-
-
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database. NBO variant.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field, \
- amountp) TALER_PQ_result_spec_amount_nbo ( \
+#define TALER_PQ_RESULT_SPEC_AMOUNT(field, \
+ amountp) TALER_PQ_result_spec_amount ( \
field,pg->currency,amountp)
diff --git a/src/auditordb/pg_insert_auditor_progress.c b/src/auditordb/pg_insert_auditor_progress.c
new file mode 100644
index 000000000..3c5d25eef
--- /dev/null
+++ b/src/auditordb/pg_insert_auditor_progress.c
@@ -0,0 +1,97 @@
+/*
+ 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 pg_insert_auditor_progress.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_auditor_progress.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_auditor_progress (
+ void *cls,
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ progress_offset);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ uint64_t);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ uint64_t offsets[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (cnt,
+ offsets,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = progress_key;
+ offsets[0] = progress_offset;
+
+ va_start (ap,
+ progress_offset);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ offsets[off] = va_arg (ap,
+ uint64_t);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_progress_insert",
+ "INSERT INTO auditor_progress "
+ "(progress_key"
+ ",progress_offset"
+ ") SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS INT8[]))"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_progress_insert",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_insert_wire_auditor_progress.h b/src/auditordb/pg_insert_auditor_progress.h
index 1e3b60805..a20e376c8 100644
--- a/src/auditordb/pg_insert_wire_auditor_progress.h
+++ b/src/auditordb/pg_insert_auditor_progress.h
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_insert_wire_auditor_progress.h
- * @brief implementation of the insert_wire_auditor_progress function
+ * @file pg_insert_auditor_progress.h
+ * @brief implementation of the insert_auditor_progress function
* @author Christian Grothoff
*/
-#ifndef PG_INSERT_WIRE_AUDITOR_PROGRESS_H
-#define PG_INSERT_WIRE_AUDITOR_PROGRESS_H
+#ifndef PG_INSERT_AUDITOR_PROGRESS_H
+#define PG_INSERT_AUDITOR_PROGRESS_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -31,15 +31,16 @@
* data.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param pp where is the auditor in processing
+ * @param progress_key name of the progress indicator
+ * @param progress_offset offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to insert
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_insert_wire_auditor_progress (
+TAH_PG_insert_auditor_progress (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp);
-
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...);
#endif
diff --git a/src/auditordb/pg_insert_auditor_progress_aggregation.c b/src/auditordb/pg_insert_auditor_progress_aggregation.c
deleted file mode 100644
index f119548f8..000000000
--- a/src/auditordb/pg_insert_auditor_progress_aggregation.c
+++ /dev/null
@@ -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 pg_insert_auditor_progress_aggregation.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_auditor_progress_aggregation.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppa->last_wire_out_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_insert_aggregation",
- "INSERT INTO auditor_progress_aggregation "
- "(master_pub"
- ",last_wire_out_serial_id"
- ") VALUES ($1,$2);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_aggregation",
- params);
-}
diff --git a/src/auditordb/pg_insert_auditor_progress_coin.c b/src/auditordb/pg_insert_auditor_progress_coin.c
deleted file mode 100644
index aec745c5c..000000000
--- a/src/auditordb/pg_insert_auditor_progress_coin.c
+++ /dev/null
@@ -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 pg_insert_auditor_progress_coin.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_auditor_progress_coin.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppc->last_withdraw_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_deposit_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_melt_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_refund_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_refresh_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_refunds_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_insert_coin",
- "INSERT INTO auditor_progress_coin "
- "(master_pub"
- ",last_withdraw_serial_id"
- ",last_deposit_serial_id"
- ",last_melt_serial_id"
- ",last_refund_serial_id"
- ",last_recoup_serial_id"
- ",last_recoup_refresh_serial_id"
- ",last_purse_deposits_serial_id"
- ",last_purse_decision_serial_id"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_coin",
- params);
-}
diff --git a/src/auditordb/pg_insert_auditor_progress_coin.h b/src/auditordb/pg_insert_auditor_progress_coin.h
deleted file mode 100644
index 57f728cbb..000000000
--- a/src/auditordb/pg_insert_auditor_progress_coin.h
+++ /dev/null
@@ -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 pg_insert_auditor_progress_coin.h
- * @brief implementation of the insert_auditor_progress_coin function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_AUDITOR_PROGRESS_COIN_H
-#define PG_INSERT_AUDITOR_PROGRESS_COIN_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppc where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc);
-
-#endif
diff --git a/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c b/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c
deleted file mode 100644
index 4f4c7390e..000000000
--- a/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c
+++ /dev/null
@@ -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 pg_insert_auditor_progress_deposit_confirmation.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_auditor_progress_deposit_confirmation.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppdc->last_deposit_confirmation_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_insert_deposit_confirmation",
- "INSERT INTO auditor_progress_deposit_confirmation "
- "(master_pub"
- ",last_deposit_confirmation_serial_id"
- ") VALUES ($1,$2);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_deposit_confirmation",
- params);
-}
diff --git a/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.h b/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.h
deleted file mode 100644
index 21a5ed282..000000000
--- a/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.h
+++ /dev/null
@@ -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 pg_insert_auditor_progress_deposit_confirmation.h
- * @brief implementation of the insert_auditor_progress_deposit_confirmation function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H
-#define PG_INSERT_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppdc where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc);
-
-#endif
diff --git a/src/auditordb/pg_insert_auditor_progress_purse.c b/src/auditordb/pg_insert_auditor_progress_purse.c
deleted file mode 100644
index fa4f0bd29..000000000
--- a/src/auditordb/pg_insert_auditor_progress_purse.c
+++ /dev/null
@@ -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 pg_insert_auditor_progress_purse.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_auditor_progress_purse.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_purse (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointPurse *ppp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_request_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_decision_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_merge_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_account_merge_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_insert_purse",
- "INSERT INTO auditor_progress_purse "
- "(master_pub"
- ",last_purse_request_serial_id"
- ",last_purse_decision_serial_id"
- ",last_purse_merges_serial_id"
- ",last_account_merges_serial_id"
- ",last_purse_deposits_serial_id"
- ") VALUES ($1,$2,$3,$4,$5,$6);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_purse",
- params);
-}
diff --git a/src/auditordb/pg_insert_auditor_progress_purse.h b/src/auditordb/pg_insert_auditor_progress_purse.h
deleted file mode 100644
index d364f2f0d..000000000
--- a/src/auditordb/pg_insert_auditor_progress_purse.h
+++ /dev/null
@@ -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 pg_insert_auditor_progress_purse.h
- * @brief implementation of the insert_auditor_progress_purse function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_AUDITOR_PROGRESS_PURSE_H
-#define PG_INSERT_AUDITOR_PROGRESS_PURSE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppp where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_purse (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointPurse *ppp);
-
-#endif
diff --git a/src/auditordb/pg_insert_auditor_progress_reserve.c b/src/auditordb/pg_insert_auditor_progress_reserve.c
deleted file mode 100644
index 864ca6f0f..000000000
--- a/src/auditordb/pg_insert_auditor_progress_reserve.c
+++ /dev/null
@@ -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 pg_insert_auditor_progress_reserve.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_auditor_progress_reserve.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_open_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_close_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_purse_decisions_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_account_merges_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_history_requests_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_insert_reserve",
- "INSERT INTO auditor_progress_reserve "
- "(master_pub"
- ",last_reserve_in_serial_id"
- ",last_reserve_out_serial_id"
- ",last_reserve_recoup_serial_id"
- ",last_reserve_open_serial_id"
- ",last_reserve_close_serial_id"
- ",last_purse_decision_serial_id"
- ",last_account_merges_serial_id"
- ",last_history_requests_serial_id"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_reserve",
- params);
-}
diff --git a/src/auditordb/pg_insert_auditor_progress_reserve.h b/src/auditordb/pg_insert_auditor_progress_reserve.h
deleted file mode 100644
index d1e4d04e0..000000000
--- a/src/auditordb/pg_insert_auditor_progress_reserve.h
+++ /dev/null
@@ -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 pg_insert_auditor_progress_reserve.h
- * @brief implementation of the insert_auditor_progress_reserve function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_AUDITOR_PROGRESS_RESERVE_H
-#define PG_INSERT_AUDITOR_PROGRESS_RESERVE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppr where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr);
-
-#endif
diff --git a/src/auditordb/pg_insert_balance.c b/src/auditordb/pg_insert_balance.c
new file mode 100644
index 000000000..0d1762acc
--- /dev/null
+++ b/src/auditordb/pg_insert_balance.c
@@ -0,0 +1,97 @@
+/*
+ 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 pg_insert_balance.c
+ * @brief Implementation of the insert_balance function
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_balance (void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_value,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ balance_value);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ const struct TALER_Amount *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ struct TALER_Amount amounts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (cnt,
+ amounts,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = balance_key;
+ amounts[0] = *balance_value;
+
+ va_start (ap,
+ balance_value);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ amounts[off] = *va_arg (ap,
+ const struct TALER_Amount *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_balance_insert",
+ "INSERT INTO auditor_balances "
+ "(balance_key"
+ ",balance_value.val"
+ ",balance_value.frac"
+ ") SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS taler_amount[]))"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_balance_insert",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_get_auditor_progress_purse.h b/src/auditordb/pg_insert_balance.h
index db8d48e8e..dff69eec9 100644
--- a/src/auditordb/pg_get_auditor_progress_purse.h
+++ b/src/auditordb/pg_insert_balance.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,31 +14,32 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_get_auditor_progress_purse.h
- * @brief implementation of the get_auditor_progress_purse function
+ * @file pg_insert_balance.h
+ * @brief implementation of the insert_balance function
* @author Christian Grothoff
*/
-#ifndef PG_GET_AUDITOR_PROGRESS_PURSE_H
-#define PG_GET_AUDITOR_PROGRESS_PURSE_H
+#ifndef PG_INSERT_BALANCE_H
+#define PG_INSERT_BALANCE_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_auditordb_plugin.h"
-
/**
- * Get information about the progress of the auditor.
+ * Insert information about a balance tracked by the auditor. There must not be an
+ * existing record.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppp set to where the auditor is in processing
+ * @param balance_key key of the balance to store
+ * @param balance_value value to store
+ * @param ... NULL terminated list of additional key-value pairs to insert
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_purse (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointPurse *ppp);
+TAH_PG_insert_balance (void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_value,
+ ...);
#endif
diff --git a/src/auditordb/pg_insert_balance_summary.c b/src/auditordb/pg_insert_balance_summary.c
deleted file mode 100644
index a965eefa6..000000000
--- a/src/auditordb/pg_insert_balance_summary.c
+++ /dev/null
@@ -1,77 +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 pg_insert_balance_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_balance_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_GlobalCoinBalance *dfb)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (&dfb->total_escrowed),
- TALER_PQ_query_param_amount (&dfb->deposit_fee_balance),
- TALER_PQ_query_param_amount (&dfb->melt_fee_balance),
- TALER_PQ_query_param_amount (&dfb->refund_fee_balance),
- TALER_PQ_query_param_amount (&dfb->purse_fee_balance),
- TALER_PQ_query_param_amount (&dfb->open_deposit_fee_balance),
- TALER_PQ_query_param_amount (&dfb->risk),
- TALER_PQ_query_param_amount (&dfb->loss),
- TALER_PQ_query_param_amount (&dfb->irregular_loss),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_balance_summary_insert",
- "INSERT INTO auditor_balance_summary "
- "(master_pub"
- ",denom_balance_val"
- ",denom_balance_frac"
- ",deposit_fee_balance_val"
- ",deposit_fee_balance_frac"
- ",melt_fee_balance_val"
- ",melt_fee_balance_frac"
- ",refund_fee_balance_val"
- ",refund_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",open_deposit_fee_balance_val"
- ",open_deposit_fee_balance_frac"
- ",risk_val"
- ",risk_frac"
- ",loss_val"
- ",loss_frac"
- ",irregular_loss_val"
- ",irregular_loss_frac"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,"
- " $11,$12,$13,$14,$15,$16,$17,$18,$19);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_balance_summary_insert",
- params);
-}
diff --git a/src/auditordb/pg_insert_balance_summary.h b/src/auditordb/pg_insert_balance_summary.h
deleted file mode 100644
index ee00ae7f0..000000000
--- a/src/auditordb/pg_insert_balance_summary.h
+++ /dev/null
@@ -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 pg_insert_balance_summary.h
- * @brief implementation of the insert_balance_summary function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_BALANCE_SUMMARY_H
-#define PG_INSERT_BALANCE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about an exchange's denomination balances. There
- * must not be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param dfb denomination balance data to store
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_GlobalCoinBalance *dfb);
-
-#endif
diff --git a/src/auditordb/pg_insert_denomination_balance.c b/src/auditordb/pg_insert_denomination_balance.c
index 324c872a4..bbf4127f4 100644
--- a/src/auditordb/pg_insert_denomination_balance.c
+++ b/src/auditordb/pg_insert_denomination_balance.c
@@ -35,11 +35,15 @@ TAH_PG_insert_denomination_balance (
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- TALER_PQ_query_param_amount (&dcd->denom_balance),
- TALER_PQ_query_param_amount (&dcd->denom_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_loss),
GNUNET_PQ_query_param_uint64 (&dcd->num_issued),
- TALER_PQ_query_param_amount (&dcd->denom_risk),
- TALER_PQ_query_param_amount (&dcd->recoup_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_risk),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->recoup_loss),
GNUNET_PQ_query_param_end
};
@@ -47,17 +51,13 @@ TAH_PG_insert_denomination_balance (
"auditor_denomination_pending_insert",
"INSERT INTO auditor_denomination_pending "
"(denom_pub_hash"
- ",denom_balance_val"
- ",denom_balance_frac"
- ",denom_loss_val"
- ",denom_loss_frac"
+ ",denom_balance"
+ ",denom_loss"
",num_issued"
- ",denom_risk_val"
- ",denom_risk_frac"
- ",recoup_loss_val"
- ",recoup_loss_frac"
+ ",denom_risk"
+ ",recoup_loss"
") VALUES ("
- "$1,$2,$3,$4,$5,$6,$7,$8,$9,$10"
+ "$1,$2,$3,$4,$5,$6"
");");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_denomination_pending_insert",
diff --git a/src/auditordb/pg_insert_deposit_confirmation.c b/src/auditordb/pg_insert_deposit_confirmation.c
index 675f8ed0d..1b5205782 100644
--- a/src/auditordb/pg_insert_deposit_confirmation.c
+++ b/src/auditordb/pg_insert_deposit_confirmation.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -33,15 +33,20 @@ TAH_PG_insert_deposit_confirmation (
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&dc->master_public_key),
GNUNET_PQ_query_param_auto_from_type (&dc->h_contract_terms),
GNUNET_PQ_query_param_auto_from_type (&dc->h_policy),
GNUNET_PQ_query_param_auto_from_type (&dc->h_wire),
GNUNET_PQ_query_param_timestamp (&dc->exchange_timestamp),
GNUNET_PQ_query_param_timestamp (&dc->wire_deadline),
GNUNET_PQ_query_param_timestamp (&dc->refund_deadline),
- TALER_PQ_query_param_amount (&dc->amount_without_fee),
- GNUNET_PQ_query_param_auto_from_type (&dc->coin_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dc->total_without_fee),
+ GNUNET_PQ_query_param_array_auto_from_type (dc->num_coins,
+ dc->coin_pubs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_auto_from_type (dc->num_coins,
+ dc->coin_sigs,
+ pg->conn),
GNUNET_PQ_query_param_auto_from_type (&dc->merchant),
GNUNET_PQ_query_param_auto_from_type (&dc->exchange_sig),
GNUNET_PQ_query_param_auto_from_type (&dc->exchange_pub),
@@ -52,21 +57,20 @@ TAH_PG_insert_deposit_confirmation (
PREPARE (pg,
"auditor_deposit_confirmation_insert",
"INSERT INTO deposit_confirmations "
- "(master_pub"
- ",h_contract_terms"
+ "(h_contract_terms"
",h_policy"
",h_wire"
",exchange_timestamp"
",wire_deadline"
",refund_deadline"
- ",amount_without_fee_val"
- ",amount_without_fee_frac"
- ",coin_pub"
+ ",total_without_fee"
+ ",coin_pubs"
+ ",coin_sigs"
",merchant_pub"
",exchange_sig"
",exchange_pub"
",master_sig" /* master_sig could be normalized... */
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);");
+ ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_deposit_confirmation_insert",
params);
diff --git a/src/auditordb/pg_insert_exchange.h b/src/auditordb/pg_insert_exchange.h
deleted file mode 100644
index c06f2115c..000000000
--- a/src/auditordb/pg_insert_exchange.h
+++ /dev/null
@@ -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 pg_insert_exchange.h
- * @brief implementation of the insert_exchange function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_EXCHANGE_H
-#define PG_INSERT_EXCHANGE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about an exchange this auditor will be auditing.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param exchange_url public (base) URL of the API of the exchange
- * @return query result status
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *exchange_url);
-
-
-#endif
diff --git a/src/auditordb/pg_insert_exchange_signkey.c b/src/auditordb/pg_insert_exchange_signkey.c
index fa310f2ef..8bf439da0 100644
--- a/src/auditordb/pg_insert_exchange_signkey.c
+++ b/src/auditordb/pg_insert_exchange_signkey.c
@@ -33,7 +33,6 @@ TAH_PG_insert_exchange_signkey (
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&sk->master_public_key),
GNUNET_PQ_query_param_timestamp (&sk->ep_start),
GNUNET_PQ_query_param_timestamp (&sk->ep_expire),
GNUNET_PQ_query_param_timestamp (&sk->ep_end),
@@ -45,13 +44,12 @@ TAH_PG_insert_exchange_signkey (
PREPARE (pg,
"auditor_insert_exchange_signkey",
"INSERT INTO auditor_exchange_signkeys "
- "(master_pub"
- ",ep_start"
+ "(ep_start"
",ep_expire"
",ep_end"
",exchange_pub"
",master_sig"
- ") VALUES ($1,$2,$3,$4,$5,$6);");
+ ") VALUES ($1,$2,$3,$4,$5);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_insert_exchange_signkey",
params);
diff --git a/src/auditordb/pg_insert_historic_denom_revenue.c b/src/auditordb/pg_insert_historic_denom_revenue.c
index d44d37340..2c3dd44cc 100644
--- a/src/auditordb/pg_insert_historic_denom_revenue.c
+++ b/src/auditordb/pg_insert_historic_denom_revenue.c
@@ -29,7 +29,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_insert_historic_denom_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_DenominationHashP *denom_pub_hash,
struct GNUNET_TIME_Timestamp revenue_timestamp,
const struct TALER_Amount *revenue_balance,
@@ -37,25 +36,23 @@ TAH_PG_insert_historic_denom_revenue (
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
GNUNET_PQ_query_param_timestamp (&revenue_timestamp),
- TALER_PQ_query_param_amount (revenue_balance),
- TALER_PQ_query_param_amount (loss_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ revenue_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ loss_balance),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
"auditor_historic_denomination_revenue_insert",
"INSERT INTO auditor_historic_denomination_revenue"
- "(master_pub"
- ",denom_pub_hash"
+ "(denom_pub_hash"
",revenue_timestamp"
- ",revenue_balance_val"
- ",revenue_balance_frac"
- ",loss_balance_val"
- ",loss_balance_frac"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7);");
+ ",revenue_balance"
+ ",loss_balance"
+ ") VALUES ($1,$2,$3,$4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_historic_denomination_revenue_insert",
params);
diff --git a/src/auditordb/pg_insert_historic_denom_revenue.h b/src/auditordb/pg_insert_historic_denom_revenue.h
index 2f8e005d7..02567119b 100644
--- a/src/auditordb/pg_insert_historic_denom_revenue.h
+++ b/src/auditordb/pg_insert_historic_denom_revenue.h
@@ -31,7 +31,6 @@
* revenue about a denomination key.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @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
@@ -43,7 +42,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_insert_historic_denom_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_DenominationHashP *denom_pub_hash,
struct GNUNET_TIME_Timestamp revenue_timestamp,
const struct TALER_Amount *revenue_balance,
diff --git a/src/auditordb/pg_insert_historic_reserve_revenue.c b/src/auditordb/pg_insert_historic_reserve_revenue.c
index 8218aab70..953fba34a 100644
--- a/src/auditordb/pg_insert_historic_reserve_revenue.c
+++ b/src/auditordb/pg_insert_historic_reserve_revenue.c
@@ -28,29 +28,26 @@
enum GNUNET_DB_QueryStatus
TAH_PG_insert_historic_reserve_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_Amount *reserve_profits)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_timestamp (&start_time),
GNUNET_PQ_query_param_timestamp (&end_time),
- TALER_PQ_query_param_amount (reserve_profits),
+ TALER_PQ_query_param_amount (pg->conn,
+ reserve_profits),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
"auditor_historic_reserve_summary_insert",
"INSERT INTO auditor_historic_reserve_summary"
- "(master_pub"
- ",start_date"
+ "(start_date"
",end_date"
- ",reserve_profits_val"
- ",reserve_profits_frac"
- ") VALUES ($1,$2,$3,$4,$5);");
+ ",reserve_profits"
+ ") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_historic_reserve_summary_insert",
params);
diff --git a/src/auditordb/pg_insert_historic_reserve_revenue.h b/src/auditordb/pg_insert_historic_reserve_revenue.h
index d6c29ed08..a76a50b39 100644
--- a/src/auditordb/pg_insert_historic_reserve_revenue.h
+++ b/src/auditordb/pg_insert_historic_reserve_revenue.h
@@ -30,7 +30,6 @@
* Insert information about an exchange's historic revenue from reserves.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param start_time beginning of aggregated time interval
* @param end_time end of aggregated time interval
* @param reserve_profits total profits made
@@ -39,7 +38,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_insert_historic_reserve_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_Amount *reserve_profits);
diff --git a/src/auditordb/pg_insert_purse_summary.c b/src/auditordb/pg_insert_pending_deposit.c
index f058815f4..50b655ee7 100644
--- a/src/auditordb/pg_insert_purse_summary.c
+++ b/src/auditordb/pg_insert_pending_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,41 +14,45 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file auditordb/pg_insert_purse_summary.c
- * @brief Implementation of the insert_purse_summary function for Postgres
+ * @file auditordb/pg_insert_pending_deposit.c
+ * @brief Implementation of the insert_pending_deposit function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
-#include "pg_insert_purse_summary.h"
+#include "pg_insert_pending_deposit.h"
#include "pg_helper.h"
enum GNUNET_DB_QueryStatus
-TAH_PG_insert_purse_summary (
+TAH_PG_insert_pending_deposit (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_PurseBalance *sum)
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ const struct TALER_Amount *total_amount,
+ struct GNUNET_TIME_Timestamp deadline)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (&sum->balance),
- GNUNET_PQ_query_param_uint64 (&sum->open_purses),
+ TALER_PQ_query_param_amount (pg->conn,
+ total_amount),
+ GNUNET_PQ_query_param_auto_from_type (wire_target_h_payto),
+ GNUNET_PQ_query_param_uint64 (&batch_deposit_serial_id),
+ GNUNET_PQ_query_param_timestamp (&deadline),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
- "auditor_purse_summary_insert",
- "INSERT INTO auditor_purse_summary "
- "(master_pub"
- ",balance_val"
- ",balance_frac"
- ",open_purses"
+ "auditor_insert_pending_deposit",
+ "INSERT INTO auditor_pending_deposits "
+ "(total_amount"
+ ",wire_target_h_payto"
+ ",batch_deposit_serial_id"
+ ",deadline"
") VALUES ($1,$2,$3,$4);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_purse_summary_insert",
+ "auditor_insert_pending_deposit",
params);
}
diff --git a/src/auditordb/pg_insert_auditor_progress_aggregation.h b/src/auditordb/pg_insert_pending_deposit.h
index 74d4b6fd6..7c2b59809 100644
--- a/src/auditordb/pg_insert_auditor_progress_aggregation.h
+++ b/src/auditordb/pg_insert_pending_deposit.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_insert_auditor_progress_aggregation.h
- * @brief implementation of the insert_auditor_progress_aggregation function
+ * @file auditordb/pg_insert_pending_deposit.h
+ * @brief implementation of the insert_pending_deposit function for Postgres
* @author Christian Grothoff
*/
-#ifndef PG_INSERT_AUDITOR_PROGRESS_AGGREGATION_H
-#define PG_INSERT_AUDITOR_PROGRESS_AGGREGATION_H
+#ifndef PG_INSERT_PENDING_DEPOSIT_H
+#define PG_INSERT_PENDING_DEPOSIT_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -27,19 +27,22 @@
/**
- * Insert information about the auditor's progress with an exchange's
- * data.
+ * Insert new row into the pending deposits table.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppa where is the auditor in processing
+ * @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 requested wire transfer deadline
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_insert_auditor_progress_aggregation (
+TAH_PG_insert_pending_deposit (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa);
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ const struct TALER_Amount *total_amount,
+ struct GNUNET_TIME_Timestamp deadline);
#endif
diff --git a/src/auditordb/pg_insert_predicted_result.c b/src/auditordb/pg_insert_predicted_result.c
deleted file mode 100644
index 4e8e54201..000000000
--- a/src/auditordb/pg_insert_predicted_result.c
+++ /dev/null
@@ -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 pg_insert_predicted_result.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_predicted_result.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_predicted_result (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance,
- const struct TALER_Amount *drained)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (balance),
- TALER_PQ_query_param_amount (drained),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_predicted_result_insert",
- "INSERT INTO auditor_predicted_result"
- "(master_pub"
- ",balance_val"
- ",balance_frac"
- ",drained_val"
- ",drained_frac"
- ") VALUES ($1,$2,$3,$4,$5);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_predicted_result_insert",
- params);
-}
diff --git a/src/auditordb/pg_insert_predicted_result.h b/src/auditordb/pg_insert_predicted_result.h
deleted file mode 100644
index ef9f4c3b3..000000000
--- a/src/auditordb/pg_insert_predicted_result.h
+++ /dev/null
@@ -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 pg_insert_predicted_result.h
- * @brief implementation of the insert_predicted_result function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_PREDICTED_RESULT_H
-#define PG_INSERT_PREDICTED_RESULT_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about the predicted exchange's bank
- * account balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param balance what the bank account balance of the exchange should show
- * @param drained amount that was drained in profits
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_predicted_result (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance,
- const struct TALER_Amount *drained);
-
-#endif
diff --git a/src/auditordb/pg_insert_purse_info.c b/src/auditordb/pg_insert_purse_info.c
index f82f9e1de..7eaad8d3c 100644
--- a/src/auditordb/pg_insert_purse_info.c
+++ b/src/auditordb/pg_insert_purse_info.c
@@ -30,15 +30,14 @@ enum GNUNET_DB_QueryStatus
TAH_PG_insert_purse_info (
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *balance,
struct GNUNET_TIME_Timestamp expiration_date)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
GNUNET_PQ_query_param_timestamp (&expiration_date),
GNUNET_PQ_query_param_end
};
@@ -47,11 +46,9 @@ TAH_PG_insert_purse_info (
"auditor_purses_insert",
"INSERT INTO auditor_purses "
"(purse_pub"
- ",master_pub"
- ",target_val"
- ",target_frac"
+ ",target"
",expiration_date"
- ") VALUES ($1,$2,$3,$4,$5);");
+ ") VALUES ($1,$2,$3);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_purses_insert",
params);
diff --git a/src/auditordb/pg_insert_purse_info.h b/src/auditordb/pg_insert_purse_info.h
index 67ac3dba1..ee1b3eebd 100644
--- a/src/auditordb/pg_insert_purse_info.h
+++ b/src/auditordb/pg_insert_purse_info.h
@@ -31,7 +31,6 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub public key of the purse
- * @param master_pub master public key of the exchange
* @param balance balance of the purse
* @param expiration_date expiration date of the purse
* @return transaction status code
@@ -40,7 +39,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_insert_purse_info (
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *balance,
struct GNUNET_TIME_Timestamp expiration_date);
diff --git a/src/auditordb/pg_insert_purse_summary.h b/src/auditordb/pg_insert_purse_summary.h
deleted file mode 100644
index 37e1843d7..000000000
--- a/src/auditordb/pg_insert_purse_summary.h
+++ /dev/null
@@ -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 auditordb/pg_insert_purse_summary.h
- * @brief implementation of the insert_purse_summary function for Postgres
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_PURSE_SUMMARY_H
-#define PG_INSERT_PURSE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about all purses. There must not be an
- * existing record for the @a master_pub.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param sum purse balance summary to store
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_purse_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_PurseBalance *sum);
-
-
-#endif
diff --git a/src/auditordb/pg_insert_reserve_info.c b/src/auditordb/pg_insert_reserve_info.c
index 22b17819e..4c99394fe 100644
--- a/src/auditordb/pg_insert_reserve_info.c
+++ b/src/auditordb/pg_insert_reserve_info.c
@@ -30,7 +30,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_insert_reserve_info (
void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
struct GNUNET_TIME_Timestamp expiration_date,
const char *origin_account)
@@ -38,14 +37,20 @@ TAH_PG_insert_reserve_info (
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (&rfb->reserve_balance),
- TALER_PQ_query_param_amount (&rfb->reserve_loss),
- TALER_PQ_query_param_amount (&rfb->withdraw_fee_balance),
- TALER_PQ_query_param_amount (&rfb->close_fee_balance),
- TALER_PQ_query_param_amount (&rfb->purse_fee_balance),
- TALER_PQ_query_param_amount (&rfb->open_fee_balance),
- TALER_PQ_query_param_amount (&rfb->history_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->withdraw_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->close_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->purse_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->open_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->history_fee_balance),
GNUNET_PQ_query_param_timestamp (&expiration_date),
NULL == origin_account
? GNUNET_PQ_query_param_null ()
@@ -54,31 +59,21 @@ TAH_PG_insert_reserve_info (
};
PREPARE (pg,
- "auditor_reserves_insert",
+ "auditor_insert_reserve_info",
"INSERT INTO auditor_reserves "
"(reserve_pub"
- ",master_pub"
- ",reserve_balance_val"
- ",reserve_balance_frac"
- ",reserve_loss_val"
- ",reserve_loss_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",close_fee_balance_val"
- ",close_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",open_fee_balance_val"
- ",open_fee_balance_frac"
- ",history_fee_balance_val"
- ",history_fee_balance_frac"
+ ",reserve_balance"
+ ",reserve_loss"
+ ",withdraw_fee_balance"
+ ",close_fee_balance"
+ ",purse_fee_balance"
+ ",open_fee_balance"
+ ",history_fee_balance"
",expiration_date"
",origin_account"
-
") VALUES "
- "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18);");
-
+ "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserves_insert",
+ "auditor_insert_reserve_info",
params);
}
diff --git a/src/auditordb/pg_insert_reserve_info.h b/src/auditordb/pg_insert_reserve_info.h
index 5b5aa67eb..b416aa556 100644
--- a/src/auditordb/pg_insert_reserve_info.h
+++ b/src/auditordb/pg_insert_reserve_info.h
@@ -32,7 +32,6 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @param rfb balance amounts for the reserve
* @param expiration_date when will the reserve expire
* @param origin_account where did the money in the reserve originally come from
@@ -42,7 +41,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_insert_reserve_info (
void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
struct GNUNET_TIME_Timestamp expiration_date,
const char *origin_account);
diff --git a/src/auditordb/pg_insert_reserve_summary.c b/src/auditordb/pg_insert_reserve_summary.c
deleted file mode 100644
index bcae388f5..000000000
--- a/src/auditordb/pg_insert_reserve_summary.c
+++ /dev/null
@@ -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 pg_insert_reserve_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_reserve_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_reserve_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ReserveFeeBalance *rfb)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (&rfb->reserve_balance),
- TALER_PQ_query_param_amount (&rfb->reserve_loss),
- TALER_PQ_query_param_amount (&rfb->withdraw_fee_balance),
- TALER_PQ_query_param_amount (&rfb->close_fee_balance),
- TALER_PQ_query_param_amount (&rfb->purse_fee_balance),
- TALER_PQ_query_param_amount (&rfb->open_fee_balance),
- TALER_PQ_query_param_amount (&rfb->history_fee_balance),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_reserve_balance_insert",
- "INSERT INTO auditor_reserve_balance"
- "(master_pub"
- ",reserve_balance_val"
- ",reserve_balance_frac"
- ",reserve_loss_val"
- ",reserve_loss_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",close_fee_balance_val"
- ",close_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",open_fee_balance_val"
- ",open_fee_balance_frac"
- ",history_fee_balance_val"
- ",history_fee_balance_frac"
- ") VALUES "
- "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)");
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (&rfb->reserve_balance,
- &rfb->withdraw_fee_balance));
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserve_balance_insert",
- params);
-}
diff --git a/src/auditordb/pg_insert_reserve_summary.h b/src/auditordb/pg_insert_reserve_summary.h
deleted file mode 100644
index b5e200766..000000000
--- a/src/auditordb/pg_insert_reserve_summary.h
+++ /dev/null
@@ -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 pg_insert_reserve_summary.h
- * @brief implementation of the insert_reserve_summary function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_RESERVE_SUMMARY_H
-#define PG_INSERT_RESERVE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about all reserves. There must not be an
- * existing record for the @a master_pub.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param rfb balances to be stored for the reserve
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_reserve_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ReserveFeeBalance *rfb);
-
-
-#endif
diff --git a/src/auditordb/pg_insert_wire_auditor_account_progress.c b/src/auditordb/pg_insert_wire_auditor_account_progress.c
deleted file mode 100644
index b0e416a42..000000000
--- a/src/auditordb/pg_insert_wire_auditor_account_progress.c
+++ /dev/null
@@ -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 pg_insert_wire_auditor_account_progress.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_wire_auditor_account_progress.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- const struct TALER_AUDITORDB_BankAccountProgressPoint *bapp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&pp->last_wire_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&bapp->in_wire_off),
- GNUNET_PQ_query_param_uint64 (&bapp->out_wire_off),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "wire_auditor_account_progress_insert",
- "INSERT INTO wire_auditor_account_progress "
- "(master_pub"
- ",account_name"
- ",last_wire_reserve_in_serial_id"
- ",last_wire_wire_out_serial_id"
- ",wire_in_off"
- ",wire_out_off"
- ") VALUES ($1,$2,$3,$4,$5,$6);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_account_progress_insert",
- params);
-}
diff --git a/src/auditordb/pg_insert_wire_auditor_account_progress.h b/src/auditordb/pg_insert_wire_auditor_account_progress.h
deleted file mode 100644
index 72c2b595c..000000000
--- a/src/auditordb/pg_insert_wire_auditor_account_progress.h
+++ /dev/null
@@ -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 pg_insert_wire_auditor_account_progress.h
- * @brief implementation of the insert_wire_auditor_account_progress function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_WIRE_AUDITOR_ACCOUNT_PROGRESS_H
-#define PG_INSERT_WIRE_AUDITOR_ACCOUNT_PROGRESS_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp how far are we in the auditor's tables
- * @param bapp progress in wire transaction histories
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- const struct TALER_AUDITORDB_BankAccountProgressPoint *bapp);
-
-#endif
diff --git a/src/auditordb/pg_insert_wire_auditor_progress.c b/src/auditordb/pg_insert_wire_auditor_progress.c
deleted file mode 100644
index 7853d3ff6..000000000
--- a/src/auditordb/pg_insert_wire_auditor_progress.c
+++ /dev/null
@@ -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 pg_insert_wire_auditor_progress.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_insert_wire_auditor_progress.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_wire_auditor_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_timestamp (&pp->last_timestamp),
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_close_uuid),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "wire_auditor_progress_insert",
- "INSERT INTO wire_auditor_progress "
- "(master_pub"
- ",last_timestamp"
- ",last_reserve_close_uuid"
- ") VALUES ($1,$2,$3);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_progress_insert",
- params);
-}
diff --git a/src/auditordb/pg_insert_wire_fee_summary.h b/src/auditordb/pg_insert_wire_fee_summary.h
deleted file mode 100644
index 9c969fb65..000000000
--- a/src/auditordb/pg_insert_wire_fee_summary.h
+++ /dev/null
@@ -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 pg_insert_wire_fee_summary.h
- * @brief implementation of the insert_wire_fee_summary function
- * @author Christian Grothoff
- */
-#ifndef PG_INSERT_WIRE_FEE_SUMMARY_H
-#define PG_INSERT_WIRE_FEE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Insert information about exchange's wire fee balance. There must not be an
- * existing record for the same @a master_pub.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param wire_fee_balance amount the exchange gained in wire fees
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_insert_wire_fee_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *wire_fee_balance);
-
-#endif
diff --git a/src/auditordb/pg_list_exchanges.c b/src/auditordb/pg_list_exchanges.c
deleted file mode 100644
index f0637b13f..000000000
--- a/src/auditordb/pg_list_exchanges.c
+++ /dev/null
@@ -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 pg_list_exchanges.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_list_exchanges.h"
-#include "pg_helper.h"
-
-
-/**
- * Closure for #exchange_info_cb().
- */
-struct ExchangeInfoContext
-{
-
- /**
- * Function to call for each exchange.
- */
- TALER_AUDITORDB_ExchangeCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #TAH_PG_list_exchanges().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ExchangeInfoContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-exchange_info_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ExchangeInfoContext *eic = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_MasterPublicKeyP master_pub;
- char *exchange_url;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_pub", &master_pub),
- GNUNET_PQ_result_spec_string ("exchange_url", &exchange_url),
- 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;
- eic->cb (eic->cb_cls,
- &master_pub,
- exchange_url);
- GNUNET_free (exchange_url);
- }
-}
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_list_exchanges (void *cls,
- TALER_AUDITORDB_ExchangeCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct ExchangeInfoContext eic = {
- .cb = cb,
- .cb_cls = cb_cls
- };
- enum GNUNET_DB_QueryStatus qs;
-
- PREPARE (pg,
- "auditor_list_exchanges",
- "SELECT"
- " master_pub"
- ",exchange_url"
- " FROM auditor_exchanges");
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "auditor_list_exchanges",
- params,
- &exchange_info_cb,
- &eic);
- if (qs > 0)
- return eic.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
diff --git a/src/auditordb/pg_select_historic_denom_revenue.c b/src/auditordb/pg_select_historic_denom_revenue.c
index 1812bb5d2..aa44625e7 100644
--- a/src/auditordb/pg_select_historic_denom_revenue.c
+++ b/src/auditordb/pg_select_historic_denom_revenue.c
@@ -113,13 +113,11 @@ historic_denom_revenue_cb (void *cls,
enum GNUNET_DB_QueryStatus
TAH_PG_select_historic_denom_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
void *cb_cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
struct HistoricDenomRevenueContext hrc = {
@@ -134,12 +132,9 @@ TAH_PG_select_historic_denom_revenue (
"SELECT"
" denom_pub_hash"
",revenue_timestamp"
- ",revenue_balance_val"
- ",revenue_balance_frac"
- ",loss_balance_val"
- ",loss_balance_frac"
- " FROM auditor_historic_denomination_revenue"
- " WHERE master_pub=$1;");
+ ",revenue_balance"
+ ",loss_balance"
+ " FROM auditor_historic_denomination_revenue;");
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
"auditor_historic_denomination_revenue_select",
params,
diff --git a/src/auditordb/pg_select_historic_denom_revenue.h b/src/auditordb/pg_select_historic_denom_revenue.h
index 68afcd019..25a68dacb 100644
--- a/src/auditordb/pg_select_historic_denom_revenue.h
+++ b/src/auditordb/pg_select_historic_denom_revenue.h
@@ -28,10 +28,8 @@
/**
* Obtain all of the historic denomination key revenue
- * of the given @a master_pub.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param cb function to call with the results
* @param cb_cls closure for @a cb
* @return transaction status code
@@ -39,7 +37,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_select_historic_denom_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
void *cb_cls);
diff --git a/src/auditordb/pg_select_historic_reserve_revenue.c b/src/auditordb/pg_select_historic_reserve_revenue.c
index a381cf41c..877c3e2d7 100644
--- a/src/auditordb/pg_select_historic_reserve_revenue.c
+++ b/src/auditordb/pg_select_historic_reserve_revenue.c
@@ -108,13 +108,11 @@ historic_reserve_revenue_cb (void *cls,
enum GNUNET_DB_QueryStatus
TAH_PG_select_historic_reserve_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
void *cb_cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
enum GNUNET_DB_QueryStatus qs;
@@ -129,10 +127,8 @@ TAH_PG_select_historic_reserve_revenue (
"SELECT"
" start_date"
",end_date"
- ",reserve_profits_val"
- ",reserve_profits_frac"
- " FROM auditor_historic_reserve_summary"
- " WHERE master_pub=$1;");
+ ",reserve_profits"
+ " FROM auditor_historic_reserve_summary");
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
"auditor_historic_reserve_summary_select",
params,
diff --git a/src/auditordb/pg_select_historic_reserve_revenue.h b/src/auditordb/pg_select_historic_reserve_revenue.h
index 87a6b06a1..b067c8917 100644
--- a/src/auditordb/pg_select_historic_reserve_revenue.h
+++ b/src/auditordb/pg_select_historic_reserve_revenue.h
@@ -29,7 +29,6 @@
* Return information about an exchange's historic revenue from reserves.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param cb function to call with results
* @param cb_cls closure for @a cb
* @return transaction status code
@@ -37,7 +36,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_select_historic_reserve_revenue (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
void *cb_cls);
diff --git a/src/auditordb/pg_select_pending_deposits.c b/src/auditordb/pg_select_pending_deposits.c
new file mode 100644
index 000000000..1190fb132
--- /dev/null
+++ b/src/auditordb/pg_select_pending_deposits.c
@@ -0,0 +1,149 @@
+/*
+ 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 auditordb/pg_select_pending_deposits.c
+ * @brief Implementation of the select_pending_deposits function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_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 PostgresClosure *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_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 PostgresClosure *pg = eic->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t batch_deposit_serial_id;
+ struct TALER_Amount total_amount;
+ struct TALER_PaytoHashP wire_target_h_payto;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ 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_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,
+ batch_deposit_serial_id,
+ &total_amount,
+ &wire_target_h_payto,
+ deadline);
+ }
+ eic->qs = num_results;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_pending_deposits (
+ void *cls,
+ struct GNUNET_TIME_Absolute deadline,
+ TALER_AUDITORDB_WireMissingCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&deadline),
+ 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",
+ "SELECT"
+ " batch_deposit_serial_id"
+ ",total_amount"
+ ",wire_target_h_payto"
+ ",deadline"
+ " FROM auditor_pending_deposits"
+ " WHERE deadline<$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "auditor_select_pending_deposits",
+ 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/pg_get_auditor_progress_reserve.h b/src/auditordb/pg_select_pending_deposits.h
index 6b9cfabed..e165098c5 100644
--- a/src/auditordb/pg_get_auditor_progress_reserve.h
+++ b/src/auditordb/pg_select_pending_deposits.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_get_auditor_progress_reserve.h
- * @brief implementation of the get_auditor_progress_reserve function
+ * @file auditordb/pg_select_pending_deposits.h
+ * @brief implementation of the select_pending_deposits function for Postgres
* @author Christian Grothoff
*/
-#ifndef PG_GET_AUDITOR_PROGRESS_RESERVE_H
-#define PG_GET_AUDITOR_PROGRESS_RESERVE_H
+#ifndef PG_SELECT_PENDING_DEPOSITS_H
+#define PG_SELECT_PENDING_DEPOSITS_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -27,17 +27,20 @@
/**
- * Get information about the progress of the auditor.
+ * Return (batch) deposits for which we have not yet
+ * seen the required wire transfer.
*
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppr set to where the auditor is in processing
+ * @param cls closure
+ * @param deadline only return up to this deadline
+ * @param cb function to call on each entry
+ * @param cb_cls closure for @a cb
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_get_auditor_progress_reserve (
+TAH_PG_select_pending_deposits (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointReserve *ppr);
+ struct GNUNET_TIME_Absolute deadline,
+ TALER_AUDITORDB_WireMissingCallback cb,
+ void *cb_cls);
#endif
diff --git a/src/auditordb/pg_select_purse_expired.c b/src/auditordb/pg_select_purse_expired.c
index 49a8c5a97..77c6d3b26 100644
--- a/src/auditordb/pg_select_purse_expired.c
+++ b/src/auditordb/pg_select_purse_expired.c
@@ -109,7 +109,6 @@ purse_expired_cb (void *cls,
enum GNUNET_DB_QueryStatus
TAH_PG_select_purse_expired (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_ExpiredPurseCallback cb,
void *cb_cls)
{
@@ -117,7 +116,6 @@ TAH_PG_select_purse_expired (
struct GNUNET_TIME_Timestamp now
= GNUNET_TIME_timestamp_get ();
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_timestamp (&now),
GNUNET_PQ_query_param_end
};
@@ -133,11 +131,9 @@ TAH_PG_select_purse_expired (
"SELECT"
" purse_pub"
",expiration_date"
- ",balance_val"
- ",balance_frac"
+ ",balance"
" FROM auditor_purses"
- " WHERE master_pub=$1"
- " AND expiration_date<$2;");
+ " AND expiration_date<$1;");
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
"auditor_select_expired_purses",
params,
diff --git a/src/auditordb/pg_select_purse_expired.h b/src/auditordb/pg_select_purse_expired.h
index 9f501408a..36d81285c 100644
--- a/src/auditordb/pg_select_purse_expired.h
+++ b/src/auditordb/pg_select_purse_expired.h
@@ -30,7 +30,6 @@
* Get information about expired purses.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
* @param cb function to call on expired purses
* @param cb_cls closure for @a cb
* @return transaction status code
@@ -38,7 +37,6 @@
enum GNUNET_DB_QueryStatus
TAH_PG_select_purse_expired (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_ExpiredPurseCallback cb,
void *cb_cls);
diff --git a/src/auditordb/pg_template.c b/src/auditordb/pg_template.c
index 3e9cb642e..e44fdab60 100644
--- a/src/auditordb/pg_template.c
+++ b/src/auditordb/pg_template.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
diff --git a/src/auditordb/pg_template.h b/src/auditordb/pg_template.h
index acada6059..911faf107 100644
--- a/src/auditordb/pg_template.h
+++ b/src/auditordb/pg_template.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
diff --git a/src/auditordb/pg_update_auditor_progress.c b/src/auditordb/pg_update_auditor_progress.c
new file mode 100644
index 000000000..b30be18bd
--- /dev/null
+++ b/src/auditordb/pg_update_auditor_progress.c
@@ -0,0 +1,99 @@
+/*
+ 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 pg_update_auditor_progress.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_auditor_progress.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_auditor_progress (
+ void *cls,
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ progress_offset);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ uint64_t);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ uint64_t offsets[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (cnt,
+ offsets,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = progress_key;
+ offsets[0] = progress_offset;
+
+ va_start (ap,
+ progress_offset);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ offsets[off] = va_arg (ap,
+ uint64_t);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_progress_update",
+ "UPDATE auditor_progress"
+ " SET progress_offset=data.off"
+ " FROM ("
+ " SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS INT8[]))"
+ " AS t(key,off)"
+ " ) AS data"
+ " WHERE auditor_progress.progress_key=data.key;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_progress_update",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_update_wire_auditor_progress.h b/src/auditordb/pg_update_auditor_progress.h
index e46c6119b..e8de58161 100644
--- a/src/auditordb/pg_update_wire_auditor_progress.h
+++ b/src/auditordb/pg_update_auditor_progress.h
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file pg_update_wire_auditor_progress.h
- * @brief implementation of the update_wire_auditor_progress function
+ * @file pg_update_auditor_progress.h
+ * @brief implementation of the update_auditor_progress function
* @author Christian Grothoff
*/
-#ifndef PG_UPDATE_WIRE_AUDITOR_PROGRESS_H
-#define PG_UPDATE_WIRE_AUDITOR_PROGRESS_H
+#ifndef PG_UPDATE_AUDITOR_PROGRESS_H
+#define PG_UPDATE_AUDITOR_PROGRESS_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -31,15 +31,16 @@
* must be an existing record for the exchange.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param pp where is the auditor in processing
+ * @param progress_key name of the progress indicator
+ * @param progress_offset offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to update
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_update_wire_auditor_progress (
+TAH_PG_update_auditor_progress (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp);
-
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...);
#endif
diff --git a/src/auditordb/pg_update_auditor_progress_aggregation.c b/src/auditordb/pg_update_auditor_progress_aggregation.c
deleted file mode 100644
index 24404e4aa..000000000
--- a/src/auditordb/pg_update_auditor_progress_aggregation.c
+++ /dev/null
@@ -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 pg_update_auditor_progress_aggregation.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_auditor_progress_aggregation.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppa->last_wire_out_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_update_aggregation",
- "UPDATE auditor_progress_aggregation SET "
- " last_wire_out_serial_id=$1"
- " WHERE master_pub=$2");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_aggregation",
- params);
-}
diff --git a/src/auditordb/pg_update_auditor_progress_aggregation.h b/src/auditordb/pg_update_auditor_progress_aggregation.h
deleted file mode 100644
index f8917ca7c..000000000
--- a/src/auditordb/pg_update_auditor_progress_aggregation.h
+++ /dev/null
@@ -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 pg_update_auditor_progress_aggregation.h
- * @brief implementation of the update_auditor_progress_aggregation function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_AUDITOR_PROGRESS_AGGREGATION_H
-#define PG_UPDATE_AUDITOR_PROGRESS_AGGREGATION_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppa where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa);
-
-#endif
diff --git a/src/auditordb/pg_update_auditor_progress_coin.c b/src/auditordb/pg_update_auditor_progress_coin.c
deleted file mode 100644
index 1d7e01525..000000000
--- a/src/auditordb/pg_update_auditor_progress_coin.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file pg_update_auditor_progress_coin.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_auditor_progress_coin.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppc->last_withdraw_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_deposit_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_melt_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_refund_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_refresh_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_refunds_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_update_coin",
- "UPDATE auditor_progress_coin SET "
- " last_withdraw_serial_id=$1"
- ",last_deposit_serial_id=$2"
- ",last_melt_serial_id=$3"
- ",last_refund_serial_id=$4"
- ",last_recoup_serial_id=$5"
- ",last_recoup_refresh_serial_id=$6"
- ",last_purse_deposits_serial_id=$7"
- ",last_purse_decision_serial_id=$8"
- " WHERE master_pub=$9");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_coin",
- params);
-}
diff --git a/src/auditordb/pg_update_auditor_progress_coin.h b/src/auditordb/pg_update_auditor_progress_coin.h
deleted file mode 100644
index 0ce7f1495..000000000
--- a/src/auditordb/pg_update_auditor_progress_coin.h
+++ /dev/null
@@ -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 pg_update_auditor_progress_coin.h
- * @brief implementation of the update_auditor_progress_coin function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_AUDITOR_PROGRESS_COIN_H
-#define PG_UPDATE_AUDITOR_PROGRESS_COIN_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppc where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc);
-
-#endif
diff --git a/src/auditordb/pg_update_auditor_progress_deposit_confirmation.c b/src/auditordb/pg_update_auditor_progress_deposit_confirmation.c
deleted file mode 100644
index 9a244f5f1..000000000
--- a/src/auditordb/pg_update_auditor_progress_deposit_confirmation.c
+++ /dev/null
@@ -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 pg_update_auditor_progress_deposit_confirmation.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_auditor_progress_deposit_confirmation.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppdc->last_deposit_confirmation_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_update_deposit_confirmation",
- "UPDATE auditor_progress_deposit_confirmation SET "
- " last_deposit_confirmation_serial_id=$1"
- " WHERE master_pub=$2");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_deposit_confirmation",
- params);
-}
diff --git a/src/auditordb/pg_update_auditor_progress_deposit_confirmation.h b/src/auditordb/pg_update_auditor_progress_deposit_confirmation.h
deleted file mode 100644
index 7927e485b..000000000
--- a/src/auditordb/pg_update_auditor_progress_deposit_confirmation.h
+++ /dev/null
@@ -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 pg_update_auditor_progress_deposit_confirmation.h
- * @brief implementation of the update_auditor_progress_deposit_confirmation function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H
-#define PG_UPDATE_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppdc where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc);
-
-
-#endif
diff --git a/src/auditordb/pg_update_auditor_progress_purse.c b/src/auditordb/pg_update_auditor_progress_purse.c
deleted file mode 100644
index c8fb64660..000000000
--- a/src/auditordb/pg_update_auditor_progress_purse.c
+++ /dev/null
@@ -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 pg_update_auditor_progress_purse.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_auditor_progress_purse.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_purse (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointPurse *ppp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_request_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_decision_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_merge_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_account_merge_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppp->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_update_purse",
- "UPDATE auditor_progress_purse SET "
- " last_purse_request_serial_id=$1"
- ",last_purse_decision_serial_id=$2"
- ",last_purse_merges_serial_id=$3"
- ",last_account_merges_serial_id=$4"
- ",last_purse_deposits_serial_id=$5"
- " WHERE master_pub=$6");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_purse",
- params);
-}
diff --git a/src/auditordb/pg_update_auditor_progress_purse.h b/src/auditordb/pg_update_auditor_progress_purse.h
deleted file mode 100644
index 12a643e52..000000000
--- a/src/auditordb/pg_update_auditor_progress_purse.h
+++ /dev/null
@@ -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 pg_update_auditor_progress_purse.h
- * @brief implementation of the update_auditor_progress_purse function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_AUDITOR_PROGRESS_PURSE_H
-#define PG_UPDATE_AUDITOR_PROGRESS_PURSE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppp where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_purse (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointPurse *ppp);
-
-#endif
diff --git a/src/auditordb/pg_update_auditor_progress_reserve.c b/src/auditordb/pg_update_auditor_progress_reserve.c
deleted file mode 100644
index a8ef39286..000000000
--- a/src/auditordb/pg_update_auditor_progress_reserve.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file pg_update_auditor_progress_reserve.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_auditor_progress_reserve.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_open_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_close_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_purse_decisions_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_account_merges_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_history_requests_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_progress_update_reserve",
- "UPDATE auditor_progress_reserve SET "
- " last_reserve_in_serial_id=$1"
- ",last_reserve_out_serial_id=$2"
- ",last_reserve_recoup_serial_id=$3"
- ",last_reserve_open_serial_id=$4"
- ",last_reserve_close_serial_id=$5"
- ",last_purse_decision_serial_id=$6"
- ",last_account_merges_serial_id=$7"
- ",last_history_requests_serial_id=$8"
- " WHERE master_pub=$9");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_reserve",
- params);
-}
diff --git a/src/auditordb/pg_update_auditor_progress_reserve.h b/src/auditordb/pg_update_auditor_progress_reserve.h
deleted file mode 100644
index 3feaa0dc4..000000000
--- a/src/auditordb/pg_update_auditor_progress_reserve.h
+++ /dev/null
@@ -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 pg_update_auditor_progress_reserve.h
- * @brief implementation of the update_auditor_progress_reserve function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_AUDITOR_PROGRESS_RESERVE_H
-#define PG_UPDATE_AUDITOR_PROGRESS_RESERVE_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppr where is the auditor in processing
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr);
-
-#endif
diff --git a/src/auditordb/pg_update_balance.c b/src/auditordb/pg_update_balance.c
new file mode 100644
index 000000000..eff03056b
--- /dev/null
+++ b/src/auditordb/pg_update_balance.c
@@ -0,0 +1,100 @@
+/*
+ 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 auditordb/pg_update_balance.c
+ * @brief Implementation of the update_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_balance (
+ void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_amount,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ balance_amount);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ const struct TALER_Amount *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ struct TALER_Amount amounts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (cnt,
+ amounts,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = balance_key;
+ amounts[0] = *balance_amount;
+
+ va_start (ap,
+ balance_amount);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ amounts[off] = *va_arg (ap,
+ const struct TALER_Amount *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_balance_update",
+ "UPDATE auditor_balances"
+ " SET balance_value.val=data.val"
+ " ,balance_value.frac=data.frac"
+ " FROM ("
+ " SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS taler_amount[]))"
+ " AS t(key,val,frac)"
+ " ) AS data"
+ " WHERE auditor_balances.balance_key=data.key;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_balance_update",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_update_purse_summary.h b/src/auditordb/pg_update_balance.h
index b613f7c0d..8f83726f5 100644
--- a/src/auditordb/pg_update_purse_summary.h
+++ b/src/auditordb/pg_update_balance.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ 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
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file auditordb/pg_update_purse_summary.h
- * @brief implementation of the update_purse_summary function for Postgres
+ * @file auditordb/pg_update_balance.h
+ * @brief implementation of the update_balance function for Postgres
* @author Christian Grothoff
*/
-#ifndef PG_UPDATE_PURSE_SUMMARY_H
-#define PG_UPDATE_PURSE_SUMMARY_H
+#ifndef PG_UPDATE_BALANCE_H
+#define PG_UPDATE_BALANCE_H
#include "taler_util.h"
#include "taler_json_lib.h"
@@ -27,19 +27,21 @@
/**
- * Update information about all purses. Destructively updates an
+ * Insert information about a balance tracked by the auditor. Destructively updates an
* existing record, which must already exist.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param sum purse balances summary to store
+ * @param balance_key key of the balance to store
+ * @param balance_amount value to store
+ * @param ... NULL terminated list of additional key-value pairs to update
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
-TAH_PG_update_purse_summary (
+TAH_PG_update_balance (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_PurseBalance *sum);
+ const char *balance_key,
+ const struct TALER_Amount *balance_amount,
+ ...);
#endif
diff --git a/src/auditordb/pg_update_balance_summary.c b/src/auditordb/pg_update_balance_summary.c
deleted file mode 100644
index 96f074cba..000000000
--- a/src/auditordb/pg_update_balance_summary.c
+++ /dev/null
@@ -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 pg_update_balance_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_balance_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_GlobalCoinBalance *dfb)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (&dfb->total_escrowed),
- TALER_PQ_query_param_amount (&dfb->deposit_fee_balance),
- TALER_PQ_query_param_amount (&dfb->melt_fee_balance),
- TALER_PQ_query_param_amount (&dfb->refund_fee_balance),
- TALER_PQ_query_param_amount (&dfb->purse_fee_balance),
- TALER_PQ_query_param_amount (&dfb->open_deposit_fee_balance),
- TALER_PQ_query_param_amount (&dfb->risk),
- TALER_PQ_query_param_amount (&dfb->loss),
- TALER_PQ_query_param_amount (&dfb->irregular_loss),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_balance_summary_update",
- "UPDATE auditor_balance_summary SET"
- " denom_balance_val=$1"
- ",denom_balance_frac=$2"
- ",deposit_fee_balance_val=$3"
- ",deposit_fee_balance_frac=$4"
- ",melt_fee_balance_val=$5"
- ",melt_fee_balance_frac=$6"
- ",refund_fee_balance_val=$7"
- ",refund_fee_balance_frac=$8"
- ",purse_fee_balance_val=$9"
- ",purse_fee_balance_frac=$10"
- ",open_deposit_fee_balance_val=$11"
- ",open_deposit_fee_balance_frac=$12"
- ",risk_val=$13"
- ",risk_frac=$14"
- ",loss_val=$15"
- ",loss_frac=$16"
- ",irregular_loss_val=$17"
- ",irregular_loss_frac=$18"
- " WHERE master_pub=$19;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_balance_summary_update",
- params);
-}
diff --git a/src/auditordb/pg_update_balance_summary.h b/src/auditordb/pg_update_balance_summary.h
deleted file mode 100644
index dbb721ecc..000000000
--- a/src/auditordb/pg_update_balance_summary.h
+++ /dev/null
@@ -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 pg_update_balance_summary.h
- * @brief implementation of the update_balance_summary function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_BALANCE_SUMMARY_H
-#define PG_UPDATE_BALANCE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about an exchange's denomination balances. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param dfb denomination balance data to store
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_GlobalCoinBalance *dfb);
-
-#endif
diff --git a/src/auditordb/pg_update_denomination_balance.c b/src/auditordb/pg_update_denomination_balance.c
index 2fb0f5647..0c738779e 100644
--- a/src/auditordb/pg_update_denomination_balance.c
+++ b/src/auditordb/pg_update_denomination_balance.c
@@ -34,11 +34,15 @@ TAH_PG_update_denomination_balance (
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (&dcd->denom_balance),
- TALER_PQ_query_param_amount (&dcd->denom_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_loss),
GNUNET_PQ_query_param_uint64 (&dcd->num_issued),
- TALER_PQ_query_param_amount (&dcd->denom_risk),
- TALER_PQ_query_param_amount (&dcd->recoup_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_risk),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->recoup_loss),
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
GNUNET_PQ_query_param_end
};
@@ -46,16 +50,12 @@ TAH_PG_update_denomination_balance (
PREPARE (pg,
"auditor_denomination_pending_update",
"UPDATE auditor_denomination_pending SET"
- " denom_balance_val=$1"
- ",denom_balance_frac=$2"
- ",denom_loss_val=$3"
- ",denom_loss_frac=$4"
- ",num_issued=$5"
- ",denom_risk_val=$6"
- ",denom_risk_frac=$7"
- ",recoup_loss_val=$8"
- ",recoup_loss_frac=$9"
- " WHERE denom_pub_hash=$10");
+ " denom_balance=$1"
+ ",denom_loss=$2"
+ ",num_issued=$3"
+ ",denom_risk=$4"
+ ",recoup_loss=$5"
+ " WHERE denom_pub_hash=$6");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_denomination_pending_update",
params);
diff --git a/src/auditordb/pg_update_predicted_result.c b/src/auditordb/pg_update_predicted_result.c
deleted file mode 100644
index 5c9618adf..000000000
--- a/src/auditordb/pg_update_predicted_result.c
+++ /dev/null
@@ -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 pg_update_predicted_result.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_predicted_result.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_predicted_result (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance,
- const struct TALER_Amount *drained)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (balance),
- TALER_PQ_query_param_amount (drained),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_predicted_result_update",
- "UPDATE auditor_predicted_result SET"
- " balance_val=$1"
- ",balance_frac=$2"
- ",drained_val=$3"
- ",drained_frac=$4"
- " WHERE master_pub=$5;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_predicted_result_update",
- params);
-}
diff --git a/src/auditordb/pg_update_predicted_result.h b/src/auditordb/pg_update_predicted_result.h
deleted file mode 100644
index e70d079d6..000000000
--- a/src/auditordb/pg_update_predicted_result.h
+++ /dev/null
@@ -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 pg_update_predicted_result.h
- * @brief implementation of the update_predicted_result function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_PREDICTED_RESULT_H
-#define PG_UPDATE_PREDICTED_RESULT_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about an exchange's predicted balance. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param balance what the bank account balance of the exchange should show
- * @param drained amount that was drained in profits
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_predicted_result (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance,
- const struct TALER_Amount *drained);
-
-#endif
diff --git a/src/auditordb/pg_update_purse_info.c b/src/auditordb/pg_update_purse_info.c
index 87c507b45..66dfd490e 100644
--- a/src/auditordb/pg_update_purse_info.c
+++ b/src/auditordb/pg_update_purse_info.c
@@ -30,25 +30,22 @@ enum GNUNET_DB_QueryStatus
TAH_PG_update_purse_info (
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *balance)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
"auditor_purses_update",
- "UPDATE auditor_purses SET "
- " balance_val=$3"
- ",balance_frac=$4"
- " WHERE purse_pub=$1"
- " AND master_pub=$2;");
+ "UPDATE auditor_purses"
+ " SET balance=$2"
+ " WHERE purse_pub=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_purses_update",
params);
diff --git a/src/auditordb/pg_update_purse_info.h b/src/auditordb/pg_update_purse_info.h
index 0b1f71d31..ac37be7b4 100644
--- a/src/auditordb/pg_update_purse_info.h
+++ b/src/auditordb/pg_update_purse_info.h
@@ -32,7 +32,6 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub public key of the purse
- * @param master_pub master public key of the exchange
* @param balance new balance for the purse
* @return transaction status code
*/
@@ -40,7 +39,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_update_purse_info (
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *balance);
diff --git a/src/auditordb/pg_update_purse_summary.c b/src/auditordb/pg_update_purse_summary.c
deleted file mode 100644
index 45afe2c8c..000000000
--- a/src/auditordb/pg_update_purse_summary.c
+++ /dev/null
@@ -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 auditordb/pg_update_purse_summary.c
- * @brief Implementation of the update_purse_summary function for Postgres
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_purse_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_purse_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_PurseBalance *sum)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (&sum->balance),
- GNUNET_PQ_query_param_uint64 (&sum->open_purses),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_purse_summary_update",
- "UPDATE auditor_purse_summary SET"
- " balance_val=$2"
- ",balance_frac=$3"
- ",open_purses=$4"
- " WHERE master_pub=$1;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_purse_summary_update",
- params);
-}
diff --git a/src/auditordb/pg_update_reserve_info.c b/src/auditordb/pg_update_reserve_info.c
index 49d4f0256..2d38a2b0e 100644
--- a/src/auditordb/pg_update_reserve_info.c
+++ b/src/auditordb/pg_update_reserve_info.c
@@ -30,43 +30,40 @@ enum GNUNET_DB_QueryStatus
TAH_PG_update_reserve_info (
void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
struct GNUNET_TIME_Timestamp expiration_date)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (&rfb->reserve_balance),
- TALER_PQ_query_param_amount (&rfb->reserve_loss),
- TALER_PQ_query_param_amount (&rfb->withdraw_fee_balance),
- TALER_PQ_query_param_amount (&rfb->purse_fee_balance),
- TALER_PQ_query_param_amount (&rfb->open_fee_balance),
- TALER_PQ_query_param_amount (&rfb->history_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->withdraw_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->purse_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->open_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->history_fee_balance),
GNUNET_PQ_query_param_timestamp (&expiration_date),
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
- "auditor_reserves_update",
+ "auditor_update_reserve_info",
"UPDATE auditor_reserves SET"
- " reserve_balance_val=$1"
- ",reserve_balance_frac=$2"
- ",reserve_loss_val=$3"
- ",reserve_loss_frac=$4"
- ",withdraw_fee_balance_val=$5"
- ",withdraw_fee_balance_frac=$6"
- ",purse_fee_balance_val=$7"
- ",purse_fee_balance_frac=$8"
- ",open_fee_balance_val=$9"
- ",open_fee_balance_frac=$10"
- ",history_fee_balance_val=$11"
- ",history_fee_balance_frac=$12"
- ",expiration_date=$13"
- " WHERE reserve_pub=$14"
- " AND master_pub=$15;");
+ " reserve_balance=$1"
+ ",reserve_loss=$2"
+ ",withdraw_fee_balance=$3"
+ ",purse_fee_balance=$4"
+ ",open_fee_balance=$5"
+ ",history_fee_balance=$6"
+ ",expiration_date=$7"
+ " WHERE reserve_pub=$8");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserves_update",
+ "auditor_update_reserve_info",
params);
}
diff --git a/src/auditordb/pg_update_reserve_info.h b/src/auditordb/pg_update_reserve_info.h
index 1c7707f07..25f43476a 100644
--- a/src/auditordb/pg_update_reserve_info.h
+++ b/src/auditordb/pg_update_reserve_info.h
@@ -32,7 +32,6 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @param rfb amounts for the reserve
* @param expiration_date expiration date of the reserve
* @return transaction status code
@@ -41,7 +40,6 @@ enum GNUNET_DB_QueryStatus
TAH_PG_update_reserve_info (
void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
struct GNUNET_TIME_Timestamp expiration_date);
diff --git a/src/auditordb/pg_update_reserve_summary.c b/src/auditordb/pg_update_reserve_summary.c
deleted file mode 100644
index 3cb18ea5e..000000000
--- a/src/auditordb/pg_update_reserve_summary.c
+++ /dev/null
@@ -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 pg_update_reserve_summary.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_reserve_summary.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_reserve_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ReserveFeeBalance *rfb)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (&rfb->reserve_balance),
- TALER_PQ_query_param_amount (&rfb->reserve_loss),
- TALER_PQ_query_param_amount (&rfb->withdraw_fee_balance),
- TALER_PQ_query_param_amount (&rfb->close_fee_balance),
- TALER_PQ_query_param_amount (&rfb->purse_fee_balance),
- TALER_PQ_query_param_amount (&rfb->open_fee_balance),
- TALER_PQ_query_param_amount (&rfb->history_fee_balance),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "auditor_reserve_balance_update",
- "UPDATE auditor_reserve_balance SET"
- " reserve_balance_val=$1"
- ",reserve_balance_frac=$2"
- ",reserve_loss_val=$3"
- ",reserve_loss_frac=$4"
- ",withdraw_fee_balance_val=$5"
- ",withdraw_fee_balance_frac=$6"
- ",close_fee_balance_val=$7"
- ",close_fee_balance_frac=$8"
- ",purse_fee_balance_val=$9"
- ",purse_fee_balance_frac=$10"
- ",open_fee_balance_val=$11"
- ",open_fee_balance_frac=$12"
- ",history_fee_balance_val=$13"
- ",history_fee_balance_frac=$14"
- " WHERE master_pub=$15;");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserve_balance_update",
- params);
-}
diff --git a/src/auditordb/pg_update_reserve_summary.h b/src/auditordb/pg_update_reserve_summary.h
deleted file mode 100644
index 50d730750..000000000
--- a/src/auditordb/pg_update_reserve_summary.h
+++ /dev/null
@@ -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 pg_update_reserve_summary.h
- * @brief implementation of the update_reserve_summary function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_RESERVE_SUMMARY_H
-#define PG_UPDATE_RESERVE_SUMMARY_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about all reserves. Destructively updates an
- * existing record, which must already exist.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param rfb balances to be stored for the reserve
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_reserve_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ReserveFeeBalance *rfb);
-
-
-#endif
diff --git a/src/auditordb/pg_update_wire_auditor_account_progress.c b/src/auditordb/pg_update_wire_auditor_account_progress.c
deleted file mode 100644
index ff01be09c..000000000
--- a/src/auditordb/pg_update_wire_auditor_account_progress.c
+++ /dev/null
@@ -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 pg_update_wire_auditor_account_progress.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_wire_auditor_account_progress.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- const struct TALER_AUDITORDB_BankAccountProgressPoint *bapp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&pp->last_wire_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&bapp->in_wire_off),
- GNUNET_PQ_query_param_uint64 (&bapp->out_wire_off),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "wire_auditor_account_progress_update",
- "UPDATE wire_auditor_account_progress SET "
- " last_wire_reserve_in_serial_id=$1"
- ",last_wire_wire_out_serial_id=$2"
- ",wire_in_off=$3"
- ",wire_out_off=$4"
- " WHERE master_pub=$5 AND account_name=$6");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_account_progress_update",
- params);
-}
diff --git a/src/auditordb/pg_update_wire_auditor_account_progress.h b/src/auditordb/pg_update_wire_auditor_account_progress.h
deleted file mode 100644
index 03f5701c0..000000000
--- a/src/auditordb/pg_update_wire_auditor_account_progress.h
+++ /dev/null
@@ -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 pg_update_wire_auditor_account_progress.h
- * @brief implementation of the update_wire_auditor_account_progress function
- * @author Christian Grothoff
- */
-#ifndef PG_UPDATE_WIRE_AUDITOR_ACCOUNT_PROGRESS_H
-#define PG_UPDATE_WIRE_AUDITOR_ACCOUNT_PROGRESS_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_auditordb_plugin.h"
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp where is the auditor in processing
- * @param bapp progress in wire transaction histories
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- const struct TALER_AUDITORDB_BankAccountProgressPoint *bapp);
-
-
-#endif
diff --git a/src/auditordb/pg_update_wire_auditor_progress.c b/src/auditordb/pg_update_wire_auditor_progress.c
deleted file mode 100644
index 5fb0ff31a..000000000
--- a/src/auditordb/pg_update_wire_auditor_progress.c
+++ /dev/null
@@ -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 pg_update_wire_auditor_progress.c
- * @brief Low-level (statement-level) Postgres database access for the exchange
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_update_wire_auditor_progress.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-TAH_PG_update_wire_auditor_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&pp->last_timestamp),
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_close_uuid),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "wire_auditor_progress_update",
- "UPDATE wire_auditor_progress SET "
- " last_timestamp=$1"
- ",last_reserve_close_uuid=$2"
- " WHERE master_pub=$3");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_progress_update",
- params);
-}
diff --git a/src/auditordb/pg_update_wire_fee_summary.c b/src/auditordb/pg_update_wire_fee_summary.c
index 28ee39c44..192612f17 100644
--- a/src/auditordb/pg_update_wire_fee_summary.c
+++ b/src/auditordb/pg_update_wire_fee_summary.c
@@ -29,22 +29,19 @@
enum GNUNET_DB_QueryStatus
TAH_PG_update_wire_fee_summary (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *wire_fee_balance)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (wire_fee_balance),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ wire_fee_balance),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
"auditor_wire_fee_balance_update",
"UPDATE auditor_wire_fee_balance SET"
- " wire_fee_balance_val=$1"
- ",wire_fee_balance_frac=$2"
- " WHERE master_pub=$3;");
+ " wire_fee_balance=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"auditor_wire_fee_balance_update",
params);
diff --git a/src/auditordb/pg_update_wire_fee_summary.h b/src/auditordb/pg_update_wire_fee_summary.h
index 5a1760eeb..a004a2db4 100644
--- a/src/auditordb/pg_update_wire_fee_summary.h
+++ b/src/auditordb/pg_update_wire_fee_summary.h
@@ -31,14 +31,12 @@
* existing record, which must already exist.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
* @param wire_fee_balance amount the exchange gained in wire fees
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
TAH_PG_update_wire_fee_summary (
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *wire_fee_balance);
#endif
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 5ed01e5d2..f5c405d8d 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -23,78 +23,40 @@
#include "taler_pq_lib.h"
#include <pthread.h>
#include <libpq-fe.h>
-#include "pg_helper.h"
-#include "pg_insert_auditor_progress_reserve.h"
-#include "pg_update_auditor_progress_reserve.h"
-#include "pg_get_auditor_progress_reserve.h"
-#include "pg_insert_auditor_progress_purse.h"
-#include "pg_update_auditor_progress_purse.h"
-#include "pg_get_auditor_progress_purse.h"
-#include "pg_insert_auditor_progress_aggregation.h"
-#include "pg_update_auditor_progress_aggregation.h"
-#include "pg_get_auditor_progress_aggregation.h"
-#include "pg_insert_auditor_progress_deposit_confirmation.h"
-#include "pg_update_auditor_progress_deposit_confirmation.h"
-#include "pg_get_auditor_progress_deposit_confirmation.h"
-#include "pg_insert_auditor_progress_coin.h"
-#include "pg_update_auditor_progress_coin.h"
-#include "pg_get_auditor_progress_coin.h"
-#include "pg_insert_wire_auditor_account_progress.h"
-#include "pg_update_wire_auditor_account_progress.h"
-#include "pg_get_wire_auditor_account_progress.h"
-#include "pg_insert_wire_auditor_progress.h"
-#include "pg_update_wire_auditor_progress.h"
-#include "pg_get_wire_auditor_progress.h"
-#include "pg_insert_reserve_info.h"
-#include "pg_update_reserve_info.h"
+#include "pg_delete_deposit_confirmations.h"
+#include "pg_delete_pending_deposit.h"
+#include "pg_delete_purse_info.h"
+#include "pg_del_denomination_balance.h"
#include "pg_del_reserve_info.h"
+#include "pg_get_auditor_progress.h"
+#include "pg_get_balance.h"
+#include "pg_get_denomination_balance.h"
+#include "pg_get_deposit_confirmations.h"
+#include "pg_get_purse_info.h"
#include "pg_get_reserve_info.h"
-#include "pg_insert_reserve_summary.h"
-#include "pg_update_reserve_summary.h"
-#include "pg_get_reserve_summary.h"
-#include "pg_insert_wire_fee_summary.h"
-#include "pg_update_wire_fee_summary.h"
#include "pg_get_wire_fee_summary.h"
+#include "pg_helper.h"
+#include "pg_insert_auditor_progress.h"
+#include "pg_insert_balance.h"
#include "pg_insert_denomination_balance.h"
-#include "pg_update_denomination_balance.h"
-#include "pg_get_denomination_balance.h"
-#include "pg_insert_balance_summary.h"
-#include "pg_update_balance_summary.h"
-#include "pg_get_balance_summary.h"
-#include "pg_insert_historic_denom_revenue.h"
-#include "pg_select_historic_denom_revenue.h"
-#include "pg_insert_historic_reserve_revenue.h"
-#include "pg_select_historic_reserve_revenue.h"
-#include "pg_insert_predicted_result.h"
-#include "pg_update_predicted_result.h"
-#include "pg_get_predicted_balance.h"
-#include "pg_insert_exchange.h"
-#include "pg_list_exchanges.h"
-#include "pg_delete_exchange.h"
-#include "pg_insert_exchange_signkey.h"
#include "pg_insert_deposit_confirmation.h"
-#include "pg_get_deposit_confirmations.h"
-#include "pg_insert_auditor_progress_coin.h"
-#include "pg_update_auditor_progress_coin.h"
-#include "pg_get_auditor_progress_coin.h"
-#include "pg_insert_auditor_progress_purse.h"
-#include "pg_update_auditor_progress_purse.h"
-#include "pg_get_auditor_progress_purse.h"
-#include "pg_get_reserve_info.h"
-#include "pg_insert_historic_reserve_revenue.h"
-#include "pg_insert_wire_auditor_progress.h"
-#include "pg_update_wire_auditor_progress.h"
-#include "pg_get_wire_auditor_progress.h"
+#include "pg_insert_exchange_signkey.h"
+#include "pg_insert_historic_denom_revenue.h"
#include "pg_insert_historic_reserve_revenue.h"
-#include "pg_helper.h"
-#include "pg_get_purse_info.h"
-#include "pg_delete_purse_info.h"
-#include "pg_update_purse_info.h"
+#include "pg_insert_pending_deposit.h"
#include "pg_insert_purse_info.h"
-#include "pg_get_purse_summary.h"
+#include "pg_insert_reserve_info.h"
+#include "pg_select_historic_denom_revenue.h"
+#include "pg_select_historic_reserve_revenue.h"
+#include "pg_select_pending_deposits.h"
#include "pg_select_purse_expired.h"
-#include "pg_insert_purse_summary.h"
-#include "pg_update_purse_summary.h"
+#include "pg_update_auditor_progress.h"
+#include "pg_update_balance.h"
+#include "pg_update_denomination_balance.h"
+#include "pg_update_purse_info.h"
+#include "pg_update_reserve_info.h"
+#include "pg_update_wire_fee_summary.h"
+
#define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", \
__VA_ARGS__)
@@ -137,13 +99,31 @@ postgres_drop_tables (void *cls,
* Create the necessary tables if they are not present
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param support_partitions true to support partitioning
+ * @param num_partitions number of partitions to use
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static enum GNUNET_GenericReturnValue
-postgres_create_tables (void *cls)
+postgres_create_tables (void *cls,
+ bool support_partitions,
+ uint32_t num_partitions)
{
struct PostgresClosure *pc = cls;
+ enum GNUNET_GenericReturnValue ret = GNUNET_OK;
struct GNUNET_PQ_Context *conn;
+ struct GNUNET_PQ_QueryParam params[] = {
+ support_partitions
+ ? GNUNET_PQ_query_param_uint32 (&num_partitions)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ GNUNET_PQ_make_prepare ("create_tables",
+ "SELECT"
+ " auditor.do_create_tables"
+ " ($1);"),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
@@ -153,11 +133,95 @@ postgres_create_tables (void *cls)
"auditordb-postgres",
"auditor-",
es,
- NULL);
+ ps);
if (NULL == conn)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to database\n");
return GNUNET_SYSERR;
+ }
+ if (0 >
+ GNUNET_PQ_eval_prepared_non_select (conn,
+ "create_tables",
+ params))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to run 'create_tables' prepared statement\n");
+ ret = GNUNET_SYSERR;
+ }
+ if (GNUNET_OK == ret)
+ {
+ ret = GNUNET_PQ_exec_sql (conn,
+ "procedures");
+ if (GNUNET_OK != ret)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to load stored procedures\n");
+ }
GNUNET_PQ_disconnect (conn);
- return GNUNET_OK;
+ return ret;
+}
+
+
+/**
+ * Register callback to be invoked on events of type @a es.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to listen for
+ * @param timeout how long to wait for the event
+ * @param cb function to call when the event happens, possibly
+ * mulrewardle times (until cancel is invoked)
+ * @param cb_cls closure for @a cb
+ * @return handle useful to cancel the listener
+ */
+static struct GNUNET_DB_EventHandler *
+postgres_event_listen (void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DB_EventCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+
+ return GNUNET_PQ_event_listen (pg->conn,
+ es,
+ timeout,
+ cb,
+ cb_cls);
+}
+
+
+/**
+ * Stop notifications.
+ *
+ * @param eh handle to unregister.
+ */
+static void
+postgres_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
+{
+ GNUNET_PQ_event_listen_cancel (eh);
+}
+
+
+/**
+ * Notify all that listen on @a es of an event.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to generate
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+static void
+postgres_event_notify (void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ const void *extra,
+ size_t extra_size)
+{
+ struct PostgresClosure *pg = cls;
+
+ return GNUNET_PQ_event_notify (pg->conn,
+ es,
+ extra,
+ extra_size);
}
@@ -333,11 +397,6 @@ postgres_gc (void *cls)
struct GNUNET_PQ_Context *conn;
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_PQ_PreparedStatement ps[] = {
-#if 0
- GNUNET_PQ_make_prepare ("gc_auditor",
- "TODO: #4960",
- 0),
-#endif
GNUNET_PQ_PREPARED_STATEMENT_END
};
struct GNUNET_PQ_ExecuteStatement es[] = {
@@ -395,17 +454,26 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->preflight = &postgres_preflight;
plugin->drop_tables = &postgres_drop_tables;
plugin->create_tables = &postgres_create_tables;
+ plugin->event_listen = &postgres_event_listen;
+ plugin->event_listen_cancel = &postgres_event_listen_cancel;
+ plugin->event_notify = &postgres_event_notify;
plugin->start = &postgres_start;
plugin->commit = &postgres_commit;
plugin->rollback = &postgres_rollback;
plugin->gc = &postgres_gc;
- plugin->insert_exchange
- = &TAH_PG_insert_exchange;
- plugin->delete_exchange
- = &TAH_PG_delete_exchange;
- plugin->list_exchanges
- = &TAH_PG_list_exchanges;
+ plugin->get_auditor_progress
+ = &TAH_PG_get_auditor_progress;
+ plugin->get_balance
+ = &TAH_PG_get_balance;
+ plugin->insert_auditor_progress
+ = &TAH_PG_insert_auditor_progress;
+ plugin->insert_balance
+ = &TAH_PG_insert_balance;
+ plugin->update_auditor_progress
+ = &TAH_PG_update_auditor_progress;
+ plugin->update_balance
+ = &TAH_PG_update_balance;
plugin->insert_exchange_signkey
= &TAH_PG_insert_exchange_signkey;
@@ -413,127 +481,54 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
= &TAH_PG_insert_deposit_confirmation;
plugin->get_deposit_confirmations
= &TAH_PG_get_deposit_confirmations;
+ plugin->delete_deposit_confirmation
+ = &TAH_PG_delete_deposit_confirmation;
- plugin->get_auditor_progress_reserve
- = &TAH_PG_get_auditor_progress_reserve;
- plugin->update_auditor_progress_reserve
- = &TAH_PG_update_auditor_progress_reserve;
- plugin->insert_auditor_progress_reserve
- = &TAH_PG_insert_auditor_progress_reserve;
-
- plugin->get_auditor_progress_purse
- = &TAH_PG_get_auditor_progress_purse;
- plugin->update_auditor_progress_purse
- = &TAH_PG_update_auditor_progress_purse;
- plugin->insert_auditor_progress_purse
- = &TAH_PG_insert_auditor_progress_purse;
-
- plugin->get_auditor_progress_aggregation
- = &TAH_PG_get_auditor_progress_aggregation;
- plugin->update_auditor_progress_aggregation
- = &TAH_PG_update_auditor_progress_aggregation;
- plugin->insert_auditor_progress_aggregation
- = &TAH_PG_insert_auditor_progress_aggregation;
-
- plugin->get_auditor_progress_deposit_confirmation
- = &TAH_PG_get_auditor_progress_deposit_confirmation;
- plugin->update_auditor_progress_deposit_confirmation
- = &TAH_PG_update_auditor_progress_deposit_confirmation;
- plugin->insert_auditor_progress_deposit_confirmation
- = &TAH_PG_insert_auditor_progress_deposit_confirmation;
-
- plugin->get_auditor_progress_coin
- = &TAH_PG_get_auditor_progress_coin;
- plugin->update_auditor_progress_coin
- = &TAH_PG_update_auditor_progress_coin;
- plugin->insert_auditor_progress_coin
- = &TAH_PG_insert_auditor_progress_coin;
-
- plugin->get_wire_auditor_account_progress
- = &TAH_PG_get_wire_auditor_account_progress;
- plugin->update_wire_auditor_account_progress
- = &TAH_PG_update_wire_auditor_account_progress;
- plugin->insert_wire_auditor_account_progress
- = &TAH_PG_insert_wire_auditor_account_progress;
-
- plugin->get_wire_auditor_progress
- = &TAH_PG_get_wire_auditor_progress;
- plugin->update_wire_auditor_progress
- = &TAH_PG_update_wire_auditor_progress;
- plugin->insert_wire_auditor_progress
- = &TAH_PG_insert_wire_auditor_progress;
-
- plugin->del_reserve_info
- = &TAH_PG_del_reserve_info;
- plugin->get_reserve_info
- = &TAH_PG_get_reserve_info;
- plugin->update_reserve_info
- = &TAH_PG_update_reserve_info;
plugin->insert_reserve_info
= &TAH_PG_insert_reserve_info;
+ plugin->update_reserve_info
+ = &TAH_PG_update_reserve_info;
+ plugin->get_reserve_info
+ = &TAH_PG_get_reserve_info;
+ plugin->del_reserve_info
+ = &TAH_PG_del_reserve_info;
- plugin->get_reserve_summary
- = &TAH_PG_get_reserve_summary;
- plugin->update_reserve_summary
- = &TAH_PG_update_reserve_summary;
- plugin->insert_reserve_summary
- = &TAH_PG_insert_reserve_summary;
+ plugin->insert_pending_deposit
+ = &TAH_PG_insert_pending_deposit;
+ plugin->select_pending_deposits
+ = &TAH_PG_select_pending_deposits;
+ plugin->delete_pending_deposit
+ = &TAH_PG_delete_pending_deposit;
- plugin->get_wire_fee_summary
- = &TAH_PG_get_wire_fee_summary;
- plugin->update_wire_fee_summary
- = &TAH_PG_update_wire_fee_summary;
- plugin->insert_wire_fee_summary
- = &TAH_PG_insert_wire_fee_summary;
+ plugin->insert_purse_info
+ = &TAH_PG_insert_purse_info;
+ plugin->update_purse_info
+ = &TAH_PG_update_purse_info;
+ plugin->get_purse_info
+ = &TAH_PG_get_purse_info;
+ plugin->delete_purse_info
+ = &TAH_PG_delete_purse_info;
+ plugin->select_purse_expired
+ = &TAH_PG_select_purse_expired;
- plugin->get_denomination_balance
- = &TAH_PG_get_denomination_balance;
- plugin->update_denomination_balance
- = &TAH_PG_update_denomination_balance;
plugin->insert_denomination_balance
= &TAH_PG_insert_denomination_balance;
+ plugin->update_denomination_balance
+ = &TAH_PG_update_denomination_balance;
+ plugin->del_denomination_balance
+ = &TAH_PG_del_denomination_balance;
+ plugin->get_denomination_balance
+ = &TAH_PG_get_denomination_balance;
- plugin->get_balance_summary
- = &TAH_PG_get_balance_summary;
- plugin->update_balance_summary
- = &TAH_PG_update_balance_summary;
- plugin->insert_balance_summary
- = &TAH_PG_insert_balance_summary;
-
- plugin->select_historic_denom_revenue
- = &TAH_PG_select_historic_denom_revenue;
plugin->insert_historic_denom_revenue
= &TAH_PG_insert_historic_denom_revenue;
+ plugin->select_historic_denom_revenue
+ = &TAH_PG_select_historic_denom_revenue;
- plugin->select_historic_reserve_revenue
- = &TAH_PG_select_historic_reserve_revenue;
plugin->insert_historic_reserve_revenue
= &TAH_PG_insert_historic_reserve_revenue;
-
- plugin->get_predicted_balance
- = &TAH_PG_get_predicted_balance;
- plugin->update_predicted_result
- = &TAH_PG_update_predicted_result;
- plugin->insert_predicted_result
- = &TAH_PG_insert_predicted_result;
- plugin->get_purse_info
- = &TAH_PG_get_purse_info;
-
- plugin->delete_purse_info
- = &TAH_PG_delete_purse_info;
- plugin->update_purse_info
- = &TAH_PG_update_purse_info;
- plugin->insert_purse_info
- = &TAH_PG_insert_purse_info;
- plugin->get_purse_summary
- = &TAH_PG_get_purse_summary;
-
- plugin->select_purse_expired
- = &TAH_PG_select_purse_expired;
- plugin->insert_purse_summary
- = &TAH_PG_insert_purse_summary;
- plugin->update_purse_summary
- = &TAH_PG_update_purse_summary;
+ plugin->select_historic_reserve_revenue
+ = &TAH_PG_select_historic_reserve_revenue;
return plugin;
}
diff --git a/src/auditordb/procedures.sql.in b/src/auditordb/procedures.sql.in
new file mode 100644
index 000000000..0c83bdb5e
--- /dev/null
+++ b/src/auditordb/procedures.sql.in
@@ -0,0 +1,24 @@
+--
+-- 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/>
+--
+
+BEGIN;
+
+SET search_path TO auditor;
+
+#include "auditor_do_get_auditor_progress.sql"
+#include "auditor_do_get_balance.sql"
+
+COMMIT;
diff --git a/src/auditordb/restart.sql b/src/auditordb/restart.sql
index a3cf09e6e..2dc6864ff 100644
--- a/src/auditordb/restart.sql
+++ b/src/auditordb/restart.sql
@@ -31,20 +31,14 @@ SET search_path TO auditor;
-- Unlike the other SQL files, it SHOULD be updated to reflect the
-- latest requirements for dropping tables.
-DELETE FROM auditor_predicted_result;
-DELETE FROM auditor_historic_denomination_revenue;
-DELETE FROM auditor_balance_summary;
+DELETE FROM auditor_amount_arithmetic_inconsistency;
+DELETE FROM auditor_balances;
DELETE FROM auditor_denomination_pending;
-DELETE FROM auditor_reserve_balance;
-DELETE FROM auditor_wire_fee_balance;
-DELETE FROM auditor_reserves;
-DELETE FROM auditor_progress_reserve;
-DELETE FROM auditor_progress_aggregation;
-DELETE FROM auditor_progress_deposit_confirmation;
-DELETE FROM auditor_progress_coin;
-DELETE FROM wire_auditor_progress;
-DELETE FROM wire_auditor_account_progress;
+DELETE FROM auditor_historic_denomination_revenue;
DELETE FROM auditor_historic_reserve_summary;
+DELETE FROM auditor_progress;
+DELETE FROM auditor_purses;
+DELETE FROM auditor_reserves;
-- And we're out of here...
COMMIT;
diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c
index d39d08b91..5184722f0 100644
--- a/src/auditordb/test_auditordb.c
+++ b/src/auditordb/test_auditordb.c
@@ -196,7 +196,9 @@ run (void *cls)
(void) plugin->drop_tables (plugin->cls,
GNUNET_YES);
if (GNUNET_OK !=
- plugin->create_tables (plugin->cls))
+ plugin->create_tables (plugin->cls,
+ false,
+ 0))
{
result = 77;
goto unload;
@@ -236,19 +238,17 @@ run (void *cls)
TALER_string_to_amount (CURRENCY ":0.000014",
&fee_refund));
- struct TALER_MasterPublicKeyP master_pub;
struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_DenominationPrivateKey denom_priv;
struct TALER_DenominationPublicKey denom_pub;
struct GNUNET_TIME_Timestamp date;
- RND_BLK (&master_pub);
RND_BLK (&reserve_pub);
RND_BLK (&rnd_hash);
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&denom_priv,
&denom_pub,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
1024));
TALER_denom_pub_hash (&denom_pub,
&denom_pub_hash);
@@ -267,59 +267,6 @@ run (void *cls)
GNUNET_TIME_UNIT_HOURS,
4)));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: auditor_insert_exchange\n");
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_exchange (plugin->cls,
- &master_pub,
- "https://exchange/"));
-
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_auditor_progress\n");
-
- struct TALER_AUDITORDB_ProgressPointCoin ppc = {
- .last_deposit_serial_id = 123,
- .last_melt_serial_id = 456,
- .last_refund_serial_id = 789,
- .last_withdraw_serial_id = 555
- };
- struct TALER_AUDITORDB_ProgressPointCoin ppc2 = {
- .last_deposit_serial_id = 0,
- .last_melt_serial_id = 0,
- .last_refund_serial_id = 0,
- .last_withdraw_serial_id = 0
- };
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_auditor_progress_coin (plugin->cls,
- &master_pub,
- &ppc));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_auditor_progress\n");
-
- ppc.last_deposit_serial_id++;
- ppc.last_melt_serial_id++;
- ppc.last_refund_serial_id++;
- ppc.last_withdraw_serial_id++;
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_auditor_progress_coin (plugin->cls,
- &master_pub,
- &ppc));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_auditor_progress\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_auditor_progress_coin (plugin->cls,
- &master_pub,
- &ppc2));
- FAILIF ( (ppc.last_deposit_serial_id != ppc2.last_deposit_serial_id) ||
- (ppc.last_melt_serial_id != ppc2.last_melt_serial_id) ||
- (ppc.last_refund_serial_id != ppc2.last_refund_serial_id) ||
- (ppc.last_withdraw_serial_id != ppc2.last_withdraw_serial_id) );
-
{
struct TALER_AUDITORDB_ReserveFeeBalance rfb;
struct TALER_AUDITORDB_ReserveFeeBalance rfb2;
@@ -350,7 +297,6 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_reserve_info (plugin->cls,
&reserve_pub,
- &master_pub,
&rfb,
past,
"payto://bla/blub"));
@@ -359,7 +305,6 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->update_reserve_info (plugin->cls,
&reserve_pub,
- &master_pub,
&rfb,
future));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -370,7 +315,6 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_reserve_info (plugin->cls,
&reserve_pub,
- &master_pub,
&rowid,
&rfb2,
&date,
@@ -394,39 +338,6 @@ run (void *cls)
|| (0 != TALER_amount_cmp (&rfb2.history_fee_balance,
&rfb.history_fee_balance))
);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_reserve_summary\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_reserve_summary (plugin->cls,
- &master_pub,
- &rfb));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_reserve_summary\n");
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_reserve_summary (plugin->cls,
- &master_pub,
- &rfb));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_reserve_summary\n");
- ZR_BLK (&rfb2);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_reserve_summary (plugin->cls,
- &master_pub,
- &rfb2));
- FAILIF ( (0 != TALER_amount_cmp (&rfb2.reserve_balance,
- &rfb.reserve_balance) ||
- (0 != TALER_amount_cmp (&rfb2.withdraw_fee_balance,
- &rfb.withdraw_fee_balance)) ||
- (0 != TALER_amount_cmp (&rfb2.close_fee_balance,
- &rfb.close_fee_balance)) ||
- (0 != TALER_amount_cmp (&rfb2.purse_fee_balance,
- &rfb.purse_fee_balance)) ||
- (0 != TALER_amount_cmp (&rfb2.open_fee_balance,
- &rfb.open_fee_balance)) ||
- (0 != TALER_amount_cmp (&rfb2.history_fee_balance,
- &rfb.history_fee_balance))));
}
{
@@ -477,77 +388,6 @@ run (void *cls)
FAILIF (dcd2.num_issued != dcd.num_issued);
}
- {
- struct TALER_AUDITORDB_GlobalCoinBalance gcb;
- struct TALER_AUDITORDB_GlobalCoinBalance gcb2;
-
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":12.345678",
- &gcb.total_escrowed));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":23.456789",
- &gcb.deposit_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":34.567890",
- &gcb.melt_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":45.678901",
- &gcb.refund_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":55.678901",
- &gcb.purse_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":65.678901",
- &gcb.open_deposit_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":13.57986",
- &gcb.risk));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":0.1",
- &gcb.loss));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1",
- &gcb.irregular_loss));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_balance_summary\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_balance_summary (plugin->cls,
- &master_pub,
- &gcb));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_balance_summary\n");
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_balance_summary (plugin->cls,
- &master_pub,
- &gcb));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_balance_summary\n");
- ZR_BLK (&gcb2);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_balance_summary (plugin->cls,
- &master_pub,
- &gcb2));
- FAILIF (0 != TALER_amount_cmp (&gcb2.total_escrowed,
- &gcb.total_escrowed));
- FAILIF (0 != TALER_amount_cmp (&gcb2.deposit_fee_balance,
- &gcb.deposit_fee_balance) );
- FAILIF (0 != TALER_amount_cmp (&gcb2.melt_fee_balance,
- &gcb.melt_fee_balance) );
- FAILIF (0 != TALER_amount_cmp (&gcb2.refund_fee_balance,
- &gcb.refund_fee_balance));
- FAILIF (0 != TALER_amount_cmp (&gcb2.purse_fee_balance,
- &gcb.purse_fee_balance));
- FAILIF (0 != TALER_amount_cmp (&gcb2.open_deposit_fee_balance,
- &gcb.open_deposit_fee_balance));
- FAILIF (0 != TALER_amount_cmp (&gcb2.risk,
- &gcb.risk));
- FAILIF (0 != TALER_amount_cmp (&gcb2.loss,
- &gcb.loss));
- FAILIF (0 != TALER_amount_cmp (&gcb2.irregular_loss,
- &gcb.irregular_loss));
- }
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_historic_denom_revenue\n");
GNUNET_assert (GNUNET_OK ==
@@ -558,14 +398,12 @@ run (void *cls)
&rloss));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_denom_revenue (plugin->cls,
- &master_pub,
&denom_pub_hash,
past,
&rbalance,
&rloss));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_denom_revenue (plugin->cls,
- &master_pub,
&rnd_hash,
now,
&rbalance,
@@ -575,7 +413,6 @@ run (void *cls)
FAILIF (0 >=
plugin->select_historic_denom_revenue (
plugin->cls,
- &master_pub,
&select_historic_denom_revenue_result,
NULL));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -585,13 +422,11 @@ run (void *cls)
&reserve_profits));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_reserve_revenue (plugin->cls,
- &master_pub,
past,
future,
&reserve_profits));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_reserve_revenue (plugin->cls,
- &master_pub,
now,
future,
&reserve_profits));
@@ -599,85 +434,15 @@ run (void *cls)
"Test: select_historic_reserve_revenue\n");
FAILIF (0 >=
plugin->select_historic_reserve_revenue (plugin->cls,
- &master_pub,
select_historic_reserve_revenue_result,
NULL));
- {
- struct TALER_Amount dbalance;
- struct TALER_Amount dbalance2;
- struct TALER_Amount rbalance2;
-
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":2.535678",
- &dbalance));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_predicted_result\n");
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_predicted_result (plugin->cls,
- &master_pub,
- &rbalance,
- &dbalance));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_predicted_result\n");
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":78.901234",
- &rbalance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":73.901234",
- &dbalance));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_predicted_result (plugin->cls,
- &master_pub,
- &rbalance,
- &dbalance));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_wire_fee_summary (plugin->cls,
- &master_pub,
- &rbalance));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_wire_fee_summary (plugin->cls,
- &master_pub,
- &reserve_profits));
- {
- struct TALER_Amount rprof;
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_wire_fee_summary (plugin->cls,
- &master_pub,
- &rprof));
- FAILIF (0 !=
- TALER_amount_cmp (&rprof,
- &reserve_profits));
- }
- FAILIF (0 >
- plugin->commit (plugin->cls));
+ FAILIF (0 >
+ plugin->commit (plugin->cls));
-
- FAILIF (GNUNET_OK !=
- plugin->start (plugin->cls));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_predicted_balance\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_predicted_balance (plugin->cls,
- &master_pub,
- &rbalance2,
- &dbalance2));
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->del_reserve_info (plugin->cls,
- &reserve_pub,
- &master_pub));
-
- FAILIF (0 != TALER_amount_cmp (&rbalance2,
- &rbalance));
- FAILIF (0 != TALER_amount_cmp (&dbalance2,
- &dbalance));
-
- plugin->rollback (plugin->cls);
- }
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->del_reserve_info (plugin->cls,
+ &reserve_pub));
#if GC_IMPLEMENTED
FAILIF (GNUNET_OK !=
@@ -687,18 +452,7 @@ run (void *cls)
result = 0;
drop:
- {
- plugin->rollback (plugin->cls);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: auditor_delete_exchange\n");
- GNUNET_break (GNUNET_OK ==
- plugin->start (plugin->cls));
- GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
- plugin->delete_exchange (plugin->cls,
- &master_pub));
- GNUNET_break (0 <=
- plugin->commit (plugin->cls));
- }
+ plugin->rollback (plugin->cls);
GNUNET_break (GNUNET_OK ==
plugin->drop_tables (plugin->cls,
GNUNET_YES));
@@ -719,17 +473,20 @@ main (int argc,
(void) argc;
result = -1;
- if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ TALER_OS_init ();
+ if (NULL == (plugin_name = strrchr (argv[0],
+ (int) '-')))
{
GNUNET_break (0);
return -1;
}
- GNUNET_log_setup (argv[0],
- "WARNING",
- NULL);
plugin_name++;
(void) GNUNET_asprintf (&testname,
- "test-auditor-db-%s", plugin_name);
+ "test-auditor-db-%s",
+ plugin_name);
(void) GNUNET_asprintf (&config_filename,
"%s.conf", testname);
cfg = GNUNET_CONFIGURATION_create ();
@@ -742,7 +499,8 @@ main (int argc,
GNUNET_free (testname);
return 2;
}
- GNUNET_SCHEDULER_run (&run, cfg);
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (config_filename);
GNUNET_free (testname);
diff --git a/src/auditordb/test_auditordb_checkpoints.c b/src/auditordb/test_auditordb_checkpoints.c
new file mode 100644
index 000000000..f9bb83142
--- /dev/null
+++ b/src/auditordb/test_auditordb_checkpoints.c
@@ -0,0 +1,386 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2016--2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file auditordb/test_auditordb_checkpoints.c
+ * @brief test cases for DB interaction functions
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_db_lib.h>
+#include "taler_auditordb_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf".
+ */
+#define CURRENCY "EUR"
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) { break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, \
+ sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+
+/**
+ * Global result from the testcase.
+ */
+static int result = -1;
+
+/**
+ * Database plugin under test.
+ */
+static struct TALER_AUDITORDB_Plugin *plugin;
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+static void
+run (void *cls)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct TALER_Amount a1;
+ struct TALER_Amount a2;
+ struct TALER_Amount a3;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":11.245678",
+ &a1));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":2",
+ &a2));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":3",
+ &a3));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "loading database plugin\n");
+ if (NULL ==
+ (plugin = TALER_AUDITORDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to database\n");
+ result = 77;
+ return;
+ }
+
+ (void) plugin->drop_tables (plugin->cls,
+ GNUNET_YES);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ false,
+ 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to 'create_tables'\n");
+ result = 77;
+ goto unload;
+ }
+ if (GNUNET_SYSERR ==
+ plugin->preflight (plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed preflight check\n");
+ result = 77;
+ goto drop;
+ }
+
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls));
+
+ /* Test inserting a blank value, should tell us one result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 69,
+ NULL)
+ );
+ /* Test re-inserting the same value; should yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 69,
+ NULL)
+ );
+ /* Test inserting multiple values, with one already existing */
+ GNUNET_assert (
+ 2 == plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 69,
+ "Test2",
+ 123,
+ "Test3",
+ 245,
+ NULL)
+ );
+ /* Test re-re-inserting the same key with a different value; should also yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 42,
+ NULL)
+ );
+ /* Test updating the same key (again) with a different value; should yield a result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->update_auditor_progress (plugin->cls,
+ "Test",
+ 42,
+ NULL)
+ );
+ /* Test updating a key that doesn't exist; should yield 0 */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->update_auditor_progress (plugin->cls,
+ "NonexistentTest",
+ 1,
+ NULL)
+ );
+
+ /* Right now, the state should look like this:
+ * Test = 42
+ * Test2 = 123
+ * Test3 = 245
+ * Let's make sure that's the case! */
+ uint64_t value;
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "Test",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (value == 42);
+
+ /* Ensure the rest are also at their expected values */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "Test2",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (value == 123);
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "Test3",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (value == 245);
+
+ /* Try fetching value that does not exist */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "TestNX",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (0 == value);
+
+
+ /* Test inserting a blank value, should tell us one result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_balance (plugin->cls,
+ "Test",
+ &a1,
+ NULL)
+ );
+ /* Test re-inserting the same value; should yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_balance (plugin->cls,
+ "Test",
+ &a1,
+ NULL)
+ );
+ /* Test inserting multiple values, with one already existing */
+ GNUNET_assert (
+ 2 == plugin->insert_balance (plugin->cls,
+ "Test",
+ &a1,
+ "Test2",
+ &a2,
+ "Test3",
+ &a3,
+ NULL)
+ );
+ /* Test re-re-inserting the same key with a different value; should also yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_balance (plugin->cls,
+ "Test",
+ &a2,
+ NULL)
+ );
+ /* Test updating the same key (again) with a different value; should yield a result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->update_balance (plugin->cls,
+ "Test",
+ &a2,
+ NULL)
+ );
+ /* Test updating a key that doesn't exist; should yield 0 */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->update_balance (plugin->cls,
+ "NonexistentTest",
+ &a2,
+ NULL)
+ );
+
+ /* Right now, the state should look like this:
+ * Test = a2
+ * Test2 = a2
+ * Test3 = a3
+ * Let's make sure that's the case! */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "Test",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (0 ==
+ TALER_amount_cmp (&a1,
+ &a2));
+
+ /* Ensure the rest are also at their expected values */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "Test2",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (0 ==
+ TALER_amount_cmp (&a1,
+ &a2));
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "Test3",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (0 ==
+ TALER_amount_cmp (&a1,
+ &a3));
+
+ /* Try fetching value that does not exist */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "TestNX",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (GNUNET_OK !=
+ TALER_amount_is_valid (&a1));
+
+ result = 0;
+ GNUNET_break (0 <=
+ plugin->commit (plugin->cls));
+drop:
+ GNUNET_break (GNUNET_OK ==
+ plugin->drop_tables (plugin->cls,
+ GNUNET_YES));
+unload:
+ TALER_AUDITORDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ char *testname;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ (void) argc;
+ result = -1;
+ TALER_OS_init ();
+ GNUNET_log_setup (argv[0],
+ "INFO",
+ NULL);
+ if (NULL == (plugin_name = strrchr (argv[0],
+ (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ plugin_name++;
+ (void) GNUNET_asprintf (&testname,
+ "test-auditor-db-%s",
+ plugin_name);
+ (void) GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run, cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return result;
+}
diff --git a/src/auditordb/versioning.sql b/src/auditordb/versioning.sql
index 116f409b7..444cf95ed 100644
--- a/src/auditordb/versioning.sql
+++ b/src/auditordb/versioning.sql
@@ -146,12 +146,13 @@
BEGIN;
+
-- This file adds versioning support to database it will be loaded to.
-- It requires that PL/pgSQL is already loaded - will raise exception otherwise.
-- All versioning "stuff" (tables, functions) is in "_v" schema.
-- All functions are defined as 'RETURNS SETOF INT4' to be able to make them to RETURN literally nothing (0 rows).
--- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling.
+-- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling
CREATE SCHEMA IF NOT EXISTS _v;
COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';