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_pending-deposits-get.c (4738B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2025 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 "taler/platform.h"
     17 #include <gnunet/gnunet_util_lib.h>
     18 #include <gnunet/gnunet_json_lib.h>
     19 #include <jansson.h>
     20 #include <microhttpd.h>
     21 #include <pthread.h>
     22 #include "taler/taler_json_lib.h"
     23 #include "taler/taler_mhd_lib.h"
     24 #include "taler-auditor-httpd.h"
     25 #include "taler-auditor-httpd_pending-deposits-get.h"
     26 
     27 
     28 /**
     29  * Add pending deposit to the list.
     30  *
     31  * @param[in,out] cls a `json_t *` array to extend
     32  * @param row_id row ID of the alert in the auditor database
     33  * @param batch_deposit_serial_id where in the exchange table are we
     34  * @param total_amount value of all missing deposits, including fees
     35  * @param wire_target_h_payto hash of the recipient account's payto URI
     36  * @param deadline what was the earliest requested wire transfer deadline
     37  * @param suppressed true if this report was suppressed
     38  */
     39 static void
     40 add_pending_deposit (
     41   void *cls,
     42   uint64_t row_id,
     43   uint64_t batch_deposit_serial_id,
     44   const struct TALER_Amount *total_amount,
     45   const struct TALER_FullPaytoHashP *wire_target_h_payto,
     46   struct GNUNET_TIME_Timestamp deadline,
     47   bool suppressed)
     48 {
     49   json_t *list = cls;
     50   json_t *obj;
     51 
     52   obj = GNUNET_JSON_PACK (
     53     GNUNET_JSON_pack_uint64 ("row_id",
     54                              row_id),
     55     GNUNET_JSON_pack_uint64 ("batch_deposit_serial_id",
     56                              batch_deposit_serial_id),
     57     TALER_JSON_pack_amount ("total_amount",
     58                             total_amount),
     59     GNUNET_JSON_pack_data_auto ("h_wire",
     60                                 wire_target_h_payto),
     61     GNUNET_JSON_pack_timestamp ("deadline",
     62                                 deadline),
     63     GNUNET_JSON_pack_bool ("suppressed",
     64                            suppressed)
     65     );
     66   GNUNET_break (0 ==
     67                 json_array_append_new (list,
     68                                        obj));
     69 }
     70 
     71 
     72 MHD_RESULT
     73 TAH_pending_deposits_handler_get (
     74   struct TAH_RequestHandler *rh,
     75   struct MHD_Connection *connection,
     76   void **connection_cls,
     77   const char *upload_data,
     78   size_t *upload_data_size,
     79   const char *const args[])
     80 {
     81   json_t *ja;
     82   enum GNUNET_DB_QueryStatus qs;
     83   int64_t limit = -20;
     84   uint64_t offset;
     85   bool return_suppressed = false;
     86 
     87   if (GNUNET_SYSERR ==
     88       TAH_plugin->preflight (TAH_plugin->cls))
     89   {
     90     GNUNET_break (0);
     91     return TALER_MHD_reply_with_error (connection,
     92                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     93                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     94                                        NULL);
     95   }
     96   TALER_MHD_parse_request_snumber (connection,
     97                                    "limit",
     98                                    &limit);
     99   if (limit < 0)
    100     offset = INT64_MAX;
    101   else
    102     offset = 0;
    103   TALER_MHD_parse_request_number (connection,
    104                                   "offset",
    105                                   &offset);
    106   {
    107     const char *ret_s = MHD_lookup_connection_value (connection,
    108                                                      MHD_GET_ARGUMENT_KIND,
    109                                                      "return_suppressed");
    110     if ( (NULL != ret_s) &&
    111          (0 == strcmp (ret_s,
    112                        "true")) )
    113     {
    114       return_suppressed = true;
    115     }
    116   }
    117   ja = json_array ();
    118   GNUNET_break (NULL != ja);
    119   qs = TAH_plugin->select_pending_deposits (
    120     TAH_plugin->cls,
    121     GNUNET_TIME_absolute_get (),
    122     limit,
    123     offset,
    124     return_suppressed,
    125     &add_pending_deposit,
    126     ja);
    127   if (0 > qs)
    128   {
    129     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    130     json_decref (ja);
    131     TALER_LOG_WARNING (
    132       "Failed to handle GET /pending-deposits in database\n");
    133     return TALER_MHD_reply_with_error (connection,
    134                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    135                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    136                                        "select_pending_deposits");
    137   }
    138   return TALER_MHD_REPLY_JSON_PACK (
    139     connection,
    140     MHD_HTTP_OK,
    141     GNUNET_JSON_pack_array_steal ("pending_deposits",
    142                                   ja));
    143 }