LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_pending-deposits-get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 31 0
Test Date: 2025-12-28 14:06:02 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 "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            0 : 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            0 :   json_t *list = cls;
      50              :   json_t *obj;
      51              : 
      52            0 :   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            0 :   GNUNET_break (0 ==
      67              :                 json_array_append_new (list,
      68              :                                        obj));
      69            0 : }
      70              : 
      71              : 
      72              : MHD_RESULT
      73            0 : 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            0 :   int64_t limit = -20;
      84              :   uint64_t offset;
      85            0 :   bool return_suppressed = false;
      86              : 
      87            0 :   if (GNUNET_SYSERR ==
      88            0 :       TAH_plugin->preflight (TAH_plugin->cls))
      89              :   {
      90            0 :     GNUNET_break (0);
      91            0 :     return TALER_MHD_reply_with_error (connection,
      92              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      93              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      94              :                                        NULL);
      95              :   }
      96            0 :   TALER_MHD_parse_request_snumber (connection,
      97              :                                    "limit",
      98              :                                    &limit);
      99            0 :   if (limit < 0)
     100            0 :     offset = INT64_MAX;
     101              :   else
     102            0 :     offset = 0;
     103            0 :   TALER_MHD_parse_request_number (connection,
     104              :                                   "offset",
     105              :                                   &offset);
     106              :   {
     107            0 :     const char *ret_s = MHD_lookup_connection_value (connection,
     108              :                                                      MHD_GET_ARGUMENT_KIND,
     109              :                                                      "return_suppressed");
     110            0 :     if ( (NULL != ret_s) &&
     111            0 :          (0 == strcmp (ret_s,
     112              :                        "true")) )
     113              :     {
     114            0 :       return_suppressed = true;
     115              :     }
     116              :   }
     117            0 :   ja = json_array ();
     118            0 :   GNUNET_break (NULL != ja);
     119            0 :   qs = TAH_plugin->select_pending_deposits (
     120            0 :     TAH_plugin->cls,
     121              :     GNUNET_TIME_absolute_get (),
     122              :     limit,
     123              :     offset,
     124              :     return_suppressed,
     125              :     &add_pending_deposit,
     126              :     ja);
     127            0 :   if (0 > qs)
     128              :   {
     129            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     130            0 :     json_decref (ja);
     131            0 :     TALER_LOG_WARNING (
     132              :       "Failed to handle GET /pending-deposits in database\n");
     133            0 :     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            0 :   return TALER_MHD_REPLY_JSON_PACK (
     139              :     connection,
     140              :     MHD_HTTP_OK,
     141              :     GNUNET_JSON_pack_array_steal ("pending_deposits",
     142              :                                   ja));
     143              : }
        

Generated by: LCOV version 2.0-1