LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-reserves.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 19 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2019-2021 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU Affero 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             :  * @file taler-merchant-httpd_private-get-reserves.c
      18             :  * @brief implement GET /reserves
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include <taler/taler_json_lib.h>
      23             : #include "taler-merchant-httpd_private-get-reserves.h"
      24             : 
      25             : 
      26             : /**
      27             :  * Add reserve details to our JSON array.
      28             :  *
      29             :  * @param cls a `json_t *` JSON array to build
      30             :  * @param reserve_pub public key of the reserve
      31             :  * @param creation_time time when the reserve was setup
      32             :  * @param expiration_time time when the reserve will be closed by the exchange
      33             :  * @param merchant_initial_amount initial amount that the merchant claims to have filled the
      34             :  *           reserve with
      35             :  * @param exchange_initial_amount initial amount that the exchange claims to have received
      36             :  * @param pickup_amount total of tips that were picked up from this reserve
      37             :  * @param committed_amount total of tips that the merchant committed to, but that were not
      38             :  *           picked up yet
      39             :  * @param active  true if the reserve is still active (we have the private key)
      40             :  */
      41             : static void
      42           0 : add_reserve (void *cls,
      43             :              const struct TALER_ReservePublicKeyP *reserve_pub,
      44             :              struct GNUNET_TIME_Timestamp creation_time,
      45             :              struct GNUNET_TIME_Timestamp expiration_time,
      46             :              const struct TALER_Amount *merchant_initial_amount,
      47             :              const struct TALER_Amount *exchange_initial_amount,
      48             :              const struct TALER_Amount *pickup_amount,
      49             :              const struct TALER_Amount *committed_amount,
      50             :              bool active)
      51             : {
      52           0 :   json_t *pa = cls;
      53             : 
      54           0 :   GNUNET_assert (0 ==
      55             :                  json_array_append_new (
      56             :                    pa,
      57             :                    GNUNET_JSON_PACK (
      58             :                      GNUNET_JSON_pack_data_auto ("reserve_pub",
      59             :                                                  reserve_pub),
      60             :                      GNUNET_JSON_pack_timestamp ("creation_time",
      61             :                                                  creation_time),
      62             :                      GNUNET_JSON_pack_timestamp ("expiration_time",
      63             :                                                  expiration_time),
      64             :                      TALER_JSON_pack_amount ("merchant_initial_amount",
      65             :                                              merchant_initial_amount),
      66             :                      TALER_JSON_pack_amount ("exchange_initial_amount",
      67             :                                              exchange_initial_amount),
      68             :                      TALER_JSON_pack_amount ("pickup_amount",
      69             :                                              pickup_amount),
      70             :                      TALER_JSON_pack_amount ("committed_amount",
      71             :                                              committed_amount),
      72             :                      GNUNET_JSON_pack_bool ("active",
      73             :                                             active))));
      74           0 : }
      75             : 
      76             : 
      77             : /**
      78             :  * Handle a GET "/reserves" request.
      79             :  *
      80             :  * @param rh context of the handler
      81             :  * @param connection the MHD connection to handle
      82             :  * @param[in,out] hc context with further information about the request
      83             :  * @return MHD result code
      84             :  */
      85             : MHD_RESULT
      86           0 : TMH_private_get_reserves (const struct TMH_RequestHandler *rh,
      87             :                           struct MHD_Connection *connection,
      88             :                           struct TMH_HandlerContext *hc)
      89             : {
      90             :   json_t *ra;
      91             :   enum GNUNET_DB_QueryStatus qs;
      92           0 :   struct GNUNET_TIME_Timestamp created_after
      93             :     = GNUNET_TIME_UNIT_ZERO_TS;
      94             :   enum TALER_EXCHANGE_YesNoAll active;
      95             :   enum TALER_EXCHANGE_YesNoAll failures;
      96             : 
      97             :   (void) rh;
      98           0 :   if (! (TALER_arg_to_yna (connection,
      99             :                            "active",
     100             :                            TALER_EXCHANGE_YNA_ALL,
     101             :                            &active)) )
     102             :   {
     103           0 :     return TALER_MHD_reply_with_error (connection,
     104             :                                        MHD_HTTP_BAD_REQUEST,
     105             :                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     106             :                                        "active");
     107             :   }
     108             : 
     109           0 :   if (! (TALER_arg_to_yna (connection,
     110             :                            "failures",
     111             :                            TALER_EXCHANGE_YNA_ALL,
     112             :                            &failures)) )
     113             :   {
     114           0 :     return TALER_MHD_reply_with_error (connection,
     115             :                                        MHD_HTTP_BAD_REQUEST,
     116             :                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     117             :                                        "failures");
     118             :   }
     119             : 
     120           0 :   ra = json_array ();
     121           0 :   GNUNET_assert (NULL != ra);
     122           0 :   qs = TMH_db->lookup_reserves (TMH_db->cls,
     123           0 :                                 hc->instance->settings.id,
     124             :                                 created_after,
     125             :                                 active,
     126             :                                 failures,
     127             :                                 &add_reserve,
     128             :                                 ra);
     129           0 :   if (0 > qs)
     130             :   {
     131           0 :     GNUNET_break (0);
     132           0 :     json_decref (ra);
     133           0 :     return TALER_MHD_reply_with_error (connection,
     134             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     135             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     136             :                                        "reserves");
     137             :   }
     138           0 :   return TALER_MHD_REPLY_JSON_PACK (
     139             :     connection,
     140             :     MHD_HTTP_OK,
     141             :     GNUNET_JSON_pack_array_steal ("reserves",
     142             :                                   ra));
     143             : }
     144             : 
     145             : 
     146             : /* end of taler-merchant-httpd_private-get-reserves.c */

Generated by: LCOV version 1.14