exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

taler-auditor-httpd_get-monitoring-reserve-balance-insufficient-inconsistency.c (4612B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2024 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 #include <gnunet/gnunet_util_lib.h>
     17 #include <gnunet/gnunet_json_lib.h>
     18 #include <jansson.h>
     19 #include <microhttpd.h>
     20 #include <pthread.h>
     21 #include "taler/taler_json_lib.h"
     22 #include "taler/taler_mhd_lib.h"
     23 #include "taler-auditor-httpd.h"
     24 #include \
     25   "taler-auditor-httpd_get-monitoring-reserve-balance-insufficient-inconsistency.h"
     26 #include \
     27   "auditor-database/get_reserve_balance_insufficient_inconsistency.h"
     28 #include "auditor-database/preflight.h"
     29 
     30 
     31 /**
     32  * Add reserve-balance-insufficient-inconsistency to the list.
     33  *
     34  * @param[in,out] cls a `json_t *` array to extend
     35  * @param dc struct of inconsistencies
     36  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
     37  */
     38 static enum GNUNET_GenericReturnValue
     39 process_reserve_balance_insufficient_inconsistency (
     40   void *cls,
     41   const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc)
     42 {
     43   json_t *list = cls;
     44   json_t *obj;
     45 
     46   obj = GNUNET_JSON_PACK (
     47     GNUNET_JSON_pack_uint64 ("row_id",
     48                              dc->row_id),
     49     GNUNET_JSON_pack_data_auto ("reserve_pub",
     50                                 &dc->reserve_pub),
     51     GNUNET_JSON_pack_bool ("inconsistency_gain",
     52                            dc->inconsistency_gain),
     53     TALER_JSON_pack_amount ("inconsistency_amount",
     54                             &dc->inconsistency_amount),
     55     GNUNET_JSON_pack_bool ("suppressed",
     56                            dc->suppressed)
     57     );
     58   GNUNET_break (0 ==
     59                 json_array_append_new (list,
     60                                        obj));
     61   return GNUNET_OK;
     62 }
     63 
     64 
     65 MHD_RESULT
     66 TAH_get_monitoring_reserve_balance_insufficient_inconsistency (
     67   struct TAH_RequestHandler *rh,
     68   struct MHD_Connection *connection,
     69   void **connection_cls,
     70   const char *upload_data,
     71   size_t *upload_data_size,
     72   const char *const args[])
     73 {
     74   json_t *ja;
     75   enum GNUNET_DB_QueryStatus qs;
     76   int64_t limit = -20;
     77   uint64_t offset;
     78   bool return_suppressed = false;
     79 
     80   (void) rh;
     81   (void) connection_cls;
     82   (void) upload_data;
     83   (void) upload_data_size;
     84   if (GNUNET_SYSERR ==
     85       TALER_AUDITORDB_preflight (TAH_apg))
     86   {
     87     GNUNET_break (0);
     88     return TALER_MHD_reply_with_error (connection,
     89                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     90                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     91                                        NULL);
     92   }
     93   TALER_MHD_parse_request_snumber (connection,
     94                                    "limit",
     95                                    &limit);
     96   if (limit < 0)
     97     offset = INT64_MAX;
     98   else
     99     offset = 0;
    100   TALER_MHD_parse_request_number (connection,
    101                                   "offset",
    102                                   &offset);
    103 
    104   {
    105     const char *ret_s
    106       = MHD_lookup_connection_value (connection,
    107                                      MHD_GET_ARGUMENT_KIND,
    108                                      "return_suppressed");
    109     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
    110     {
    111       return_suppressed = true;
    112     }
    113   }
    114   ja = json_array ();
    115   GNUNET_break (NULL != ja);
    116   qs = TALER_AUDITORDB_get_reserve_balance_insufficient_inconsistency (
    117     TAH_apg,
    118     limit,
    119     offset,
    120     return_suppressed,
    121     &process_reserve_balance_insufficient_inconsistency,
    122     ja);
    123   if (0 > qs)
    124   {
    125     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    126     json_decref (ja);
    127     TALER_LOG_WARNING (
    128       "Failed to handle GET /reserve-balance-insufficient-inconsistency\n");
    129     return TALER_MHD_reply_with_error (connection,
    130                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    131                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    132                                        "reserve-balance-insufficient-inconsistency");
    133   }
    134   return TALER_MHD_REPLY_JSON_PACK (
    135     connection,
    136     MHD_HTTP_OK,
    137     GNUNET_JSON_pack_array_steal ("reserve_balance_insufficient_inconsistency",
    138                                   ja));
    139 }