aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2024-03-08 11:12:50 +0100
committerChristian Grothoff <grothoff@gnunet.org>2024-03-08 11:12:50 +0100
commita50e69908e7205021167415fac42162be96f98d0 (patch)
tree3de2eb42d6c5243e860dc02fe8846fadb3d1dd5a /src
parentfb02619f98eca93de71aaee9c7c8d83ac77025bc (diff)
add taler-exchange-dbinit -a option
Diffstat (limited to 'src')
-rw-r--r--src/exchange-tools/taler-exchange-dbinit.c20
-rw-r--r--src/exchangedb/Makefile.am2
-rw-r--r--src/exchangedb/auditor-triggers-0001.sql41
-rw-r--r--src/exchangedb/drop.sql10
-rw-r--r--src/exchangedb/pg_create_tables.c1
-rw-r--r--src/exchangedb/pg_inject_auditor_triggers.c57
-rw-r--r--src/exchangedb/pg_inject_auditor_triggers.h41
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c3
-rw-r--r--src/include/taler_exchangedb_plugin.h28
9 files changed, 196 insertions, 7 deletions
diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c
index d2cd22c1e..41ff2ab24 100644
--- a/src/exchange-tools/taler-exchange-dbinit.c
+++ b/src/exchange-tools/taler-exchange-dbinit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -30,6 +30,11 @@
static int global_ret;
/**
+ * -a option: inject auditor triggers
+ */
+static int inject_auditor;
+
+/**
* -r option: do full DB reset
*/
static int reset_db;
@@ -133,6 +138,15 @@ run (void *cls,
}
}
}
+ if (inject_auditor)
+ {
+ if (GNUNET_SYSERR == plugin->inject_auditor_triggers (plugin->cls))
+ {
+ fprintf (stderr,
+ "Injecting auditor triggers failed!\n");
+ global_ret = EXIT_FAILURE;
+ }
+ }
TALER_EXCHANGEDB_plugin_unload (plugin);
plugin = NULL;
}
@@ -151,6 +165,10 @@ main (int argc,
char *const *argv)
{
const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_flag ('a',
+ "inject-auditor",
+ "inject auditor triggers",
+ &inject_auditor),
GNUNET_GETOPT_option_flag ('g',
"gc",
"garbage collect database",
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index 2959f07e2..af6e2166b 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -23,6 +23,7 @@ sqlinputs = \
sql_DATA = \
benchmark-0001.sql \
versioning.sql \
+ auditor-triggers-0001.sql \
exchange-0001.sql \
exchange-0002.sql \
drop.sql \
@@ -98,6 +99,7 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \
pg_select_contract_by_purse.h pg_select_contract_by_purse.c \
pg_insert_drain_profit.h pg_insert_drain_profit.c \
pg_insert_kyc_failure.h pg_insert_kyc_failure.c \
+ pg_inject_auditor_triggers.h pg_inject_auditor_triggers.c \
pg_create_tables.h pg_create_tables.c \
pg_event_listen.h pg_event_listen.c \
pg_event_listen_cancel.h pg_event_listen_cancel.c \
diff --git a/src/exchangedb/auditor-triggers-0001.sql b/src/exchangedb/auditor-triggers-0001.sql
new file mode 100644
index 000000000..4e2ea66ce
--- /dev/null
+++ b/src/exchangedb/auditor-triggers-0001.sql
@@ -0,0 +1,41 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- Everything in one big transaction
+BEGIN;
+
+SELECT _v.register_patch('auditor-triggers-0001');
+
+SET search_path TO exchange;
+
+CREATE OR REPLACE FUNCTION auditor_new_deposits_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $$
+BEGIN
+ NOTIFY XFIXME;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION auditor_new_deposits_trigger()
+ IS 'Call XXX on new entry';
+
+CREATE TRIGGER auditor_notify_helper_insert_deposits
+ AFTER INSERT
+ ON exchange.batch_deposits
+EXECUTE PROCEDURE auditor_new_deposits_trigger();
+
+
+COMMIT;
diff --git a/src/exchangedb/drop.sql b/src/exchangedb/drop.sql
index ff383d743..fa7609bfd 100644
--- a/src/exchangedb/drop.sql
+++ b/src/exchangedb/drop.sql
@@ -17,10 +17,18 @@
-- Everything in one big transaction
BEGIN;
-
+-- TODO: consider use exchange-* in the future!
SELECT _v.unregister_patch('exchange-0001');
SELECT _v.unregister_patch('exchange-0002');
+WITH xpatches AS (
+ SELECT patch_name
+ FROM _v.patches
+ WHERE patch_name='auditor-triggers-0001' -- TODO: use auditor-triggers-* in the future!
+)
+ SELECT _v.unregister_patch(xpatches.patch_name)
+ FROM xpatches;
+
DROP SCHEMA exchange CASCADE;
COMMIT;
diff --git a/src/exchangedb/pg_create_tables.c b/src/exchangedb/pg_create_tables.c
index 1d5728d89..f6a061904 100644
--- a/src/exchangedb/pg_create_tables.c
+++ b/src/exchangedb/pg_create_tables.c
@@ -52,7 +52,6 @@ TEH_PG_create_tables (void *cls,
GNUNET_PQ_EXECUTE_STATEMENT_END
};
-
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
"exchange-",
diff --git a/src/exchangedb/pg_inject_auditor_triggers.c b/src/exchangedb/pg_inject_auditor_triggers.c
new file mode 100644
index 000000000..562a1a22c
--- /dev/null
+++ b/src/exchangedb/pg_inject_auditor_triggers.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_inject_auditor_triggers.c
+ * @brief Implementation of the inject_auditor_triggers function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_gc.h"
+#include "pg_helper.h"
+
+
+/**
+ * Function called to inject auditor triggers into the
+ * database, triggering the real-time auditor upon
+ * relevant INSERTs.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_inject_auditor_triggers (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_Context *conn;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
+ "exchangedb-postgres",
+ "auditor-triggers-",
+ es,
+ NULL);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ GNUNET_PQ_disconnect (conn);
+ return GNUNET_OK;
+}
diff --git a/src/exchangedb/pg_inject_auditor_triggers.h b/src/exchangedb/pg_inject_auditor_triggers.h
new file mode 100644
index 000000000..2dfa9468c
--- /dev/null
+++ b/src/exchangedb/pg_inject_auditor_triggers.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_inject_auditor_triggers.h
+ * @brief implementation of the inject_auditor_triggers function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INJECT_AUDITOR_TRIGGERS_H
+#define PG_INJECT_AUDITOR_TRIGGERS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to inject auditor triggers into the
+ * database, triggering the real-time auditor upon
+ * relevant INSERTs.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_inject_auditor_triggers (void *cls);
+
+
+#endif
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 2c51a5bf1..108b55219 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -161,6 +161,7 @@
#include "pg_start_deferred_wire_out.h"
#include "pg_store_wire_transfer_out.h"
#include "pg_gc.h"
+#include "pg_inject_auditor_triggers.h"
#include "pg_select_coin_deposits_above_serial_id.h"
#include "pg_select_purse_decisions_above_serial_id.h"
#include "pg_select_purse_deposits_by_purse.h"
@@ -790,6 +791,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->batch_ensure_coin_known
= &TEH_PG_batch_ensure_coin_known;
+ plugin->inject_auditor_triggers
+ = &TEH_PG_inject_auditor_triggers;
return plugin;
}
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index c7bffbd89..5cd63f2bf 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -34,16 +34,24 @@
*/
enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict
{
- /* Value OK, no conflict */
+ /**
+ * Value OK, no conflict
+ */
TALER_AgeCommitmentHash_NoConflict = 0,
- /* Given hash had a value, but NULL (or zero) was expected */
+ /**
+ * Given hash had a value, but NULL (or zero) was expected
+ */
TALER_AgeCommitmentHash_NullExpected = 1,
- /* Given hash was NULL, but value was expected */
+ /**
+ * Given hash was NULL, but value was expected
+ */
TALER_AgeCommitmentHash_ValueExpected = 2,
- /* Given hash differs from value in the known coin */
+ /**
+ * Given hash differs from value in the known coin
+ */
TALER_AgeCommitmentHash_ValueDiffers = 3,
};
@@ -7206,6 +7214,18 @@ struct TALER_EXCHANGEDB_Plugin
const char *provider_account_id,
const char *provider_legitimization_id);
+ /**
+ * Function called to inject auditor triggers into the
+ * database, triggering the real-time auditor upon
+ * relevant INSERTs.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+ enum GNUNET_GenericReturnValue
+ (*inject_auditor_triggers)(void *cls);
+
};
#endif /* _TALER_EXCHANGE_DB_H */