From 8c31e07f21958dba418129fcedc47193936d28ab Mon Sep 17 00:00:00 2001 From: Cedric Zwahlen Date: Fri, 22 Mar 2024 15:14:28 +0100 Subject: Add more functions --- src/auditor/Makefile.am | 7 ++ ...tor-httpd_amount-arithmetic-inconsistency-del.c | 59 +++++++++ ...tor-httpd_amount-arithmetic-inconsistency-del.h | 41 +++++++ ...tor-httpd_amount-arithmetic-inconsistency-put.c | 131 ++++++++++++++++++++ ...tor-httpd_amount-arithmetic-inconsistency-put.h | 45 +++++++ .../taler-auditor-httpd_coin-inconsistency-del.c | 58 +++++++++ .../taler-auditor-httpd_coin-inconsistency-del.h | 45 +++++++ .../taler-auditor-httpd_coin-inconsistency-put.c | 133 +++++++++++++++++++++ .../taler-auditor-httpd_coin-inconsistency-put.h | 45 +++++++ .../taler-auditor-httpd_row-inconsistency-del.c | 59 +++++++++ .../taler-auditor-httpd_row-inconsistency-del.h | 45 +++++++ .../taler-auditor-httpd_row-inconsistency-put.c | 132 ++++++++++++++++++++ .../taler-auditor-httpd_row-inconsistency-put.h | 45 +++++++ src/auditordb/0002-auditor_coin_inconsistency.sql | 2 +- src/auditordb/Makefile.am | 10 +- .../pg_del_amount_arithmetic_inconsistency.c | 29 +++++ .../pg_del_amount_arithmetic_inconsistency.h | 24 ++++ src/auditordb/pg_del_coin_inconsistency.c | 29 +++++ src/auditordb/pg_del_coin_inconsistency.h | 24 ++++ src/auditordb/pg_del_row_inconsistency.c | 28 +++++ src/auditordb/pg_del_row_inconsistency.h | 24 ++++ .../pg_insert_amount_arithmetic_inconsistency.c | 42 +++++++ .../pg_insert_amount_arithmetic_inconsistency.h | 25 ++++ src/auditordb/pg_insert_coin_inconsistency.c | 44 +++++++ src/auditordb/pg_insert_coin_inconsistency.h | 25 ++++ src/auditordb/pg_insert_row_inconsistency.c | 34 ++++++ src/auditordb/pg_insert_row_inconsistency.h | 25 ++++ src/auditordb/plugin_auditordb_postgres.c | 29 +++++ src/include/taler_auditordb_plugin.h | 50 ++++++++ 29 files changed, 1287 insertions(+), 2 deletions(-) create mode 100644 src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c create mode 100644 src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.h create mode 100644 src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.c create mode 100644 src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.h create mode 100644 src/auditor/taler-auditor-httpd_coin-inconsistency-del.c create mode 100644 src/auditor/taler-auditor-httpd_coin-inconsistency-del.h create mode 100644 src/auditor/taler-auditor-httpd_coin-inconsistency-put.c create mode 100644 src/auditor/taler-auditor-httpd_coin-inconsistency-put.h create mode 100644 src/auditor/taler-auditor-httpd_row-inconsistency-del.c create mode 100644 src/auditor/taler-auditor-httpd_row-inconsistency-del.h create mode 100644 src/auditor/taler-auditor-httpd_row-inconsistency-put.c create mode 100644 src/auditor/taler-auditor-httpd_row-inconsistency-put.h create mode 100644 src/auditordb/pg_del_amount_arithmetic_inconsistency.c create mode 100644 src/auditordb/pg_del_amount_arithmetic_inconsistency.h create mode 100644 src/auditordb/pg_del_coin_inconsistency.c create mode 100644 src/auditordb/pg_del_coin_inconsistency.h create mode 100644 src/auditordb/pg_del_row_inconsistency.c create mode 100644 src/auditordb/pg_del_row_inconsistency.h create mode 100644 src/auditordb/pg_insert_amount_arithmetic_inconsistency.c create mode 100644 src/auditordb/pg_insert_amount_arithmetic_inconsistency.h create mode 100644 src/auditordb/pg_insert_coin_inconsistency.c create mode 100644 src/auditordb/pg_insert_coin_inconsistency.h create mode 100644 src/auditordb/pg_insert_row_inconsistency.c create mode 100644 src/auditordb/pg_insert_row_inconsistency.h diff --git a/src/auditor/Makefile.am b/src/auditor/Makefile.am index f2aef6c84..1ef3f2b9e 100644 --- a/src/auditor/Makefile.am +++ b/src/auditor/Makefile.am @@ -158,6 +158,7 @@ taler_helper_auditor_wire_LDADD = \ -lgnunetutil \ $(XLIB) +# MARK: CRUD taler_auditor_httpd_SOURCES = \ taler-auditor-httpd.c taler-auditor-httpd.h \ @@ -167,6 +168,12 @@ taler_auditor_httpd_SOURCES = \ 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_amount-arithmetic-inconsistency-del.c taler-auditor-httpd_amount-arithmetic-inconsistency-del.h \ + taler-auditor-httpd_coin-inconsistency-del.c taler-auditor-httpd_coin-inconsistency-del.h \ + taler-auditor-httpd_row-inconsistency-del.c taler-auditor-httpd_row-inconsistency-del.h \ + taler-auditor-httpd_amount-arithmetic-inconsistency-put.c taler-auditor-httpd_amount-arithmetic-inconsistency-put.h \ + taler-auditor-httpd_coin-inconsistency-put.c taler-auditor-httpd_coin-inconsistency-put.h \ + taler-auditor-httpd_row-inconsistency-put.c taler-auditor-httpd_row-inconsistency-put.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_amount-arithmetic-inconsistency-del.c b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c new file mode 100644 index 000000000..1fcf3c6b3 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c @@ -0,0 +1,59 @@ +#include "taler-auditor-httpd_amount-arithmetic-inconsistency-del.h" + + +MHD_RESULT +TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + // TODO: check for null first + uint64_t row_id = atoi (args[1]); + + + 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); + } + + + // execute the transaction + qs = TAH_plugin->delete_amount_arithmetic_inconsistency (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /amount-arithmetic-inconsistency/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "AMOUNT_ARITHMETIC_INCONSISTENCY_OK")); + + return res; +} \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.h b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.h new file mode 100644 index 000000000..138847768 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.h @@ -0,0 +1,41 @@ +#ifndef SRC_TALER_AUDITOR_HTTPD_AMOUNT_ARITHMETIC_INCONSISTENCY_DEL_H +#define SRC_TALER_AUDITOR_HTTPD_AMOUNT_ARITHMETIC_INCONSISTENCY_DEL_H + +#include +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_AMOUNT_ARITHMETIC_INCONSISTENCY_DELETE_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_AMOUNT_ARITHMETIC_INCONSISTENCY_DELETE_done (void); + +/** + * Handle a "/deposit-confirmation" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @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_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_delete (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_AMOUNT_ARITHMETIC_INCONSISTENCY_DEL_H \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.c b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.c new file mode 100644 index 000000000..2471b4d94 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.c @@ -0,0 +1,131 @@ +// +// Created by parallels on 21/03/24. +// + +#include "platform.h" +#include +#include +#include +#include +#include +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" +#include "taler-auditor-httpd_amount-arithmetic-inconsistency-put.h" + +/** + * We have parsed the JSON information about the deposit, do some + * basic sanity checks (especially that the signature on the coin is + * valid, and that this type of coin exists) and then execute the + * deposit. + * + * @param connection the MHD connection to handle + * @param dc information about the deposit confirmation + * @param es information about the exchange's signing key + * @return MHD result code + */ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + /* execute transaction */ + qs = TAH_plugin->insert_amount_arithmetic_inconsistency (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /insert-amount-arithmetic in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert amount arithmetic"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "INSERT_AMOUNT_ARITHMETIC_OK")); +} + + +MHD_RESULT +TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_AmountArithmeticInconsistency dc = { + + }; + + + struct GNUNET_JSON_Specification spec[] = { + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + + GNUNET_JSON_parse_free (spec); + json_decref (json); + return res; + +} + + +void +TEAH_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_init (void) +{ + +} + + +void +TEAH_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_done (void) +{ + +} \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.h b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.h new file mode 100644 index 000000000..c0a85ac63 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-put.h @@ -0,0 +1,45 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_TALER_AUDITOR_HTTPD_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_H +#define SRC_TALER_AUDITOR_HTTPD_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_H + +#include +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_done (void); + + +/** + * Handle a "/deposit-confirmation" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @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_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_handler (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_AMOUNT_ARITHMETIC_INCONSISTENCY_PUT_H diff --git a/src/auditor/taler-auditor-httpd_coin-inconsistency-del.c b/src/auditor/taler-auditor-httpd_coin-inconsistency-del.c new file mode 100644 index 000000000..3f767a649 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_coin-inconsistency-del.c @@ -0,0 +1,58 @@ +// +// Created by parallels on 21/03/24. +// + +#include "taler-auditor-httpd_coin-inconsistency-del.h" + +MHD_RESULT +TAH_COIN_INCONSISTENCY_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + // TODO: check for null first + uint64_t row_id = atoi (args[1]); + + + 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); + } + + + // execute the transaction + qs = TAH_plugin->delete_coin_inconsistency (TAH_plugin->cls,row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ("Failed to handle DELETE /coin-inconsistency/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "COIN_INCONSISTENCY_OK")); + + return res; +} \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_coin-inconsistency-del.h b/src/auditor/taler-auditor-httpd_coin-inconsistency-del.h new file mode 100644 index 000000000..765fcf233 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_coin-inconsistency-del.h @@ -0,0 +1,45 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_DEL_H +#define SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_DEL_H + + +#include +#include +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_COIN_INCONSISTENCY_DELETE_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_COIN_INCONSISTENCY_DELETE_done (void); + +/** + * Handle a "/deposit-confirmation" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @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_delete (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_DEL_H diff --git a/src/auditor/taler-auditor-httpd_coin-inconsistency-put.c b/src/auditor/taler-auditor-httpd_coin-inconsistency-put.c new file mode 100644 index 000000000..d000b9b3b --- /dev/null +++ b/src/auditor/taler-auditor-httpd_coin-inconsistency-put.c @@ -0,0 +1,133 @@ +// +// Created by parallels on 21/03/24. +// + + +#include "platform.h" +#include +#include +#include +#include +#include +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" +#include "taler-auditor-httpd_coin-inconsistency-put.h" + +/** + * We have parsed the JSON information about the deposit, do some + * basic sanity checks (especially that the signature on the coin is + * valid, and that this type of coin exists) and then execute the + * deposit. + * + * @param connection the MHD connection to handle + * @param dc information about the deposit confirmation + * @param es information about the exchange's signing key + * @return MHD result code + */ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + /* execute transaction */ + qs = TAH_plugin->insert_amount_arithmetic_inconsistency (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /insert-amount-arithmetic in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert amount arithmetic"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "INSERT_AMOUNT_ARITHMETIC_OK")); +} + + +MHD_RESULT +TAH_COIN_INCONSISTENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_AmountArithmeticInconsistency dc = { + + }; + + + struct GNUNET_JSON_Specification spec[] = { + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + + GNUNET_JSON_parse_free (spec); + json_decref (json); + return res; + +} + + +void +TEAH_COIN_INCONSISTENCY_PUT_init (void) +{ + +} + + +void +TEAH_COIN_INCONSISTENCY_PUT_done (void) +{ + +} \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_coin-inconsistency-put.h b/src/auditor/taler-auditor-httpd_coin-inconsistency-put.h new file mode 100644 index 000000000..7fab43ef0 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_coin-inconsistency-put.h @@ -0,0 +1,45 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_PUT_H +#define SRC_TALER_AUDITOR_HTTPD_COIN_INCONSISTENCY_PUT_H + + +#include +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_COIN_INCONSISTENCY_PUT_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_COIN_INCONSISTENCY_PUT_done (void); + + +/** + * Handle a "/deposit-confirmation" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @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_PUT_handler (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_PUT_H diff --git a/src/auditor/taler-auditor-httpd_row-inconsistency-del.c b/src/auditor/taler-auditor-httpd_row-inconsistency-del.c new file mode 100644 index 000000000..04d32d775 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_row-inconsistency-del.c @@ -0,0 +1,59 @@ +// +// Created by parallels on 21/03/24. +// + +#include "taler-auditor-httpd_row-inconsistency-del.h" + + +MHD_RESULT +TAH_ROW_INCONSISTENCY_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + // TODO: check for null first + uint64_t row_id = atoi (args[1]); + + + 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); + } + + + // execute the transaction + qs = TAH_plugin->delete_row_inconsistency (TAH_plugin->cls,row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ("Failed to handle DELETE /row-inconsistency/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "ROW_INCONSISTENCY_OK")); + + return res; +} \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_row-inconsistency-del.h b/src/auditor/taler-auditor-httpd_row-inconsistency-del.h new file mode 100644 index 000000000..a1dea7c71 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_row-inconsistency-del.h @@ -0,0 +1,45 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_DEL_H +#define SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_DEL_H + + +#include +#include +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_ROW_INCONSISTENCY_DELETE_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_ROW_INCONSISTENCY_DELETE_done (void); + +/** + * Handle a "/deposit-confirmation" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @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_delete (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_DEL_H diff --git a/src/auditor/taler-auditor-httpd_row-inconsistency-put.c b/src/auditor/taler-auditor-httpd_row-inconsistency-put.c new file mode 100644 index 000000000..028c9e858 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_row-inconsistency-put.c @@ -0,0 +1,132 @@ +// +// Created by parallels on 21/03/24. +// + +#include "platform.h" +#include +#include +#include +#include +#include +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" +#include "taler-auditor-httpd_coin-inconsistency-put.h" + + +/** + * We have parsed the JSON information about the deposit, do some + * basic sanity checks (especially that the signature on the coin is + * valid, and that this type of coin exists) and then execute the + * deposit. + * + * @param connection the MHD connection to handle + * @param dc information about the deposit confirmation + * @param es information about the exchange's signing key + * @return MHD result code + */ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc) +{ + enum GNUNET_DB_QueryStatus qs; + + /* execute transaction */ + qs = TAH_plugin->insert_amount_arithmetic_inconsistency (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /insert-amount-arithmetic in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert amount arithmetic"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "INSERT_AMOUNT_ARITHMETIC_OK")); +} + + +MHD_RESULT +TAH_ROW_INCONSISTENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_AmountArithmeticInconsistency dc = { + + }; + + + struct GNUNET_JSON_Specification spec[] = { + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + + GNUNET_JSON_parse_free (spec); + json_decref (json); + return res; + +} + + +void +TEAH_ROW_INCONSISTENCY_PUT_init (void) +{ + +} + + +void +TEAH_ROW_INCONSISTENCY_PUT_done (void) +{ + +} \ No newline at end of file diff --git a/src/auditor/taler-auditor-httpd_row-inconsistency-put.h b/src/auditor/taler-auditor-httpd_row-inconsistency-put.h new file mode 100644 index 000000000..571ea507c --- /dev/null +++ b/src/auditor/taler-auditor-httpd_row-inconsistency-put.h @@ -0,0 +1,45 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_PUT_H +#define SRC_TALER_AUDITOR_HTTPD_ROW_INCONSISTENCY_PUT_H + + +#include +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_ROW_INCONSISTENCY_PUT_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_ROW_INCONSISTENCY_PUT_done (void); + + +/** + * Handle a "/deposit-confirmation" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @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_PUT_handler (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_PUT_H diff --git a/src/auditordb/0002-auditor_coin_inconsistency.sql b/src/auditordb/0002-auditor_coin_inconsistency.sql index 46400172b..90d8c54e7 100644 --- a/src/auditordb/0002-auditor_coin_inconsistency.sql +++ b/src/auditordb/0002-auditor_coin_inconsistency.sql @@ -18,7 +18,7 @@ SET search_path TO auditor; CREATE TABLE IF NOT EXISTS auditor_coin_inconsistency ( row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY, - operation BYTEA, + operation BYTEA NOT NULL CHECK (LENGTH(operation)=64), exchange_amount taler_amount, auditor_amount taler_amount, coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32), diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am index 0042ace8d..abf884b66 100644 --- a/src/auditordb/Makefile.am +++ b/src/auditordb/Makefile.am @@ -56,6 +56,8 @@ plugin_LTLIBRARIES = \ libtaler_plugin_auditordb_postgres.la endif +# MARK: CRUD + libtaler_plugin_auditordb_postgres_la_SOURCES = \ plugin_auditordb_postgres.c pg_helper.h \ pg_delete_deposit_confirmations.c pg_delete_deposit_confirmations.h \ @@ -92,7 +94,13 @@ libtaler_plugin_auditordb_postgres_la_SOURCES = \ 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_coin_inconsistency.c pg_get_coin_inconsistency.h \ - pg_get_row_inconsistency.c pg_get_row_inconsistency.h + pg_get_row_inconsistency.c pg_get_row_inconsistency.h \ + pg_insert_amount_arithmetic_inconsistency.c pg_insert_amount_arithmetic_inconsistency.h \ + pg_insert_coin_inconsistency.c pg_insert_coin_inconsistency.h \ + pg_insert_row_inconsistency.c pg_insert_row_inconsistency.h \ + pg_del_amount_arithmetic_inconsistency.c pg_del_amount_arithmetic_inconsistency.h \ + pg_del_coin_inconsistency.c pg_del_coin_inconsistency.h \ + pg_del_row_inconsistency.c pg_del_row_inconsistency.h libtaler_plugin_auditordb_postgres_la_LDFLAGS = \ $(TALER_PLUGIN_LDFLAGS) libtaler_plugin_auditordb_postgres_la_LIBADD = \ diff --git a/src/auditordb/pg_del_amount_arithmetic_inconsistency.c b/src/auditordb/pg_del_amount_arithmetic_inconsistency.c new file mode 100644 index 000000000..42dd2d2b1 --- /dev/null +++ b/src/auditordb/pg_del_amount_arithmetic_inconsistency.c @@ -0,0 +1,29 @@ +// +// Created by parallels on 21/03/24. +// + +#include "pg_del_amount_arithmetic_inconsistency.h" + +#include "taler_pq_lib.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TAH_PG_del_amount_arithmetic_inconsistency ( + void *cls, + uint64_t row_id) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&row_id), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_delete_amount_arithmetic_inconsistency", + "DELETE" + " FROM auditor_amount_arithmetic_inconsistency" + " WHERE row_id=$1;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_delete_amount_arithmetic_inconsistency", + params); +} diff --git a/src/auditordb/pg_del_amount_arithmetic_inconsistency.h b/src/auditordb/pg_del_amount_arithmetic_inconsistency.h new file mode 100644 index 000000000..bf253617d --- /dev/null +++ b/src/auditordb/pg_del_amount_arithmetic_inconsistency.h @@ -0,0 +1,24 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_PG_DEL_AMOUNT_ARITHMETIC_INCONSISTENCY_H +#define SRC_PG_DEL_AMOUNT_ARITHMETIC_INCONSISTENCY_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 row_id row to delete + * @return query transaction status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_del_amount_arithmetic_inconsistency ( + void *cls, + uint64_t row_id); + +#endif // SRC_PG_DEL_AMOUNT_ARITHMETIC_INCONSISTENCY_H diff --git a/src/auditordb/pg_del_coin_inconsistency.c b/src/auditordb/pg_del_coin_inconsistency.c new file mode 100644 index 000000000..9d9265ebb --- /dev/null +++ b/src/auditordb/pg_del_coin_inconsistency.c @@ -0,0 +1,29 @@ +// +// Created by parallels on 21/03/24. +// + +#include "pg_del_coin_inconsistency.h" + +#include "taler_pq_lib.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TAH_PG_del_coin_inconsistency ( + void *cls, + uint64_t row_id) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&row_id), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_delete_coin_inconsistency", + "DELETE" + " FROM auditor_coin_inconsistency" + " WHERE row_id=$1;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_delete_coin_inconsistency", + params); +} diff --git a/src/auditordb/pg_del_coin_inconsistency.h b/src/auditordb/pg_del_coin_inconsistency.h new file mode 100644 index 000000000..c190d6d9f --- /dev/null +++ b/src/auditordb/pg_del_coin_inconsistency.h @@ -0,0 +1,24 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_PG_DEL_COIN_INCONSISTENCY_H +#define SRC_PG_DEL_COIN_INCONSISTENCY_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 row_id row to delete + * @return query transaction status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_del_coin_inconsistency ( + void *cls, + uint64_t row_id); + +#endif // SRC_PG_DEL_COIN_INCONSISTENCY_H diff --git a/src/auditordb/pg_del_row_inconsistency.c b/src/auditordb/pg_del_row_inconsistency.c new file mode 100644 index 000000000..d906628c9 --- /dev/null +++ b/src/auditordb/pg_del_row_inconsistency.c @@ -0,0 +1,28 @@ +// +// Created by parallels on 21/03/24. +// + +#include "pg_del_row_inconsistency.h" +#include "taler_pq_lib.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TAH_PG_del_row_inconsistency ( + void *cls, + uint64_t row_id) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&row_id), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_delete_row_inconsistency", + "DELETE" + " FROM auditor_row_inconsistency" + " WHERE row_id=$1;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_delete_row_inconsistency", + params); +} diff --git a/src/auditordb/pg_del_row_inconsistency.h b/src/auditordb/pg_del_row_inconsistency.h new file mode 100644 index 000000000..665792c3b --- /dev/null +++ b/src/auditordb/pg_del_row_inconsistency.h @@ -0,0 +1,24 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_PG_DEL_ROW_INCONSISTENCY_H +#define SRC_PG_DEL_ROW_INCONSISTENCY_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 row_id row to delete + * @return query transaction status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_del_row_inconsistency ( + void *cls, + uint64_t row_id); + +#endif // SRC_PG_DEL_ROW_INCONSISTENCY_H diff --git a/src/auditordb/pg_insert_amount_arithmetic_inconsistency.c b/src/auditordb/pg_insert_amount_arithmetic_inconsistency.c new file mode 100644 index 000000000..50a3bf86c --- /dev/null +++ b/src/auditordb/pg_insert_amount_arithmetic_inconsistency.c @@ -0,0 +1,42 @@ +// +// Created by parallels on 21/03/24. +// + +#include "pg_insert_amount_arithmetic_inconsistency.h" + + +#include "platform.h" +#include "taler_pq_lib.h" + +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TAH_PG_insert_amount_arithmetic_inconsistency ( + void *cls, + const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + + GNUNET_PQ_query_param_auto_from_type (&dc->operation), + TALER_PQ_query_param_amount (pg->conn, + &dc->exchange_amount), + TALER_PQ_query_param_amount (pg->conn, + &dc->auditor_amount), + GNUNET_PQ_query_param_bool (dc->profitable), + + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_amount_arithmetic_inconsistency_insert", + "INSERT INTO auditor_amount_arithmetic_inconsistency " + "(operation" + ",exchange_amount" + ",auditor_amount" + ",profitable" + ") VALUES ($1,$2,$3,$4,$5);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_amount_arithmetic_inconsistency_insert", + params); +} diff --git a/src/auditordb/pg_insert_amount_arithmetic_inconsistency.h b/src/auditordb/pg_insert_amount_arithmetic_inconsistency.h new file mode 100644 index 000000000..4bde6c2b2 --- /dev/null +++ b/src/auditordb/pg_insert_amount_arithmetic_inconsistency.h @@ -0,0 +1,25 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_PG_INSERT_AMOUNT_ARITHMETIC_INCONSISTENCY_H +#define SRC_PG_INSERT_AMOUNT_ARITHMETIC_INCONSISTENCY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about a deposit confirmation into the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param dc deposit confirmation information to store + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_amount_arithmetic_inconsistency ( + void *cls, + const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc); + +#endif // SRC_PG_INSERT_AMOUNT_ARITHMETIC_INCONSISTENCY_H diff --git a/src/auditordb/pg_insert_coin_inconsistency.c b/src/auditordb/pg_insert_coin_inconsistency.c new file mode 100644 index 000000000..3b052cd4e --- /dev/null +++ b/src/auditordb/pg_insert_coin_inconsistency.c @@ -0,0 +1,44 @@ +// +// Created by parallels on 21/03/24. +// + +#include "pg_insert_coin_inconsistency.h" + +#include "platform.h" +#include "taler_pq_lib.h" + +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_insert_coin_inconsistency ( + void *cls, + const struct TALER_AUDITORDB_CoinInconsistency *dc) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + + GNUNET_PQ_query_param_auto_from_type (&dc->operation), + TALER_PQ_query_param_amount (pg->conn, + &dc->exchange_amount), + TALER_PQ_query_param_amount (pg->conn, + &dc->auditor_amount), + GNUNET_PQ_query_param_auto_from_type (&dc->coin_pub), + GNUNET_PQ_query_param_bool (dc->profitable), + + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_coin_inconsistency_insert", + "INSERT INTO auditor_coin_inconsistency " + "(operation" + ",exchange_amount" + ",auditor_amount" + ",coin_pub" + ",profitable" + ") VALUES ($1,$2,$3,$4,$5);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_coin_inconsistency_insert", + params); +} diff --git a/src/auditordb/pg_insert_coin_inconsistency.h b/src/auditordb/pg_insert_coin_inconsistency.h new file mode 100644 index 000000000..fc1893b5e --- /dev/null +++ b/src/auditordb/pg_insert_coin_inconsistency.h @@ -0,0 +1,25 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_PG_INSERT_COIN_INCONSISTENCY_H +#define SRC_PG_INSERT_COIN_INCONSISTENCY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about a deposit confirmation into the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param dc deposit confirmation information to store + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_coin_inconsistency ( + void *cls, + const struct TALER_AUDITORDB_CoinInconsistency *dc); + +#endif // SRC_PG_INSERT_COIN_INCONSISTENCY_H diff --git a/src/auditordb/pg_insert_row_inconsistency.c b/src/auditordb/pg_insert_row_inconsistency.c new file mode 100644 index 000000000..6d90f0244 --- /dev/null +++ b/src/auditordb/pg_insert_row_inconsistency.c @@ -0,0 +1,34 @@ +// +// Created by parallels on 21/03/24. +// + +#include "pg_insert_row_inconsistency.h" + +#include "platform.h" +#include "taler_pq_lib.h" + +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TAH_PG_insert_row_inconsistency ( + void *cls, + const struct TALER_AUDITORDB_RowInconsistency *dc) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + + GNUNET_PQ_query_param_string (dc->row_table), + GNUNET_PQ_query_param_string (dc->diagnostic), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "auditor_row_inconsistency_insert", + "INSERT INTO auditor_row_inconsistency " + "(row_table" + ",diagnostic" + ") VALUES ($1,$2);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "auditor_row_inconsistency_insert", + params); +} diff --git a/src/auditordb/pg_insert_row_inconsistency.h b/src/auditordb/pg_insert_row_inconsistency.h new file mode 100644 index 000000000..cb3b62f56 --- /dev/null +++ b/src/auditordb/pg_insert_row_inconsistency.h @@ -0,0 +1,25 @@ +// +// Created by parallels on 21/03/24. +// + +#ifndef SRC_PG_INSERT_ROW_INCONSISTENCY_H +#define SRC_PG_INSERT_ROW_INCONSISTENCY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Insert information about a deposit confirmation into the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param dc deposit confirmation information to store + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_insert_row_inconsistency ( + void *cls, + const struct TALER_AUDITORDB_RowInconsistency *dc); + +#endif // SRC_PG_INSERT_ROW_INCONSISTENCY_H diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index c204fc81f..bb5ff1fe4 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -60,6 +60,15 @@ #include "pg_get_coin_inconsistency.h" #include "pg_get_row_inconsistency.h" +// MARK: CRUD + +#include "pg_del_amount_arithmetic_inconsistency.h" +#include "pg_del_coin_inconsistency.h" +#include "pg_del_row_inconsistency.h" + +#include "pg_insert_coin_inconsistency.h" +#include "pg_insert_row_inconsistency.h" +#include "pg_insert_amount_arithmetic_inconsistency.h" #define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", \ __VA_ARGS__) @@ -452,6 +461,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } + + // MARK: CRUD + plugin = GNUNET_new (struct TALER_AUDITORDB_Plugin); plugin->cls = pg; plugin->preflight = &postgres_preflight; @@ -487,6 +499,7 @@ 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 @@ -494,6 +507,22 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->get_row_inconsistency = &TAH_PG_get_row_inconsistency; + + plugin->delete_row_inconsistency + = &TAH_PG_del_row_inconsistency; + plugin->delete_coin_inconsistency + = &TAH_PG_del_coin_inconsistency; + plugin->delete_amount_arithmetic_inconsistency + = &TAH_PG_del_amount_arithmetic_inconsistency; + + + plugin->insert_amount_arithmetic_inconsistency + = &TAH_PG_insert_amount_arithmetic_inconsistency; + plugin->insert_coin_inconsistency + = &TAH_PG_insert_coin_inconsistency; + plugin->insert_row_inconsistency + = &TAH_PG_insert_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 fc74a53d4..f0e8369d9 100644 --- a/src/include/taler_auditordb_plugin.h +++ b/src/include/taler_auditordb_plugin.h @@ -195,6 +195,8 @@ struct TALER_AUDITORDB_DepositConfirmation }; +// MARK: CRUD + /** * Information about an arithmetic inconsistency */ @@ -230,6 +232,8 @@ struct TALER_AUDITORDB_RowInconsistency char *diagnostic; }; +// MARK: CRUD + /** * Function called with arithmetic inconsistencies stored in * the auditor's database. @@ -713,6 +717,8 @@ struct TALER_AUDITORDB_Plugin void *cls, uint64_t row_id); + // MARK: CRUD + /** * Get information about arithmetic inconsistencies from the database. * @@ -749,6 +755,50 @@ struct TALER_AUDITORDB_Plugin void *cb_cls); + /** + * Delete information about a deposit confirmation from the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param row_id row to delete + * @return query result status + */ + enum GNUNET_DB_QueryStatus + (*delete_amount_arithmetic_inconsistency)( + void *cls, + uint64_t row_id); + + enum GNUNET_DB_QueryStatus + (*delete_coin_inconsistency)( + void *cls, + uint64_t row_id); + + enum GNUNET_DB_QueryStatus + (*delete_row_inconsistency)( + void *cls, + uint64_t row_id); + + /** + * Insert information about a deposit confirmation into the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param dc deposit confirmation information to store + * @return query result status + */ + enum GNUNET_DB_QueryStatus + (*insert_amount_arithmetic_inconsistency)( + void *cls, + const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc); + + enum GNUNET_DB_QueryStatus + (*insert_coin_inconsistency)( + void *cls, + const struct TALER_AUDITORDB_CoinInconsistency *dc); + + enum GNUNET_DB_QueryStatus + (*insert_row_inconsistency)( + void *cls, + const struct TALER_AUDITORDB_RowInconsistency *dc); + /** * Insert information about a reserve. There must not be an * existing record for the reserve. -- cgit v1.2.3