diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/Makefile.am | 2 | ||||
-rw-r--r-- | src/exchangedb/auditor-triggers-0001.sql | 41 | ||||
-rw-r--r-- | src/exchangedb/drop.sql | 10 | ||||
-rw-r--r-- | src/exchangedb/pg_create_tables.c | 1 | ||||
-rw-r--r-- | src/exchangedb/pg_inject_auditor_triggers.c | 57 | ||||
-rw-r--r-- | src/exchangedb/pg_inject_auditor_triggers.h | 41 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 3 |
7 files changed, 153 insertions, 2 deletions
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; } |