[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-exchange] 01/02: add taler-exchange-dbinit -a option
From: |
gnunet |
Subject: |
[taler-exchange] 01/02: add taler-exchange-dbinit -a option |
Date: |
Fri, 08 Mar 2024 11:18:25 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository exchange.
commit a50e69908e7205021167415fac42162be96f98d0
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Fri Mar 8 11:12:50 2024 +0100
add taler-exchange-dbinit -a option
---
contrib/gana | 2 +-
contrib/wallet-core | 2 +-
doc/prebuilt | 2 +-
src/exchange-tools/taler-exchange-dbinit.c | 20 ++++++++-
src/exchangedb/Makefile.am | 2 +
.../{drop.sql => auditor-triggers-0001.sql} | 23 +++++++++--
src/exchangedb/drop.sql | 10 ++++-
src/exchangedb/pg_create_tables.c | 1 -
...reate_tables.c => pg_inject_auditor_triggers.c} | 48 ++++++++--------------
src/exchangedb/pg_inject_auditor_triggers.h | 41 ++++++++++++++++++
src/exchangedb/plugin_exchangedb_postgres.c | 3 ++
src/include/taler_exchangedb_plugin.h | 28 +++++++++++--
12 files changed, 136 insertions(+), 46 deletions(-)
diff --git a/contrib/gana b/contrib/gana
index 2b581279..4728c9e6 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit 2b581279ae67a1068b07a8c010ac1ab7b85e18df
+Subproject commit 4728c9e60ce121f439b3db30cc08f06ff0beff71
diff --git a/contrib/wallet-core b/contrib/wallet-core
index c0f30699..a431332f 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit c0f3069970e24d1fa9e308347350d6e5221aed88
+Subproject commit a431332f59a8557edba64b24b8c6a6fcc140e2bd
diff --git a/doc/prebuilt b/doc/prebuilt
index af8c69df..60ccf04b 160000
--- a/doc/prebuilt
+++ b/doc/prebuilt
@@ -1 +1 @@
-Subproject commit af8c69dfe397ff4bed7abca98ed8f3b2ed70541b
+Subproject commit 60ccf04bb3579c249a899c4ae88e120acda13c83
diff --git a/src/exchange-tools/taler-exchange-dbinit.c
b/src/exchange-tools/taler-exchange-dbinit.c
index d2cd22c1..41ff2ab2 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
@@ -29,6 +29,11 @@
*/
static int global_ret;
+/**
+ * -a option: inject auditor triggers
+ */
+static int inject_auditor;
+
/**
* -r option: do full DB reset
*/
@@ -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 2959f07e..af6e2166 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/drop.sql b/src/exchangedb/auditor-triggers-0001.sql
similarity index 58%
copy from src/exchangedb/drop.sql
copy to src/exchangedb/auditor-triggers-0001.sql
index ff383d74..4e2ea66c 100644
--- a/src/exchangedb/drop.sql
+++ b/src/exchangedb/auditor-triggers-0001.sql
@@ -1,6 +1,6 @@
--
-- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
+-- Copyright (C) 2024 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
@@ -17,10 +17,25 @@
-- Everything in one big transaction
BEGIN;
+SELECT _v.register_patch('auditor-triggers-0001');
-SELECT _v.unregister_patch('exchange-0001');
-SELECT _v.unregister_patch('exchange-0002');
+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();
-DROP SCHEMA exchange CASCADE;
COMMIT;
diff --git a/src/exchangedb/drop.sql b/src/exchangedb/drop.sql
index ff383d74..fa7609bf 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 1d5728d8..f6a06190 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_create_tables.c
b/src/exchangedb/pg_inject_auditor_triggers.c
similarity index 53%
copy from src/exchangedb/pg_create_tables.c
copy to src/exchangedb/pg_inject_auditor_triggers.c
index 1d5728d8..562a1a22 100644
--- a/src/exchangedb/pg_create_tables.c
+++ b/src/exchangedb/pg_inject_auditor_triggers.c
@@ -14,60 +14,44 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file exchangedb/pg_create_tables.c
- * @brief Implementation of the create_tables function for Postgres
+ * @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_create_tables.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_create_tables (void *cls,
- bool support_partitions,
- uint32_t num_partitions)
+TEH_PG_inject_auditor_triggers (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
- struct GNUNET_PQ_QueryParam params[] = {
- support_partitions
- ? GNUNET_PQ_query_param_uint32 (&num_partitions)
- : GNUNET_PQ_query_param_null (),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare ("create_tables",
- "SELECT"
- " exchange.do_create_tables"
- " ($1);"),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
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",
- "exchange-",
+ "auditor-triggers-",
es,
- ps);
+ NULL);
if (NULL == conn)
return GNUNET_SYSERR;
- if (0 >
- GNUNET_PQ_eval_prepared_non_select (conn,
- "create_tables",
- params))
- ret = GNUNET_SYSERR;
- if (GNUNET_OK == ret)
- ret = GNUNET_PQ_exec_sql (conn,
- "procedures");
GNUNET_PQ_disconnect (conn);
- return ret;
+ 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 00000000..2dfa9468
--- /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 2c51a5bf..108b5521 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 c7bffbd8..5cd63f2b 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 */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.