From 7cc7f81d8a716ba82319e256b6c292dc1a4afd86 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 1 Nov 2022 00:11:12 +0100 Subject: [PATCH] split up auditor db plugin into individual files per main query --- src/auditordb/Makefile.am | 52 +- src/auditordb/hdr.h | 0 src/auditordb/pg_del_reserve_info.c | 50 + src/auditordb/pg_del_reserve_info.h | 43 + src/auditordb/pg_delete_exchange.c | 47 + src/auditordb/pg_delete_exchange.h | 43 + .../pg_get_auditor_progress_aggregation.c | 56 + .../pg_get_auditor_progress_aggregation.h | 43 + src/auditordb/pg_get_auditor_progress_coin.c | 77 + src/auditordb/pg_get_auditor_progress_coin.h | 43 + ...et_auditor_progress_deposit_confirmation.c | 56 + ...et_auditor_progress_deposit_confirmation.h | 43 + src/auditordb/pg_get_auditor_progress_purse.c | 68 + src/auditordb/pg_get_auditor_progress_purse.h | 44 + .../pg_get_auditor_progress_reserve.c | 77 + .../pg_get_auditor_progress_reserve.h | 43 + src/auditordb/pg_get_balance_summary.c | 89 + src/auditordb/pg_get_balance_summary.h | 43 + src/auditordb/pg_get_denomination_balance.c | 72 + src/auditordb/pg_get_denomination_balance.h | 43 + src/auditordb/pg_get_deposit_confirmations.c | 185 ++ src/auditordb/pg_get_deposit_confirmations.h | 48 + src/auditordb/pg_get_predicted_balance.c | 61 + src/auditordb/pg_get_predicted_balance.h | 44 + src/auditordb/pg_get_reserve_info.c | 97 + src/auditordb/pg_get_reserve_info.h | 51 + src/auditordb/pg_get_reserve_summary.c | 88 + src/auditordb/pg_get_reserve_summary.h | 43 + .../pg_get_wire_auditor_account_progress.c | 68 + .../pg_get_wire_auditor_account_progress.h | 48 + src/auditordb/pg_get_wire_auditor_progress.c | 59 + src/auditordb/pg_get_wire_auditor_progress.h | 44 + src/auditordb/pg_get_wire_fee_summary.c | 64 + src/auditordb/pg_get_wire_fee_summary.h | 43 + src/auditordb/pg_helper.h | 130 + .../pg_insert_auditor_progress_aggregation.c | 51 + .../pg_insert_auditor_progress_aggregation.h | 45 + .../pg_insert_auditor_progress_coin.c | 65 + .../pg_insert_auditor_progress_coin.h | 44 + ...rt_auditor_progress_deposit_confirmation.c | 51 + ...rt_auditor_progress_deposit_confirmation.h | 44 + .../pg_insert_auditor_progress_purse.c | 59 + .../pg_insert_auditor_progress_purse.h | 44 + .../pg_insert_auditor_progress_reserve.c | 65 + .../pg_insert_auditor_progress_reserve.h | 43 + src/auditordb/pg_insert_balance_summary.c | 77 + src/auditordb/pg_insert_balance_summary.h | 44 + .../pg_insert_denomination_balance.c | 65 + .../pg_insert_denomination_balance.h | 45 + .../pg_insert_deposit_confirmation.c | 73 + .../pg_insert_deposit_confirmation.h | 42 + src/auditordb/pg_insert_exchange.c | 49 + src/auditordb/pg_insert_exchange.h | 43 + src/auditordb/pg_insert_exchange_signkey.c | 58 + src/auditordb/pg_insert_exchange_signkey.h | 41 + .../pg_insert_historic_denom_revenue.c | 62 + .../pg_insert_historic_denom_revenue.h | 52 + .../pg_insert_historic_reserve_revenue.c | 57 + .../pg_insert_historic_reserve_revenue.h | 47 + src/auditordb/pg_insert_predicted_result.c | 56 + src/auditordb/pg_insert_predicted_result.h | 46 + src/auditordb/pg_insert_reserve_info.c | 84 + src/auditordb/pg_insert_reserve_info.h | 50 + src/auditordb/pg_insert_reserve_summary.c | 75 + src/auditordb/pg_insert_reserve_summary.h | 45 + .../pg_insert_wire_auditor_account_progress.c | 61 + .../pg_insert_wire_auditor_account_progress.h | 48 + .../pg_insert_wire_auditor_progress.c | 53 + .../pg_insert_wire_auditor_progress.h | 45 + src/auditordb/pg_insert_wire_fee_summary.c | 52 + src/auditordb/pg_insert_wire_fee_summary.h | 44 + src/auditordb/pg_list_exchanges.c | 126 + src/auditordb/pg_list_exchanges.h | 43 + .../pg_select_historic_denom_revenue.c | 151 + .../pg_select_historic_denom_revenue.h | 46 + .../pg_select_historic_reserve_revenue.c | 144 + .../pg_select_historic_reserve_revenue.h | 45 + .../pg_update_auditor_progress_aggregation.c | 50 + .../pg_update_auditor_progress_aggregation.h | 44 + .../pg_update_auditor_progress_coin.c | 64 + .../pg_update_auditor_progress_coin.h | 44 + ...te_auditor_progress_deposit_confirmation.c | 50 + ...te_auditor_progress_deposit_confirmation.h | 45 + .../pg_update_auditor_progress_purse.c | 58 + .../pg_update_auditor_progress_purse.h | 44 + .../pg_update_auditor_progress_reserve.c | 64 + .../pg_update_auditor_progress_reserve.h | 43 + src/auditordb/pg_update_balance_summary.c | 75 + src/auditordb/pg_update_balance_summary.h | 44 + .../pg_update_denomination_balance.c | 62 + .../pg_update_denomination_balance.h | 45 + src/auditordb/pg_update_predicted_result.c | 55 + src/auditordb/pg_update_predicted_result.h | 46 + src/auditordb/pg_update_reserve_info.c | 72 + src/auditordb/pg_update_reserve_info.h | 48 + src/auditordb/pg_update_reserve_summary.c | 69 + src/auditordb/pg_update_reserve_summary.h | 45 + .../pg_update_wire_auditor_account_progress.c | 59 + .../pg_update_wire_auditor_account_progress.h | 49 + .../pg_update_wire_auditor_progress.c | 52 + .../pg_update_wire_auditor_progress.h | 45 + src/auditordb/pg_update_wire_fee_summary.c | 51 + src/auditordb/pg_update_wire_fee_summary.h | 44 + src/auditordb/plugin_auditordb_postgres.c | 2933 +---------------- 104 files changed, 6102 insertions(+), 2783 deletions(-) create mode 100644 src/auditordb/hdr.h create mode 100644 src/auditordb/pg_del_reserve_info.c create mode 100644 src/auditordb/pg_del_reserve_info.h create mode 100644 src/auditordb/pg_delete_exchange.c create mode 100644 src/auditordb/pg_delete_exchange.h create mode 100644 src/auditordb/pg_get_auditor_progress_aggregation.c create mode 100644 src/auditordb/pg_get_auditor_progress_aggregation.h create mode 100644 src/auditordb/pg_get_auditor_progress_coin.c create mode 100644 src/auditordb/pg_get_auditor_progress_coin.h create mode 100644 src/auditordb/pg_get_auditor_progress_deposit_confirmation.c create mode 100644 src/auditordb/pg_get_auditor_progress_deposit_confirmation.h create mode 100644 src/auditordb/pg_get_auditor_progress_purse.c create mode 100644 src/auditordb/pg_get_auditor_progress_purse.h create mode 100644 src/auditordb/pg_get_auditor_progress_reserve.c create mode 100644 src/auditordb/pg_get_auditor_progress_reserve.h create mode 100644 src/auditordb/pg_get_balance_summary.c create mode 100644 src/auditordb/pg_get_balance_summary.h create mode 100644 src/auditordb/pg_get_denomination_balance.c create mode 100644 src/auditordb/pg_get_denomination_balance.h create mode 100644 src/auditordb/pg_get_deposit_confirmations.c create mode 100644 src/auditordb/pg_get_deposit_confirmations.h create mode 100644 src/auditordb/pg_get_predicted_balance.c create mode 100644 src/auditordb/pg_get_predicted_balance.h create mode 100644 src/auditordb/pg_get_reserve_info.c create mode 100644 src/auditordb/pg_get_reserve_info.h create mode 100644 src/auditordb/pg_get_reserve_summary.c create mode 100644 src/auditordb/pg_get_reserve_summary.h create mode 100644 src/auditordb/pg_get_wire_auditor_account_progress.c create mode 100644 src/auditordb/pg_get_wire_auditor_account_progress.h create mode 100644 src/auditordb/pg_get_wire_auditor_progress.c create mode 100644 src/auditordb/pg_get_wire_auditor_progress.h create mode 100644 src/auditordb/pg_get_wire_fee_summary.c create mode 100644 src/auditordb/pg_get_wire_fee_summary.h create mode 100644 src/auditordb/pg_helper.h create mode 100644 src/auditordb/pg_insert_auditor_progress_aggregation.c create mode 100644 src/auditordb/pg_insert_auditor_progress_aggregation.h create mode 100644 src/auditordb/pg_insert_auditor_progress_coin.c create mode 100644 src/auditordb/pg_insert_auditor_progress_coin.h create mode 100644 src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c create mode 100644 src/auditordb/pg_insert_auditor_progress_deposit_confirmation.h create mode 100644 src/auditordb/pg_insert_auditor_progress_purse.c create mode 100644 src/auditordb/pg_insert_auditor_progress_purse.h create mode 100644 src/auditordb/pg_insert_auditor_progress_reserve.c create mode 100644 src/auditordb/pg_insert_auditor_progress_reserve.h create mode 100644 src/auditordb/pg_insert_balance_summary.c create mode 100644 src/auditordb/pg_insert_balance_summary.h create mode 100644 src/auditordb/pg_insert_denomination_balance.c create mode 100644 src/auditordb/pg_insert_denomination_balance.h create mode 100644 src/auditordb/pg_insert_deposit_confirmation.c create mode 100644 src/auditordb/pg_insert_deposit_confirmation.h create mode 100644 src/auditordb/pg_insert_exchange.c create mode 100644 src/auditordb/pg_insert_exchange.h create mode 100644 src/auditordb/pg_insert_exchange_signkey.c create mode 100644 src/auditordb/pg_insert_exchange_signkey.h create mode 100644 src/auditordb/pg_insert_historic_denom_revenue.c create mode 100644 src/auditordb/pg_insert_historic_denom_revenue.h create mode 100644 src/auditordb/pg_insert_historic_reserve_revenue.c create mode 100644 src/auditordb/pg_insert_historic_reserve_revenue.h create mode 100644 src/auditordb/pg_insert_predicted_result.c create mode 100644 src/auditordb/pg_insert_predicted_result.h create mode 100644 src/auditordb/pg_insert_reserve_info.c create mode 100644 src/auditordb/pg_insert_reserve_info.h create mode 100644 src/auditordb/pg_insert_reserve_summary.c create mode 100644 src/auditordb/pg_insert_reserve_summary.h create mode 100644 src/auditordb/pg_insert_wire_auditor_account_progress.c create mode 100644 src/auditordb/pg_insert_wire_auditor_account_progress.h create mode 100644 src/auditordb/pg_insert_wire_auditor_progress.c create mode 100644 src/auditordb/pg_insert_wire_auditor_progress.h create mode 100644 src/auditordb/pg_insert_wire_fee_summary.c create mode 100644 src/auditordb/pg_insert_wire_fee_summary.h create mode 100644 src/auditordb/pg_list_exchanges.c create mode 100644 src/auditordb/pg_list_exchanges.h create mode 100644 src/auditordb/pg_select_historic_denom_revenue.c create mode 100644 src/auditordb/pg_select_historic_denom_revenue.h create mode 100644 src/auditordb/pg_select_historic_reserve_revenue.c create mode 100644 src/auditordb/pg_select_historic_reserve_revenue.h create mode 100644 src/auditordb/pg_update_auditor_progress_aggregation.c create mode 100644 src/auditordb/pg_update_auditor_progress_aggregation.h create mode 100644 src/auditordb/pg_update_auditor_progress_coin.c create mode 100644 src/auditordb/pg_update_auditor_progress_coin.h create mode 100644 src/auditordb/pg_update_auditor_progress_deposit_confirmation.c create mode 100644 src/auditordb/pg_update_auditor_progress_deposit_confirmation.h create mode 100644 src/auditordb/pg_update_auditor_progress_purse.c create mode 100644 src/auditordb/pg_update_auditor_progress_purse.h create mode 100644 src/auditordb/pg_update_auditor_progress_reserve.c create mode 100644 src/auditordb/pg_update_auditor_progress_reserve.h create mode 100644 src/auditordb/pg_update_balance_summary.c create mode 100644 src/auditordb/pg_update_balance_summary.h create mode 100644 src/auditordb/pg_update_denomination_balance.c create mode 100644 src/auditordb/pg_update_denomination_balance.h create mode 100644 src/auditordb/pg_update_predicted_result.c create mode 100644 src/auditordb/pg_update_predicted_result.h create mode 100644 src/auditordb/pg_update_reserve_info.c create mode 100644 src/auditordb/pg_update_reserve_info.h create mode 100644 src/auditordb/pg_update_reserve_summary.c create mode 100644 src/auditordb/pg_update_reserve_summary.h create mode 100644 src/auditordb/pg_update_wire_auditor_account_progress.c create mode 100644 src/auditordb/pg_update_wire_auditor_account_progress.h create mode 100644 src/auditordb/pg_update_wire_auditor_progress.c create mode 100644 src/auditordb/pg_update_wire_auditor_progress.h create mode 100644 src/auditordb/pg_update_wire_fee_summary.c create mode 100644 src/auditordb/pg_update_wire_fee_summary.h diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am index eef79256c..7ca168d01 100644 --- a/src/auditordb/Makefile.am +++ b/src/auditordb/Makefile.am @@ -33,7 +33,57 @@ plugin_LTLIBRARIES = \ endif libtaler_plugin_auditordb_postgres_la_SOURCES = \ - plugin_auditordb_postgres.c + 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_deposit_confirmations.h pg_get_deposit_confirmations.c libtaler_plugin_auditordb_postgres_la_LIBADD = \ $(LTLIBINTL) libtaler_plugin_auditordb_postgres_la_LDFLAGS = \ diff --git a/src/auditordb/hdr.h b/src/auditordb/hdr.h new file mode 100644 index 000000000..e69de29bb diff --git a/src/auditordb/pg_del_reserve_info.c b/src/auditordb/pg_del_reserve_info.c new file mode 100644 index 000000000..81db98df9 --- /dev/null +++ b/src/auditordb/pg_del_reserve_info.c @@ -0,0 +1,50 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_del_reserve_info.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_del_reserve_info.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_del_reserve_info (void *cls, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_MasterPublicKeyP *master_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", + "DELETE" + " FROM auditor_reserves" + " WHERE reserve_pub=$1" + " AND master_pub=$2;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_reserves_delete", + params); +} diff --git a/src/auditordb/pg_del_reserve_info.h b/src/auditordb/pg_del_reserve_info.h new file mode 100644 index 000000000..1bed879d9 --- /dev/null +++ b/src/auditordb/pg_del_reserve_info.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_del_reserve_info.h + * @brief implementation of the del_reserve_info function + * @author Christian Grothoff + */ +#ifndef PG_DEL_RESERVE_INFO_H +#define PG_DEL_RESERVE_INFO_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Delete information about a reserve. + * + * @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); + + +#endif diff --git a/src/auditordb/pg_delete_exchange.c b/src/auditordb/pg_delete_exchange.c new file mode 100644 index 000000000..9415335c2 --- /dev/null +++ b/src/auditordb/pg_delete_exchange.c @@ -0,0 +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 + */ +/** + * @file pg_delete_exchange.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_delete_exchange.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_delete_exchange (void *cls, + const struct TALER_MasterPublicKeyP *master_pub) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (master_pub), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_delete_exchange", + "DELETE" + " FROM auditor_exchanges" + " WHERE master_pub=$1;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_delete_exchange", + params); +} diff --git a/src/auditordb/pg_delete_exchange.h b/src/auditordb/pg_delete_exchange.h new file mode 100644 index 000000000..4b639a62b --- /dev/null +++ b/src/auditordb/pg_delete_exchange.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_get_auditor_progress_aggregation.c b/src/auditordb/pg_get_auditor_progress_aggregation.c new file mode 100644 index 000000000..a9f89d07a --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_aggregation.c @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..b20a00adf --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_aggregation.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..a160f1ccc --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_coin.c @@ -0,0 +1,77 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..46f997b36 --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_coin.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..f69f4a692 --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_deposit_confirmation.h b/src/auditordb/pg_get_auditor_progress_deposit_confirmation.h new file mode 100644 index 000000000..3b558d0c6 --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_deposit_confirmation.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_auditor_progress_deposit_confirmation.h + * @brief implementation of the get_auditor_progress_deposit_confirmation function + * @author Christian Grothoff + */ +#ifndef PG_GET_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_H +#define PG_GET_AUDITOR_PROGRESS_DEPOSIT_CONFIRMATION_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] ppdc set to where the auditor is in processing + * @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); + +#endif diff --git a/src/auditordb/pg_get_auditor_progress_purse.c b/src/auditordb/pg_get_auditor_progress_purse.c new file mode 100644 index 000000000..de8628ce7 --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_purse.c @@ -0,0 +1,68 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_purse.h b/src/auditordb/pg_get_auditor_progress_purse.h new file mode 100644 index 000000000..db8d48e8e --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_purse.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_auditor_progress_purse.h + * @brief implementation of the get_auditor_progress_purse function + * @author Christian Grothoff + */ +#ifndef PG_GET_AUDITOR_PROGRESS_PURSE_H +#define PG_GET_AUDITOR_PROGRESS_PURSE_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] ppp set to where the auditor is in processing + * @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); + + +#endif diff --git a/src/auditordb/pg_get_auditor_progress_reserve.c b/src/auditordb/pg_get_auditor_progress_reserve.c new file mode 100644 index 000000000..90923a0f7 --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_reserve.c @@ -0,0 +1,77 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_auditor_progress_reserve.h b/src/auditordb/pg_get_auditor_progress_reserve.h new file mode 100644 index 000000000..6b9cfabed --- /dev/null +++ b/src/auditordb/pg_get_auditor_progress_reserve.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_auditor_progress_reserve.h + * @brief implementation of the get_auditor_progress_reserve function + * @author Christian Grothoff + */ +#ifndef PG_GET_AUDITOR_PROGRESS_RESERVE_H +#define PG_GET_AUDITOR_PROGRESS_RESERVE_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] ppr set to where the auditor is in processing + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_get_auditor_progress_reserve ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + struct TALER_AUDITORDB_ProgressPointReserve *ppr); + +#endif diff --git a/src/auditordb/pg_get_balance_summary.c b/src/auditordb/pg_get_balance_summary.c new file mode 100644 index 000000000..a8ba733bb --- /dev/null +++ b/src/auditordb/pg_get_balance_summary.c @@ -0,0 +1,89 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_balance_summary.h b/src/auditordb/pg_get_balance_summary.h new file mode 100644 index 000000000..1fc31109f --- /dev/null +++ b/src/auditordb/pg_get_balance_summary.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_balance_summary.h + * @brief implementation of the get_balance_summary function + * @author Christian Grothoff + */ +#ifndef PG_GET_BALANCE_SUMMARY_H +#define PG_GET_BALANCE_SUMMARY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Get information about an exchange's denomination balances. + * + * @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 + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_get_balance_summary ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + struct TALER_AUDITORDB_GlobalCoinBalance *dfb); + +#endif diff --git a/src/auditordb/pg_get_denomination_balance.c b/src/auditordb/pg_get_denomination_balance.c new file mode 100644 index 000000000..10d5a4be7 --- /dev/null +++ b/src/auditordb/pg_get_denomination_balance.c @@ -0,0 +1,72 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_denomination_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_denomination_balance.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_get_denomination_balance ( + void *cls, + const struct TALER_DenominationHashP *denom_pub_hash, + struct TALER_AUDITORDB_DenominationCirculationData *dcd) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance", + &dcd->denom_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss", + &dcd->denom_loss), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk", + &dcd->denom_risk), + TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss", + &dcd->recoup_loss), + GNUNET_PQ_result_spec_uint64 ("num_issued", + &dcd->num_issued), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "auditor_denomination_pending_select", + "SELECT" + " denom_balance_val" + ",denom_balance_frac" + ",denom_loss_val" + ",denom_loss_frac" + ",num_issued" + ",denom_risk_val" + ",denom_risk_frac" + ",recoup_loss_val" + ",recoup_loss_frac" + " FROM auditor_denomination_pending" + " WHERE denom_pub_hash=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "auditor_denomination_pending_select", + params, + rs); +} diff --git a/src/auditordb/pg_get_denomination_balance.h b/src/auditordb/pg_get_denomination_balance.h new file mode 100644 index 000000000..31f377066 --- /dev/null +++ b/src/auditordb/pg_get_denomination_balance.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_denomination_balance.h + * @brief implementation of the get_denomination_balance function + * @author Christian Grothoff + */ +#ifndef PG_GET_DENOMINATION_BALANCE_H +#define PG_GET_DENOMINATION_BALANCE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Get information about a denomination key's balances. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param denom_pub_hash hash of the denomination public key + * @param[out] dcd circulation data to initialize + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_get_denomination_balance ( + void *cls, + const struct TALER_DenominationHashP *denom_pub_hash, + struct TALER_AUDITORDB_DenominationCirculationData *dcd); + +#endif diff --git a/src/auditordb/pg_get_deposit_confirmations.c b/src/auditordb/pg_get_deposit_confirmations.c new file mode 100644 index 000000000..ed8a60fb0 --- /dev/null +++ b/src/auditordb/pg_get_deposit_confirmations.c @@ -0,0 +1,185 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_deposit_confirmations.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_deposit_confirmations.h" +#include "pg_helper.h" + + +/** + * Closure for #deposit_confirmation_cb(). + */ +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; + + /** + * Closure for @e cb + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Query status to return. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Helper function for #postgres_get_deposit_confirmations(). + * To be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct DepositConfirmationContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +deposit_confirmation_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct DepositConfirmationContext *dcc = cls; + struct PostgresClosure *pg = dcc->pg; + + 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 GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("serial_id", + &serial_id), + GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", + &dc.h_contract_terms), + GNUNET_PQ_result_spec_auto_from_type ("h_extensions", + &dc.h_extensions), + GNUNET_PQ_result_spec_auto_from_type ("h_wire", + &dc.h_wire), + GNUNET_PQ_result_spec_timestamp ("exchange_timestamp", + &dc.exchange_timestamp), + GNUNET_PQ_result_spec_timestamp ("refund_deadline", + &dc.refund_deadline), + GNUNET_PQ_result_spec_timestamp ("wire_deadline", + &dc.wire_deadline), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_without_fee", + &dc.amount_without_fee), + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &dc.coin_pub), + GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", + &dc.merchant), + GNUNET_PQ_result_spec_auto_from_type ("exchange_sig", + &dc.exchange_sig), + GNUNET_PQ_result_spec_auto_from_type ("exchange_pub", + &dc.exchange_pub), + GNUNET_PQ_result_spec_auto_from_type ("master_sig", + &dc.master_sig), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + dcc->qs = i + 1; + if (GNUNET_OK != + dcc->cb (dcc->cb_cls, + serial_id, + &dc)) + break; + } +} + + +enum GNUNET_DB_QueryStatus +TAH_PG_get_deposit_confirmations ( + void *cls, + const struct TALER_MasterPublicKeyP *master_public_key, + uint64_t start_id, + 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_end + }; + struct DepositConfirmationContext dcc = { + .master_pub = master_public_key, + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "auditor_deposit_confirmation_select", + "SELECT" + " serial_id" + ",h_contract_terms" + ",h_extensions" + ",h_wire" + ",exchange_timestamp" + ",wire_deadline" + ",refund_deadline" + ",amount_without_fee_val" + ",amount_without_fee_frac" + ",coin_pub" + ",merchant_pub" + ",exchange_sig" + ",exchange_pub" + ",master_sig" /* master_sig could be normalized... */ + " FROM deposit_confirmations" + " WHERE master_pub=$1" + " AND serial_id>$2"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "auditor_deposit_confirmation_select", + params, + &deposit_confirmation_cb, + &dcc); + if (qs > 0) + return dcc.qs; + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); + return qs; +} diff --git a/src/auditordb/pg_get_deposit_confirmations.h b/src/auditordb/pg_get_deposit_confirmations.h new file mode 100644 index 000000000..48ee70634 --- /dev/null +++ b/src/auditordb/pg_get_deposit_confirmations.h @@ -0,0 +1,48 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_deposit_confirmations.h + * @brief implementation of the get_deposit_confirmations function + * @author Christian Grothoff + */ +#ifndef PG_GET_DEPOSIT_CONFIRMATIONS_H +#define PG_GET_DEPOSIT_CONFIRMATIONS_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * 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 cb function to call with results + * @param cb_cls closure for @a cb + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_get_deposit_confirmations ( + void *cls, + const struct TALER_MasterPublicKeyP *master_public_key, + uint64_t start_id, + TALER_AUDITORDB_DepositConfirmationCallback cb, + void *cb_cls); + +#endif diff --git a/src/auditordb/pg_get_predicted_balance.c b/src/auditordb/pg_get_predicted_balance.c new file mode 100644 index 000000000..07d1faae4 --- /dev/null +++ b/src/auditordb/pg_get_predicted_balance.c @@ -0,0 +1,61 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..15949fd9d --- /dev/null +++ b/src/auditordb/pg_get_predicted_balance.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_predicted_.h + * @brief implementation of the get_predicted_ function + * @author Christian Grothoff + */ +#ifndef PG_GET_PREDICTED__H +#define PG_GET_PREDICTED__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_reserve_info.c b/src/auditordb/pg_get_reserve_info.c new file mode 100644 index 000000000..6beb0c8de --- /dev/null +++ b/src/auditordb/pg_get_reserve_info.c @@ -0,0 +1,97 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_reserve_info.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_info.h" +#include "pg_helper.h" + + +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, + char **sender_account) +{ + 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[] = { + 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_timestamp ("expiration_date", + expiration_date), + GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid", + rowid), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("origin_account", + sender_account), + NULL), + GNUNET_PQ_result_spec_end + }; + + *sender_account = NULL; + PREPARE (pg, + "auditor_reserves_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" + ",expiration_date" + ",auditor_reserves_rowid" + ",origin_account" + " FROM auditor_reserves" + " WHERE reserve_pub=$1 AND master_pub=$2;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "auditor_reserves_select", + params, + rs); +} diff --git a/src/auditordb/pg_get_reserve_info.h b/src/auditordb/pg_get_reserve_info.h new file mode 100644 index 000000000..a04d23c27 --- /dev/null +++ b/src/auditordb/pg_get_reserve_info.h @@ -0,0 +1,51 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_reserve_info.h + * @brief implementation of the get_reserve_info function + * @author Christian Grothoff + */ +#ifndef PG_GET_RESERVE_INFO_H +#define PG_GET_RESERVE_INFO_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Get information about a reserve. + * + * @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 + * @param[out] sender_account from where did the money in the reserve originally come from + * @return transaction status code + */ +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, + char **sender_account); + + +#endif diff --git a/src/auditordb/pg_get_reserve_summary.c b/src/auditordb/pg_get_reserve_summary.c new file mode 100644 index 000000000..225d7e6a8 --- /dev/null +++ b/src/auditordb/pg_get_reserve_summary.c @@ -0,0 +1,88 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..d9a3ea5aa --- /dev/null +++ b/src/auditordb/pg_get_reserve_summary.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..147fffa7c --- /dev/null +++ b/src/auditordb/pg_get_wire_auditor_account_progress.c @@ -0,0 +1,68 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..ab1d2bb96 --- /dev/null +++ b/src/auditordb/pg_get_wire_auditor_account_progress.h @@ -0,0 +1,48 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..c5caf3f01 --- /dev/null +++ b/src/auditordb/pg_get_wire_auditor_progress.c @@ -0,0 +1,59 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_auditor_progress.h b/src/auditordb/pg_get_wire_auditor_progress.h new file mode 100644 index 000000000..dec554acc --- /dev/null +++ b/src/auditordb/pg_get_wire_auditor_progress.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_wire_auditor_progress.h + * @brief implementation of the get_wire_auditor_progress function + * @author Christian Grothoff + */ +#ifndef PG_GET_WIRE_AUDITOR_PROGRESS_H +#define PG_GET_WIRE_AUDITOR_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[out] pp set to where the auditor is in processing + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_get_wire_auditor_progress ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + struct TALER_AUDITORDB_WireProgressPoint *pp); + + +#endif diff --git a/src/auditordb/pg_get_wire_fee_summary.c b/src/auditordb/pg_get_wire_fee_summary.c new file mode 100644 index 000000000..8b48a4d47 --- /dev/null +++ b/src/auditordb/pg_get_wire_fee_summary.c @@ -0,0 +1,64 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_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_get_wire_fee_summary.h" +#include "pg_helper.h" + + +/** + * 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[] = { + TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee_balance", + wire_fee_balance), + GNUNET_PQ_result_spec_end + }; + + 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;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "auditor_wire_fee_balance_select", + params, + rs); +} diff --git a/src/auditordb/pg_get_wire_fee_summary.h b/src/auditordb/pg_get_wire_fee_summary.h new file mode 100644 index 000000000..c6e5bacde --- /dev/null +++ b/src/auditordb/pg_get_wire_fee_summary.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_get_wire_fee_summary.h + * @brief implementation of the get_wire_fee_summary function + * @author Christian Grothoff + */ +#ifndef PG_GET_WIRE_FEE_SUMMARY_H +#define PG_GET_WIRE_FEE_SUMMARY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * 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); + + +#endif diff --git a/src/auditordb/pg_helper.h b/src/auditordb/pg_helper.h new file mode 100644 index 000000000..7ebe5a179 --- /dev/null +++ b/src/auditordb/pg_helper.h @@ -0,0 +1,130 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_helper.h + * @brief shared internal definitions for postgres DB plugin + * @author Christian Grothoff + */ +#ifndef PG_HELPER_H +#define PG_HELPER_H + + +#include "taler_auditordb_plugin.h" + + +/** + * Type of the "cls" argument given to each of the functions in + * our API. + */ +struct PostgresClosure +{ + + /** + * Postgres connection handle. + */ + struct GNUNET_PQ_Context *conn; + + /** + * Name of the ongoing transaction, used to debug cases where + * a transaction is not properly terminated via COMMIT or + * ROLLBACK. + */ + const char *transaction_name; + + /** + * Our configuration. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * How often have we connected to the DB so far? + */ + unsigned long long prep_gen; + + /** + * Which currency should we assume all amounts to be in? + */ + char *currency; +}; + + +/** + * Prepares SQL statement @a sql under @a name for + * connection @a pg once. + * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure. + * + * @param pg a `struct PostgresClosure` + * @param name name to prepare the statement under + * @param sql actual SQL text + */ +#define PREPARE(pg,name,sql) \ + do { \ + static struct { \ + unsigned long long cnt; \ + struct PostgresClosure *pg; \ + } preps[2]; /* 2 ctrs for taler-auditor-sync*/ \ + unsigned int off = 0; \ + \ + while ( (NULL != preps[off].pg) && \ + (pg != preps[off].pg) && \ + (off < sizeof(preps) / sizeof(*preps)) ) \ + off++; \ + GNUNET_assert (off < \ + sizeof(preps) / sizeof(*preps)); \ + if (preps[off].cnt < pg->prep_gen) \ + { \ + struct GNUNET_PQ_PreparedStatement ps[] = { \ + GNUNET_PQ_make_prepare (name, sql), \ + GNUNET_PQ_PREPARED_STATEMENT_END \ + }; \ + \ + if (GNUNET_OK != \ + GNUNET_PQ_prepare_statements (pg->conn, \ + ps)) \ + { \ + GNUNET_break (0); \ + return GNUNET_DB_STATUS_HARD_ERROR; \ + } \ + preps[off].pg = pg; \ + preps[off].cnt = pg->prep_gen; \ + } \ + } while (0) + + +/** + * Wrapper macro to add the currency from the plugin's state + * when fetching amounts from the database. + * + * @param field name of the database field to fetch amount from + * @param[out] amountp pointer to amount to set + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount ( \ + field,pg->currency,amountp) + + +/** + * 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 ( \ + field,pg->currency,amountp) + + +#endif diff --git a/src/auditordb/pg_insert_auditor_progress_aggregation.c b/src/auditordb/pg_insert_auditor_progress_aggregation.c new file mode 100644 index 000000000..f119548f8 --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_aggregation.c @@ -0,0 +1,51 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_aggregation.h b/src/auditordb/pg_insert_auditor_progress_aggregation.h new file mode 100644 index 000000000..74d4b6fd6 --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_aggregation.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_auditor_progress_aggregation.h + * @brief implementation of the insert_auditor_progress_aggregation function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_AUDITOR_PROGRESS_AGGREGATION_H +#define PG_INSERT_AUDITOR_PROGRESS_AGGREGATION_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 ppa where is the auditor in processing + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_auditor_progress_aggregation ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + const struct TALER_AUDITORDB_ProgressPointAggregation *ppa); + + +#endif diff --git a/src/auditordb/pg_insert_auditor_progress_coin.c b/src/auditordb/pg_insert_auditor_progress_coin.c new file mode 100644 index 000000000..aec745c5c --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_coin.c @@ -0,0 +1,65 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..57f728cbb --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_coin.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..4f4c7390e --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c @@ -0,0 +1,51 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..21a5ed282 --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..fa4f0bd29 --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_purse.c @@ -0,0 +1,59 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..d364f2f0d --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_purse.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..864ca6f0f --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_reserve.c @@ -0,0 +1,65 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..d1e4d04e0 --- /dev/null +++ b/src/auditordb/pg_insert_auditor_progress_reserve.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_summary.c b/src/auditordb/pg_insert_balance_summary.c new file mode 100644 index 000000000..a965eefa6 --- /dev/null +++ b/src/auditordb/pg_insert_balance_summary.c @@ -0,0 +1,77 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..ee00ae7f0 --- /dev/null +++ b/src/auditordb/pg_insert_balance_summary.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..324c872a4 --- /dev/null +++ b/src/auditordb/pg_insert_denomination_balance.c @@ -0,0 +1,65 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_denomination_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_insert_denomination_balance.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_insert_denomination_balance ( + void *cls, + const struct TALER_DenominationHashP *denom_pub_hash, + const struct TALER_AUDITORDB_DenominationCirculationData *dcd) +{ + 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), + GNUNET_PQ_query_param_uint64 (&dcd->num_issued), + TALER_PQ_query_param_amount (&dcd->denom_risk), + TALER_PQ_query_param_amount (&dcd->recoup_loss), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_denomination_pending_insert", + "INSERT INTO auditor_denomination_pending " + "(denom_pub_hash" + ",denom_balance_val" + ",denom_balance_frac" + ",denom_loss_val" + ",denom_loss_frac" + ",num_issued" + ",denom_risk_val" + ",denom_risk_frac" + ",recoup_loss_val" + ",recoup_loss_frac" + ") VALUES (" + "$1,$2,$3,$4,$5,$6,$7,$8,$9,$10" + ");"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_denomination_pending_insert", + params); +} diff --git a/src/auditordb/pg_insert_denomination_balance.h b/src/auditordb/pg_insert_denomination_balance.h new file mode 100644 index 000000000..90776367c --- /dev/null +++ b/src/auditordb/pg_insert_denomination_balance.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_denomination_balance.h + * @brief implementation of the insert_denomination_balance function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_DENOMINATION_BALANCE_H +#define PG_INSERT_DENOMINATION_BALANCE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about a denomination key's balances. There + * must not be an existing record for the denomination key. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param denom_pub_hash hash of the denomination public key + * @param dcd circulation data to store + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_denomination_balance ( + void *cls, + const struct TALER_DenominationHashP *denom_pub_hash, + const struct TALER_AUDITORDB_DenominationCirculationData *dcd); + + +#endif diff --git a/src/auditordb/pg_insert_deposit_confirmation.c b/src/auditordb/pg_insert_deposit_confirmation.c new file mode 100644 index 000000000..cc52ba4e5 --- /dev/null +++ b/src/auditordb/pg_insert_deposit_confirmation.c @@ -0,0 +1,73 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_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_deposit_confirmation.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_insert_deposit_confirmation ( + void *cls, + const struct TALER_AUDITORDB_DepositConfirmation *dc) +{ + 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_extensions), + 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), + 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), + GNUNET_PQ_query_param_auto_from_type (&dc->master_sig), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_deposit_confirmation_insert", + "INSERT INTO deposit_confirmations " + "(master_pub" + ",h_contract_terms" + ",h_extensions" + ",h_wire" + ",exchange_timestamp" + ",wire_deadline" + ",refund_deadline" + ",amount_without_fee_val" + ",amount_without_fee_frac" + ",coin_pub" + ",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);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_deposit_confirmation_insert", + params); +} diff --git a/src/auditordb/pg_insert_deposit_confirmation.h b/src/auditordb/pg_insert_deposit_confirmation.h new file mode 100644 index 000000000..f3d11e3cb --- /dev/null +++ b/src/auditordb/pg_insert_deposit_confirmation.h @@ -0,0 +1,42 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_deposit_confirmation.h + * @brief implementation of the insert_deposit_confirmation function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_DEPOSIT_CONFIRMATION_H +#define PG_INSERT_DEPOSIT_CONFIRMATION_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about a deposit confirmation into the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param dc deposit confirmation information to store + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_deposit_confirmation ( + void *cls, + const struct TALER_AUDITORDB_DepositConfirmation *dc); + + +#endif diff --git a/src/auditordb/pg_insert_exchange.c b/src/auditordb/pg_insert_exchange.c new file mode 100644 index 000000000..bc84ad77c --- /dev/null +++ b/src/auditordb/pg_insert_exchange.c @@ -0,0 +1,49 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_exchange.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_exchange.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) +{ + 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_end + }; + + PREPARE (pg, + "auditor_insert_exchange", + "INSERT INTO auditor_exchanges " + "(master_pub" + ",exchange_url" + ") VALUES ($1,$2);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_insert_exchange", + params); +} diff --git a/src/auditordb/pg_insert_exchange.h b/src/auditordb/pg_insert_exchange.h new file mode 100644 index 000000000..c06f2115c --- /dev/null +++ b/src/auditordb/pg_insert_exchange.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..fa310f2ef --- /dev/null +++ b/src/auditordb/pg_insert_exchange_signkey.c @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_exchange_signkey.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_exchange_signkey.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_insert_exchange_signkey ( + void *cls, + const struct TALER_AUDITORDB_ExchangeSigningKey *sk) +{ + 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), + GNUNET_PQ_query_param_auto_from_type (&sk->exchange_pub), + GNUNET_PQ_query_param_auto_from_type (&sk->master_sig), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_insert_exchange_signkey", + "INSERT INTO auditor_exchange_signkeys " + "(master_pub" + ",ep_start" + ",ep_expire" + ",ep_end" + ",exchange_pub" + ",master_sig" + ") VALUES ($1,$2,$3,$4,$5,$6);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_insert_exchange_signkey", + params); +} diff --git a/src/auditordb/pg_insert_exchange_signkey.h b/src/auditordb/pg_insert_exchange_signkey.h new file mode 100644 index 000000000..1c1eefe35 --- /dev/null +++ b/src/auditordb/pg_insert_exchange_signkey.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_exchange_signkey.h + * @brief implementation of the insert_exchange_signkey function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_EXCHANGE_SIGNKEY_H +#define PG_INSERT_EXCHANGE_SIGNKEY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + +/** + * Insert information about a signing key of the exchange. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param sk signing key information to store + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_exchange_signkey ( + void *cls, + const struct TALER_AUDITORDB_ExchangeSigningKey *sk); + + +#endif diff --git a/src/auditordb/pg_insert_historic_denom_revenue.c b/src/auditordb/pg_insert_historic_denom_revenue.c new file mode 100644 index 000000000..d44d37340 --- /dev/null +++ b/src/auditordb/pg_insert_historic_denom_revenue.c @@ -0,0 +1,62 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_historic_denom_revenue.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_historic_denom_revenue.h" +#include "pg_helper.h" + + +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, + const struct TALER_Amount *loss_balance) +{ + 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), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_historic_denomination_revenue_insert", + "INSERT INTO auditor_historic_denomination_revenue" + "(master_pub" + ",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);"); + 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 new file mode 100644 index 000000000..2f8e005d7 --- /dev/null +++ b/src/auditordb/pg_insert_historic_denom_revenue.h @@ -0,0 +1,52 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_historic_denom_revenue.h + * @brief implementation of the insert_historic_denom_revenue function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_HISTORIC_DENOM_REVENUE_H +#define PG_INSERT_HISTORIC_DENOM_REVENUE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about an exchange's historic + * 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 + * deposit fees, melting fees, refresh fees + * and coins that were never returned? + * @param loss_balance total losses suffered by the exchange at the time + * @return transaction status code + */ +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, + const struct TALER_Amount *loss_balance); + +#endif diff --git a/src/auditordb/pg_insert_historic_reserve_revenue.c b/src/auditordb/pg_insert_historic_reserve_revenue.c new file mode 100644 index 000000000..8218aab70 --- /dev/null +++ b/src/auditordb/pg_insert_historic_reserve_revenue.c @@ -0,0 +1,57 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_historic_reserve_revenue.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_historic_reserve_revenue.h" +#include "pg_helper.h" + +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), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_historic_reserve_summary_insert", + "INSERT INTO auditor_historic_reserve_summary" + "(master_pub" + ",start_date" + ",end_date" + ",reserve_profits_val" + ",reserve_profits_frac" + ") VALUES ($1,$2,$3,$4,$5);"); + 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 new file mode 100644 index 000000000..d6c29ed08 --- /dev/null +++ b/src/auditordb/pg_insert_historic_reserve_revenue.h @@ -0,0 +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 + */ +/** + * @file pg_insert_historic_reserve_revenue.h + * @brief implementation of the insert_historic_reserve_revenue function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_HISTORIC_RESERVE_REVENUE_H +#define PG_INSERT_HISTORIC_RESERVE_REVENUE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * 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 + * @return transaction status code + */ +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); + +#endif diff --git a/src/auditordb/pg_insert_predicted_result.c b/src/auditordb/pg_insert_predicted_result.c new file mode 100644 index 000000000..4e8e54201 --- /dev/null +++ b/src/auditordb/pg_insert_predicted_result.c @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..ef9f4c3b3 --- /dev/null +++ b/src/auditordb/pg_insert_predicted_result.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_reserve_info.c b/src/auditordb/pg_insert_reserve_info.c new file mode 100644 index 000000000..22b17819e --- /dev/null +++ b/src/auditordb/pg_insert_reserve_info.c @@ -0,0 +1,84 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_reserve_info.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_info.h" +#include "pg_helper.h" + + +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) +{ + 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), + GNUNET_PQ_query_param_timestamp (&expiration_date), + NULL == origin_account + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (origin_account), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_reserves_insert", + "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" + ",expiration_date" + ",origin_account" + + ") VALUES " + "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18);"); + + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_reserves_insert", + params); +} diff --git a/src/auditordb/pg_insert_reserve_info.h b/src/auditordb/pg_insert_reserve_info.h new file mode 100644 index 000000000..5b5aa67eb --- /dev/null +++ b/src/auditordb/pg_insert_reserve_info.h @@ -0,0 +1,50 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_reserve_info.h + * @brief implementation of the insert_reserve_info function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_RESERVE_INFO_H +#define PG_INSERT_RESERVE_INFO_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about a reserve. There must not be an + * existing record for the reserve. + * + * @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 + * @return transaction status code + */ +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); + +#endif diff --git a/src/auditordb/pg_insert_reserve_summary.c b/src/auditordb/pg_insert_reserve_summary.c new file mode 100644 index 000000000..bcae388f5 --- /dev/null +++ b/src/auditordb/pg_insert_reserve_summary.c @@ -0,0 +1,75 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..b5e200766 --- /dev/null +++ b/src/auditordb/pg_insert_reserve_summary.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..b0e416a42 --- /dev/null +++ b/src/auditordb/pg_insert_wire_auditor_account_progress.c @@ -0,0 +1,61 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..72c2b595c --- /dev/null +++ b/src/auditordb/pg_insert_wire_auditor_account_progress.h @@ -0,0 +1,48 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..7853d3ff6 --- /dev/null +++ b/src/auditordb/pg_insert_wire_auditor_progress.c @@ -0,0 +1,53 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_auditor_progress.h b/src/auditordb/pg_insert_wire_auditor_progress.h new file mode 100644 index 000000000..1e3b60805 --- /dev/null +++ b/src/auditordb/pg_insert_wire_auditor_progress.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_insert_wire_auditor_progress.h + * @brief implementation of the insert_wire_auditor_progress function + * @author Christian Grothoff + */ +#ifndef PG_INSERT_WIRE_AUDITOR_PROGRESS_H +#define PG_INSERT_WIRE_AUDITOR_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 pp where is the auditor in processing + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_wire_auditor_progress ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + const struct TALER_AUDITORDB_WireProgressPoint *pp); + + +#endif diff --git a/src/auditordb/pg_insert_wire_fee_summary.c b/src/auditordb/pg_insert_wire_fee_summary.c new file mode 100644 index 000000000..2de51a7c8 --- /dev/null +++ b/src/auditordb/pg_insert_wire_fee_summary.c @@ -0,0 +1,52 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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); +} diff --git a/src/auditordb/pg_insert_wire_fee_summary.h b/src/auditordb/pg_insert_wire_fee_summary.h new file mode 100644 index 000000000..9c969fb65 --- /dev/null +++ b/src/auditordb/pg_insert_wire_fee_summary.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..964c01925 --- /dev/null +++ b/src/auditordb/pg_list_exchanges.c @@ -0,0 +1,126 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 #postgres_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_list_exchanges.h b/src/auditordb/pg_list_exchanges.h new file mode 100644 index 000000000..4396603ee --- /dev/null +++ b/src/auditordb/pg_list_exchanges.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_list_exchanges.h + * @brief implementation of the list_exchanges function + * @author Christian Grothoff + */ +#ifndef PG_LIST_EXCHANGES_H +#define PG_LIST_EXCHANGES_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Obtain information about exchanges this auditor is auditing. + * + * @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 + */ +enum GNUNET_DB_QueryStatus +TAH_PG_list_exchanges (void *cls, + TALER_AUDITORDB_ExchangeCallback cb, + void *cb_cls); + + +#endif diff --git a/src/auditordb/pg_select_historic_denom_revenue.c b/src/auditordb/pg_select_historic_denom_revenue.c new file mode 100644 index 000000000..efeb81b13 --- /dev/null +++ b/src/auditordb/pg_select_historic_denom_revenue.c @@ -0,0 +1,151 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_select_historic_denom_revenue.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_select_historic_denom_revenue.h" +#include "pg_helper.h" + + +/** + * Closure for #historic_denom_revenue_cb(). + */ +struct HistoricDenomRevenueContext +{ + /** + * Function to call for each result. + */ + TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Number of results processed. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Helper function for #postgres_select_historic_denom_revenue(). + * To be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct HistoricRevenueContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +historic_denom_revenue_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct HistoricDenomRevenueContext *hrc = cls; + struct PostgresClosure *pg = hrc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_DenominationHashP denom_pub_hash; + struct GNUNET_TIME_Timestamp revenue_timestamp; + struct TALER_Amount revenue_balance; + struct TALER_Amount loss; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", + &denom_pub_hash), + GNUNET_PQ_result_spec_timestamp ("revenue_timestamp", + &revenue_timestamp), + TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance", + &revenue_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance", + &loss), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + hrc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + + hrc->qs = i + 1; + if (GNUNET_OK != + hrc->cb (hrc->cb_cls, + &denom_pub_hash, + revenue_timestamp, + &revenue_balance, + &loss)) + break; + } +} + + +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 = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "auditor_historic_denomination_revenue_select", + "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;"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "auditor_historic_denomination_revenue_select", + params, + &historic_denom_revenue_cb, + &hrc); + if (qs <= 0) + return qs; + return hrc.qs; +} diff --git a/src/auditordb/pg_select_historic_denom_revenue.h b/src/auditordb/pg_select_historic_denom_revenue.h new file mode 100644 index 000000000..68afcd019 --- /dev/null +++ b/src/auditordb/pg_select_historic_denom_revenue.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_select_historic_denom_revenue.h + * @brief implementation of the select_historic_denom_revenue function + * @author Christian Grothoff + */ +#ifndef PG_SELECT_HISTORIC_DENOM_REVENUE_H +#define PG_SELECT_HISTORIC_DENOM_REVENUE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * 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 + */ +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); + +#endif diff --git a/src/auditordb/pg_select_historic_reserve_revenue.c b/src/auditordb/pg_select_historic_reserve_revenue.c new file mode 100644 index 000000000..e3172f9fe --- /dev/null +++ b/src/auditordb/pg_select_historic_reserve_revenue.c @@ -0,0 +1,144 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_select_historic_reserve_revenue.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_select_historic_reserve_revenue.h" +#include "pg_helper.h" + + +/** + * Closure for #historic_reserve_revenue_cb(). + */ +struct HistoricReserveRevenueContext +{ + /** + * Function to call for each result. + */ + TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Number of results processed. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Helper function for #postgres_select_historic_reserve_revenue(). + * To be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct HistoricRevenueContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +historic_reserve_revenue_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct HistoricReserveRevenueContext *hrc = cls; + struct PostgresClosure *pg = hrc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + struct GNUNET_TIME_Timestamp start_date; + struct GNUNET_TIME_Timestamp end_date; + struct TALER_Amount reserve_profits; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_timestamp ("start_date", + &start_date), + GNUNET_PQ_result_spec_timestamp ("end_date", + &end_date), + TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits", + &reserve_profits), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + hrc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + hrc->qs = i + 1; + if (GNUNET_OK != + hrc->cb (hrc->cb_cls, + start_date, + end_date, + &reserve_profits)) + break; + } +} + + +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; + struct HistoricReserveRevenueContext hrc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + + PREPARE (pg, + "auditor_historic_reserve_summary_select", + "SELECT" + " start_date" + ",end_date" + ",reserve_profits_val" + ",reserve_profits_frac" + " FROM auditor_historic_reserve_summary" + " WHERE master_pub=$1;"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "auditor_historic_reserve_summary_select", + params, + &historic_reserve_revenue_cb, + &hrc); + if (0 >= qs) + return qs; + return hrc.qs; +} diff --git a/src/auditordb/pg_select_historic_reserve_revenue.h b/src/auditordb/pg_select_historic_reserve_revenue.h new file mode 100644 index 000000000..87a6b06a1 --- /dev/null +++ b/src/auditordb/pg_select_historic_reserve_revenue.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_select_historic_reserve_revenue.h + * @brief implementation of the select_historic_reserve_revenue function + * @author Christian Grothoff + */ +#ifndef PG_SELECT_HISTORIC_RESERVE_REVENUE_H +#define PG_SELECT_HISTORIC_RESERVE_REVENUE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + +/** + * 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 + */ +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); + + +#endif diff --git a/src/auditordb/pg_update_auditor_progress_aggregation.c b/src/auditordb/pg_update_auditor_progress_aggregation.c new file mode 100644 index 000000000..24404e4aa --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_aggregation.c @@ -0,0 +1,50 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..f8917ca7c --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_aggregation.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..1d7e01525 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_coin.c @@ -0,0 +1,64 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..0ce7f1495 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_coin.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..9a244f5f1 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_deposit_confirmation.c @@ -0,0 +1,50 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..7927e485b --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_deposit_confirmation.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..c8fb64660 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_purse.c @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..12a643e52 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_purse.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..a8ef39286 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_reserve.c @@ -0,0 +1,64 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..3feaa0dc4 --- /dev/null +++ b/src/auditordb/pg_update_auditor_progress_reserve.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_summary.c b/src/auditordb/pg_update_balance_summary.c new file mode 100644 index 000000000..96f074cba --- /dev/null +++ b/src/auditordb/pg_update_balance_summary.c @@ -0,0 +1,75 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..dbb721ecc --- /dev/null +++ b/src/auditordb/pg_update_balance_summary.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..2fb0f5647 --- /dev/null +++ b/src/auditordb/pg_update_denomination_balance.c @@ -0,0 +1,62 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_denomination_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_update_denomination_balance.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_update_denomination_balance ( + void *cls, + const struct TALER_DenominationHashP *denom_pub_hash, + const struct TALER_AUDITORDB_DenominationCirculationData *dcd) +{ + 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), + GNUNET_PQ_query_param_uint64 (&dcd->num_issued), + TALER_PQ_query_param_amount (&dcd->denom_risk), + TALER_PQ_query_param_amount (&dcd->recoup_loss), + GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), + GNUNET_PQ_query_param_end + }; + + 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"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_denomination_pending_update", + params); +} diff --git a/src/auditordb/pg_update_denomination_balance.h b/src/auditordb/pg_update_denomination_balance.h new file mode 100644 index 000000000..474fcaafd --- /dev/null +++ b/src/auditordb/pg_update_denomination_balance.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_denomination_balance.h + * @brief implementation of the update_denomination_balance function + * @author Christian Grothoff + */ +#ifndef PG_UPDATE_DENOMINATION_BALANCE_H +#define PG_UPDATE_DENOMINATION_BALANCE_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Update information about a denomination key's balances. There + * must be an existing record for the denomination key. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param denom_pub_hash hash of the denomination public key + * @param dcd circulation data to store + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_update_denomination_balance ( + void *cls, + const struct TALER_DenominationHashP *denom_pub_hash, + const struct TALER_AUDITORDB_DenominationCirculationData *dcd); + + +#endif diff --git a/src/auditordb/pg_update_predicted_result.c b/src/auditordb/pg_update_predicted_result.c new file mode 100644 index 000000000..5c9618adf --- /dev/null +++ b/src/auditordb/pg_update_predicted_result.c @@ -0,0 +1,55 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..e70d079d6 --- /dev/null +++ b/src/auditordb/pg_update_predicted_result.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_reserve_info.c b/src/auditordb/pg_update_reserve_info.c new file mode 100644 index 000000000..49d4f0256 --- /dev/null +++ b/src/auditordb/pg_update_reserve_info.c @@ -0,0 +1,72 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_reserve_info.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_info.h" +#include "pg_helper.h" + + +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), + 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", + "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;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_reserves_update", + params); +} diff --git a/src/auditordb/pg_update_reserve_info.h b/src/auditordb/pg_update_reserve_info.h new file mode 100644 index 000000000..1c7707f07 --- /dev/null +++ b/src/auditordb/pg_update_reserve_info.h @@ -0,0 +1,48 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_reserve_info.h + * @brief implementation of the update_reserve_info function + * @author Christian Grothoff + */ +#ifndef PG_UPDATE_RESERVE_INFO_H +#define PG_UPDATE_RESERVE_INFO_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Update information about a reserve. Destructively updates an + * existing record, which must already exist. + * + * @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 + */ +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); + +#endif diff --git a/src/auditordb/pg_update_reserve_summary.c b/src/auditordb/pg_update_reserve_summary.c new file mode 100644 index 000000000..3cb18ea5e --- /dev/null +++ b/src/auditordb/pg_update_reserve_summary.c @@ -0,0 +1,69 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..50d730750 --- /dev/null +++ b/src/auditordb/pg_update_reserve_summary.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..ff01be09c --- /dev/null +++ b/src/auditordb/pg_update_wire_auditor_account_progress.c @@ -0,0 +1,59 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..03f5701c0 --- /dev/null +++ b/src/auditordb/pg_update_wire_auditor_account_progress.h @@ -0,0 +1,49 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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 new file mode 100644 index 000000000..5fb0ff31a --- /dev/null +++ b/src/auditordb/pg_update_wire_auditor_progress.c @@ -0,0 +1,52 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @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_auditor_progress.h b/src/auditordb/pg_update_wire_auditor_progress.h new file mode 100644 index 000000000..e46c6119b --- /dev/null +++ b/src/auditordb/pg_update_wire_auditor_progress.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_wire_auditor_progress.h + * @brief implementation of the update_wire_auditor_progress function + * @author Christian Grothoff + */ +#ifndef PG_UPDATE_WIRE_AUDITOR_PROGRESS_H +#define PG_UPDATE_WIRE_AUDITOR_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 pp where is the auditor in processing + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TAH_PG_update_wire_auditor_progress ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + const struct TALER_AUDITORDB_WireProgressPoint *pp); + + +#endif diff --git a/src/auditordb/pg_update_wire_fee_summary.c b/src/auditordb/pg_update_wire_fee_summary.c new file mode 100644 index 000000000..28ee39c44 --- /dev/null +++ b/src/auditordb/pg_update_wire_fee_summary.c @@ -0,0 +1,51 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_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_update_wire_fee_summary.h" +#include "pg_helper.h" + + +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), + 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;"); + 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 new file mode 100644 index 000000000..5a1760eeb --- /dev/null +++ b/src/auditordb/pg_update_wire_fee_summary.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + */ +/** + * @file pg_update_wire_fee_summary.h + * @brief implementation of the update_wire_fee_summary function + * @author Christian Grothoff + */ +#ifndef PG_UPDATE_WIRE_FEE_SUMMARY_H +#define PG_UPDATE_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. 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 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 318311d4d..2a6f200cc 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -21,69 +21,77 @@ */ #include "platform.h" #include "taler_pq_lib.h" -#include "taler_auditordb_plugin.h" #include #include - +#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_del_reserve_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_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_historic_reserve_revenue.h" +#include "pg_helper.h" #define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", \ __VA_ARGS__) -/** - * Wrapper macro to add the currency from the plugin's state - * when fetching amounts from the database. - * - * @param field name of the database field to fetch amount from - * @param[out] amountp pointer to amount to set - */ -#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) \ - TALER_PQ_result_spec_amount ( \ - field,pg->currency,amountp) - -/** - * 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 ( \ - field,pg->currency,amountp) - - -/** - * Type of the "cls" argument given to each of the functions in - * our API. - */ -struct PostgresClosure -{ - - /** - * Postgres connection handle. - */ - struct GNUNET_PQ_Context *conn; - - /** - * Name of the ongoing transaction, used to debug cases where - * a transaction is not properly terminated via COMMIT or - * ROLLBACK. - */ - const char *transaction_name; - - /** - * Our configuration. - */ - const struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * Which currency should we assume all amounts to be in? - */ - char *currency; -}; - - /** * Drop all auditor tables OR deletes recoverable auditor state. * This should only be used by testcases or when restarting the @@ -154,586 +162,6 @@ postgres_create_tables (void *cls) static enum GNUNET_GenericReturnValue setup_connection (struct PostgresClosure *pg) { - struct GNUNET_PQ_PreparedStatement ps[] = { - /* used in #postgres_commit */ - GNUNET_PQ_make_prepare ("do_commit", - "COMMIT"), - /* used in #postgres_insert_exchange */ - GNUNET_PQ_make_prepare ("auditor_insert_exchange", - "INSERT INTO auditor_exchanges " - "(master_pub" - ",exchange_url" - ") VALUES ($1,$2);"), - /* used in #postgres_delete_exchange */ - GNUNET_PQ_make_prepare ("auditor_delete_exchange", - "DELETE" - " FROM auditor_exchanges" - " WHERE master_pub=$1;"), - /* used in #postgres_list_exchanges */ - GNUNET_PQ_make_prepare ("auditor_list_exchanges", - "SELECT" - " master_pub" - ",exchange_url" - " FROM auditor_exchanges"), - /* used in #postgres_insert_exchange_signkey */ - GNUNET_PQ_make_prepare ("auditor_insert_exchange_signkey", - "INSERT INTO auditor_exchange_signkeys " - "(master_pub" - ",ep_start" - ",ep_expire" - ",ep_end" - ",exchange_pub" - ",master_sig" - ") VALUES ($1,$2,$3,$4,$5,$6);"), - /* Used in #postgres_insert_deposit_confirmation() */ - GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_insert", - "INSERT INTO deposit_confirmations " - "(master_pub" - ",h_contract_terms" - ",h_extensions" - ",h_wire" - ",exchange_timestamp" - ",wire_deadline" - ",refund_deadline" - ",amount_without_fee_val" - ",amount_without_fee_frac" - ",coin_pub" - ",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);"), - /* Used in #postgres_get_deposit_confirmations() */ - GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_select", - "SELECT" - " serial_id" - ",h_contract_terms" - ",h_extensions" - ",h_wire" - ",exchange_timestamp" - ",wire_deadline" - ",refund_deadline" - ",amount_without_fee_val" - ",amount_without_fee_frac" - ",coin_pub" - ",merchant_pub" - ",exchange_sig" - ",exchange_pub" - ",master_sig" /* master_sig could be normalized... */ - " FROM deposit_confirmations" - " WHERE master_pub=$1" - " AND serial_id>$2"), - /* Used in #postgres_update_auditor_progress_reserve() */ - GNUNET_PQ_make_prepare ("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"), - /* Used in #postgres_get_auditor_progress_reserve() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_insert_auditor_progress_reserve() */ - GNUNET_PQ_make_prepare ("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);"), - /* Used in #postgres_update_auditor_progress_purse() */ - GNUNET_PQ_make_prepare ("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"), - /* Used in #postgres_get_auditor_progress_purse() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_insert_auditor_progress_purse() */ - GNUNET_PQ_make_prepare ("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);"), - /* Used in #postgres_update_auditor_progress_aggregation() */ - GNUNET_PQ_make_prepare ("auditor_progress_update_aggregation", - "UPDATE auditor_progress_aggregation SET " - " last_wire_out_serial_id=$1" - " WHERE master_pub=$2"), - /* Used in #postgres_get_auditor_progress_aggregation() */ - GNUNET_PQ_make_prepare ("auditor_progress_select_aggregation", - "SELECT" - " last_wire_out_serial_id" - " FROM auditor_progress_aggregation" - " WHERE master_pub=$1;"), - /* Used in #postgres_insert_auditor_progress_aggregation() */ - GNUNET_PQ_make_prepare ("auditor_progress_insert_aggregation", - "INSERT INTO auditor_progress_aggregation " - "(master_pub" - ",last_wire_out_serial_id" - ") VALUES ($1,$2);"), - /* Used in #postgres_update_auditor_progress_deposit_confirmation() */ - GNUNET_PQ_make_prepare ("auditor_progress_update_deposit_confirmation", - "UPDATE auditor_progress_deposit_confirmation SET " - " last_deposit_confirmation_serial_id=$1" - " WHERE master_pub=$2"), - /* Used in #postgres_get_auditor_progress_deposit_confirmation() */ - GNUNET_PQ_make_prepare ("auditor_progress_select_deposit_confirmation", - "SELECT" - " last_deposit_confirmation_serial_id" - " FROM auditor_progress_deposit_confirmation" - " WHERE master_pub=$1;"), - /* Used in #postgres_insert_auditor_progress_deposit_confirmation() */ - GNUNET_PQ_make_prepare ("auditor_progress_insert_deposit_confirmation", - "INSERT INTO auditor_progress_deposit_confirmation " - "(master_pub" - ",last_deposit_confirmation_serial_id" - ") VALUES ($1,$2);"), - /* Used in #postgres_update_auditor_progress_coin() */ - GNUNET_PQ_make_prepare ("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"), - /* Used in #postgres_get_auditor_progress_coin() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_insert_auditor_progress() */ - GNUNET_PQ_make_prepare ("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);"), - /* Used in #postgres_insert_wire_auditor_account_progress() */ - GNUNET_PQ_make_prepare ("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);"), - /* Used in #postgres_update_wire_auditor_account_progress() */ - GNUNET_PQ_make_prepare ("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"), - /* Used in #postgres_get_wire_auditor_account_progress() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_insert_wire_auditor_progress() */ - GNUNET_PQ_make_prepare ("wire_auditor_progress_insert", - "INSERT INTO wire_auditor_progress " - "(master_pub" - ",last_timestamp" - ",last_reserve_close_uuid" - ") VALUES ($1,$2,$3);"), - /* Used in #postgres_update_wire_auditor_progress() */ - GNUNET_PQ_make_prepare ("wire_auditor_progress_update", - "UPDATE wire_auditor_progress SET " - " last_timestamp=$1" - ",last_reserve_close_uuid=$2" - " WHERE master_pub=$3"), - /* Used in #postgres_get_wire_auditor_progress() */ - GNUNET_PQ_make_prepare ("wire_auditor_progress_select", - "SELECT" - " last_timestamp" - ",last_reserve_close_uuid" - " FROM wire_auditor_progress" - " WHERE master_pub=$1;"), - /* Used in #postgres_insert_reserve_info() */ - GNUNET_PQ_make_prepare ("auditor_reserves_insert", - "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" - ",expiration_date" - ",origin_account" - ") VALUES " - "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18);"), - /* Used in #postgres_update_reserve_info() */ - GNUNET_PQ_make_prepare ("auditor_reserves_update", - "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;"), - /* Used in #postgres_get_reserve_info() */ - GNUNET_PQ_make_prepare ("auditor_reserves_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" - ",expiration_date" - ",auditor_reserves_rowid" - ",origin_account" - " FROM auditor_reserves" - " WHERE reserve_pub=$1 AND master_pub=$2;"), - /* Used in #postgres_del_reserve_info() */ - GNUNET_PQ_make_prepare ("auditor_reserves_delete", - "DELETE" - " FROM auditor_reserves" - " WHERE reserve_pub=$1 AND master_pub=$2;"), - /* Used in #postgres_insert_reserve_summary() */ - GNUNET_PQ_make_prepare ("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)"), - /* Used in #postgres_update_reserve_summary() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_get_reserve_summary() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_insert_wire_fee_summary() */ - GNUNET_PQ_make_prepare ("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)"), - /* Used in #postgres_update_wire_fee_summary() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_get_wire_fee_summary() */ - GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_select", - "SELECT" - " wire_fee_balance_val" - ",wire_fee_balance_frac" - " FROM auditor_wire_fee_balance" - " WHERE master_pub=$1;"), - /* Used in #postgres_insert_denomination_balance() */ - GNUNET_PQ_make_prepare ("auditor_denomination_pending_insert", - "INSERT INTO auditor_denomination_pending " - "(denom_pub_hash" - ",denom_balance_val" - ",denom_balance_frac" - ",denom_loss_val" - ",denom_loss_frac" - ",num_issued" - ",denom_risk_val" - ",denom_risk_frac" - ",recoup_loss_val" - ",recoup_loss_frac" - ") VALUES (" - "$1,$2,$3,$4,$5,$6,$7,$8,$9,$10" - ");"), - /* Used in #postgres_update_denomination_balance() */ - GNUNET_PQ_make_prepare ("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"), - /* Used in #postgres_get_denomination_balance() */ - GNUNET_PQ_make_prepare ("auditor_denomination_pending_select", - "SELECT" - " denom_balance_val" - ",denom_balance_frac" - ",denom_loss_val" - ",denom_loss_frac" - ",num_issued" - ",denom_risk_val" - ",denom_risk_frac" - ",recoup_loss_val" - ",recoup_loss_frac" - " FROM auditor_denomination_pending" - " WHERE denom_pub_hash=$1"), - /* Used in #postgres_insert_balance_summary() */ - GNUNET_PQ_make_prepare ("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);"), - /* Used in #postgres_update_balance_summary() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_get_balance_summary() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_insert_historic_denom_revenue() */ - GNUNET_PQ_make_prepare ("auditor_historic_denomination_revenue_insert", - "INSERT INTO auditor_historic_denomination_revenue" - "(master_pub" - ",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);"), - /* Used in #postgres_select_historic_denom_revenue() */ - GNUNET_PQ_make_prepare ("auditor_historic_denomination_revenue_select", - "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;"), - /* Used in #postgres_insert_historic_reserve_revenue() */ - GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_insert", - "INSERT INTO auditor_historic_reserve_summary" - "(master_pub" - ",start_date" - ",end_date" - ",reserve_profits_val" - ",reserve_profits_frac" - ") VALUES ($1,$2,$3,$4,$5);"), - /* Used in #postgres_select_historic_reserve_revenue() */ - GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_select", - "SELECT" - " start_date" - ",end_date" - ",reserve_profits_val" - ",reserve_profits_frac" - " FROM auditor_historic_reserve_summary" - " WHERE master_pub=$1;"), - /* Used in #postgres_insert_predicted_result() */ - GNUNET_PQ_make_prepare ("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);"), - /* Used in #postgres_update_predicted_result() */ - GNUNET_PQ_make_prepare ("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;"), - /* Used in #postgres_get_predicted_balance() */ - GNUNET_PQ_make_prepare ("auditor_predicted_result_select", - "SELECT" - " balance_val" - ",balance_frac" - ",drained_val" - ",drained_frac" - " FROM auditor_predicted_result" - " WHERE master_pub=$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 @@ -749,10 +177,11 @@ setup_connection (struct PostgresClosure *pg) "auditordb-postgres", NULL, es, - ps); + NULL); if (NULL == db_conn) return GNUNET_SYSERR; pg->conn = db_conn; + pg->prep_gen++; return GNUNET_OK; } @@ -867,6 +296,9 @@ postgres_commit (void *cls) GNUNET_PQ_query_param_end }; + PREPARE (pg, + "do_commit", + "COMMIT"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "do_commit", params); @@ -928,2101 +360,6 @@ postgres_gc (void *cls) } -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_exchange (void *cls, - const struct TALER_MasterPublicKeyP *master_pub, - const char *exchange_url) -{ - 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_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_insert_exchange", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_delete_exchange (void *cls, - const struct TALER_MasterPublicKeyP *master_pub) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_delete_exchange", - params); -} - - -/** - * 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 #postgres_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); - } -} - - -/** - * Obtain information about exchanges this auditor is auditing. - * - * @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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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; - - 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; -} - - -/** - * Insert information about a signing key of the exchange. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param sk signing key information to store - * @return query result status - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_exchange_signkey ( - void *cls, - const struct TALER_AUDITORDB_ExchangeSigningKey *sk) -{ - 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), - GNUNET_PQ_query_param_auto_from_type (&sk->exchange_pub), - GNUNET_PQ_query_param_auto_from_type (&sk->master_sig), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_insert_exchange_signkey", - params); -} - - -/** - * Insert information about a deposit confirmation into the database. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param dc deposit confirmation information to store - * @return query result status - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_deposit_confirmation ( - void *cls, - const struct TALER_AUDITORDB_DepositConfirmation *dc) -{ - 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_extensions), - 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), - 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), - GNUNET_PQ_query_param_auto_from_type (&dc->master_sig), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_deposit_confirmation_insert", - params); -} - - -/** - * Closure for #deposit_confirmation_cb(). - */ -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; - - /** - * Closure for @e cb - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Query status to return. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Helper function for #postgres_get_deposit_confirmations(). - * To be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct DepositConfirmationContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -deposit_confirmation_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct DepositConfirmationContext *dcc = cls; - struct PostgresClosure *pg = dcc->pg; - - 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 GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("serial_id", - &serial_id), - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &dc.h_contract_terms), - GNUNET_PQ_result_spec_auto_from_type ("h_extensions", - &dc.h_extensions), - GNUNET_PQ_result_spec_auto_from_type ("h_wire", - &dc.h_wire), - GNUNET_PQ_result_spec_timestamp ("exchange_timestamp", - &dc.exchange_timestamp), - GNUNET_PQ_result_spec_timestamp ("refund_deadline", - &dc.refund_deadline), - GNUNET_PQ_result_spec_timestamp ("wire_deadline", - &dc.wire_deadline), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_without_fee", - &dc.amount_without_fee), - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &dc.coin_pub), - GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", - &dc.merchant), - GNUNET_PQ_result_spec_auto_from_type ("exchange_sig", - &dc.exchange_sig), - GNUNET_PQ_result_spec_auto_from_type ("exchange_pub", - &dc.exchange_pub), - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - &dc.master_sig), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - dcc->qs = i + 1; - if (GNUNET_OK != - dcc->cb (dcc->cb_cls, - serial_id, - &dc)) - break; - } -} - - -/** - * 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 cb function to call with results - * @param cb_cls closure for @a cb - * @return query result status - */ -static enum GNUNET_DB_QueryStatus -postgres_get_deposit_confirmations ( - void *cls, - const struct TALER_MasterPublicKeyP *master_public_key, - uint64_t start_id, - 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_end - }; - struct DepositConfirmationContext dcc = { - .master_pub = master_public_key, - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "auditor_deposit_confirmation_select", - params, - &deposit_confirmation_cb, - &dcc); - if (qs > 0) - return dcc.qs; - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); - return qs; -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_insert_reserve", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_update_reserve", - params); -} - - -/** - * 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] ppr set to where the auditor is in processing - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_progress_select_reserve", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_insert_purse", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_update_purse", - params); -} - - -/** - * 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] ppp set to where the auditor is in processing - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_progress_select_purse", - params, - rs); -} - - -/** - * 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 ppa where is the auditor in processing - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_insert_aggregation", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_update_aggregation", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_progress_select_aggregation", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_insert_deposit_confirmation", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_update_deposit_confirmation", - params); -} - - -/** - * 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 - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_progress_select_deposit_confirmation", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_insert_coin", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_progress_update_coin", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_progress_select_coin", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "wire_auditor_account_progress_insert", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "wire_auditor_account_progress_update", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "wire_auditor_account_progress_select", - params, - rs); -} - - -/** - * 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 pp where is the auditor in processing - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "wire_auditor_progress_insert", - params); -} - - -/** - * 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 pp where is the auditor in processing - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "wire_auditor_progress_update", - params); -} - - -/** - * 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] pp set to where the auditor is in processing - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "wire_auditor_progress_select", - params, - rs); -} - - -/** - * Insert information about a reserve. There must not be an - * existing record for the reserve. - * - * @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 - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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) -{ - 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), - GNUNET_PQ_query_param_timestamp (&expiration_date), - NULL == origin_account - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (origin_account), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_reserves_insert", - params); -} - - -/** - * Update information about a reserve. Destructively updates an - * existing record, which must already exist. - * - * @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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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), - 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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_reserves_update", - params); -} - - -/** - * Delete information about a reserve. - * - * @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 - */ -static enum GNUNET_DB_QueryStatus -postgres_del_reserve_info (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_MasterPublicKeyP *master_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_reserves_delete", - params); -} - - -/** - * Get information about a reserve. - * - * @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 - * @param[out] sender_account from where did the money in the reserve originally come from - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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, - char **sender_account) -{ - 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[] = { - 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_timestamp ("expiration_date", - expiration_date), - GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid", - rowid), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("origin_account", - sender_account), - NULL), - GNUNET_PQ_result_spec_end - }; - - *sender_account = NULL; - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_reserves_select", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - 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); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_reserve_balance_update", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_reserve_balance_select", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_wire_fee_balance_insert", - params); -} - - -/** - * Insert information about exchange's wire fee balance. 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 wire_fee_balance amount the exchange gained in wire fees - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_wire_fee_balance_update", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee_balance", - wire_fee_balance), - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_wire_fee_balance_select", - params, - rs); -} - - -/** - * Insert information about a denomination key's balances. There - * must not be an existing record for the denomination key. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param denom_pub_hash hash of the denomination public key - * @param dcd circulation data to store - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_denomination_balance ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - const struct TALER_AUDITORDB_DenominationCirculationData *dcd) -{ - 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), - GNUNET_PQ_query_param_uint64 (&dcd->num_issued), - TALER_PQ_query_param_amount (&dcd->denom_risk), - TALER_PQ_query_param_amount (&dcd->recoup_loss), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_denomination_pending_insert", - params); -} - - -/** - * Update information about a denomination key's balances. There - * must be an existing record for the denomination key. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param denom_pub_hash hash of the denomination public key - * @param dcd circulation data to store - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_update_denomination_balance ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - const struct TALER_AUDITORDB_DenominationCirculationData *dcd) -{ - 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), - GNUNET_PQ_query_param_uint64 (&dcd->num_issued), - TALER_PQ_query_param_amount (&dcd->denom_risk), - TALER_PQ_query_param_amount (&dcd->recoup_loss), - GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_denomination_pending_update", - params); -} - - -/** - * Get information about a denomination key's balances. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param denom_pub_hash hash of the denomination public key - * @param[out] dcd circulation data to initialize - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_get_denomination_balance ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - struct TALER_AUDITORDB_DenominationCirculationData *dcd) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance", - &dcd->denom_balance), - TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss", - &dcd->denom_loss), - TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk", - &dcd->denom_risk), - TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss", - &dcd->recoup_loss), - GNUNET_PQ_result_spec_uint64 ("num_issued", - &dcd->num_issued), - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_denomination_pending_select", - params, - rs); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_balance_summary_insert", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_balance_summary_update", - params); -} - - -/** - * Get information about an exchange's denomination balances. - * - * @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 - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_balance_summary_select", - params, - rs); -} - - -/** - * Insert information about an exchange's historic - * 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 - * deposit fees, melting fees, refresh fees - * and coins that were never returned? - * @param loss_balance total losses suffered by the exchange at the time - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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, - const struct TALER_Amount *loss_balance) -{ - 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), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_historic_denomination_revenue_insert", - params); -} - - -/** - * Closure for #historic_denom_revenue_cb(). - */ -struct HistoricDenomRevenueContext -{ - /** - * Function to call for each result. - */ - TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Number of results processed. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Helper function for #postgres_select_historic_denom_revenue(). - * To be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct HistoricRevenueContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -historic_denom_revenue_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct HistoricDenomRevenueContext *hrc = cls; - struct PostgresClosure *pg = hrc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_DenominationHashP denom_pub_hash; - struct GNUNET_TIME_Timestamp revenue_timestamp; - struct TALER_Amount revenue_balance; - struct TALER_Amount loss; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &denom_pub_hash), - GNUNET_PQ_result_spec_timestamp ("revenue_timestamp", - &revenue_timestamp), - TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance", - &revenue_balance), - TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance", - &loss), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - hrc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - - hrc->qs = i + 1; - if (GNUNET_OK != - hrc->cb (hrc->cb_cls, - &denom_pub_hash, - revenue_timestamp, - &revenue_balance, - &loss)) - break; - } -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "auditor_historic_denomination_revenue_select", - params, - &historic_denom_revenue_cb, - &hrc); - if (qs <= 0) - return qs; - return hrc.qs; -} - - -/** - * 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 - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_historic_reserve_summary_insert", - params); -} - - -/** - * Closure for #historic_reserve_revenue_cb(). - */ -struct HistoricReserveRevenueContext -{ - /** - * Function to call for each result. - */ - TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Number of results processed. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Helper function for #postgres_select_historic_reserve_revenue(). - * To be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct HistoricRevenueContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -historic_reserve_revenue_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct HistoricReserveRevenueContext *hrc = cls; - struct PostgresClosure *pg = hrc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct GNUNET_TIME_Timestamp start_date; - struct GNUNET_TIME_Timestamp end_date; - struct TALER_Amount reserve_profits; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("start_date", - &start_date), - GNUNET_PQ_result_spec_timestamp ("end_date", - &end_date), - TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits", - &reserve_profits), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - hrc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - hrc->qs = i + 1; - if (GNUNET_OK != - hrc->cb (hrc->cb_cls, - start_date, - end_date, - &reserve_profits)) - break; - } -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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; - struct HistoricReserveRevenueContext hrc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "auditor_historic_reserve_summary_select", - params, - &historic_reserve_revenue_cb, - &hrc); - if (0 >= qs) - return qs; - return hrc.qs; -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_predicted_result_insert", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "auditor_predicted_result_update", - params); -} - - -/** - * 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 - */ -static enum GNUNET_DB_QueryStatus -postgres_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 - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "auditor_predicted_result_select", - params, - rs); -} - - /** * Initialize Postgres database subsystem. * @@ -3055,90 +392,122 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->rollback = &postgres_rollback; plugin->gc = &postgres_gc; - plugin->insert_exchange = &postgres_insert_exchange; - plugin->delete_exchange = &postgres_delete_exchange; - plugin->list_exchanges = &postgres_list_exchanges; - plugin->insert_exchange_signkey = &postgres_insert_exchange_signkey; - plugin->insert_deposit_confirmation = &postgres_insert_deposit_confirmation; - plugin->get_deposit_confirmations = &postgres_get_deposit_confirmations; + plugin->insert_exchange + = &TAH_PG_insert_exchange; + plugin->delete_exchange + = &TAH_PG_delete_exchange; + plugin->list_exchanges + = &TAH_PG_list_exchanges; + + plugin->insert_exchange_signkey + = &TAH_PG_insert_exchange_signkey; + plugin->insert_deposit_confirmation + = &TAH_PG_insert_deposit_confirmation; + plugin->get_deposit_confirmations + = &TAH_PG_get_deposit_confirmations; plugin->get_auditor_progress_reserve - = &postgres_get_auditor_progress_reserve; + = &TAH_PG_get_auditor_progress_reserve; plugin->update_auditor_progress_reserve - = &postgres_update_auditor_progress_reserve; + = &TAH_PG_update_auditor_progress_reserve; plugin->insert_auditor_progress_reserve - = &postgres_insert_auditor_progress_reserve; + = &TAH_PG_insert_auditor_progress_reserve; plugin->get_auditor_progress_purse - = &postgres_get_auditor_progress_purse; + = &TAH_PG_get_auditor_progress_purse; plugin->update_auditor_progress_purse - = &postgres_update_auditor_progress_purse; + = &TAH_PG_update_auditor_progress_purse; plugin->insert_auditor_progress_purse - = &postgres_insert_auditor_progress_purse; + = &TAH_PG_insert_auditor_progress_purse; plugin->get_auditor_progress_aggregation - = &postgres_get_auditor_progress_aggregation; + = &TAH_PG_get_auditor_progress_aggregation; plugin->update_auditor_progress_aggregation - = &postgres_update_auditor_progress_aggregation; + = &TAH_PG_update_auditor_progress_aggregation; plugin->insert_auditor_progress_aggregation - = &postgres_insert_auditor_progress_aggregation; + = &TAH_PG_insert_auditor_progress_aggregation; plugin->get_auditor_progress_deposit_confirmation - = &postgres_get_auditor_progress_deposit_confirmation; + = &TAH_PG_get_auditor_progress_deposit_confirmation; plugin->update_auditor_progress_deposit_confirmation - = &postgres_update_auditor_progress_deposit_confirmation; + = &TAH_PG_update_auditor_progress_deposit_confirmation; plugin->insert_auditor_progress_deposit_confirmation - = &postgres_insert_auditor_progress_deposit_confirmation; + = &TAH_PG_insert_auditor_progress_deposit_confirmation; - plugin->get_auditor_progress_coin = &postgres_get_auditor_progress_coin; - plugin->update_auditor_progress_coin = &postgres_update_auditor_progress_coin; - plugin->insert_auditor_progress_coin = &postgres_insert_auditor_progress_coin; + 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 - = &postgres_get_wire_auditor_account_progress; + = &TAH_PG_get_wire_auditor_account_progress; plugin->update_wire_auditor_account_progress - = &postgres_update_wire_auditor_account_progress; + = &TAH_PG_update_wire_auditor_account_progress; plugin->insert_wire_auditor_account_progress - = &postgres_insert_wire_auditor_account_progress; + = &TAH_PG_insert_wire_auditor_account_progress; - plugin->get_wire_auditor_progress = &postgres_get_wire_auditor_progress; - plugin->update_wire_auditor_progress = &postgres_update_wire_auditor_progress; - plugin->insert_wire_auditor_progress = &postgres_insert_wire_auditor_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 = &postgres_del_reserve_info; - plugin->get_reserve_info = &postgres_get_reserve_info; - plugin->update_reserve_info = &postgres_update_reserve_info; - plugin->insert_reserve_info = &postgres_insert_reserve_info; + 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->get_reserve_summary = &postgres_get_reserve_summary; - plugin->update_reserve_summary = &postgres_update_reserve_summary; - plugin->insert_reserve_summary = &postgres_insert_reserve_summary; + 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->get_wire_fee_summary = &postgres_get_wire_fee_summary; - plugin->update_wire_fee_summary = &postgres_update_wire_fee_summary; - plugin->insert_wire_fee_summary = &postgres_insert_wire_fee_summary; + 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->get_denomination_balance = &postgres_get_denomination_balance; - plugin->update_denomination_balance = &postgres_update_denomination_balance; - plugin->insert_denomination_balance = &postgres_insert_denomination_balance; + 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->get_balance_summary = &postgres_get_balance_summary; - plugin->update_balance_summary = &postgres_update_balance_summary; - plugin->insert_balance_summary = &postgres_insert_balance_summary; + 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 - = &postgres_select_historic_denom_revenue; + = &TAH_PG_select_historic_denom_revenue; plugin->insert_historic_denom_revenue - = &postgres_insert_historic_denom_revenue; + = &TAH_PG_insert_historic_denom_revenue; plugin->select_historic_reserve_revenue - = &postgres_select_historic_reserve_revenue; + = &TAH_PG_select_historic_reserve_revenue; plugin->insert_historic_reserve_revenue - = &postgres_insert_historic_reserve_revenue; + = &TAH_PG_insert_historic_reserve_revenue; - plugin->get_predicted_balance = &postgres_get_predicted_balance; - plugin->update_predicted_result = &postgres_update_predicted_result; - plugin->insert_predicted_result = &postgres_insert_predicted_result; + 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; return plugin; }