From 4f0e38ab12340cea7297fc661c98ddba2d2ef681 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 14 Nov 2020 22:27:50 +0100 Subject: more work on crypto RSA helper --- src/exchangedb/Makefile.am | 4 ++- src/exchangedb/drop0002.sql | 26 ++++++++++++++++ src/exchangedb/exchange-0002.sql | 48 +++++++++++++++++++++++++++++ src/exchangedb/plugin_exchangedb_postgres.c | 48 ++++++++++++++++++++++++----- 4 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 src/exchangedb/drop0002.sql create mode 100644 src/exchangedb/exchange-0002.sql (limited to 'src/exchangedb') diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index 74512636b..6736ce379 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -17,7 +17,9 @@ sqldir = $(prefix)/share/taler/sql/exchange/ sql_DATA = \ exchange-0000.sql \ exchange-0001.sql \ - drop0001.sql + exchange-0002.sql \ + drop0001.sql \ + drop0002.sql EXTRA_DIST = \ exchangedb.conf \ diff --git a/src/exchangedb/drop0002.sql b/src/exchangedb/drop0002.sql new file mode 100644 index 000000000..224c7f50c --- /dev/null +++ b/src/exchangedb/drop0002.sql @@ -0,0 +1,26 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2020 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 +-- + +-- Everything in one big transaction +BEGIN; + +-- exchange-0002 did not create new tables, so nothing to do here. + +-- Unregister patch (0002.sql) +SELECT _v.unregister_patch('exchange-0002'); + +-- And we're out of here... +COMMIT; diff --git a/src/exchangedb/exchange-0002.sql b/src/exchangedb/exchange-0002.sql new file mode 100644 index 000000000..9a2793f1a --- /dev/null +++ b/src/exchangedb/exchange-0002.sql @@ -0,0 +1,48 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2020 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 +-- + +-- Everything in one big transaction +BEGIN; + +-- Check patch versioning is in place. +SELECT _v.register_patch('exchange-0002', NULL, NULL); + +ALTER TABLE prewire + ADD failed BOOLEAN NOT NULL DEFAULT false; + +COMMENT ON COLUMN prewire.failed + IS 'set to TRUE if the bank responded with a non-transient failure to our transfer request'; +COMMENT ON COLUMN prewire.finished + IS 'set to TRUE once bank confirmed receiving the wire transfer request'; +COMMENT ON COLUMN prewire.buf + IS 'serialized data to send to the bank to execute the wire transfer'; + +-- change comment, existing index is still useful, but only for gc_prewire. +COMMENT ON INDEX prepare_iteration_index + IS 'for gc_prewire'; + +-- need a new index for updated wire_prepare_data_get statement: +CREATE INDEX IF NOT EXISTS prepare_get_index + ON prewire + (failed,finished); +COMMENT ON INDEX prepare_get_index + IS 'for wire_prepare_data_get'; + + + + +-- Complete transaction +COMMIT; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 47b741390..f94dd7395 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -1098,7 +1098,13 @@ postgres_get_session (void *cls) /* Used in #postgres_wire_prepare_data_mark_finished() */ GNUNET_PQ_make_prepare ("wire_prepare_data_mark_done", "UPDATE prewire" - " SET finished=true" + " SET finished=TRUE" + " WHERE prewire_uuid=$1;", + 1), + /* Used in #postgres_wire_prepare_data_mark_failed() */ + GNUNET_PQ_make_prepare ("wire_prepare_data_mark_failed", + "UPDATE prewire" + " SET failed=TRUE" " WHERE prewire_uuid=$1;", 1), /* Used in #postgres_wire_prepare_data_get() */ @@ -1108,11 +1114,11 @@ postgres_get_session (void *cls) ",type" ",buf" " FROM prewire" - " WHERE finished=false" + " WHERE finished=FALSE" + " AND failed=FALSE" " ORDER BY prewire_uuid ASC" " LIMIT 1;", 0), - /* Used in #postgres_select_deposits_missing_wire */ GNUNET_PQ_make_prepare ("deposits_get_overdue", "SELECT" @@ -5224,10 +5230,10 @@ postgres_wire_prepare_data_insert (void *cls, * @return transaction status code */ static enum GNUNET_DB_QueryStatus -postgres_wire_prepare_data_mark_finished (void *cls, - struct TALER_EXCHANGEDB_Session * - session, - uint64_t rowid) +postgres_wire_prepare_data_mark_finished ( + void *cls, + struct TALER_EXCHANGEDB_Session *session, + uint64_t rowid) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&rowid), @@ -5241,6 +5247,32 @@ postgres_wire_prepare_data_mark_finished (void *cls, } +/** + * Function called to mark wire transfer commit data as failed. + * + * @param cls closure + * @param session database connection + * @param rowid which entry to mark as failed + * @return transaction status code + */ +static enum GNUNET_DB_QueryStatus +postgres_wire_prepare_data_mark_failed ( + void *cls, + struct TALER_EXCHANGEDB_Session *session, + uint64_t rowid) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&rowid), + GNUNET_PQ_query_param_end + }; + + (void) cls; + return GNUNET_PQ_eval_prepared_non_select (session->conn, + "wire_prepare_data_mark_failed", + params); +} + + /** * Function called to get an unfinished wire transfer * preparation data. Fetches at most one item. @@ -7379,6 +7411,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->wire_prepare_data_insert = &postgres_wire_prepare_data_insert; plugin->wire_prepare_data_mark_finished = &postgres_wire_prepare_data_mark_finished; + plugin->wire_prepare_data_mark_failed = + &postgres_wire_prepare_data_mark_failed; plugin->wire_prepare_data_get = &postgres_wire_prepare_data_get; plugin->start_deferred_wire_out = &postgres_start_deferred_wire_out; plugin->store_wire_transfer_out = &postgres_store_wire_transfer_out; -- cgit v1.2.3