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 (4730B)


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