commit c3d3c09f0b114641341e5ee55f41fade5b47ad33 parent 208ded455c97ba7b96394001f05ae4ca75e7cf4a Author: Stefan Kügel <skuegel@web.de> Date: Sun, 15 Sep 2024 18:35:38 +0200 Merge branch 'master' of git+ssh://git.taler.net/exchange Diffstat:
44 files changed, 1023 insertions(+), 1331 deletions(-)
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c @@ -66,8 +66,6 @@ #include "taler-auditor-httpd_closure-lags-get.h" #include "taler-auditor-httpd_closure-lags-del.h" -#include "taler-auditor-httpd_progress-get.h" - #include "taler-auditor-httpd_refreshes-hanging-get.h" #include "taler-auditor-httpd_refreshes-hanging-del.h" @@ -134,6 +132,8 @@ #include "taler-auditor-httpd_fee-time-inconsistency-upd.h" #include "taler-auditor-httpd_balances-get.h" +#include "taler-auditor-httpd_progress-get.h" + /** * Auditor protocol version string. @@ -542,11 +542,6 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_update, MHD_HTTP_OK, true }, - { "/monitoring/progress", MHD_HTTP_METHOD_GET, - "application/json", - NULL, 0, - &TAH_PROGRESS_handler_get, - MHD_HTTP_OK, true }, { "/monitoring/reserve-balance-insufficient-inconsistency", MHD_HTTP_METHOD_GET, "application/json", @@ -768,6 +763,11 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_BALANCES_handler_get, MHD_HTTP_OK, true }, + { "/monitoring/progress", MHD_HTTP_METHOD_GET, + "application/json", + NULL, 0, + &TAH_PROGRESS_handler_get, + MHD_HTTP_OK, true }, { "/config", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, &handle_config, MHD_HTTP_OK, false }, @@ -858,7 +858,9 @@ handle_mhd_request (void *cls, } if (NULL == match) { - GNUNET_break_op (0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Could not find handler for `%s'\n", + url); goto not_found; } if (match->requires_auth && diff --git a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-get.c @@ -13,7 +13,6 @@ 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/> */ - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -30,30 +29,32 @@ * 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_amount_arithmetic_inconsistency ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_int64 ("row_id", - serial_id), - GNUNET_JSON_pack_data_auto ("operation", - &dc->operation), + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_uint64 ("problem_row_id", + dc->problem_row_id), + GNUNET_JSON_pack_string ("operation", + dc->operation), TALER_JSON_pack_amount ("exchange_amount", &dc->exchange_amount), TALER_JSON_pack_amount ("auditor_amount", &dc->auditor_amount), GNUNET_JSON_pack_bool ("profitable", - dc->profitable) + dc->profitable), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, @@ -123,7 +124,6 @@ TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_get ( return_suppressed, &add_amount_arithmetic_inconsistency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,14 +24,15 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_bad-sig-losses-get.h" + /** -* Add bad-sig-losses 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 -*/ + * Add bad-sig-losses 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_bad_sig_losses ( void *cls, @@ -44,18 +43,18 @@ add_bad_sig_losses ( json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_uint64 ("row_id", serial_id), - GNUNET_JSON_pack_string ("operation", dc->operation), - TALER_JSON_pack_amount ("loss", &dc->loss), + GNUNET_JSON_pack_uint64 ("row_id", + serial_id), + GNUNET_JSON_pack_string ("operation", + dc->operation), + TALER_JSON_pack_amount ("loss", + &dc->loss), GNUNET_JSON_pack_data_auto ("operation_specific_pub", &dc->operation_specific_pub) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -71,6 +70,12 @@ TAH_BAD_SIG_LOSSES_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; + struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub; + bool filter_spec_pub = false; + const char *op; (void) rh; (void) connection_cls; @@ -85,12 +90,6 @@ TAH_BAD_SIG_LOSSES_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); @@ -103,88 +102,39 @@ TAH_BAD_SIG_LOSSES_handler_get ( TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; - } - - const char *op = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "op"); - - - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub; - memset (&op_spec_pub,0, sizeof(op_spec_pub)); - - bool filter_spec_pub = false; - const char *ret_osp = MHD_lookup_connection_value (connection, + const char *ret_s = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, - "use_op_spec_pub"); - if (ret_osp != NULL && strcmp (ret_osp, "true") == 0) - { - filter_spec_pub = true; - - - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_fixed_auto ("operation_specific_pub", &op_spec_pub), - GNUNET_JSON_spec_end () - }; - - - json_t *json; + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - 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 */ - } + return_suppressed = true; } - } - + op = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "op"); + TALER_MHD_parse_request_arg_auto (connection, + "op_spec_pub", + &op_spec_pub, + filter_spec_pub); + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_bad_sig_losses ( TAH_plugin->cls, limit, offset, return_suppressed, - filter_spec_pub, - op_spec_pub, + filter_spec_pub ? &op_spec_pub : NULL, op, &add_bad_sig_losses, ja); if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_break (0); json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /bad-sig-losses\n"); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, diff --git a/src/auditor/taler-auditor-httpd_balances-get.c b/src/auditor/taler-auditor-httpd_balances-get.c @@ -28,22 +28,18 @@ * Add balance 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 + * @param dc struct of with balance data * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ static enum GNUNET_GenericReturnValue process_balances ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Balances *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_uint64 ("row_id", - serial_id), GNUNET_JSON_pack_string ("balance_key", dc->balance_key), TALER_JSON_pack_amount ("balance_value", @@ -52,8 +48,6 @@ process_balances ( GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -69,8 +63,6 @@ TAH_BALANCES_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; - int64_t limit = -20; - uint64_t offset; const char *balance_key; (void) rh; @@ -86,17 +78,6 @@ TAH_BALANCES_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - TALER_MHD_parse_request_snumber (connection, - "limit", - &limit); - - if (limit < 0) - offset = INT64_MAX; - else - offset = 0; - TALER_MHD_parse_request_number (connection, - "offset", - &offset); balance_key = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, @@ -105,8 +86,6 @@ TAH_BALANCES_handler_get ( GNUNET_break (NULL != ja); qs = TAH_plugin->get_balances ( TAH_plugin->cls, - limit, - offset, balance_key, &process_balances, ja); diff --git a/src/auditor/taler-auditor-httpd_balances-get.h b/src/auditor/taler-auditor-httpd_balances-get.h @@ -13,24 +13,13 @@ 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/> */ -#ifndef SRC_TALER_AUDITOR_HTTPD_BALANCES_GET_H -#define SRC_TALER_AUDITOR_HTTPD_BALANCES_GET_H +#ifndef TALER_AUDITOR_HTTPD_BALANCES_GET_H +#define TALER_AUDITOR_HTTPD_BALANCES_GET_H #include <gnunet/gnunet_util_lib.h> #include <microhttpd.h> #include "taler-auditor-httpd.h" -/** -* Initialize subsystem. -*/ -void -TEAH_BALANCES_GET_init (void); - -/** -* Shut down subsystem. -*/ -void -TEAH_BAD_BALANCES_GET_done (void); /** * Handle a "/balances" request. diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -28,28 +26,33 @@ "taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h" /** -* Add denomination-key-validity-withdraw-inconsistency 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 -*/ + * Add denomination-key-validity-withdraw-inconsistency to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate + */ static enum GNUNET_GenericReturnValue process_denomination_key_validity_withdraw_inconsistency ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - TALER_JSON_pack_time_abs_human ("execution_date", dc->execution_date), - GNUNET_JSON_pack_data_auto ("reserve_pub", &dc->reserve_pub), - GNUNET_JSON_pack_data_auto ("denompub_h", &dc->denompub_h) - + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_uint64 ("problem_row_id", + dc->problem_row_id), + TALER_JSON_pack_time_abs_human ("execution_date", + dc->execution_date), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &dc->reserve_pub), + GNUNET_JSON_pack_data_auto ("denompub_h", + &dc->denompub_h), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, @@ -71,6 +74,9 @@ TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -85,34 +91,28 @@ TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } - - + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_denomination_key_validity_withdraw_inconsistency ( TAH_plugin->cls, limit, @@ -120,7 +120,6 @@ TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_get ( return_suppressed, &process_denomination_key_validity_withdraw_inconsistency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); diff --git a/src/auditor/taler-auditor-httpd_denominations-without-sigs-get.c b/src/auditor/taler-auditor-httpd_denominations-without-sigs-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,39 +24,39 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_denominations-without-sigs-get.h" + /** -* Add denominations-without-sigs 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 -*/ + * Add denominations-without-sigs to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_denominations_without_sigs ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_int64 ("row_id", serial_id), - GNUNET_JSON_pack_data_auto ("denompub_h", &dc->denompub_h), - TALER_JSON_pack_amount ("value", &dc->value), - TALER_JSON_pack_time_abs_human ("start_time", dc->start_time), - TALER_JSON_pack_time_abs_human ("end_time", dc->end_time), - GNUNET_JSON_pack_bool ("suppressed", dc->suppressed) - - + GNUNET_JSON_pack_int64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_data_auto ("denompub_h", + &dc->denompub_h), + TALER_JSON_pack_amount ("value", + &dc->value), + TALER_JSON_pack_time_abs_human ("start_time", + dc->start_time), + TALER_JSON_pack_time_abs_human ("end_time", + dc->end_time), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -74,6 +72,9 @@ TAH_DENOMINATIONS_WITHOUT_SIGS_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -88,34 +89,28 @@ TAH_DENOMINATIONS_WITHOUT_SIGS_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_denominations_without_sigs ( TAH_plugin->cls, limit, diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-get.c b/src/auditor/taler-auditor-httpd_emergency-by-count-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -27,39 +25,43 @@ #include "taler-auditor-httpd_emergency-by-count-get.h" /** -* Add emergency-by-count 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 -*/ + * Add emergency-by-count to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_emergency_by_count ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_EmergenciesByCount *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_uint64 ("row_id", serial_id), - GNUNET_JSON_pack_data_auto ("denompub_h", &dc->denompub_h), - GNUNET_JSON_pack_int64 ("num_issued", dc->num_issued), - GNUNET_JSON_pack_int64 ("num_known", dc->num_known), - TALER_JSON_pack_amount ("risk", &dc->risk), - TALER_JSON_pack_time_abs_human ("start", dc->start), - TALER_JSON_pack_time_abs_human ("deposit_end", dc->deposit_end), - TALER_JSON_pack_amount ("value", &dc->value) - + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_data_auto ("denompub_h", + &dc->denompub_h), + GNUNET_JSON_pack_int64 ("num_issued", + dc->num_issued), + GNUNET_JSON_pack_int64 ("num_known", + dc->num_known), + TALER_JSON_pack_amount ("risk", + &dc->risk), + TALER_JSON_pack_time_abs_human ("start", + dc->start), + TALER_JSON_pack_time_abs_human ("deposit_end", + dc->deposit_end), + TALER_JSON_pack_amount ("value", + &dc->value), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -75,6 +77,9 @@ TAH_EMERGENCY_BY_COUNT_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -89,34 +94,29 @@ TAH_EMERGENCY_BY_COUNT_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_emergency_by_count ( TAH_plugin->cls, limit, @@ -124,7 +124,6 @@ TAH_EMERGENCY_BY_COUNT_handler_get ( return_suppressed, &process_emergency_by_count, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); diff --git a/src/auditor/taler-auditor-httpd_emergency-get.c b/src/auditor/taler-auditor-httpd_emergency-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -28,42 +26,41 @@ /** -* Add emergency 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 -*/ + * Add emergency to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_emergency ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Emergency *dc) { json_t *list = cls; json_t *obj; - obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_int64 ("row_id", serial_id), - - GNUNET_JSON_pack_data_auto ("denompub_h", &dc->denompub_h), - - TALER_JSON_pack_amount ("denom_risk", &dc->denom_risk), - TALER_JSON_pack_amount ("denom_loss", &dc->denom_loss), - - TALER_JSON_pack_time_abs_human ("deposit_start", dc->deposit_start), - TALER_JSON_pack_time_abs_human ("deposit_end", dc->deposit_end), - - TALER_JSON_pack_amount ("value", &dc->value) + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_data_auto ("denompub_h", + &dc->denompub_h), + TALER_JSON_pack_amount ("denom_risk", + &dc->denom_risk), + TALER_JSON_pack_amount ("denom_loss", + &dc->denom_loss), + TALER_JSON_pack_time_abs_human ("deposit_start", + dc->deposit_start), + TALER_JSON_pack_time_abs_human ("deposit_end", + dc->deposit_end), + TALER_JSON_pack_amount ("value", + &dc->value), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -79,6 +76,9 @@ TAH_EMERGENCY_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -93,27 +93,29 @@ TAH_EMERGENCY_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); + { + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } + } - bool return_suppressed = false; - + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_emergency ( TAH_plugin->cls, limit, @@ -121,7 +123,6 @@ TAH_EMERGENCY_handler_get ( return_suppressed, &process_emergency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.c b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,38 +24,37 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_fee-time-inconsistency-get.h" + /** -* Add fee-time-inconsistency 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 -*/ + * Add fee-time-inconsistency to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_fee_time_inconsistency ( void *cls, - uint64_t serial_id, - const struct - TALER_AUDITORDB_FeeTimeInconsistency - *dc) + const struct TALER_AUDITORDB_FeeTimeInconsistency *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_string ("type", dc->type), - TALER_JSON_pack_time_abs_human ("time", dc->time), - GNUNET_JSON_pack_string ("diagnostic", dc->diagnostic) - - + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_uint64 ("problem_row_id", + dc->problem_row_id), + GNUNET_JSON_pack_string ("type", + dc->type), + TALER_JSON_pack_time_abs_human ("time", + dc->time), + GNUNET_JSON_pack_string ("diagnostic", + dc->diagnostic) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -73,6 +70,9 @@ TAH_FEE_TIME_INCONSISTENCY_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -87,34 +87,29 @@ TAH_FEE_TIME_INCONSISTENCY_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_fee_time_inconsistency ( TAH_plugin->cls, limit, @@ -122,7 +117,6 @@ TAH_FEE_TIME_INCONSISTENCY_handler_get ( return_suppressed, &process_fee_time_inconsistency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); @@ -137,6 +131,6 @@ TAH_FEE_TIME_INCONSISTENCY_handler_get ( return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("fee-time-inconsistency", + GNUNET_JSON_pack_array_steal ("fee_time_inconsistency", ja)); } diff --git a/src/auditor/taler-auditor-httpd_misattribution-in-inconsistency-get.c b/src/auditor/taler-auditor-httpd_misattribution-in-inconsistency-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,38 +24,37 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_misattribution-in-inconsistency-get.h" + /** -* Add misattribution-in-inconsistency 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 -*/ + * Add misattribution-in-inconsistency to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_misattribution_in_inconsistency ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_MisattributionInInconsistency *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_int64 ("row_id", serial_id), - TALER_JSON_pack_amount ("amount", &dc->amount), - GNUNET_JSON_pack_int64 ("bank_row", dc->bank_row), - GNUNET_JSON_pack_data_auto ("reserve_pub", &dc->reserve_pub), - GNUNET_JSON_pack_bool ("suppressed", dc->suppressed) - - + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + TALER_JSON_pack_amount ("amount", + &dc->amount), + GNUNET_JSON_pack_uint64 ("bank_row", + dc->bank_row), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &dc->reserve_pub), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -73,6 +70,9 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -87,34 +87,29 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_misattribution_in_inconsistency ( TAH_plugin->cls, limit, @@ -122,7 +117,6 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( return_suppressed, &process_misattribution_in_inconsistency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); @@ -137,6 +131,6 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("misattribution-in-inconsistency", + GNUNET_JSON_pack_array_steal ("misattribution_in_inconsistency", ja)); } diff --git a/src/auditor/taler-auditor-httpd_progress-get.c b/src/auditor/taler-auditor-httpd_progress-get.c @@ -24,34 +24,31 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_progress-get.h" + /** * Add progress 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 + * @param dc struct with progress data * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ static enum GNUNET_GenericReturnValue process_progress ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Progress *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_string ("progress_key", dc->progress_key), - GNUNET_JSON_pack_int64 ("progress_offset", dc->progress_offset) - + GNUNET_JSON_pack_string ("progress_key", + dc->progress_key), + GNUNET_JSON_pack_int64 ("progress_offset", + dc->progress_offset) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -67,6 +64,7 @@ TAH_PROGRESS_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + const char *progress_key; (void) rh; (void) connection_cls; @@ -81,42 +79,21 @@ TAH_PROGRESS_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } + progress_key + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "progress_key"); ja = json_array (); GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - - TALER_MHD_parse_request_snumber (connection, - "limit", - &limit); - - if (limit < 0) - offset = INT64_MAX; - else - offset = 0; - - TALER_MHD_parse_request_number (connection, - "offset", - &offset); - - bool return_suppressed = false; - - - qs = TAH_plugin->get_progress ( + qs = TAH_plugin->get_progress_points ( TAH_plugin->cls, - limit, - offset, - return_suppressed, + progress_key, &process_progress, ja); - if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_break (0); json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /progress\n"); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, diff --git a/src/auditor/taler-auditor-httpd_progress-get.h b/src/auditor/taler-auditor-httpd_progress-get.h @@ -13,37 +13,14 @@ 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/> */ -#ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H -#define SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H +#ifndef TALER_AUDITOR_HTTPD_PROGRESS_GET_H +#define TALER_AUDITOR_HTTPD_PROGRESS_GET_H #include <gnunet/gnunet_util_lib.h> #include <microhttpd.h> #include "taler-auditor-httpd.h" -/** -* Initialize subsystem. -*/ -void -TEAH_PROGRESS_GET_init (void); -/** -* Shut down subsystem. -*/ -void -TEAH_PROGRESS_GET_done (void); - -/** - * Handle a "/progress" 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 - * @param args NULL-terminated array of remaining parts of the URI broken up at '/' - * @return MHD result code - */ -// FIXME: very bad name! MHD_RESULT TAH_PROGRESS_handler_get ( struct TAH_RequestHandler *rh, @@ -53,5 +30,4 @@ TAH_PROGRESS_handler_get ( size_t *upload_data_size, const char *const args[]); - #endif diff --git a/src/auditor/taler-auditor-httpd_progress-put.c b/src/auditor/taler-auditor-httpd_progress-put.c @@ -1,156 +0,0 @@ -/* - 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/> - */ - - -#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_progress-put.h" - -/** -* We have parsed the JSON information about the progress, do some -* basic sanity checks and then execute the -* transaction. -* -* @param connection the MHD connection to handle -* @param dc information about the progress -* @return MHD result code -*/ -static MHD_RESULT -process_inconsistency ( - struct MHD_Connection *connection, - const struct TALER_AUDITORDB_Progress *dc) -{ - - enum GNUNET_DB_QueryStatus qs; - - 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 transaction */ - qs = TAH_plugin->insert_progress (TAH_plugin->cls, - dc); - if (0 > qs) - { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - TALER_LOG_WARNING ( - "Failed to store /progress in database\n"); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "progress"); - } - return TALER_MHD_REPLY_JSON_PACK (connection, - MHD_HTTP_OK, - GNUNET_JSON_pack_string ("status", - "PROGRESS_OK")); -} - - -MHD_RESULT -TAH_PROGRESS_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_Progress dc; - - - struct GNUNET_JSON_Specification spec[] = { - - GNUNET_JSON_spec_string ("progress_key", (const char **) &dc.progress_key), - GNUNET_JSON_spec_string ("progress_offset", (const - char **) &dc.progress_offset), - - - 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_PROGRESS_PUT_init (void) -{ - -} - - -void -TEAH_PROGRESS_PUT_done (void) -{ - -} diff --git a/src/auditor/taler-auditor-httpd_progress-put.h b/src/auditor/taler-auditor-httpd_progress-put.h @@ -1,57 +0,0 @@ -/* - 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/> - */ -#ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H -#define SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H - -#include <microhttpd.h> -#include "taler-auditor-httpd.h" - -/** -* Initialize subsystem. -*/ -void -TEAH_PROGRESS_PUT_init (void); - -/** -* Shut down subsystem. -*/ -void -TEAH_PROGRESS_PUT_done (void); - - -/** - * Handle a "/progress" 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 - * @param args NULL-terminated array of remaining parts of the URI broken up at '/' - * @return MHD result code - */ -MHD_RESULT -TAH_PROGRESS_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 diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c @@ -13,8 +13,6 @@ 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/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,36 +24,37 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h" + /** -* Add reserve-balance-insufficient-inconsistency 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 -*/ + * Add reserve-balance-insufficient-inconsistency to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_reserve_balance_insufficient_inconsistency ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_uint64 ("row_id", serial_id), - GNUNET_JSON_pack_data_auto ("reserve_pub", &dc->reserve_pub), - GNUNET_JSON_pack_bool ("inconsistency_gain", dc->inconsistency_gain), - TALER_JSON_pack_amount ("inconsistency_amount", &dc->inconsistency_amount) - + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &dc->reserve_pub), + GNUNET_JSON_pack_bool ("inconsistency_gain", + dc->inconsistency_gain), + TALER_JSON_pack_amount ("inconsistency_amount", + &dc->inconsistency_amount), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -71,6 +70,9 @@ TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -85,33 +87,29 @@ TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_reserve_balance_insufficient_inconsistency ( TAH_plugin->cls, limit, @@ -119,7 +117,6 @@ TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get ( return_suppressed, &process_reserve_balance_insufficient_inconsistency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); @@ -134,6 +131,6 @@ TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get ( return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("reserve-balance-insufficient-inconsistency", + GNUNET_JSON_pack_array_steal ("reserve_balance_insufficient_inconsistency", ja)); } diff --git a/src/auditor/taler-auditor-httpd_reserve-in-inconsistency-get.c b/src/auditor/taler-auditor-httpd_reserve-in-inconsistency-get.c @@ -132,10 +132,8 @@ TAH_RESERVE_IN_INCONSISTENCY_handler_get ( ja); if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_break (0); json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /reserve-in-inconsistency"); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, @@ -144,6 +142,6 @@ TAH_RESERVE_IN_INCONSISTENCY_handler_get ( return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("reserve-in-inconsistency", + GNUNET_JSON_pack_array_steal ("reserve_in_inconsistency", ja)); } diff --git a/src/auditor/taler-auditor-httpd_reserve-not-closed-inconsistency-get.c b/src/auditor/taler-auditor-httpd_reserve-not-closed-inconsistency-get.c @@ -41,16 +41,16 @@ process_reserve_not_closed_inconsistency ( json_t *obj; obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_int64 ("row_id", - dc->row_id), + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), GNUNET_JSON_pack_data_auto ("reserve_pub", &dc->reserve_pub), TALER_JSON_pack_amount ("balance", &dc->balance), TALER_JSON_pack_time_abs_human ("expiration_time", dc->expiration_time), - GNUNET_JSON_pack_data_auto ("diagnostic", - &dc->diagnostic), + GNUNET_JSON_pack_string ("diagnostic", + dc->diagnostic), GNUNET_JSON_pack_bool ("suppressed", dc->suppressed) ); diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c @@ -580,7 +580,8 @@ handle_reserve_out ( <, execution_date)) { - struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dkvwi ={ + struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dkvwi = + { .problem_row_id = rowid, .execution_date = execution_date.abs_time, .denompub_h = *&h_denom_pub, @@ -1540,8 +1541,8 @@ verify_reserve_balance (void *cls, struct TALER_AUDITORDB_ReserveNotClosedInconsistency rnci = { .reserve_pub = rs->reserve_pub, .expiration_time = rs->a_expiration_date.abs_time, - .balance = nbalance - + .balance = nbalance, + .diagnostic = rs->sender_account }; /* remaining balance (according to us) exceeds closing fee */ @@ -1712,18 +1713,18 @@ verify_reserve_balance (void *cls, #define CHECK_DB() do { \ - if (qs < 0) { \ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); \ - return qs; \ - } \ - if (global_qs < 0) { \ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == global_qs); \ - return global_qs; \ - } \ - if (rc.qs < 0) { \ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == rc.qs); \ - return rc.qs; \ - } \ + if (qs < 0) { \ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); \ + return qs; \ + } \ + if (global_qs < 0) { \ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == global_qs); \ + return global_qs; \ + } \ + if (rc.qs < 0) { \ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == rc.qs); \ + return rc.qs; \ + } \ } while (0) diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh @@ -65,7 +65,7 @@ function cleanup() echo "DONE" unset EPID fi - stop_libeufin + stop_libeufin &> /dev/null } # Cleanup to run whenever we exit @@ -309,7 +309,6 @@ function post_audit () { -g \ || exit_fail "exchange DB GC failed" cleanup - echo " DONE" } @@ -329,14 +328,14 @@ function run_audit () { 2> "${MY_TMP_DIR}/exchange-httpd-drain.err" & EPID=$! - # Wait for all services to be available + # Wait for exchange service to be available for n in $(seq 1 50) do echo -n "." sleep 0.1 OK=0 # exchange - wget "http://localhost:8081/seed" \ + wget "http://localhost:8081/config" \ -o /dev/null \ -O /dev/null \ >/dev/null \ @@ -403,40 +402,40 @@ function full_reload() function run_auditor_httpd() { echo -n "Starting auditor..." - taler-auditor-httpd \ - -c "${CONF}" \ - -L INFO \ - 2> "${MY_TMP_DIR}/auditor-httpd-drain.err" & - APID=$! - - # Wait for all services to be available - for n in $(seq 1 50) - do - echo -n "." - sleep 0.1 - OK=0 - # exchange - wget "http://localhost:8083/seed" \ - -o /dev/null \ - -O /dev/null \ - >/dev/null \ - || continue - OK=1 - break - done - echo "... DONE." - export CONF + taler-auditor-httpd \ + -c "${CONF}" \ + -L INFO \ + 2> "${MY_TMP_DIR}/auditor-httpd.err" & + APID=$! + + # Wait for auditor service to be available + for n in $(seq 1 50) + do + echo -n "." + sleep 0.2 + OK=0 + # auditor + wget "http://localhost:8083/config" \ + -o /dev/null \ + -O /dev/null \ + >/dev/null \ + || continue + OK=1 + break + done + echo "... DONE." + export CONF } function stop_auditor_httpd() { -if [ -n "${APID:-}" ] - then - echo -n "Stopping auditor $APID..." - kill -TERM "$APID" - wait "$APID" || true - echo "DONE" - unset APID - fi + if [ -n "${APID:-}" ] + then + echo -n "Stopping auditor $APID..." + kill -TERM "$APID" + wait "$APID" || true + echo "DONE" + unset APID + fi } function check_auditor_running() { @@ -483,6 +482,49 @@ function check_not_balance() { } +function check_report() { + call_endpoint "$1" + NAME=$(echo "$1" | tr '-' '_') + VAL=$(jq -r .\"${NAME}\"[0].\"$2\" < "${MY_TMP_DIR}/${1}.json") + if [ "$VAL" != "$3" ] + then + exit_fail "$1::$2 (got $VAL, wanted $3)" + fi + echo "PASS" +} + +function check_report_neg() { + call_endpoint "$1" + NAME=$(echo "$1" | tr '-' '_') + VAL=$(jq -r .\"${NAME}\"[0].\"$2\" < "${MY_TMP_DIR}/${1}.json") + if [ "$VAL" == "$3" ] + then + exit_fail "$1::$2 (got $VAL, wanted $3)" + fi + echo "PASS" +} + +function check_row() { + call_endpoint "$1" + NAME=$(echo "$1" | tr '-' '_') + if [ -n "${3+x}" ] + then + RID="$2" + WANT="$3" + else + RID="row_id" + WANT="$2" + fi + + ROW=$(jq -r .\"${NAME}\"[0].\"${RID}\" < "${MY_TMP_DIR}/${1}.json") + if [ "$ROW" != "$WANT" ] + then + exit_fail "Row ${1} wrong (got ${ROW}, wanted ${WANT})" + fi + echo "PASS" +} + + function test_0() { echo "===========0: normal run with aggregator===========" @@ -673,42 +715,39 @@ function test_1() { function test_2() { echo "===========2: reserves_in inconsistency ===========" + echo -n "Modifying database: " echo "UPDATE exchange.reserves_in SET credit.val=5 WHERE reserve_in_serial_id=1" \ | psql -At "$DB" run_audit check_auditor_running - #echo -n "Testing inconsistency detection... " - #ROW=$(jq .reserve_in_amount_inconsistencies[0].row < test-audit-wire.json") - #if [ "$ROW" != 1 ] - #then - # exit_fail "Row $ROW is wrong" - #fi - #WIRED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-audit-wire.json") - #if [ "$WIRED" != "TESTKUDOS:10" ] - #then - # exit_fail "Amount wrong" - #fi - #EXPECTED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json") - #if [ "$EXPECTED" != "TESTKUDOS:5" ] - #then - # exit_fail "Expected amount wrong" - #fi -# - #WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json") - #if [ "$WIRED" != "TESTKUDOS:0" ] - #then - # exit_fail "Wrong total wire_in_delta_minus, got $WIRED" - #fi - #DELTA=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json") - #if [ "$DELTA" != "TESTKUDOS:5" ] - #then - # exit_fail "Expected total wire delta plus wrong, got $DELTA" - #fi - #echo "PASS" + echo -n "Testing inconsistency detection ... " + check_report \ + "reserve-in-inconsistency" \ + "row_id" 1 + echo -n "Testing inconsistency detection amount wired ... " + check_report \ + "reserve-in-inconsistency" \ + "amount_wired" "TESTKUDOS:10" + echo -n "Testing inconsistency detection amount expected ... " + check_report \ + "reserve-in-inconsistency" \ + "amount_exchange_expected" "TESTKUDOS:5" - # Undo database modification + call_endpoint "balances" + echo -n "Checking wire credit balance minus ... " + check_balance \ + "total_bad_amount_in_minus" \ + "TESTKUDOS:0" \ + "Wrong total_bad_amount_in_minus" + echo -n "Checking wire credit balance plus ... " + check_balance \ + "total_bad_amount_in_plus" \ + "TESTKUDOS:5" \ + "Expected total_bad_amount_in_plus wrong" + + echo -n "Undoing database modification " echo "UPDATE exchange.reserves_in SET credit.val=10 WHERE reserve_in_serial_id=1" \ | psql -Aqt "$DB" stop_auditor_httpd @@ -728,58 +767,43 @@ function test_3() { run_audit check_auditor_running - call_endpoint "reserve-balance-summary-wrong-inconsistency" - EXPECTED=$(jq -e .reserve_balance_summary_wrong_inconsistency[0].auditor_amount \ - < "${MY_TMP_DIR}/reserve-balance-summary-wrong-inconsistency.json") - if [ "$EXPECTED" != '"TESTKUDOS:5.01"' ] - then - exit_fail "Expected reserve balance summary amount wrong, got $EXPECTED (auditor)" - fi + echo "Checking reserve balance summary inconsistency detection ..." + check_report \ + "reserve-balance-summary-wrong-inconsistency" \ + "auditor_amount" "TESTKUDOS:5.01" + check_report \ + "reserve-balance-summary-wrong-inconsistency" \ + "exchange_amount" "TESTKUDOS:0.01" - EXPECTED=$(jq -e .reserve_balance_summary_wrong_inconsistency[0].exchange_amount \ - < "${MY_TMP_DIR}/reserve-balance-summary-wrong-inconsistency.json") - if [ "$EXPECTED" != '"TESTKUDOS:0.01"' ] - then - exit_fail "Expected reserve balance summary amount wrong, got $EXPECTED (exchange)" - fi - - #TODO: we receive 22.96 instead of 0 - check what it should be - #call_endpoint "balances" "reserves_reserve_loss" - #WIRED=$(jq -r .balances[0].balance_value < "${MY_TMP_DIR}/reserves_reserve_loss.json") - #if [ "$WIRED" != "TESTKUDOS:0" ] - #then - # exit_fail "Wrong total loss from insufficient balance, got $WIRED" - #fi - #TODO: fix helper wire - #ROW=$(jq -e .reserve_in_amount_inconsistencies[0].row < test-audit-wire.json") - #if [ "$ROW" != 1 ] - #then - # exit_fail "Row wrong, got $ROW" - #fi - - #WIRED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json") - #if [ "$WIRED" != "TESTKUDOS:15" ] - #then - # exit_fail "Wrong amount_exchange_expected, got $WIRED" - #fi - - #WIRED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-audit-wire.json") - #if [ "$WIRED" != "TESTKUDOS:10" ] - #then - # exit_fail "Wrong amount_wired, got $WIRED" - #fi - - #WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json") - #if [ "$WIRED" != "TESTKUDOS:5" ] - #then - # exit_fail "Wrong total wire_in_delta_minus, got $WIRED" - #fi - - #WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json") - #if [ "$WIRED" != "TESTKUDOS:0" ] - #then - # exit_fail "Wrong total wire_in_delta_plus, got $WIRED" - #fi + call_endpoint "balances" + check_balance \ + "reserves_reserve_loss" \ + "TESTKUDOS:0" \ + "Wrong total loss from insufficient balance" + + echo -n "Testing inconsistency detection ... " + check_report \ + "reserve-in-inconsistency" \ + "row_id" 1 + echo -n "Testing inconsistency detection amount wired ... " + check_report \ + "reserve-in-inconsistency" \ + "amount_wired" "TESTKUDOS:10" + echo -n "Testing inconsistency detection amount expected ... " + check_report \ + "reserve-in-inconsistency" \ + "amount_exchange_expected" "TESTKUDOS:15" + + echo -n "Checking wire credit balance minus ... " + check_balance \ + "total_bad_amount_in_minus" \ + "TESTKUDOS:5" \ + "Wrong total_bad_amount_in_minus" + echo -n "Checking wire credit balance plus ... " + check_balance \ + "total_bad_amount_in_plus" \ + "TESTKUDOS:0" \ + "Wrong total_bad_amount_in_plus" # Undo database modification echo "UPDATE exchange.reserves_in SET credit.val=10 WHERE reserve_in_serial_id=1" | psql -Aqt "$DB" @@ -917,33 +941,23 @@ function test_6() { run_audit check_auditor_running - call_endpoint "bad-sig-losses" - ROW=$(jq -e .bad_sig_losses[0].row_id < "${MY_TMP_DIR}/bad-sig-losses.json") - if [ "$ROW" != "1" ] - then - exit_fail "Row wrong, got $ROW" - fi - - LOSS=$(jq -r .bad_sig_losses[0].loss < "${MY_TMP_DIR}/bad-sig-losses.json") - if [ "$LOSS" == "TESTKUDOS:0" ] - then - exit_fail "Wrong deposit bad signature loss, got $LOSS" - fi - - OP=$(jq -r .bad_sig_losses[0].operation < "${MY_TMP_DIR}/bad-sig-losses.json") - if [ "$OP" != "melt" ] && [ "$OP" != "deposit" ] - then - exit_fail "Wrong operation, got $OP" - fi - - call_endpoint "balances" "coin_irregular_loss" - LOSS=$(jq -r .balances[0].balance_value < "${MY_TMP_DIR}/coin_irregular_loss.json") - if [ "$LOSS" == "TESTKUDOS:0" ] - then - exit_fail "Wrong total bad sig loss, got $LOSS" - fi + echo -n "Checking bad-signature-loss detected ..." + check_row "bad-sig-losses" 1 + echo -n "Checking bad-signature-loss amount detected ..." + check_report_neg \ + "bad-sig-losses" \ + "loss" "TESTKUDOS:0" + echo -n "Checking bad-signature-loss operation detected ..." + check_report \ + "bad-sig-losses" \ + "operation" "deposit" + echo -n "Checking bad-signature-loss balance update ..." + check_not_balance \ + "coin_irregular_loss" \ + "TESTKUDOS:0" \ + "Wrong total bad sig loss" - #Undo + echo -n "Undo database change ... " echo "UPDATE exchange.known_coins SET denom_sig='$OLD_SIG' WHERE coin_pub='$COIN_PUB'" | psql -Aqt "$DB" stop_auditor_httpd full_reload @@ -969,20 +983,11 @@ function test_7() { run_audit check_auditor_running - call_endpoint "bad-sig-losses" - OP=$(jq -r .bad_sig_losses[0].operation < "${MY_TMP_DIR}/bad-sig-losses.json") - if [ "$OP" != "withdraw" ] - then - exit_fail "Wrong operation, got $OP" - fi - - call_endpoint "balances" "reserves_total_bad_sig_loss" - LOSS=$(jq -r .bad_sig_losses[0].loss < "${MY_TMP_DIR}/bad-sig-losses.json") - LOSS_TOTAL=$(jq -r .balances[0].balance_value < "${MY_TMP_DIR}/reserves_total_bad_sig_loss.json") - if [ "$LOSS" != "$LOSS_TOTAL" ] - then - exit_fail "Expected loss $LOSS and total loss $LOSS_TOTAL do not match" - fi + echo -n "Checking bad signature was detected ..." + check_report \ + "bad-sig-losses" \ + "operation" "withdraw" + echo -n "Checking loss was reported ..." if [ "$A_FRAC" != 0 ] then if [ "$A_FRAC" -lt 10 ] @@ -991,16 +996,18 @@ function test_7() { else A_PREV="" fi - if [ "$LOSS" != "TESTKUDOS:$A_VAL.$A_PREV$A_FRAC" ] - then - exit_fail "Expected loss TESTKUDOS:$A_VAL.$A_PREV$A_FRAC but got $LOSS" - fi + EXPECTED_LOSS="TESTKUDOS:$A_VAL.$A_PREV$A_FRAC" else - if [ "$LOSS" != "TESTKUDOS:$A_VAL" ] - then - exit_fail "Expected loss TESTKUDOS:$A_VAL but got $LOSS" - fi + EXPECTED_LOSS="TESTKUDOS:$A_VAL" fi + check_report \ + "bad-sig-losses" \ + "loss" "$EXPECTED_LOSS" + echo "Checking loss was totaled up ..." + check_balance \ + "reserves_total_bad_sig_loss" \ + "$EXPECTED_LOSS" \ + "wrong total bad sig loss" # Undo: echo "UPDATE exchange.reserves_out SET reserve_sig='$OLD_SIG' WHERE h_blind_ev='$HBE'" | psql -Aqt "$DB" @@ -1250,22 +1257,16 @@ function test_12() { run_audit check_auditor_running - echo -n "Testing hung refresh detection... " - - call_endpoint "refreshes-hanging" call_endpoint "balances" - call_endpoint "balances" "total_refresh_hanging" - HANG=$(jq -er .refreshes_hanging[0].amount < "${MY_TMP_DIR}/refreshes-hanging.json") - TOTAL_HANG=$(jq -er .balances[0].balance_value < "${MY_TMP_DIR}/total_refresh_hanging.json") - if [ "$HANG" = "TESTKUDOS:0" ] - then - exit_fail "Hanging amount zero" - fi - if [ "$TOTAL_HANG" = "TESTKUDOS:0" ] - then - exit_fail "Total hanging amount zero" - fi - echo "PASS" + echo -n "Checking hanging refresh detected ... " + check_report_neg \ + "refreshes-hanging" \ + "amount" "TESTKUDOS:0" + echo -n "Checking total balance updated ... " + check_not_balance \ + "total_refresh_hanging" \ + "TESTKUDOS:0" \ + "Hanging amount zero" # cannot easily undo DELETE, hence full reload full_reload @@ -1289,27 +1290,18 @@ function test_13() { echo -n "Testing inconsistency detection... " - call_endpoint "bad-sig-losses" - call_endpoint "balances" "coin_irregular_loss" - - OP=$(jq -er .bad_sig_losses[0].operation < "${MY_TMP_DIR}/bad-sig-losses.json") - if [ "$OP" != "melt" ] - then - exit_fail "Operation wrong, got $OP" - fi - - LOSS=$(jq -er .bad_sig_losses[0].loss < "${MY_TMP_DIR}/bad-sig-losses.json") - TOTAL_LOSS=$(jq -er .balances[0].balance_value < "${MY_TMP_DIR}/coin_irregular_loss.json") - if [ "$LOSS" != "$TOTAL_LOSS" ] - then - exit_fail "Loss inconsistent, got $LOSS and $TOTAL_LOSS" - fi - if [ "$TOTAL_LOSS" = "TESTKUDOS:0" ] - then - exit_fail "Loss zero" - fi - - echo "PASS" + check_report \ + "bad-sig-losses" \ + "operation" "melt" + echo -n "Checking loss amount reported ..." + check_report \ + "bad-sig-losses" \ + "loss" "TESTKUDOS:3.96" + echo -n "Checking loss amount totaled ..." + check_balance \ + "coin_irregular_loss" \ + "TESTKUDOS:3.96" \ + "Loss inconsistent" # cannot easily undo DELETE, hence full reload full_reload @@ -1332,20 +1324,14 @@ function test_14() { post_audit check_auditor_running - call_endpoint "row-inconsistency" - - echo -n "Testing inconsistency detection... " - TABLE=$(jq -r .row_inconsistency[0].row_table < "${MY_TMP_DIR}/row-inconsistency.json") - if [ "$TABLE" != "wire-fee" ] - then - exit_fail "Reported table wrong: $TABLE" - fi - DIAG=$(jq -r .row_inconsistency[0].diagnostic < "${MY_TMP_DIR}/row-inconsistency.json") - if [ "$DIAG" != "wire fee signature invalid at given time" ] - then - exit_fail "Reported diagnostic wrong: $DIAG" - fi - echo "PASS" + echo -n "Checking wire-fee inconsistency was detected ..." + check_report \ + "row-inconsistency" \ + "row_table" "wire-fee" + echo -n "Checking diagnostic was set correctly ..." + check_report \ + "row-inconsistency" \ + "diagnostic" "wire fee signature invalid at given time" # cannot easily undo aggregator, hence full reload full_reload @@ -1367,15 +1353,10 @@ function test_15() { run_audit check_auditor_running - call_endpoint "bad-sig-losses" - - echo -n "Testing inconsistency detection... " - OP=$(jq -r .bad_sig_losses[0].operation < "${MY_TMP_DIR}/bad-sig-losses.json") - if [ "$OP" != "deposit" ] - then - exit_fail "Reported operation wrong: $OP" - fi - echo "PASS" + echo -n "Checking broken deposit signature detected ..." + check_report \ + "bad-sig-losses" \ + "operation" "deposit" # Restore DB echo "UPDATE exchange.batch_deposits SET wire_salt='$SALT' WHERE batch_deposit_serial_id=1;" \ @@ -1521,45 +1502,33 @@ function test_18() { run_audit check_auditor_running - call_endpoint "reserve-balance-summary-wrong-inconsistency" - call_endpoint "emergency" - call_endpoint "emergency-by-count" - call_endpoint "amount-arithmetic-inconsistency" - call_endpoint "balances" "coins_emergencies_loss_by_count" - call_endpoint "balances" "coins_emergencies_loss" - + echo -n "Testing bad reserve balance summary reporting ... " + # note: we check "suppressed" to only check the *existence* here. + check_report \ + "reserve-balance-summary-wrong-inconsistency" \ + "suppressed" "false" echo -n "Testing emergency detection... " - jq -e .reserve_balance_summary_wrong_inconsistency[0] \ - < "${MY_TMP_DIR}/reserve-balance-summary-wrong-inconsistency.json" \ - > /dev/null \ - || exit_fail "Reserve balance inconsistency not detected" - jq -e .emergency[0] \ - < "${MY_TMP_DIR}/emergency.json" \ - > /dev/null \ - || exit_fail "Emergency not detected" - jq -e .emergency_by_count[0] \ - < "${MY_TMP_DIR}/emergency-by-count.json" \ - > /dev/null \ - || exit_fail "Emergency by count not detected" - jq -e .amount_arithmetic_inconsistency[0] \ - < "${MY_TMP_DIR}/amount-arithmetic-inconsistency.json" \ - > /dev/null \ - || exit_fail "Escrow balance calculation impossibility not detected" - echo "PASS" - + check_report \ + "emergency" \ + "suppressed" "false" + echo -n "Testing emergency detection by count... " + check_report \ + "emergency-by-count" \ + "suppressed" "false" + echo -n "Testing escrow balance calculation impossibility... " + check_report \ + "amount-arithmetic-inconsistency" \ + "suppressed" "false" + echo -n "Testing loss calculation by count... " + check_not_balance \ + "coins_emergencies_loss_by_count" \ + "TESTKUDOS:0" \ + "Emergency by count loss not reported" echo -n "Testing loss calculation... " - AMOUNT=$(jq -r .balances[0].balance_value < "${MY_TMP_DIR}/coins_emergencies_loss_by_count.json") - if [ "$AMOUNT" == "TESTKUDOS:0" ] - then - exit_fail "Reported amount wrong: $AMOUNT" - fi - AMOUNT=$(jq -r .balances[0].balance_value < "${MY_TMP_DIR}/coins_emergencies_loss.json") - if [ "$AMOUNT" == "TESTKUDOS:0" ] - then - exit_fail "Reported amount wrong: $AMOUNT" - fi - echo "PASS" - + check_not_balance \ + "coins_emergencies_loss" \ + "TESTKUDOS:0" \ + "Emergency loss not reported" # cannot easily undo broad DELETE operation, hence full reload full_reload stop_auditor_httpd @@ -1728,13 +1697,11 @@ function test_22() { run_audit check_auditor_running - call_endpoint "denomination-key-validity-withdraw-inconsistency" - echo -n "Testing inconsistency detection... " - jq -e .denomination_key_validity_withdraw_inconsistency[0] < "${MY_TMP_DIR}/denomination-key-validity-withdraw-inconsistency.json" \ - > /dev/null || exit_fail "Denomination key withdraw inconsistency for $S_DENOM not detected" - - echo "PASS" + check_report \ + "denomination-key-validity-withdraw-inconsistency" \ + "suppressed" "false" + call_endpoint "denomination-key-validity-withdraw-inconsistency" # Undo modification echo "UPDATE exchange.denominations SET expire_withdraw=${OLD_WEXP} WHERE denominations_serial='${S_DENOM}';" | psql -Aqt "$DB" diff --git a/src/auditordb/0002-auditor_exchange_signkeys.sql b/src/auditordb/0002-auditor_exchange_signkeys.sql @@ -15,8 +15,8 @@ -- CREATE TABLE auditor_exchange_signkeys - (row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE, - exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32) + (row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE + ,exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32) ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64) ,ep_valid_from BIGINT NOT NULL ,ep_expire_sign BIGINT NOT NULL diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am @@ -77,6 +77,7 @@ libtaler_plugin_auditordb_postgres_la_SOURCES = \ pg_insert_balance.c pg_insert_balance.h \ pg_insert_denomination_balance.c pg_insert_denomination_balance.h \ pg_insert_deposit_confirmation.c pg_insert_deposit_confirmation.h \ + pg_get_progress_points.h pg_get_progress_points.c \ pg_insert_historic_reserve_revenue.c pg_insert_historic_reserve_revenue.h \ pg_insert_pending_deposit.c pg_insert_pending_deposit.h \ pg_insert_purse_info.c pg_insert_purse_info.h \ diff --git a/src/auditordb/pg_get_amount_arithmetic_inconsistency.c b/src/auditordb/pg_get_amount_arithmetic_inconsistency.c @@ -13,7 +13,6 @@ 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/> */ - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" @@ -68,14 +67,12 @@ amount_arithmetic_inconsistency_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; - struct TALER_AUDITORDB_AmountArithmeticInconsistency dc; - struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("row_id", - &serial_id), - // TODO: what type is this exactly + &dc.row_id), + GNUNET_PQ_result_spec_uint64 ("problem_row_id", + &dc.problem_row_id), GNUNET_PQ_result_spec_string ("operation", &dc.operation), TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_amount", @@ -84,7 +81,8 @@ amount_arithmetic_inconsistency_cb (void *cls, &dc.auditor_amount), GNUNET_PQ_result_spec_bool ("profitable", &dc.profitable), - + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -98,11 +96,8 @@ amount_arithmetic_inconsistency_cb (void *cls, dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - dcc->qs = i + 1; - rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -116,13 +111,12 @@ TAH_PG_get_amount_arithmetic_inconsistency ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_AmountArithmeticInconsistencyCallback cb, void *cb_cls) { - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -140,13 +134,15 @@ TAH_PG_get_amount_arithmetic_inconsistency ( "auditor_amount_arithmetic_inconsistency_select_desc", "SELECT" " row_id" + ",problem_row_id" ",operation" ",exchange_amount" ",auditor_amount" ",profitable" + ",suppressed" " FROM auditor_amount_arithmetic_inconsistency" " WHERE (row_id<$1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -154,28 +150,28 @@ TAH_PG_get_amount_arithmetic_inconsistency ( "auditor_amount_arithmetic_inconsistency_select_asc", "SELECT" " row_id" + ",problem_row_id" ",operation" ",exchange_amount" ",auditor_amount" ",profitable" + ",suppressed" " FROM auditor_amount_arithmetic_inconsistency" " WHERE (row_id>$1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) ? - "auditor_amount_arithmetic_inconsistency_select_asc" - : - "auditor_amount_arithmetic_inconsistency_select_desc", - params, - &amount_arithmetic_inconsistency_cb, - &dcc); - - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_amount_arithmetic_inconsistency_select_asc" + : "auditor_amount_arithmetic_inconsistency_select_desc", + params, + &amount_arithmetic_inconsistency_cb, + &dcc); 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_bad_sig_losses.c b/src/auditordb/pg_get_bad_sig_losses.c @@ -108,27 +108,23 @@ TAH_PG_get_bad_sig_losses ( int64_t limit, uint64_t offset, bool return_suppressed, - bool filter_spec_pub, - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub, + const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub, const char *op, TALER_AUDITORDB_BadSigLossesCallback cb, void *cb_cls) { struct PostgresClosure *pg = cls; uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - /*if true, does not filter for an operation specific key*/ - bool any_spec_pub = ! filter_spec_pub; - /*if true, does not filter for an operation*/ - bool any_op = (NULL == op) ? true : false; - const char *o = (NULL == op) ? "" : op; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_bool (any_spec_pub), - GNUNET_PQ_query_param_auto_from_type (&op_spec_pub), - GNUNET_PQ_query_param_bool (any_op), - GNUNET_PQ_query_param_string (o), + NULL == op_spec_pub + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_auto_from_type (op_spec_pub), + NULL == op + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (op), GNUNET_PQ_query_param_end }; struct BadSigLossesContext dcc = { @@ -147,9 +143,9 @@ TAH_PG_get_bad_sig_losses ( ",operation_specific_pub" " FROM auditor_bad_sig_losses" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" - " AND ($4 OR operation_specific_pub = $5)" - " AND ($6 OR operation = $7)" + " AND ($2 OR suppressed IS FALSE)" + " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)" + " AND ($5::TEXT IS NULL OR operation = $5)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -162,20 +158,20 @@ TAH_PG_get_bad_sig_losses ( ",operation_specific_pub" " FROM auditor_bad_sig_losses" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" - " AND ($4 OR operation_specific_pub = $5)" - " AND ($6 OR operation = $7)" + " AND ($2 OR suppressed IS FALSE)" + " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)" + " AND ($5::TEXT IS NULL OR operation = $5)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? "auditor_bad_sig_losses_get_asc" - : "auditor_bad_sig_losses_get_desc", - params, - &bad_sig_losses_cb, - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_bad_sig_losses_get_asc" + : "auditor_bad_sig_losses_get_desc", + params, + &bad_sig_losses_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_bad_sig_losses.h b/src/auditordb/pg_get_bad_sig_losses.h @@ -13,9 +13,8 @@ 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/> */ - -#ifndef SRC_PG_GET_BAD_SIG_LOSSES_H -#define SRC_PG_GET_BAD_SIG_LOSSES_H +#ifndef PG_GET_BAD_SIG_LOSSES_H +#define PG_GET_BAD_SIG_LOSSES_H #include "taler_util.h" #include "taler_json_lib.h" @@ -28,7 +27,6 @@ * @param limit number of records to return, negative for descending * @param offset table row to start from, exclusive, direction determined by @a limit * @param return_suppressed should suppressed rows be returned anyway? - * @param filter_spec_pub filter by @a op_spec_pub * @param op_spec_pub public key to filter by; FIXME: replace by pointer * @param op operation to filter by * @param cb function to call with results @@ -41,8 +39,7 @@ TAH_PG_get_bad_sig_losses ( int64_t limit, uint64_t offset, bool return_suppressed, - bool filter_spec_pub, - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub, + const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub, const char *op, TALER_AUDITORDB_BadSigLossesCallback cb, void *cb_cls); diff --git a/src/auditordb/pg_get_balances.c b/src/auditordb/pg_get_balances.c @@ -65,11 +65,8 @@ balances_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; struct TALER_AUDITORDB_Balances dc; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("row_id", - &serial_id), GNUNET_PQ_result_spec_string ("balance_key", &dc.balance_key), TALER_PQ_RESULT_SPEC_AMOUNT ("balance_value", @@ -89,7 +86,6 @@ balances_cb (void *cls, } dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -101,21 +97,15 @@ balances_cb (void *cls, enum GNUNET_DB_QueryStatus TAH_PG_get_balances ( void *cls, - int64_t limit, - uint64_t offset, const char *balance_key, TALER_AUDITORDB_BalancesCallback cb, void *cb_cls) { struct PostgresClosure *pg = cls; - bool any_balance = (NULL == balance_key); - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - const char *bk = (any_balance) ? "" : balance_key; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_bool (any_balance), - GNUNET_PQ_query_param_string (bk), + NULL == balance_key + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (balance_key), GNUNET_PQ_query_param_end }; struct BalancesContext dcc = { @@ -126,34 +116,16 @@ TAH_PG_get_balances ( enum GNUNET_DB_QueryStatus qs; PREPARE (pg, - "auditor_balances_get_desc", + "auditor_balances_get", "SELECT" - " row_id," - " balance_key," - " balance_value" + " balance_key" + ",balance_value" " FROM auditor_balances" - " WHERE (row_id < $1)" - " AND ($3 OR balance_key = $4)" - " ORDER BY row_id DESC" - " LIMIT $2" - ); - PREPARE (pg, - "auditor_balances_get_asc", - "SELECT" - " row_id," - " balance_key," - " balance_value" - " FROM auditor_balances" - " WHERE (row_id > $1)" - " AND ($3 OR balance_key = $4)" - " ORDER BY row_id ASC" - " LIMIT $2" + " WHERE ($1::TEXT IS NULL OR balance_key = $1)" ); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, - (limit > 0) - ? "auditor_balances_get_asc" - : "auditor_balances_get_desc", + "auditor_balances_get", params, &balances_cb, &dcc); diff --git a/src/auditordb/pg_get_balances.h b/src/auditordb/pg_get_balances.h @@ -24,8 +24,6 @@ * Get information about balances from the database. * * @param cls the @e cls of this struct with the plugin-specific state - * @param limit return at most this number of results, negative to descend from @a offset - * @param offset row from which to return @a limit results * @param balance_key key to filter by, NULL to match all balance keys * @param cb function to call with results * @param cb_cls closure for @a cb @@ -34,8 +32,6 @@ enum GNUNET_DB_QueryStatus TAH_PG_get_balances ( void *cls, - int64_t limit, - uint64_t offset, const char *balance_key, TALER_AUDITORDB_BalancesCallback cb, void *cb_cls); diff --git a/src/auditordb/pg_get_denomination_key_validity_withdraw_inconsistency.c b/src/auditordb/pg_get_denomination_key_validity_withdraw_inconsistency.c @@ -13,16 +13,14 @@ 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/> */ - - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" #include "pg_helper.h" - #include "pg_get_denomination_key_validity_withdraw_inconsistency.h" + /** * Closure for #denomination_key_validity_withdraw_inconsistency_cb(). */ @@ -69,18 +67,20 @@ denomination_key_validity_withdraw_inconsistency_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; - struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dc; - struct GNUNET_PQ_ResultSpec rs[] = { - - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + GNUNET_PQ_result_spec_uint64 ("problem_row_id", + &dc.problem_row_id), GNUNET_PQ_result_spec_absolute_time ("execution_date", &dc.execution_date), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", &dc.reserve_pub), - GNUNET_PQ_result_spec_auto_from_type ("denompub_h", &dc.denompub_h), - + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + &dc.reserve_pub), + GNUNET_PQ_result_spec_auto_from_type ("denompub_h", + &dc.denompub_h), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -94,11 +94,8 @@ denomination_key_validity_withdraw_inconsistency_cb (void *cls, dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - dcc->qs = i + 1; - rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -112,15 +109,12 @@ TAH_PG_get_denomination_key_validity_withdraw_inconsistency ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed - TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback - cb, + bool return_suppressed, + TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -138,12 +132,14 @@ TAH_PG_get_denomination_key_validity_withdraw_inconsistency ( "auditor_denomination_key_validity_withdraw_inconsistency_get_desc", "SELECT" " row_id" + ",problem_row_id" ",execution_date" ",reserve_pub" ",denompub_h" + ",suppressed" " FROM auditor_denomination_key_validity_withdraw_inconsistency" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -151,27 +147,27 @@ TAH_PG_get_denomination_key_validity_withdraw_inconsistency ( "auditor_denomination_key_validity_withdraw_inconsistency_get_asc", "SELECT" " row_id" + ",problem_row_id" ",execution_date" ",reserve_pub" ",denompub_h" + ",suppressed" " FROM auditor_denomination_key_validity_withdraw_inconsistency" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) ? - "auditor_denomination_key_validity_withdraw_inconsistency_get_asc" - : - "auditor_denomination_key_validity_withdraw_inconsistency_get_desc", - params, - & - denomination_key_validity_withdraw_inconsistency_cb, - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_denomination_key_validity_withdraw_inconsistency_get_asc" + : "auditor_denomination_key_validity_withdraw_inconsistency_get_desc", + params, + &denomination_key_validity_withdraw_inconsistency_cb, + &dcc); 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_denominations_without_sigs.c b/src/auditordb/pg_get_denominations_without_sigs.c @@ -13,14 +13,11 @@ 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/> */ - - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" #include "pg_helper.h" - #include "pg_get_denominations_without_sigs.h" @@ -68,21 +65,20 @@ denominations_without_sigs_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; - struct TALER_AUDITORDB_DenominationsWithoutSigs dc; - struct GNUNET_PQ_ResultSpec rs[] = { - - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - - GNUNET_PQ_result_spec_auto_from_type ("denompub_h", &dc.denompub_h), - TALER_PQ_RESULT_SPEC_AMOUNT ("value", &dc.value), - GNUNET_PQ_result_spec_absolute_time ("start_time", &dc.start_time), - GNUNET_PQ_result_spec_absolute_time ("end_time", &dc.end_time), - GNUNET_PQ_result_spec_bool ("suppressed", &dc.suppressed), - - + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + GNUNET_PQ_result_spec_auto_from_type ("denompub_h", + &dc.denompub_h), + TALER_PQ_RESULT_SPEC_AMOUNT ("value", + &dc.value), + GNUNET_PQ_result_spec_absolute_time ("start_time", + &dc.start_time), + GNUNET_PQ_result_spec_absolute_time ("end_time", + &dc.end_time), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -100,7 +96,6 @@ denominations_without_sigs_cb (void *cls, dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -114,14 +109,12 @@ TAH_PG_get_denominations_without_sigs ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_DenominationsWithoutSigsCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -146,7 +139,7 @@ TAH_PG_get_denominations_without_sigs ( " suppressed" " FROM auditor_denominations_without_sigs" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -161,20 +154,18 @@ TAH_PG_get_denominations_without_sigs ( " suppressed" " FROM auditor_denominations_without_sigs" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? - "auditor_denominations_without_sigs_get_asc" - : - "auditor_denominations_without_sigs_get_desc", - params, - &denominations_without_sigs_cb, - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_denominations_without_sigs_get_asc" + : "auditor_denominations_without_sigs_get_desc", + params, + &denominations_without_sigs_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_emergency.c b/src/auditordb/pg_get_emergency.c @@ -13,14 +13,11 @@ 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/> */ - - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" #include "pg_helper.h" - #include "pg_get_emergency.h" /** @@ -70,18 +67,24 @@ emergency_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; - struct TALER_AUDITORDB_Emergency dc; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - GNUNET_PQ_result_spec_auto_from_type ("denompub_h", &dc.denompub_h), - TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk", &dc.denom_risk), - TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss", &dc.denom_loss), - GNUNET_PQ_result_spec_absolute_time ("deposit_start", &dc.deposit_start), - GNUNET_PQ_result_spec_absolute_time ("deposit_end", &dc.deposit_end), - TALER_PQ_RESULT_SPEC_AMOUNT ("value", &dc.value), + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + GNUNET_PQ_result_spec_auto_from_type ("denompub_h", + &dc.denompub_h), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk", + &dc.denom_risk), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss", + &dc.denom_loss), + GNUNET_PQ_result_spec_absolute_time ("deposit_start", + &dc.deposit_start), + GNUNET_PQ_result_spec_absolute_time ("deposit_end", + &dc.deposit_end), + TALER_PQ_RESULT_SPEC_AMOUNT ("value", + &dc.value), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -95,11 +98,8 @@ emergency_cb (void *cls, dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - dcc->qs = i + 1; - rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -113,16 +113,15 @@ TAH_PG_get_emergency ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_EmergencyCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_bool (return_suppressed), GNUNET_PQ_query_param_uint64 (&plimit), GNUNET_PQ_query_param_end }; @@ -143,10 +142,12 @@ TAH_PG_get_emergency ( ",deposit_start" ",deposit_end" ",value" + ",suppressed" " FROM auditor_emergency" " WHERE (row_id < $1)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" - " LIMIT $2" + " LIMIT $3" ); PREPARE (pg, "auditor_emergency_get_asc", @@ -158,21 +159,24 @@ TAH_PG_get_emergency ( ",deposit_start" ",deposit_end" ",value" + ",suppressed" " FROM auditor_emergency" " WHERE (row_id > $1)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" - " LIMIT $2" + " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) ? - "auditor_emergency_get_asc" : - "auditor_emergency_get_desc", - params, - &emergency_cb, - &dcc); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_emergency_get_asc" + : "auditor_emergency_get_desc", + params, + &emergency_cb, + &dcc); 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_emergency_by_count.c b/src/auditordb/pg_get_emergency_by_count.c @@ -13,16 +13,14 @@ 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/> */ - - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" #include "pg_helper.h" - #include "pg_get_emergency_by_count.h" + /** * Closure for #emergency_cb(). */ @@ -70,17 +68,26 @@ emergency_by_count_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; struct TALER_AUDITORDB_EmergenciesByCount dc; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - GNUNET_PQ_result_spec_auto_from_type ("denompub_h", &dc.denompub_h), - GNUNET_PQ_result_spec_uint64 ("num_issued", &dc.num_issued), - GNUNET_PQ_result_spec_uint64 ("num_known", &dc.num_known), - TALER_PQ_RESULT_SPEC_AMOUNT ("risk", &dc.risk), - GNUNET_PQ_result_spec_absolute_time ("start", &dc.start), - GNUNET_PQ_result_spec_absolute_time ("deposit_end", &dc.deposit_end), - TALER_PQ_RESULT_SPEC_AMOUNT ("value", &dc.value), + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + GNUNET_PQ_result_spec_auto_from_type ("denompub_h", + &dc.denompub_h), + GNUNET_PQ_result_spec_uint64 ("num_issued", + &dc.num_issued), + GNUNET_PQ_result_spec_uint64 ("num_known", + &dc.num_known), + TALER_PQ_RESULT_SPEC_AMOUNT ("risk", + &dc.risk), + GNUNET_PQ_result_spec_absolute_time ("start", + &dc.start), + GNUNET_PQ_result_spec_absolute_time ("deposit_end", + &dc.deposit_end), + TALER_PQ_RESULT_SPEC_AMOUNT ("value", + &dc.value), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -96,7 +103,6 @@ emergency_by_count_cb (void *cls, } dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -110,12 +116,12 @@ TAH_PG_get_emergency_by_count ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_EmergenciesByCountCallback cb, void *cb_cls) { - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -140,9 +146,10 @@ TAH_PG_get_emergency_by_count ( ",start" ",deposit_end" ",value" + ",suppressed" " FROM auditor_emergency_by_count" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -157,21 +164,21 @@ TAH_PG_get_emergency_by_count ( ",start" ",deposit_end" ",value" + ",suppressed" " FROM auditor_emergency_by_count" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? - "auditor_emergency_by_count_get_asc" - : - "auditor_emergency_by_count_get_desc", - params, - &emergency_by_count_cb, - &dcc); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_emergency_by_count_get_asc" + : "auditor_emergency_by_count_get_desc", + params, + &emergency_by_count_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_fee_time_inconsistency.c b/src/auditordb/pg_get_fee_time_inconsistency.c @@ -66,11 +66,10 @@ fee_time_inconsistency_cb (void *cls, struct FeeTimeInconsistencyContext *dcc = cls; for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; struct TALER_AUDITORDB_FeeTimeInconsistency dc; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("row_id", - &serial_id), + &dc.row_id), GNUNET_PQ_result_spec_uint64 ("problem_row_id", &dc.problem_row_id), GNUNET_PQ_result_spec_string ("fee_type", @@ -94,7 +93,6 @@ fee_time_inconsistency_cb (void *cls, } dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -137,7 +135,7 @@ TAH_PG_get_fee_time_inconsistency ( ",diagnostic" " FROM auditor_fee_time_inconsistency" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -151,7 +149,7 @@ TAH_PG_get_fee_time_inconsistency ( ",diagnostic" " FROM auditor_fee_time_inconsistency" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); diff --git a/src/auditordb/pg_get_misattribution_in_inconsistency.c b/src/auditordb/pg_get_misattribution_in_inconsistency.c @@ -68,14 +68,18 @@ misattribution_in_inconsistency_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; struct TALER_AUDITORDB_MisattributionInInconsistency dc; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", &dc.amount), - GNUNET_PQ_result_spec_uint64 ("bank_row", &dc.bank_row), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", &dc.reserve_pub), - GNUNET_PQ_result_spec_bool ("suppressed", &dc.suppressed), + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", + &dc.amount), + GNUNET_PQ_result_spec_uint64 ("bank_row", + &dc.bank_row), + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + &dc.reserve_pub), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -91,7 +95,6 @@ misattribution_in_inconsistency_cb (void *cls, } dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -105,14 +108,12 @@ TAH_PG_get_misattribution_in_inconsistency ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_MisattributionInInconsistencyCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -129,42 +130,39 @@ TAH_PG_get_misattribution_in_inconsistency ( PREPARE (pg, "auditor_misattribution_in_inconsistency_get_desc", "SELECT" - " row_id," - " amount," - " bank_row," - " reserve_pub," - " suppressed" + " row_id" + ",amount" + ",bank_row" + ",reserve_pub" + ",suppressed" " FROM auditor_misattribution_in_inconsistency" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); PREPARE (pg, "auditor_misattribution_in_inconsistency_get_asc", "SELECT" - " row_id," - " amount," - " bank_row," - " reserve_pub," - " suppressed" + " row_id" + ",amount" + ",bank_row" + ",reserve_pub" + ",suppressed" " FROM auditor_misattribution_in_inconsistency" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? - "auditor_misattribution_in_inconsistency_get_asc" - : - "auditor_misattribution_in_inconsistency_get_desc", - params, - &misattribution_in_inconsistency_cb - , - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_misattribution_in_inconsistency_get_asc" + : "auditor_misattribution_in_inconsistency_get_desc", + params, + &misattribution_in_inconsistency_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_progress_points.c b/src/auditordb/pg_get_progress_points.c @@ -0,0 +1,140 @@ +/* + 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_get_progress_points.c + * @brief Implementation of the get_progress_points function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_get_progress_points.h" +#include "pg_helper.h" + + +struct ProgressContext +{ + + /** + * Function to call for each progress point. + */ + TALER_AUDITORDB_ProgressPointsCallback 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_progress_points(). + * To be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct ProgressContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +progress_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct ProgressContext *dcc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_AUDITORDB_Progress dc; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("progress_key", + &dc.progress_key), + GNUNET_PQ_result_spec_uint64 ("progress_offset", + &dc.progress_offset), + 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; + rval = dcc->cb (dcc->cb_cls, + &dc); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != rval) + break; + } +} + + +enum GNUNET_DB_QueryStatus +TAH_PG_get_progress_points ( + void *cls, + const char *progress_key, + TALER_AUDITORDB_ProgressPointsCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + NULL == progress_key + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (progress_key), + GNUNET_PQ_query_param_end + }; + struct ProgressContext dcc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "auditor_progress_points_get", + "SELECT" + " progress_key" + ",progress_offset" + " FROM auditor_progress" + " WHERE ($1::TEXT IS NULL OR progress_key = $1)" + ); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "auditor_progress_points_get", + params, + &progress_cb, + &dcc); + if (qs > 0) + return dcc.qs; + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); + return qs; +} diff --git a/src/auditordb/pg_get_progress_points.h b/src/auditordb/pg_get_progress_points.h @@ -0,0 +1,46 @@ +/* + 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_get_progress_points.h + * @brief implementation of the get_progress_points function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_GET_PROGRESS_POINTS_H +#define PG_GET_PROGRESS_POINTS_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Get information about progress from the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param progress_key only return this particular progress point + * @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_progress_points ( + void *cls, + const char *progress_key, + TALER_AUDITORDB_ProgressPointsCallback cb, + void *cb_cls); + + +#endif diff --git a/src/auditordb/pg_get_reserve_balance_insufficient_inconsistency.c b/src/auditordb/pg_get_reserve_balance_insufficient_inconsistency.c @@ -13,16 +13,14 @@ 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/> */ - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" #include "pg_helper.h" - - #include "pg_get_reserve_balance_insufficient_inconsistency.h" + /** * Closure for #reserve_balance_insufficient_inconsistency_cb(). */ @@ -70,18 +68,18 @@ reserve_balance_insufficient_inconsistency_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; - struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency dc; - struct GNUNET_PQ_ResultSpec rs[] = { - - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", &dc.reserve_pub), - GNUNET_PQ_result_spec_bool ("inconsistency_gain", &dc.inconsistency_gain), + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + &dc.reserve_pub), + GNUNET_PQ_result_spec_bool ("inconsistency_gain", + &dc.inconsistency_gain), TALER_PQ_RESULT_SPEC_AMOUNT ("inconsistency_amount", &dc.inconsistency_amount), - + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -95,11 +93,8 @@ reserve_balance_insufficient_inconsistency_cb (void *cls, dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - dcc->qs = i + 1; - rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -113,14 +108,12 @@ TAH_PG_get_reserve_balance_insufficient_inconsistency ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -141,9 +134,10 @@ TAH_PG_get_reserve_balance_insufficient_inconsistency ( ",reserve_pub" ",inconsistency_gain" ",inconsistency_amount" + ",suppressed" " FROM auditor_reserve_balance_insufficient_inconsistency" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -154,22 +148,21 @@ TAH_PG_get_reserve_balance_insufficient_inconsistency ( ",reserve_pub" ",inconsistency_gain" ",inconsistency_amount" + ",suppressed" " FROM auditor_reserve_balance_insufficient_inconsistency" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) ? - "auditor_reserve_balance_insufficient_inconsistency_get_asc" - : - "auditor_reserve_balance_insufficient_inconsistency_get_desc", - params, - & - reserve_balance_insufficient_inconsistency_cb, - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_reserve_balance_insufficient_inconsistency_get_asc" + : "auditor_reserve_balance_insufficient_inconsistency_get_desc", + params, + &reserve_balance_insufficient_inconsistency_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_reserve_in_inconsistency.c b/src/auditordb/pg_get_reserve_in_inconsistency.c @@ -139,7 +139,7 @@ TAH_PG_get_reserve_in_inconsistency ( PREPARE (pg, "auditor_reserve_in_inconsistency_get_desc", "SELECT" - " row_id," + " row_id" ",bank_row_id" ",amount_exchange_expected" ",amount_wired" diff --git a/src/auditordb/pg_get_reserve_not_closed_inconsistency.c b/src/auditordb/pg_get_reserve_not_closed_inconsistency.c @@ -129,7 +129,7 @@ TAH_PG_get_reserve_not_closed_inconsistency ( PREPARE (pg, "auditor_reserve_not_closed_inconsistency_get_desc", "SELECT" - " row_id," + " row_id" ",reserve_pub" ",balance" ",expiration_time" diff --git a/src/auditordb/pg_insert_exchange_signkey.c b/src/auditordb/pg_insert_exchange_signkey.c @@ -44,9 +44,9 @@ TAH_PG_insert_exchange_signkey ( PREPARE (pg, "auditor_insert_exchange_signkey", "INSERT INTO auditor_exchange_signkeys " - "(ep_start" - ",ep_expire" - ",ep_end" + "(ep_valid_from" + ",ep_expire_sign" + ",ep_expire_legal" ",exchange_pub" ",master_sig" ") VALUES ($1,$2,$3,$4,$5);" diff --git a/src/auditordb/pg_insert_wire_format_inconsistency.c b/src/auditordb/pg_insert_wire_format_inconsistency.c @@ -36,9 +36,9 @@ TAH_PG_insert_wire_format_inconsistency ( PREPARE (pg, "auditor_wire_format_inconsistency_insert", "INSERT INTO auditor_wire_format_inconsistency " - "(amount," - " wire_offset," - " diagnostic" + "(amount" + ",wire_offset" + ",diagnostic" ") VALUES ($1,$2,$3);" ); return GNUNET_PQ_eval_prepared_non_select (pg->conn, diff --git a/src/auditordb/pg_update_emergency.c b/src/auditordb/pg_update_emergency.c @@ -13,17 +13,14 @@ 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/> */ - - #include "platform.h" #include "taler_pq_lib.h" #include "pg_helper.h" - #include "pg_update_emergency.h" -/* -Update a given resource – for now this only means suppressing -*/ +/** + * Update a given resource – for now this only means suppressing + */ enum GNUNET_DB_QueryStatus TAH_PG_update_emergency ( void *cls, @@ -36,7 +33,6 @@ TAH_PG_update_emergency ( GNUNET_PQ_query_param_end }; - PREPARE (pg, "update_emergency", "UPDATE auditor_emergency SET" diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c @@ -49,6 +49,7 @@ #include "pg_insert_reserve_info.h" #include "pg_select_historic_denom_revenue.h" #include "pg_select_historic_reserve_revenue.h" +#include "pg_get_progress_points.h" #include "pg_select_pending_deposits.h" #include "pg_select_purse_expired.h" #include "pg_update_generic_suppressed.h" @@ -770,6 +771,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->update_denominations_without_sigs = &TAH_PG_update_denominations_without_sigs; + plugin->get_progress_points + = &TAH_PG_get_progress_points; + plugin->delete_misattribution_in_inconsistency = &TAH_PG_del_misattribution_in_inconsistency; diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h @@ -222,6 +222,7 @@ struct TALER_AUDITORDB_AmountArithmeticInconsistency struct TALER_Amount exchange_amount; struct TALER_Amount auditor_amount; bool profitable; + bool suppressed; }; /** @@ -286,6 +287,7 @@ struct TALER_AUDITORDB_Emergency struct GNUNET_TIME_Absolute deposit_start; struct GNUNET_TIME_Absolute deposit_end; struct TALER_Amount value; + bool suppressed; }; /** @@ -301,14 +303,14 @@ struct TALER_AUDITORDB_EmergenciesByCount struct GNUNET_TIME_Absolute start; struct GNUNET_TIME_Absolute deposit_end; struct TALER_Amount value; + bool suppressed; }; /** - * Information about a refreshes hanging + * Information about progress of the audit. */ struct TALER_AUDITORDB_Progress { - uint64_t row_id; char *progress_key; uint64_t progress_offset; }; @@ -345,6 +347,7 @@ struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency struct GNUNET_TIME_Absolute execution_date; struct TALER_ReservePublicKeyP reserve_pub; struct TALER_DenominationHashP denompub_h; + bool suppressed; }; /** @@ -367,6 +370,7 @@ struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency struct GNUNET_CRYPTO_EddsaPublicKey reserve_pub; bool inconsistency_gain; struct TALER_Amount inconsistency_amount; + bool suppressed; }; /** @@ -402,14 +406,12 @@ struct TALER_AUDITORDB_Balances * the auditor's database. * * @param cls closure - * @param serial_id location of the @a dc in the database * @param dc the structure itself * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_AmountArithmeticInconsistencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc); /** @@ -477,14 +479,12 @@ typedef enum GNUNET_GenericReturnValue * the auditor's database. * * @param cls closure - * @param serial_id location of the @a dc in the database * @param dc the structure itself * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_EmergencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Emergency *dc); /** @@ -492,30 +492,14 @@ typedef enum GNUNET_GenericReturnValue * the auditor's database. * * @param cls closure - * @param serial_id location of the @a dc in the database * @param dc the structure itself * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_EmergenciesByCountCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_EmergenciesByCount *dc); -/** - * Function called with progress stored in - * the auditor's database. - * - * @param cls closure - * @param serial_id location of the @a dc in the database - * @param dc the structure itself - * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating - */ -typedef enum GNUNET_GenericReturnValue -(*TALER_AUDITORDB_ProgressCallback)( - void *cls, - uint64_t serial_id, - const struct TALER_AUDITORDB_Progress *dc); /** * Function called with refreshes hanging stored in @@ -535,14 +519,12 @@ typedef enum GNUNET_GenericReturnValue * the auditor's database. * * @param cls closure - * @param serial_id location of the @a dc in the database * @param dc the structure itself * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_FeeTimeInconsistencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_FeeTimeInconsistency *dc); /** @@ -550,14 +532,12 @@ typedef enum GNUNET_GenericReturnValue * the auditor's database. * * @param cls closure - * @param serial_id location of the @a dc in the database * @param dc the structure itself * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc); @@ -581,31 +561,24 @@ typedef enum GNUNET_GenericReturnValue * the auditor's database. * * @param cls closure - * @param serial_id location of the @a dc in the database * @param dc the structure itself * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_ReserveBalanceInsufficientInconsistencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc); -/** - * Function called with reserve balance insufficient inconsistency stored in - * the auditor's database. - * - * @param cls closure - * @param serial_id location of the @a dc in the database - * @param dc the balance itself - * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating - */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_BalancesCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Balances *dc); +typedef enum GNUNET_GenericReturnValue +(*TALER_AUDITORDB_ProgressPointsCallback)( + void *cls, + const struct TALER_AUDITORDB_Progress *pp); + /** * Balance values for a reserve (or all reserves). */ @@ -898,14 +871,11 @@ typedef enum GNUNET_GenericReturnValue typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_DenominationsWithoutSigsCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc); - typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_MisattributionInInconsistencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_MisattributionInInconsistency *dc); typedef enum GNUNET_GenericReturnValue @@ -967,12 +937,6 @@ typedef enum GNUNET_GenericReturnValue const struct TALER_AUDITORDB_RowMinorInconsistencies *dc); -typedef enum GNUNET_GenericReturnValue -(*TALER_AUDITORDB_FeeTimeInconsistencyCallback)( - void *cls, - uint64_t serial_id, - const struct TALER_AUDITORDB_FeeTimeInconsistency *dc); - /** * @brief The plugin API, returned from the plugin's "init" function. * The argument given to "init" is simply a configuration handle. @@ -1224,10 +1188,7 @@ struct TALER_AUDITORDB_Plugin * Get information about balances from the database. * * @param cls the @e cls of this struct with the plugin-specific state - * @param limit number of balances to return at most, - * negative value to descend from @a offset - * @param offset row/serial ID where to start the iteration (0 from - * the start, exclusive, i.e. serial_ids must start from 1) + * @param balance_key only return this particular balance * @param cb function to call with results * @param cb_cls closure for @a cb * @return query result status @@ -1235,13 +1196,27 @@ struct TALER_AUDITORDB_Plugin enum GNUNET_DB_QueryStatus (*get_balances)( void *cls, - int64_t limit, - uint64_t offset, const char *balance_key, TALER_AUDITORDB_BalancesCallback cb, void *cb_cls); /** + * Get information about progress from the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param progress_key only return this particular progress point + * @param cb function to call with results + * @param cb_cls closure for @a cb + * @return query result status + */ + enum GNUNET_DB_QueryStatus + (*get_progress_points)( + void *cls, + const char *progress_key, + TALER_AUDITORDB_ProgressPointsCallback cb, + void *cb_cls); + + /** * Insert information about a signing key of the exchange. * * @param cls the @e cls of this struct with the plugin-specific state @@ -1391,8 +1366,7 @@ struct TALER_AUDITORDB_Plugin int64_t limit, uint64_t offset, bool return_suppressed, - bool filter_spec_pub, - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub, + const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub, const char *op, TALER_AUDITORDB_BadSigLossesCallback cb, void *cb_cls); @@ -1407,15 +1381,6 @@ struct TALER_AUDITORDB_Plugin void *cb_cls); enum GNUNET_DB_QueryStatus - (*get_progress)( - void *cls, - int64_t limit, - uint64_t offset, - bool return_suppressed, - TALER_AUDITORDB_ProgressCallback cb, - void *cb_cls); - - enum GNUNET_DB_QueryStatus (*get_refreshes_hanging)( void *cls, int64_t limit, @@ -1550,12 +1515,6 @@ struct TALER_AUDITORDB_Plugin void *cls, const struct TALER_AUDITORDB_ClosureLags *dc); - - enum GNUNET_DB_QueryStatus - (*insert_progress)( - void *cls, - const struct TALER_AUDITORDB_Progress *dc); - enum GNUNET_DB_QueryStatus (*insert_refreshes_hanging)( void *cls, diff --git a/src/testing/taler-unified-setup.sh b/src/testing/taler-unified-setup.sh @@ -823,7 +823,7 @@ do done if [ 1 != "$OK" ] then - exit_skip "Failed to launch (some) Taler services" + exit_skip "Failed to launch (some) Taler services (E: $E_DONE, M: $M_DONE, S: $S_DONE, K: $K_DONE, A: $A_DONE)" fi echo " OK"