LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_historic-denomination-revenue-get.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 26 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 2 0.0 %

          Line data    Source code
       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             : 
      17             : 
      18             : #include "platform.h"
      19             : #include <gnunet/gnunet_util_lib.h>
      20             : #include <gnunet/gnunet_json_lib.h>
      21             : #include <jansson.h>
      22             : #include <microhttpd.h>
      23             : #include <pthread.h>
      24             : #include "taler_json_lib.h"
      25             : #include "taler_mhd_lib.h"
      26             : #include "taler-auditor-httpd.h"
      27             : #include "taler-auditor-httpd_historic-denomination-revenue-get.h"
      28             : 
      29             : 
      30             : /**
      31             :  * Add historic-denomination-revenue to the list.
      32             :  *
      33             :  * @param[in,out] cls a `json_t *` array to extend
      34             :  * @param serial_id location of the @a dc in the database
      35             :  * @param denom_pub_hash public key hash of the denomination
      36             :  * @param revenue_timestamp when was the revenue effective
      37             :  * @param revenue_balance how much in profit did we make from this denomination
      38             :  * @param loss_balance how much loss did we make from this denomination
      39             :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      40             :  */
      41             : static enum GNUNET_GenericReturnValue
      42           0 : process_historic_denomination_revenue (
      43             :   void *cls,
      44             :   uint64_t serial_id,
      45             :   const struct TALER_DenominationHashP *denom_pub_hash,
      46             :   struct GNUNET_TIME_Timestamp revenue_timestamp,
      47             :   const struct TALER_Amount *revenue_balance,
      48             :   const struct TALER_Amount *loss_balance)
      49             : {
      50           0 :   json_t *list = cls;
      51             :   json_t *obj;
      52             : 
      53           0 :   obj = GNUNET_JSON_PACK (
      54             :     GNUNET_JSON_pack_uint64 ("serial_id",
      55             :                              serial_id),
      56             :     GNUNET_JSON_pack_data_auto ("denom_pub_hash",
      57             :                                 denom_pub_hash),
      58             :     TALER_JSON_pack_time_abs_human ("revenue_timestamp",
      59             :                                     revenue_timestamp.abs_time),
      60             :     TALER_JSON_pack_amount ("revenue_balance",
      61             :                             revenue_balance),
      62             :     TALER_JSON_pack_amount ("loss_balance",
      63             :                             loss_balance)
      64             :     );
      65           0 :   GNUNET_break (0 ==
      66             :                 json_array_append_new (list,
      67             :                                        obj));
      68             : 
      69             : 
      70           0 :   return GNUNET_OK;
      71             : }
      72             : 
      73             : 
      74             : MHD_RESULT
      75           0 : TAH_HISTORIC_DENOMINATION_REVENUE_handler_get (
      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           0 :   int64_t limit = -20;
      85             :   uint64_t offset;
      86             :   enum GNUNET_DB_QueryStatus qs;
      87             : 
      88             :   (void) rh;
      89             :   (void) connection_cls;
      90             :   (void) upload_data;
      91             :   (void) upload_data_size;
      92           0 :   if (GNUNET_SYSERR ==
      93           0 :       TAH_plugin->preflight (TAH_plugin->cls))
      94             :   {
      95           0 :     GNUNET_break (0);
      96           0 :     return TALER_MHD_reply_with_error (
      97             :       connection,
      98             :       MHD_HTTP_INTERNAL_SERVER_ERROR,
      99             :       TALER_EC_GENERIC_DB_SETUP_FAILED,
     100             :       NULL);
     101             :   }
     102           0 :   TALER_MHD_parse_request_snumber (connection,
     103             :                                    "limit",
     104             :                                    &limit);
     105           0 :   if (limit < 0)
     106           0 :     offset = INT64_MAX;
     107             :   else
     108           0 :     offset = 0;
     109           0 :   TALER_MHD_parse_request_number (connection,
     110             :                                   "offset",
     111             :                                   &offset);
     112           0 :   ja = json_array ();
     113           0 :   GNUNET_break (NULL != ja);
     114           0 :   qs = TAH_plugin->select_historic_denom_revenue (
     115           0 :     TAH_plugin->cls,
     116             :     limit,
     117             :     offset,
     118             :     &process_historic_denomination_revenue,
     119             :     ja);
     120           0 :   if (0 > qs)
     121             :   {
     122           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     123           0 :     json_decref (ja);
     124           0 :     TALER_LOG_WARNING (
     125             :       "Failed to handle GET /historic-denomination-revenue");
     126           0 :     return TALER_MHD_reply_with_error (
     127             :       connection,
     128             :       MHD_HTTP_INTERNAL_SERVER_ERROR,
     129             :       TALER_EC_GENERIC_DB_FETCH_FAILED,
     130             :       "select_historic_denom_revenue");
     131             :   }
     132           0 :   return TALER_MHD_REPLY_JSON_PACK (
     133             :     connection,
     134             :     MHD_HTTP_OK,
     135             :     GNUNET_JSON_pack_array_steal (
     136             :       "historic-denomination-revenue",
     137             :       ja));
     138             : }

Generated by: LCOV version 1.16