diff options
author | Nic Eigel <nic@eigel.ch> | 2024-01-16 22:37:07 +0100 |
---|---|---|
committer | Nic Eigel <nic@eigel.ch> | 2024-01-16 22:37:07 +0100 |
commit | 45b110edb2b4fd39c56f433c5c0a7f93cd29d4da (patch) | |
tree | 3ce6145e8ea7f67daaa1af55b3651002021167fd /src/auditordb | |
parent | 510d4fc5234e8e17d73e8d95a0dc66ad37c03fef (diff) | |
download | exchange-45b110edb2b4fd39c56f433c5c0a7f93cd29d4da.tar.xz |
progress on auditor helpers
Diffstat (limited to 'src/auditordb')
-rw-r--r-- | src/auditordb/0002-auditor_deposit_confirmations.sql | 2 | ||||
-rw-r--r-- | src/auditordb/Makefile.am | 13 | ||||
-rw-r--r-- | src/auditordb/auditor-0002.sql.in | 2 | ||||
-rw-r--r-- | src/auditordb/drop.sql | 1 | ||||
-rw-r--r-- | src/auditordb/pg_get_auditor_progress_deposit_confirmation.c | 4 | ||||
-rw-r--r-- | src/auditordb/pg_get_deposit_confirmations.c | 11 | ||||
-rw-r--r-- | src/auditordb/pg_get_deposit_confirmations.h | 1 | ||||
-rw-r--r-- | src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c | 4 | ||||
-rw-r--r-- | src/auditordb/pg_list_exchanges.c | 1 | ||||
-rw-r--r-- | src/auditordb/pg_select_pending_deposits.c | 4 | ||||
-rw-r--r-- | src/auditordb/plugin_auditordb_postgres.c | 66 |
11 files changed, 85 insertions, 24 deletions
diff --git a/src/auditordb/0002-auditor_deposit_confirmations.sql b/src/auditordb/0002-auditor_deposit_confirmations.sql index dd85c0a62..e26009efc 100644 --- a/src/auditordb/0002-auditor_deposit_confirmations.sql +++ b/src/auditordb/0002-auditor_deposit_confirmations.sql @@ -56,5 +56,5 @@ COMMENT ON FUNCTION auditor_new_transactions_trigger() CREATE TRIGGER auditor_notify_helper_deposits AFTER INSERT - ON auditor.deposit_confirmations + ON auditor.auditor_deposit_confirmations EXECUTE PROCEDURE auditor_new_transactions_trigger();
\ No newline at end of file diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am index 573b1b980..af5c5a1e0 100644 --- a/src/auditordb/Makefile.am +++ b/src/auditordb/Makefile.am @@ -13,18 +13,19 @@ pkgcfg_DATA = \ sqldir = $(prefix)/share/taler/sql/auditor/ -sql_DATA = \ - versioning.sql \ - auditor-0001.sql \ - drop.sql \ - restart.sql - sqlinputs = \ 0002-*.sql \ auditor-0002.sql.in # auditor_do_*.sql # procedures.sql.in +sql_DATA = \ + versioning.sql \ + auditor-0001.sql \ + auditor-0002.sql \ + drop.sql \ + restart.sql + auditor-0002.sql: auditor-0002.sql.in 0002-*.sql chmod +w $@ || true gcc -E -P -undef - < auditor-0002.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@ diff --git a/src/auditordb/auditor-0002.sql.in b/src/auditordb/auditor-0002.sql.in index 5b8f9e074..ac0dd33d4 100644 --- a/src/auditordb/auditor-0002.sql.in +++ b/src/auditordb/auditor-0002.sql.in @@ -36,7 +36,7 @@ EXCEPTION WHEN duplicate_object THEN null; END $$; - +#include "0002-auditor_amount_arithmetic_inconsistency.sql" #include "0002-auditor_balances.sql" #include "0002-auditor_denomination_pending.sql" #include "0002-auditor_exchange_signkeys.sql" diff --git a/src/auditordb/drop.sql b/src/auditordb/drop.sql index 37a50ee68..b7421b1c3 100644 --- a/src/auditordb/drop.sql +++ b/src/auditordb/drop.sql @@ -20,6 +20,7 @@ BEGIN; -- Drop versioning (auditor-0001.sql) SELECT _v.unregister_patch('auditor-0001'); +SELECT _v.unregister_patch('auditor-0002'); DROP SCHEMA auditor CASCADE; -- And we're out of here... diff --git a/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c b/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c index f69f4a692..7a14b4600 100644 --- a/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c +++ b/src/auditordb/pg_get_auditor_progress_deposit_confirmation.c @@ -34,7 +34,6 @@ TAH_PG_get_auditor_progress_deposit_confirmation ( { 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[] = { @@ -47,8 +46,7 @@ TAH_PG_get_auditor_progress_deposit_confirmation ( "auditor_progress_select_deposit_confirmation", "SELECT" " last_deposit_confirmation_serial_id" - " FROM auditor_progress_deposit_confirmation" - " WHERE master_pub=$1;"); + " FROM auditor_progress_deposit_confirmation;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "auditor_progress_select_deposit_confirmation", params, diff --git a/src/auditordb/pg_get_deposit_confirmations.c b/src/auditordb/pg_get_deposit_confirmations.c index 01d78dba4..cb52c36c2 100644 --- a/src/auditordb/pg_get_deposit_confirmations.c +++ b/src/auditordb/pg_get_deposit_confirmations.c @@ -156,29 +156,27 @@ deposit_confirmation_cb (void *cls, enum GNUNET_DB_QueryStatus TAH_PG_get_deposit_confirmations ( void *cls, - const struct TALER_MasterPublicKeyP *master_public_key, uint64_t start_id, 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; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "id above %ld\n", start_id); PREPARE (pg, "auditor_deposit_confirmation_select", "SELECT" - " serial_id" + " deposit_confirmation_serial_id" ",h_contract_terms" ",h_policy" ",h_wire" @@ -192,9 +190,8 @@ TAH_PG_get_deposit_confirmations ( ",exchange_sig" ",exchange_pub" ",master_sig" /* master_sig could be normalized... */ - " FROM deposit_confirmations" - " WHERE master_pub=$1" - " AND serial_id>$2"); + " FROM auditor_deposit_confirmations" + " WHERE deposit_confirmation_serial_id>$1"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, "auditor_deposit_confirmation_select", params, diff --git a/src/auditordb/pg_get_deposit_confirmations.h b/src/auditordb/pg_get_deposit_confirmations.h index 48ee70634..2c3c28538 100644 --- a/src/auditordb/pg_get_deposit_confirmations.h +++ b/src/auditordb/pg_get_deposit_confirmations.h @@ -40,7 +40,6 @@ 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); diff --git a/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c b/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c index 4f4c7390e..94231b1c6 100644 --- a/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c +++ b/src/auditordb/pg_insert_auditor_progress_deposit_confirmation.c @@ -38,7 +38,9 @@ TAH_PG_insert_auditor_progress_deposit_confirmation ( GNUNET_PQ_query_param_uint64 (&ppdc->last_deposit_confirmation_serial_id), GNUNET_PQ_query_param_end }; - + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "isnert ppdc last deposit conf serial id above %ld\n", + ppdc->last_deposit_confirmation_serial_id); PREPARE (pg, "auditor_progress_insert_deposit_confirmation", "INSERT INTO auditor_progress_deposit_confirmation " diff --git a/src/auditordb/pg_list_exchanges.c b/src/auditordb/pg_list_exchanges.c index f0637b13f..a455ee32a 100644 --- a/src/auditordb/pg_list_exchanges.c +++ b/src/auditordb/pg_list_exchanges.c @@ -107,7 +107,6 @@ TAH_PG_list_exchanges (void *cls, .cb_cls = cb_cls }; enum GNUNET_DB_QueryStatus qs; - PREPARE (pg, "auditor_list_exchanges", "SELECT" diff --git a/src/auditordb/pg_select_pending_deposits.c b/src/auditordb/pg_select_pending_deposits.c index a5d1c6ae8..3a46770a2 100644 --- a/src/auditordb/pg_select_pending_deposits.c +++ b/src/auditordb/pg_select_pending_deposits.c @@ -118,7 +118,6 @@ TAH_PG_select_pending_deposits ( { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_absolute_time (&deadline), GNUNET_PQ_query_param_end }; @@ -137,8 +136,7 @@ TAH_PG_select_pending_deposits ( ",wire_target_h_payto" ",deadline" " FROM auditor_pending_deposits" - " WHERE master_pub=$1" - " AND deadline<$2;"); + " WHERE deadline<$1;"); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, "auditor_select_pending_deposits", diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index dc66990ba..2366eb69f 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -166,6 +166,69 @@ postgres_create_tables (void *cls) /** + * Register callback to be invoked on events of type @a es. + * + * @param cls database context to use + * @param es specification of the event to listen for + * @param timeout how long to wait for the event + * @param cb function to call when the event happens, possibly + * mulrewardle times (until cancel is invoked) + * @param cb_cls closure for @a cb + * @return handle useful to cancel the listener + */ +static struct GNUNET_DB_EventHandler * +postgres_event_listen (void *cls, + const struct GNUNET_DB_EventHeaderP *es, + struct GNUNET_TIME_Relative timeout, + GNUNET_DB_EventCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + + return GNUNET_PQ_event_listen (pg->conn, + es, + timeout, + cb, + cb_cls); +} + + +/** + * Stop notifications. + * + * @param eh handle to unregister. + */ +static void +postgres_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) +{ + GNUNET_PQ_event_listen_cancel (eh); +} + + +/** + * Notify all that listen on @a es of an event. + * + * @param cls database context to use + * @param es specification of the event to generate + * @param extra additional event data provided + * @param extra_size number of bytes in @a extra + */ +static void +postgres_event_notify (void *cls, + const struct GNUNET_DB_EventHeaderP *es, + const void *extra, + size_t extra_size) +{ + struct PostgresClosure *pg = cls; + + return GNUNET_PQ_event_notify (pg->conn, + es, + extra, + extra_size); +} + + +/** * Connect to the db if the connection does not exist yet. * * @param[in,out] pg the plugin-specific state @@ -399,6 +462,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->preflight = &postgres_preflight; plugin->drop_tables = &postgres_drop_tables; plugin->create_tables = &postgres_create_tables; + plugin->event_listen = &postgres_event_listen; + plugin->event_listen_cancel = &postgres_event_listen_cancel; + plugin->event_notify = &postgres_event_notify; plugin->start = &postgres_start; plugin->commit = &postgres_commit; plugin->rollback = &postgres_rollback; |