From bce6a266ed4e273e40c90ecf68d7e1444f211526 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 3 May 2023 20:18:37 +0200 Subject: get new taler-merchant-exchange helper to build --- src/backenddb/Makefile.am | 1 + src/backenddb/merchant-0005.sql | 13 +++--- src/backenddb/pg_update_transfer_status.c | 65 ++++++++++++++++++++++++++++++ src/backenddb/pg_update_transfer_status.h | 51 +++++++++++++++++++++++ src/backenddb/plugin_merchantdb_postgres.c | 3 ++ 5 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 src/backenddb/pg_update_transfer_status.c create mode 100644 src/backenddb/pg_update_transfer_status.h (limited to 'src/backenddb') diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index 2debd00e..2ed54ef7 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -59,6 +59,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_select_open_transfers.h pg_select_open_transfers.c \ pg_lookup_instances.h pg_lookup_instances.c \ pg_lookup_transfers.h pg_lookup_transfers.c \ + pg_update_transfer_status.h pg_update_transfer_status.c \ pg_delete_exchange_accounts.h pg_delete_exchange_accounts.c \ pg_select_accounts_by_exchange.h pg_select_accounts_by_exchange.c \ pg_insert_exchange_account.h pg_insert_exchange_account.c \ diff --git a/src/backenddb/merchant-0005.sql b/src/backenddb/merchant-0005.sql index 5c01e55b..a0e283fa 100644 --- a/src/backenddb/merchant-0005.sql +++ b/src/backenddb/merchant-0005.sql @@ -35,6 +35,7 @@ ALTER TABLE merchant_tip_reserve_keys ADD COLUMN master_pub BYTEA NOT NULL CHECK (LENGTH(master_pub)=32); ALTER TABLE merchant_transfers + ADD COLUMN ready_time INT8 NOT NULL DEFAULT (0), ADD COLUMN failed BOOLEAN NOT NULL DEFAULT FALSE, ADD COLUMN validation_status INT4 DEFAULT NULL; COMMENT ON COLUMN merchant_transfers.failed @@ -42,12 +43,12 @@ COMMENT ON COLUMN merchant_transfers.failed COMMENT ON COLUMN merchant_transfers.validation_status IS 'Taler error code describing the state of the validation'; ---CREATE INDEX merchant_transfers_by_open --- ON merchant_transfers --- (ready_time ASC) --- WHERE confirmed AND NOT (failed OR verified); ---COMMENT ON INDEX merchant_transfers_by_open --- IS 'For select_open_transfers'; +CREATE INDEX merchant_transfers_by_open + ON merchant_transfers + (ready_time ASC) + WHERE confirmed AND NOT (failed OR verified); +COMMENT ON INDEX merchant_transfers_by_open + IS 'For select_open_transfers'; ALTER TABLE merchant_accounts diff --git a/src/backenddb/pg_update_transfer_status.c b/src/backenddb/pg_update_transfer_status.c new file mode 100644 index 00000000..9898984d --- /dev/null +++ b/src/backenddb/pg_update_transfer_status.c @@ -0,0 +1,65 @@ +/* + 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 + */ +/** + * @file backenddb/pg_update_transfer_status.c + * @brief Implementation of the update_transfer_status function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include +#include +#include +#include "pg_update_transfer_status.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TMH_PG_update_transfer_status ( + void *cls, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct GNUNET_TIME_Absolute next_attempt, + enum TALER_ErrorCode ec, + bool failed, + bool verified) +{ + struct PostgresClosure *pg = cls; + uint32_t ec32 = (uint32_t) ec; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_string (exchange_url), + GNUNET_PQ_query_param_uint32 (&ec32), + GNUNET_PQ_query_param_bool (failed), + GNUNET_PQ_query_param_bool (verified), + GNUNET_PQ_query_param_absolute_time (&next_attempt), + GNUNET_PQ_query_param_end + }; + + check_connection (pg); + PREPARE (pg, + "update_transfer_status", + "UPDATE merchant_transfers SET" + " validation_status=$3" + ",failed=$4" + ",verified=$5" + ",ready_time=$6" + " WHERE wtid=$1" + " AND exchange_url=$2"); + return GNUNET_PQ_eval_prepared_non_select ( + pg->conn, + "update_transfer_status", + params); +} diff --git a/src/backenddb/pg_update_transfer_status.h b/src/backenddb/pg_update_transfer_status.h new file mode 100644 index 00000000..2828b25e --- /dev/null +++ b/src/backenddb/pg_update_transfer_status.h @@ -0,0 +1,51 @@ +/* + 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 + */ +/** + * @file backenddb/pg_update_transfer_status.h + * @brief implementation of the update_transfer_status function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_UPDATE_TRANSFER_STATUS_H +#define PG_UPDATE_TRANSFER_STATUS_H + +#include +#include +#include "taler_merchantdb_plugin.h" + + +/** + * Update transfer status. + * + * @param cls closure + * @param exchange_url the exchange that made the transfer + * @param wtid wire transfer subject + * @param next_attempt when should we try again (if ever) + * @param ec current error state of checking the transfer + * @param failed true if validation has failed for good + * @param verified true if validation has succeeded for good + * @return database transaction status + */ +enum GNUNET_DB_QueryStatus +TMH_PG_update_transfer_status ( + void *cls, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct GNUNET_TIME_Absolute next_attempt, + enum TALER_ErrorCode ec, + bool failed, + bool verified); + +#endif diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 72ebd7e4..ca26c01d 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -41,6 +41,7 @@ #include "pg_select_accounts_by_exchange.h" #include "pg_insert_exchange_account.h" #include "pg_lookup_reserves.h" +#include "pg_update_transfer_status.h" /** @@ -9504,6 +9505,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->update_instance_auth = &postgres_update_instance_auth; plugin->activate_account = &postgres_activate_account; plugin->inactivate_account = &postgres_inactivate_account; + plugin->update_transfer_status + = &TMH_PG_update_transfer_status; plugin->lookup_products = &postgres_lookup_products; plugin->lookup_product = &postgres_lookup_product; plugin->delete_product = &postgres_delete_product; -- cgit v1.2.3