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-in-inconsistency.c (4703B)


      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 "taler-auditor-httpd_get-monitoring-reserve-in-inconsistency.h"
     25 #include "auditor-database/get_reserve_in_inconsistency.h"
     26 #include "auditor-database/preflight.h"
     27 
     28 
     29 /**
     30  * Add reserve-in-inconsistency to the list.
     31  *
     32  * @param[in,out] cls a `json_t *` array to extend
     33  * @param dc struct of inconsistencies
     34  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
     35  */
     36 static enum GNUNET_GenericReturnValue
     37 process_reserve_in_inconsistency (
     38   void *cls,
     39   const struct TALER_AUDITORDB_ReserveInInconsistency *dc)
     40 {
     41   json_t *list = cls;
     42   json_t *obj;
     43 
     44   obj = GNUNET_JSON_PACK (
     45     GNUNET_JSON_pack_uint64 ("row_id",
     46                              dc->serial_id),
     47     GNUNET_JSON_pack_uint64 ("bank_row_id",
     48                              dc->bank_row_id),
     49     TALER_JSON_pack_amount ("amount_exchange_expected",
     50                             &dc->amount_exchange_expected),
     51     TALER_JSON_pack_amount ("amount_wired",
     52                             &dc->amount_wired),
     53     GNUNET_JSON_pack_data_auto ("reserve_pub",
     54                                 &dc->reserve_pub),
     55     TALER_JSON_pack_time_abs_human ("timestamp",
     56                                     dc->timestamp),
     57     TALER_JSON_pack_full_payto ("account",
     58                                 dc->account),
     59     GNUNET_JSON_pack_string ("diagnostic",
     60                              dc->diagnostic),
     61     GNUNET_JSON_pack_bool ("suppressed",
     62                            dc->suppressed)
     63     );
     64   GNUNET_break (0 ==
     65                 json_array_append_new (list,
     66                                        obj));
     67 
     68 
     69   return GNUNET_OK;
     70 }
     71 
     72 
     73 MHD_RESULT
     74 TAH_get_monitoring_reserve_in_inconsistency (
     75   struct TAH_RequestHandler *rh,
     76   struct MHD_Connection *connection,
     77   void **connection_cls,
     78   const char *upload_data,
     79   size_t *upload_data_size,
     80   const char *const args[])
     81 {
     82   json_t *ja;
     83   enum GNUNET_DB_QueryStatus qs;
     84   int64_t limit = -20;
     85   uint64_t offset;
     86   bool return_suppressed = false;
     87 
     88   (void) rh;
     89   (void) connection_cls;
     90   (void) upload_data;
     91   (void) upload_data_size;
     92   if (GNUNET_SYSERR ==
     93       TALER_AUDITORDB_preflight (TAH_apg))
     94   {
     95     GNUNET_break (0);
     96     return TALER_MHD_reply_with_error (connection,
     97                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     98                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     99                                        NULL);
    100   }
    101   TALER_MHD_parse_request_snumber (connection,
    102                                    "limit",
    103                                    &limit);
    104   if (limit < 0)
    105     offset = INT64_MAX;
    106   else
    107     offset = 0;
    108   TALER_MHD_parse_request_number (connection,
    109                                   "offset",
    110                                   &offset);
    111   {
    112     const char *ret_s
    113       = MHD_lookup_connection_value (connection,
    114                                      MHD_GET_ARGUMENT_KIND,
    115                                      "return_suppressed");
    116     if ( (NULL != ret_s) &&
    117          (0 == strcmp (ret_s,
    118                        "true")) )
    119     {
    120       return_suppressed = true;
    121     }
    122   }
    123   ja = json_array ();
    124   GNUNET_break (NULL != ja);
    125   qs = TALER_AUDITORDB_get_reserve_in_inconsistency (
    126     TAH_apg,
    127     limit,
    128     offset,
    129     return_suppressed,
    130     &process_reserve_in_inconsistency,
    131     ja);
    132   if (0 > qs)
    133   {
    134     GNUNET_break (0);
    135     json_decref (ja);
    136     return TALER_MHD_reply_with_error (connection,
    137                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    138                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    139                                        "reserve-in-inconsistency");
    140   }
    141   return TALER_MHD_REPLY_JSON_PACK (
    142     connection,
    143     MHD_HTTP_OK,
    144     GNUNET_JSON_pack_array_steal ("reserve_in_inconsistency",
    145                                   ja));
    146 }