LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_get-monitoring-pending-deposits.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 30 0
Test Date: 2026-04-14 15:39:31 Functions: 0.0 % 2 0

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

Generated by: LCOV version 2.0-1