summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Zwahlen <cedric.zwahlen@students.bfh.ch>2024-03-21 15:03:21 +0100
committerCedric Zwahlen <cedric.zwahlen@students.bfh.ch>2024-04-19 20:47:28 +0200
commitae82f786302180d5cd447a3dd80a643909b6cc57 (patch)
tree9b3ad7b9804cd755207e54367e444a8c74274364
parent611129a4f7fe5064d4d5d2f3009fdc45259d507d (diff)
downloadexchange-ae82f786302180d5cd447a3dd80a643909b6cc57.tar.gz
exchange-ae82f786302180d5cd447a3dd80a643909b6cc57.tar.bz2
exchange-ae82f786302180d5cd447a3dd80a643909b6cc57.zip
Add more functions
-rw-r--r--src/auditor/Makefile.am2
-rw-r--r--src/auditor/taler-auditor-httpd.c12
-rw-r--r--src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c16
-rw-r--r--src/auditor/taler-auditor-httpd_coin-inconsistency-get.c150
-rw-r--r--src/auditor/taler-auditor-httpd_coin-inconsistency-get.h36
-rw-r--r--src/auditor/taler-auditor-httpd_row-inconcistency-get.c5
-rw-r--r--src/auditor/taler-auditor-httpd_row-inconcistency-get.h8
-rw-r--r--src/auditor/taler-auditor-httpd_row-inconsistency-get.c155
-rw-r--r--src/auditor/taler-auditor-httpd_row-inconsistency-get.h44
-rw-r--r--src/auditordb/0002-auditor_coin_inconsistency.sql2
-rw-r--r--src/auditordb/Makefile.am4
-rw-r--r--src/auditordb/pg_get_amount_arithmetic_inconsistency.c17
-rw-r--r--src/auditordb/pg_get_coin_inconsistency.c155
-rw-r--r--src/auditordb/pg_get_coin_inconsistency.h31
-rw-r--r--src/auditordb/pg_get_row_inconsistency.c147
-rw-r--r--src/auditordb/pg_get_row_inconsistency.h31
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c10
-rw-r--r--src/include/taler_auditordb_plugin.h70
18 files changed, 871 insertions, 24 deletions
diff --git a/src/auditor/Makefile.am b/src/auditor/Makefile.am
index bd177698f..f2aef6c84 100644
--- a/src/auditor/Makefile.am
+++ b/src/auditor/Makefile.am
@@ -165,6 +165,8 @@ taler_auditor_httpd_SOURCES = \
taler-auditor-httpd_deposit-confirmation-get.c taler-auditor-httpd_deposit-confirmation-get.h \
taler-auditor-httpd_deposit-confirmation-del.c taler-auditor-httpd_deposit-confirmation-del.h \
taler-auditor-httpd_amount-arithmetic-inconsistency-get.c taler-auditor-httpd_amount-arithmetic-inconsistency-get.h \
+ taler-auditor-httpd_coin-inconsistency-get.c taler-auditor-httpd_coin-inconsistency-get.h \
+ taler-auditor-httpd_row-inconsistency-get.c taler-auditor-httpd_row-inconsistency-get.h \
taler-auditor-httpd_mhd.c taler-auditor-httpd_mhd.h
taler_auditor_httpd_LDADD = \
$(LIBGCRYPT_LIBS) \
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c
index ba1617b57..f0d1a81fb 100644
--- a/src/auditor/taler-auditor-httpd.c
+++ b/src/auditor/taler-auditor-httpd.c
@@ -34,6 +34,8 @@
#include "taler-auditor-httpd_deposit-confirmation-del.h"
#include "taler-auditor-httpd_deposit-confirmation-get.h"
#include "taler-auditor-httpd_amount-arithmetic-inconsistency-get.h"
+#include "taler-auditor-httpd_coin-inconsistency-get.h"
+#include "taler-auditor-httpd_row-inconsistency-get.h"
#include "taler-auditor-httpd_mhd.h"
#include "taler-auditor-httpd.h"
@@ -233,6 +235,16 @@ handle_mhd_request (void *cls,
NULL, 0,
&TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_get, MHD_HTTP_OK },
+ { "/coin-inconsistency", MHD_HTTP_METHOD_GET,
+ "application/json",
+ NULL, 0,
+ &TAH_COIN_INCONSISTENCY_handler_get, MHD_HTTP_OK },
+
+ { "/row-inconsistency", MHD_HTTP_METHOD_GET,
+ "application/json",
+ NULL, 0,
+ &TAH_ROW_INCONSISTENCY_handler_get, MHD_HTTP_OK },
+
{ "/config", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0,
&handle_config, MHD_HTTP_OK },
diff --git a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c
index 0fdd77245..c51ff2e2b 100644
--- a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c
+++ b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c
@@ -2,7 +2,6 @@
// Created by parallels on 19/03/24.
//
-#include "taler-auditor-httpd_amount-arithmetic-inconsistency-get.h"
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
@@ -13,7 +12,7 @@
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler-auditor-httpd.h"
-#include "taler-auditor-httpd_deposit-confirmation-get.h"
+#include "taler-auditor-httpd_amount-arithmetic-inconsistency-get.h"
/**
* Add deposit confirmation to the list.
@@ -33,12 +32,17 @@ add_amount_arithmetic_inconsistency (void *cls,
json_t *list = cls;
json_t *obj;
+ printf ("checkpoint pg_3\n");
+
obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("dc",
dc));
GNUNET_break (0 ==
json_array_append_new (list,
obj));
+
+ printf ("checkpoint pg_4\n");
+
return GNUNET_OK;
}
@@ -124,6 +128,8 @@ TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh,
}
}
+ printf ("checkpoint httpd\n");
+
qs = TAH_plugin->get_amount_arithmetic_inconsistency (
TAH_plugin->cls,
row_id,
@@ -136,15 +142,15 @@ TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh,
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
json_decref (ja);
TALER_LOG_WARNING (
- "Failed to handle GET /deposit-confirmation in database\n");
+ "Failed to handle GET /amount-arithmetic-inconsistency in database\n");
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
- "deposit-confirmation");
+ "amount-arithmetic-inconsistency");
}
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal ("deposit-confirmation",
+ GNUNET_JSON_pack_array_steal ("amount-arithmetic-inconsistency",
ja));
}
diff --git a/src/auditor/taler-auditor-httpd_coin-inconsistency-get.c b/src/auditor/taler-auditor-httpd_coin-inconsistency-get.c
index 16649109d..54b123864 100644
--- a/src/auditor/taler-auditor-httpd_coin-inconsistency-get.c
+++ b/src/auditor/taler-auditor-httpd_coin-inconsistency-get.c
@@ -2,4 +2,154 @@
// Created by parallels on 19/03/24.
//
+
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-auditor-httpd.h"
+
#include "taler-auditor-httpd_coin-inconsistency-get.h"
+
+/**
+ * Add deposit confirmation to the list.
+ *
+ * @param[in,out] cls a `json_t *` array to extend
+ * @param serial_id location of the @a dc in the database
+ * @param dc struct of inconsistencies
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+static enum GNUNET_GenericReturnValue
+add_coin_inconsistency (void *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_CoinInconsistency *dc)
+{
+ json_t *list = cls;
+ json_t *obj;
+
+ printf ("checkpoint pg_3\n");
+
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("dc",
+ dc));
+ GNUNET_break (0 ==
+ json_array_append_new (list,
+ obj));
+
+ printf ("checkpoint pg_4\n");
+
+ return GNUNET_OK;
+}
+
+
+/**
+ *
+ * @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_COIN_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *
+ connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size,
+ const char *const args[])
+{
+ 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);
+
+ uint64_t row_id = 0;
+ bool return_suppressed;
+
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 ("row_id",
+ &row_id),
+
+ GNUNET_JSON_spec_bool ("return_suppressed",
+ &return_suppressed),
+
+ GNUNET_JSON_spec_end ()
+ };
+
+
+ // read the input json
+ json_t *json_in;
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_post_json (connection,
+ connection_cls,
+ upload_data,
+ upload_data_size,
+ &json_in);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO;
+ if ((GNUNET_NO == res) ||
+ (NULL == json_in))
+ return MHD_YES;
+ res = TALER_MHD_parse_json_data (connection,
+ json_in,
+ spec);
+ if (GNUNET_SYSERR == res)
+ {
+ json_decref (json_in);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ json_decref (json_in);
+ return MHD_YES; /* failure */
+ }
+ }
+
+ printf ("checkpoint httpd\n");
+
+ qs = TAH_plugin->get_coin_inconsistency (
+ TAH_plugin->cls,
+ row_id,
+ return_suppressed,
+ &add_coin_inconsistency,
+ ja);
+
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ json_decref (ja);
+ TALER_LOG_WARNING (
+ "Failed to handle GET /coin-inconsistency in database\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "coin-inconsistency");
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("coin-inconsistency",
+ ja));
+} \ No newline at end of file
diff --git a/src/auditor/taler-auditor-httpd_coin-inconsistency-get.h b/src/auditor/taler-auditor-httpd_coin-inconsistency-get.h
index 49f00fa8f..271b8f1d9 100644
--- a/src/auditor/taler-auditor-httpd_coin-inconsistency-get.h
+++ b/src/auditor/taler-auditor-httpd_coin-inconsistency-get.h
@@ -5,4 +5,40 @@
#ifndef SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_GET_H
#define SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_GET_H
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include "taler-auditor-httpd.h"
+
+/**
+ * Initialize subsystem.
+ */
+void
+TEAH_COIN_INCONSISTENCY_GET_init (void);
+
+/**
+ * Shut down subsystem.
+ */
+void
+TEAH_COIN_INCONSISTENCY_GET_done (void);
+
+/**
+ * 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_COIN_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *
+ connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size,
+ const char *const args[]);
+
+
#endif // SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_GET_H
diff --git a/src/auditor/taler-auditor-httpd_row-inconcistency-get.c b/src/auditor/taler-auditor-httpd_row-inconcistency-get.c
deleted file mode 100644
index fbab615e0..000000000
--- a/src/auditor/taler-auditor-httpd_row-inconcistency-get.c
+++ /dev/null
@@ -1,5 +0,0 @@
-//
-// Created by parallels on 19/03/24.
-//
-
-#include "taler-auditor-httpd_row-inconcistency-get.h"
diff --git a/src/auditor/taler-auditor-httpd_row-inconcistency-get.h b/src/auditor/taler-auditor-httpd_row-inconcistency-get.h
deleted file mode 100644
index fb73dca55..000000000
--- a/src/auditor/taler-auditor-httpd_row-inconcistency-get.h
+++ /dev/null
@@ -1,8 +0,0 @@
-//
-// Created by parallels on 19/03/24.
-//
-
-#ifndef SRC_TALER_AUDITOR_HTTPD_ROW_INCONCISTENCY_GET_H
-#define SRC_TALER_AUDITOR_HTTPD_ROW_INCONCISTENCY_GET_H
-
-#endif // SRC_TALER_AUDITOR_HTTPD_ROW_INCONCISTENCY_GET_H
diff --git a/src/auditor/taler-auditor-httpd_row-inconsistency-get.c b/src/auditor/taler-auditor-httpd_row-inconsistency-get.c
new file mode 100644
index 000000000..1b614df7b
--- /dev/null
+++ b/src/auditor/taler-auditor-httpd_row-inconsistency-get.c
@@ -0,0 +1,155 @@
+//
+// Created by parallels on 19/03/24.
+//
+
+
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-auditor-httpd.h"
+
+#include "taler-auditor-httpd_row-inconsistency-get.h"
+
+/**
+ * Add deposit confirmation to the list.
+ *
+ * @param[in,out] cls a `json_t *` array to extend
+ * @param serial_id location of the @a dc in the database
+ * @param dc struct of inconsistencies
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+static enum GNUNET_GenericReturnValue
+add_row_inconsistency (void *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_RowInconsistency *dc)
+{
+ json_t *list = cls;
+ json_t *obj;
+
+ printf ("checkpoint pg_3\n");
+
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("dc",
+ dc));
+ GNUNET_break (0 ==
+ json_array_append_new (list,
+ obj));
+
+ printf ("checkpoint pg_4\n");
+
+ return GNUNET_OK;
+}
+
+
+/**
+ *
+ * @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_ROW_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *
+ connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size,
+ const char *const args[])
+{
+ 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);
+
+ uint64_t row_id = 0;
+ bool return_suppressed;
+
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 ("row_id",
+ &row_id),
+
+ GNUNET_JSON_spec_bool ("return_suppressed",
+ &return_suppressed),
+
+ GNUNET_JSON_spec_end ()
+ };
+
+
+ // read the input json
+ json_t *json_in;
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_post_json (connection,
+ connection_cls,
+ upload_data,
+ upload_data_size,
+ &json_in);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO;
+ if ((GNUNET_NO == res) ||
+ (NULL == json_in))
+ return MHD_YES;
+ res = TALER_MHD_parse_json_data (connection,
+ json_in,
+ spec);
+ if (GNUNET_SYSERR == res)
+ {
+ json_decref (json_in);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ json_decref (json_in);
+ return MHD_YES; /* failure */
+ }
+ }
+
+ printf ("checkpoint httpd\n");
+
+ qs = TAH_plugin->get_row_inconsistency (
+ TAH_plugin->cls,
+ row_id,
+ return_suppressed,
+ &add_row_inconsistency,
+ ja);
+
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ json_decref (ja);
+ TALER_LOG_WARNING (
+ "Failed to handle GET /row-inconsistency in database\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "row-inconsistency");
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("row-inconsistency",
+ ja));
+} \ No newline at end of file
diff --git a/src/auditor/taler-auditor-httpd_row-inconsistency-get.h b/src/auditor/taler-auditor-httpd_row-inconsistency-get.h
new file mode 100644
index 000000000..e17110ded
--- /dev/null
+++ b/src/auditor/taler-auditor-httpd_row-inconsistency-get.h
@@ -0,0 +1,44 @@
+//
+// Created by parallels on 19/03/24.
+//
+
+#ifndef SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_GET_H
+#define SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_GET_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include "taler-auditor-httpd.h"
+
+/**
+ * Initialize subsystem.
+ */
+void
+TEAH_ROW_INCONSISTENCY_GET_init (void);
+
+/**
+ * Shut down subsystem.
+ */
+void
+TEAH_ROW_INCONSISTENCY_GET_done (void);
+
+/**
+ * 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_ROW_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *
+ connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size,
+ const char *const args[]);
+
+
+#endif // SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_GET_H
diff --git a/src/auditordb/0002-auditor_coin_inconsistency.sql b/src/auditordb/0002-auditor_coin_inconsistency.sql
index 91f954a68..46400172b 100644
--- a/src/auditordb/0002-auditor_coin_inconsistency.sql
+++ b/src/auditordb/0002-auditor_coin_inconsistency.sql
@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS auditor_coin_inconsistency
operation BYTEA,
exchange_amount taler_amount,
auditor_amount taler_amount,
- coin_pub BYTEA,
+ coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32),
profitable BOOLEAN
);
COMMENT ON TABLE auditor_coin_inconsistency
diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am
index 3325635b7..0042ace8d 100644
--- a/src/auditordb/Makefile.am
+++ b/src/auditordb/Makefile.am
@@ -90,7 +90,9 @@ libtaler_plugin_auditordb_postgres_la_SOURCES = \
pg_update_purse_info.c pg_update_purse_info.h \
pg_update_reserve_info.c pg_update_reserve_info.h \
pg_update_wire_fee_summary.c pg_update_wire_fee_summary.h \
- pg_get_amount_arithmetic_inconsistency.c pg_get_amount_arithmetic_inconsistency.h
+ pg_get_amount_arithmetic_inconsistency.c pg_get_amount_arithmetic_inconsistency.h \
+ pg_get_coin_inconsistency.c pg_get_coin_inconsistency.h \
+ pg_get_row_inconsistency.c pg_get_row_inconsistency.h
libtaler_plugin_auditordb_postgres_la_LDFLAGS = \
$(TALER_PLUGIN_LDFLAGS)
libtaler_plugin_auditordb_postgres_la_LIBADD = \
diff --git a/src/auditordb/pg_get_amount_arithmetic_inconsistency.c b/src/auditordb/pg_get_amount_arithmetic_inconsistency.c
index fae427a17..6d01a3eb0 100644
--- a/src/auditordb/pg_get_amount_arithmetic_inconsistency.c
+++ b/src/auditordb/pg_get_amount_arithmetic_inconsistency.c
@@ -89,6 +89,8 @@ amount_arithmetic_inconsistency_cb (void *cls,
dcc->qs = i + 1;
+ printf ("checkpoint pg_2\n");
+
rval = dcc->cb (dcc->cb_cls,
serial_id,
&dc);
@@ -107,6 +109,8 @@ TAH_PG_get_amount_arithmetic_inconsistency (
TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb,
void *cb_cls)
{
+ printf ("checkpoint pg_0\n");
+
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&start_id),
@@ -120,14 +124,16 @@ TAH_PG_get_amount_arithmetic_inconsistency (
};
enum GNUNET_DB_QueryStatus qs;
+ printf ("checkpoint pg_1\n");
+
PREPARE (pg,
"auditor_amount_arithmetic_inconsistency_select",
"SELECT"
" row_id"
- " ,operation"
- " ,exchange_amount"
- " ,auditor_amount"
- " ,profitable"
+ ",operation"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",profitable"
" FROM auditor_amount_arithmetic_inconsistency"
" WHERE row_id>$1"
);
@@ -136,6 +142,9 @@ TAH_PG_get_amount_arithmetic_inconsistency (
params,
&amount_arithmetic_inconsistency_cb,
&dcc);
+
+ printf ("checkpoint pg_5\n");
+
if (qs > 0)
return dcc.qs;
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
diff --git a/src/auditordb/pg_get_coin_inconsistency.c b/src/auditordb/pg_get_coin_inconsistency.c
new file mode 100644
index 000000000..949136ca3
--- /dev/null
+++ b/src/auditordb/pg_get_coin_inconsistency.c
@@ -0,0 +1,155 @@
+//
+// Created by parallels on 20/03/24.
+//
+
+
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_helper.h"
+#include "pg_get_coin_inconsistency.h"
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct CoinInconsistencyContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_CoinInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+coin_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinInconsistencyContext *dcc = cls;
+ struct PostgresClosure *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+
+ struct TALER_AUDITORDB_CoinInconsistency dc;
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &serial_id),
+ // TODO: what type is this exactly
+ GNUNET_PQ_result_spec_auto_from_type ("operation",
+ &dc.operation),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount",
+ &dc.exchange_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("auditor_amount",
+ &dc.auditor_amount),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &dc.coin_pub),
+ GNUNET_PQ_result_spec_bool ("profitable",
+ &dc.profitable),
+
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+
+ printf ("checkpoint pg_2\n");
+
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_coin_inconsistency (
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed, // maybe not needed
+ TALER_AUDITORDB_CoinInconsistencyCallback cb,
+ void *cb_cls)
+{
+ printf ("checkpoint pg_0\n");
+
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&start_id),
+ // GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ struct CoinInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ printf ("checkpoint pg_1\n");
+
+ PREPARE (pg,
+ "auditor_coin_inconsistency_select",
+ "SELECT"
+ " row_id"
+ ",operation"
+ ",exchange_amount"
+ ",auditor_amount"
+ ",coin_pub"
+ ",profitable"
+ " FROM auditor_coin_inconsistency"
+ " WHERE row_id>$1"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "auditor_coin_inconsistency_select",
+ params,
+ &coin_inconsistency_cb,
+ &dcc);
+
+ printf ("checkpoint pg_5\n");
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+} \ No newline at end of file
diff --git a/src/auditordb/pg_get_coin_inconsistency.h b/src/auditordb/pg_get_coin_inconsistency.h
new file mode 100644
index 000000000..f64b1aa1e
--- /dev/null
+++ b/src/auditordb/pg_get_coin_inconsistency.h
@@ -0,0 +1,31 @@
+//
+// Created by parallels on 20/03/24.
+//
+
+#ifndef SRC_PG_GET_COIN_INCONSISTENCY_H
+#define SRC_PG_GET_COIN_INCONSISTENCY_H
+
+#include "taler_util.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param start_id row/serial ID where to start the iteration (0 from
+ * the start, exclusive, i.e. serial_ids must start from 1)
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_coin_inconsistency (
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_CoinInconsistencyCallback cb,
+ void *cb_cls);
+
+
+#endif // SRC_PG_GET_COIN_INCONSISTENCY_H
diff --git a/src/auditordb/pg_get_row_inconsistency.c b/src/auditordb/pg_get_row_inconsistency.c
new file mode 100644
index 000000000..f89b2fed9
--- /dev/null
+++ b/src/auditordb/pg_get_row_inconsistency.c
@@ -0,0 +1,147 @@
+//
+// Created by parallels on 20/03/24.
+//
+
+
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_helper.h"
+#include "pg_get_row_inconsistency.h"
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct RowInconsistencyContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_RowInconsistencyCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+row_inconsistency_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RowInconsistencyContext *dcc = cls;
+ struct PostgresClosure *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+
+ struct TALER_AUDITORDB_RowInconsistency dc;
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("row_id",
+ &serial_id),
+ // TODO: not sure if they are strings
+ GNUNET_PQ_result_spec_string ("row_table",
+ &dc.row_table),
+ GNUNET_PQ_result_spec_string ("diagnostic",
+ &dc.diagnostic),
+
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ dcc->qs = i + 1;
+
+ printf ("checkpoint pg_2\n");
+
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_row_inconsistency (
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed, // maybe not needed
+ TALER_AUDITORDB_RowInconsistencyCallback cb,
+ void *cb_cls)
+{
+ printf ("checkpoint pg_0\n");
+
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&start_id),
+ // GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ struct RowInconsistencyContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ printf ("checkpoint pg_1\n");
+
+ PREPARE (pg,
+ "auditor_row_inconsistency_select",
+ "SELECT"
+ " row_id"
+ ",row_table"
+ ",diagnostic"
+ " FROM auditor_row_inconsistency"
+ " WHERE row_id>$1"
+ );
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "auditor_row_inconsistency_select",
+ params,
+ &row_inconsistency_cb,
+ &dcc);
+
+ printf ("checkpoint pg_5\n");
+
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+} \ No newline at end of file
diff --git a/src/auditordb/pg_get_row_inconsistency.h b/src/auditordb/pg_get_row_inconsistency.h
new file mode 100644
index 000000000..7bfd37e32
--- /dev/null
+++ b/src/auditordb/pg_get_row_inconsistency.h
@@ -0,0 +1,31 @@
+//
+// Created by parallels on 20/03/24.
+//
+
+#ifndef SRC_PG_GET_ROW_INCONSISTENCY_H
+#define SRC_PG_GET_ROW_INCONSISTENCY_H
+
+#include "taler_util.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param start_id row/serial ID where to start the iteration (0 from
+ * the start, exclusive, i.e. serial_ids must start from 1)
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_row_inconsistency (
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_RowInconsistencyCallback cb,
+ void *cb_cls);
+
+
+#endif // SRC_PG_GET_ROW_INCONSISTENCY_H
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index f5c405d8d..c204fc81f 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -56,6 +56,9 @@
#include "pg_update_purse_info.h"
#include "pg_update_reserve_info.h"
#include "pg_update_wire_fee_summary.h"
+#include "pg_get_amount_arithmetic_inconsistency.h"
+#include "pg_get_coin_inconsistency.h"
+#include "pg_get_row_inconsistency.h"
#define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", \
@@ -484,6 +487,13 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->delete_deposit_confirmation
= &TAH_PG_delete_deposit_confirmation;
+ plugin->get_amount_arithmetic_inconsistency
+ = &TAH_PG_get_amount_arithmetic_inconsistency;
+ plugin->get_coin_inconsistency
+ = &TAH_PG_get_coin_inconsistency;
+ plugin->get_row_inconsistency
+ = &TAH_PG_get_row_inconsistency;
+
plugin->insert_reserve_info
= &TAH_PG_insert_reserve_info;
plugin->update_reserve_info
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index 039af097a..fc74a53d4 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -200,6 +200,7 @@ struct TALER_AUDITORDB_DepositConfirmation
*/
struct TALER_AUDITORDB_AmountArithmeticInconsistency
{
+ unsigned int row_id;
struct GNUNET_HashCode operation;
struct TALER_Amount exchange_amount;
struct TALER_Amount auditor_amount;
@@ -207,6 +208,29 @@ struct TALER_AUDITORDB_AmountArithmeticInconsistency
};
/**
+ * Information about a coin inconsistency
+ */
+struct TALER_AUDITORDB_CoinInconsistency
+{
+ unsigned int row_id;
+ struct GNUNET_HashCode operation;
+ struct TALER_Amount exchange_amount;
+ struct TALER_Amount auditor_amount;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ bool profitable;
+};
+
+/**
+ * Information about a row inconsistency
+ */
+struct TALER_AUDITORDB_RowInconsistency
+{
+ unsigned int row_id;
+ char *row_table;
+ char *diagnostic;
+};
+
+/**
* Function called with arithmetic inconsistencies stored in
* the auditor's database.
*
@@ -221,6 +245,36 @@ typedef enum GNUNET_GenericReturnValue
uint64_t serial_id,
const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc);
+/**
+ * Function called with coin inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param serial_id location of the @a dc in the database
+ * @param dc the deposit confirmation itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_CoinInconsistencyCallback)(
+ void *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_CoinInconsistency *dc);
+
+/**
+ * Function called with row inconsistencies stored in
+ * the auditor's database.
+ *
+ * @param cls closure
+ * @param serial_id location of the @a dc in the database
+ * @param dc the deposit confirmation itself
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_RowInconsistencyCallback)(
+ void *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_RowInconsistency *dc);
+
/**
* Balance values for a reserve (or all reserves).
@@ -678,6 +732,22 @@ struct TALER_AUDITORDB_Plugin
TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb,
void *cb_cls);
+ enum GNUNET_DB_QueryStatus
+ (*get_coin_inconsistency)(
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_CoinInconsistencyCallback cb,
+ void *cb_cls);
+
+ enum GNUNET_DB_QueryStatus
+ (*get_row_inconsistency)(
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_RowInconsistencyCallback cb,
+ void *cb_cls);
+
/**
* Insert information about a reserve. There must not be an