aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/auditor/taler-auditor-httpd.c6
-rw-r--r--src/auditor/taler-auditor-httpd_deposit-confirmation.c135
-rw-r--r--src/auditor/taler-auditor-httpd_deposit-confirmation.h30
-rw-r--r--src/auditor/taler-helper-auditor-deposits.c69
-rw-r--r--src/auditordb/0002-auditor-triggers.sql19
-rw-r--r--src/auditordb/pg_delete_deposit_confirmations.c62
-rw-r--r--src/auditordb/pg_delete_deposit_confirmations.h51
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c1
8 files changed, 351 insertions, 22 deletions
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c
index a59ce3de0..c1853d84a 100644
--- a/src/auditor/taler-auditor-httpd.c
+++ b/src/auditor/taler-auditor-httpd.c
@@ -206,6 +206,12 @@ handle_mhd_request (void *cls,
{ "/deposit-confirmation", MHD_HTTP_METHOD_PUT, "application/json",
NULL, 0,
&TAH_DEPOSIT_CONFIRMATION_handler, MHD_HTTP_OK },
+ { "/deposit-confirmation", MHD_HTTP_METHOD_GET, "application/json",
+ NULL, 0,
+ &TAH_DEPOSIT_CONFIRMATION_get, MHD_HTTP_OK },
+// { "/deposit-confirmation", MHD_HTTP_METHOD_DELETE, "application/json",
+// NULL, 0,
+// &TAH_DEPOSIT_CONFIRMATION_delete, MHD_HTTP_OK },
{ "/exchanges", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0,
&TAH_EXCHANGES_handler, MHD_HTTP_OK },
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.c b/src/auditor/taler-auditor-httpd_deposit-confirmation.c
index 020d43d56..9a3e5475c 100644
--- a/src/auditor/taler-auditor-httpd_deposit-confirmation.c
+++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.c
@@ -31,7 +31,6 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_deposit-confirmation.h"
-
GNUNET_NETWORK_STRUCT_BEGIN
/**
@@ -118,11 +117,11 @@ verify_and_execute_deposit_confirmation (
const struct TALER_CoinSpendSignatureP *coin_sigps[
GNUNET_NZL (dc->num_coins)];
- for (unsigned int i = 0; i<dc->num_coins; i++)
+ for (unsigned int i = 0; i < dc->num_coins; i++)
coin_sigps[i] = &dc->coin_sigs[i];
if (GNUNET_TIME_absolute_is_future (es->ep_start.abs_time) ||
- GNUNET_TIME_absolute_is_past (es->ep_expire.abs_time) )
+ GNUNET_TIME_absolute_is_past (es->ep_expire.abs_time))
{
/* Signing key expired */
TALER_LOG_WARNING ("Expired exchange signing key\n");
@@ -134,7 +133,7 @@ verify_and_execute_deposit_confirmation (
/* check our cache */
GNUNET_CRYPTO_hash (&skv,
- sizeof (skv),
+ sizeof(skv),
&h);
GNUNET_assert (0 == pthread_mutex_lock (&lock));
cached = GNUNET_CONTAINER_multihashmap_get (cache,
@@ -341,8 +340,8 @@ TAH_DEPOSIT_CONFIRMATION_handler (
&json);
if (GNUNET_SYSERR == res)
return MHD_NO;
- if ( (GNUNET_NO == res) ||
- (NULL == json) )
+ if ((GNUNET_NO == res) ||
+ (NULL == json))
return MHD_YES;
res = TALER_MHD_parse_json_data (connection,
json,
@@ -350,12 +349,12 @@ TAH_DEPOSIT_CONFIRMATION_handler (
if (GNUNET_SYSERR == res)
{
json_decref (json);
- return MHD_NO; /* hard failure */
+ return MHD_NO; /* hard failure */
}
if (GNUNET_NO == res)
{
json_decref (json);
- return MHD_YES; /* failure */
+ return MHD_YES; /* failure */
}
}
num_coins = json_array_size (jcoin_sigs);
@@ -382,7 +381,7 @@ TAH_DEPOSIT_CONFIRMATION_handler (
struct TALER_CoinSpendSignatureP coin_sigs[num_coins];
MHD_RESULT res;
- for (unsigned int i = 0; i<num_coins; i++)
+ for (unsigned int i = 0; i < num_coins; i++)
{
json_t *jpub = json_array_get (jcoin_pubs,
i);
@@ -391,12 +390,12 @@ TAH_DEPOSIT_CONFIRMATION_handler (
const char *ps = json_string_value (jpub);
const char *ss = json_string_value (jsig);
- if ( (NULL == ps) ||
- (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (ps,
- strlen (ps),
- &coin_pubs[i],
- sizeof (coin_pubs[i]))) )
+ if ((NULL == ps) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (ps,
+ strlen (ps),
+ &coin_pubs[i],
+ sizeof(coin_pubs[i]))))
{
GNUNET_break_op (0);
json_decref (json);
@@ -405,12 +404,12 @@ TAH_DEPOSIT_CONFIRMATION_handler (
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"coin_pub[] malformed");
}
- if ( (NULL == ss) ||
- (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (ss,
- strlen (ss),
- &coin_sigs[i],
- sizeof (coin_sigs[i]))) )
+ if ((NULL == ss) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (ss,
+ strlen (ss),
+ &coin_sigs[i],
+ sizeof(coin_sigs[i]))))
{
GNUNET_break_op (0);
json_decref (json);
@@ -423,7 +422,7 @@ TAH_DEPOSIT_CONFIRMATION_handler (
dc.num_coins = num_coins;
dc.coin_pubs = coin_pubs;
dc.coin_sigs = coin_sigs;
- es.exchange_pub = dc.exchange_pub; /* used twice! */
+ es.exchange_pub = dc.exchange_pub; /* used twice! */
dc.master_public_key = es.master_public_key;
res = verify_and_execute_deposit_confirmation (connection,
&dc,
@@ -456,4 +455,96 @@ TEAH_DEPOSIT_CONFIRMATION_done (void)
}
+/**
+ * Add deposit confirmation to the list.
+ *
+ * @param[in,out] cls a `json_t *` array to extend
+ * @param dc struct of deposit confirmation
+ */
+static void
+add_deposit_confirmation (void *cls,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc)
+{
+ json_t *list = cls;
+ json_t *obj;
+
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("dc",
+ dc));
+ GNUNET_break (0 ==
+ json_array_append_new (list,
+ obj));
+
+}
+
+
+/**
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ json_t *ja;
+ enum GNUNET_DB_QueryStatus qs;
+
+ (void) rh;
+ (void) connection_cls;
+ (void) upload_data;
+ (void) upload_data_size;
+ if (GNUNET_SYSERR ==
+ TAH_plugin->preflight (TAH_plugin->cls))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SETUP_FAILED,
+ NULL);
+ }
+ ja = json_array ();
+ GNUNET_break (NULL != ja);
+ // TODO correct below
+ struct TALER_AUDITORDB_ProgressPointDepositConfirmation ppdc;
+
+ qs = TAH_plugin->get_deposit_confirmations (
+ TAH_plugin->cls,
+ &TAH_plugin,
+ ppdc.last_deposit_confirmation_serial_id,
+ &add_deposit_confirmation,
+ ja);
+
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ json_decref (ja);
+ TALER_LOG_WARNING (
+ "Failed to handle GET /deposit-confirmation in database\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "deposit-confirmation");
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("deposit-confirmation",
+ ja));
+}
+
+
+/*MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_delete(struct TEH_RequestContext *rc,
+ const char *const args[1]) {
+}*/
+
+
/* end of taler-auditor-httpd_deposit-confirmation.c */
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.h b/src/auditor/taler-auditor-httpd_deposit-confirmation.h
index a7c331916..ff42e4aa3 100644
--- a/src/auditor/taler-auditor-httpd_deposit-confirmation.h
+++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.h
@@ -56,4 +56,34 @@ TAH_DEPOSIT_CONFIRMATION_handler (struct TAH_RequestHandler *rh,
const char *upload_data,
size_t *upload_data_size);
+/**
+ * Handle a "/deposit-confirmation" request.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+/**
+ * Handle a DELETE "/deposit-confirmation/$dc" request.
+ *
+ * @param rc request details about the request to handle
+ * @param args argument with the dc primary key
+ * @return MHD result code
+ */
+/*MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_delete (
+ struct TEH_RequestContext *rc,
+ const char *const args[1]);*/
+
+
#endif
diff --git a/src/auditor/taler-helper-auditor-deposits.c b/src/auditor/taler-helper-auditor-deposits.c
index 8ec2b223e..4f2283739 100644
--- a/src/auditor/taler-helper-auditor-deposits.c
+++ b/src/auditor/taler-helper-auditor-deposits.c
@@ -29,6 +29,8 @@
#include "taler_bank_service.h"
#include "taler_signatures.h"
#include "report-lib.h"
+#include <taler/taler_dbevents.h>
+#include <jansson.h>
/*
--
@@ -51,6 +53,10 @@
-- AND NOT ancient;
*/
+/**
+ * Next task to run, if any.
+ */
+static struct GNUNET_SCHEDULER_Task *task;
/**
* Return value from main().
@@ -77,6 +83,13 @@ static struct TALER_Amount total_missed_deposit_confirmations;
*/
static int internal_checks;
+static struct GNUNET_DB_EventHandler *eh;
+
+/**
+ * Our database plugin.
+ */
+static struct TALER_AUDITORDB_Plugin *db_plugin;
+
/**
* Closure for #test_dc.
*/
@@ -289,6 +302,29 @@ analyze_deposit_confirmations (void *cls)
/**
+ * Function called on events received from Postgres.
+ *
+ * @param cls closure, NULL
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+static void
+db_notify (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+ (void) cls;
+ (void) extra;
+ (void) extra_size;
+
+ GNUNET_assert (NULL != task);
+ GNUNET_SCHEDULER_cancel (task);
+ task = GNUNET_SCHEDULER_add_now (&analyze_deposit_confirmations,
+ NULL);
+}
+
+
+/**
* Main function that will be run.
*
* @param cls closure
@@ -313,6 +349,39 @@ run (void *cls,
global_ret = EXIT_FAILURE;
return;
}
+
+ /*if (NULL ==
+ (db_plugin = TALER_AUDITORDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize DB subsystem\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ db_plugin->connect (db_plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to database\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ {
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (TALER_DBEVENT_AUDITOR_NEW_DEPOSIT_CONFIRMATIONS)
+ };
+
+ eh = db_plugin->event_listen (db_plugin->cls,
+ &es,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &db_notify,
+ NULL);
+ }
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&select_work,
+ NULL);*/
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting deposit audit\n");
GNUNET_assert (NULL !=
diff --git a/src/auditordb/0002-auditor-triggers.sql b/src/auditordb/0002-auditor-triggers.sql
new file mode 100644
index 000000000..43d8eb8f6
--- /dev/null
+++ b/src/auditordb/0002-auditor-triggers.sql
@@ -0,0 +1,19 @@
+SET search_path TO auditor;
+
+CREATE TRIGGER auditor_notify_helper_deposits
+ AFTER INSERT
+ ON auditor.deposit_confirmations
+EXECUTE PROCEDURE auditor_new_transactions_trigger();
+
+CREATE OR REPLACE FUNCTION auditor_new_transactions_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $$
+BEGIN
+ -- TODO Add correct notify string
+ PERFORM('NOTIFY XRE2709K6TYDBVARD9Y5SCZY7VHE4D5DKF0R8DHQ4X5T13E8X2X60');
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION auditor_new_transactions_trigger()
+ IS 'Call auditor_call_db_notify on new entry';
+
diff --git a/src/auditordb/pg_delete_deposit_confirmations.c b/src/auditordb/pg_delete_deposit_confirmations.c
new file mode 100644
index 000000000..553e97121
--- /dev/null
+++ b/src/auditordb/pg_delete_deposit_confirmations.c
@@ -0,0 +1,62 @@
+/*
+ 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/>
+ */
+/**
+ * @file auditordb/pg_delete_deposit_confirmations.c
+ * @brief Implementation of the delete_deposit_confirmations function for Postgres
+ * @author Nicola Eigel
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_deposit_confirmations.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_deposit_confirmations (
+ void *cls,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (exchange_sig),
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_delete_deposit_confirmations",
+ "DELETE"
+ " FROM deposit_confirmations"
+ " WHERE h_contract_terms=$1"
+ " AND h_wire=$2"
+ " AND merchant_pub=$3"
+ " AND exchange_sig=$4"
+ " AND exchange_pub=$5"
+ " AND master_sig=$6;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_delete_deposit_confirmations",
+ params);
+}
diff --git a/src/auditordb/pg_delete_deposit_confirmations.h b/src/auditordb/pg_delete_deposit_confirmations.h
new file mode 100644
index 000000000..f0339fd3d
--- /dev/null
+++ b/src/auditordb/pg_delete_deposit_confirmations.h
@@ -0,0 +1,51 @@
+/*
+ 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/>
+ */
+/**
+ * @file auditordb/pg_delete_deposit_confirmations.h
+ * @brief implementation of the delete_deposit_confirmations function for Postgres
+ * @author Nicola Eigel
+ */
+#ifndef PG_DELETE_DEPOSIT_CONFIRMATIONS_H
+#define PG_DELETE_DEPOSIT_CONFIRMATIONS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Delete a row from the deposit confirmations table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_contract_terms private contract hash
+ * @param h_wire merchant wire hash
+ * @param merchant_pub master key of the merchant
+ * @param exchange_sig signature of the exchange
+ * @param exchange_pub master key of the exchange
+ * @param master_sig master signature of the exchange
+ * @return
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_deposit_confirmations (
+ void *cls,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_MasterSignatureP *master_sig);
+
+
+#endif
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 2b722a5ea..dc66990ba 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -77,6 +77,7 @@
#include "pg_insert_exchange_signkey.h"
#include "pg_insert_deposit_confirmation.h"
#include "pg_get_deposit_confirmations.h"
+#include "pg_delete_deposit_confirmations.h"
#include "pg_insert_auditor_progress_coin.h"
#include "pg_update_auditor_progress_coin.h"
#include "pg_get_auditor_progress_coin.h"