LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-transfers.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.9 % 33 30
Test Date: 2025-10-23 09:15:51 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2014-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 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-transfers.c
      18              :  * @brief implement API for obtaining a list of wire transfers
      19              :  * @author Marcello Stanisci
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "platform.h"
      23              : #include <jansson.h>
      24              : #include <taler/taler_json_lib.h>
      25              : #include "taler-merchant-httpd_private-get-transfers.h"
      26              : 
      27              : 
      28              : /**
      29              :  * Function called with information about a wire transfer.
      30              :  * Generate a response (array entry) based on the given arguments.
      31              :  *
      32              :  * @param cls closure with a `json_t *` array to build up the response
      33              :  * @param credit_amount amount expected to be wired to the merchant (minus fees), NULL if unknown
      34              :  * @param wtid wire transfer identifier
      35              :  * @param payto_uri target account that received the wire transfer
      36              :  * @param exchange_url base URL of the exchange that made the wire transfer
      37              :  * @param transfer_serial_id serial number identifying the transfer in the backend
      38              :  * @param execution_time when did the exchange make the transfer, #GNUNET_TIME_UNIT_FOREVER_ABS
      39              :  *           if it did not yet happen
      40              :  * @param expected true if the merchant acknowledged the wire transfer reception
      41              :  */
      42              : static void
      43           17 : transfer_cb (void *cls,
      44              :              const struct TALER_Amount *credit_amount,
      45              :              const struct TALER_WireTransferIdentifierRawP *wtid,
      46              :              struct TALER_FullPayto payto_uri,
      47              :              const char *exchange_url,
      48              :              uint64_t transfer_serial_id,
      49              :              struct GNUNET_TIME_Absolute execution_time,
      50              :              bool expected)
      51              : {
      52           17 :   json_t *ja = cls;
      53              :   json_t *r;
      54              : 
      55           17 :   r = GNUNET_JSON_PACK (
      56              :     TALER_JSON_pack_amount ("credit_amount",
      57              :                             credit_amount),
      58              :     GNUNET_JSON_pack_data_auto ("wtid",
      59              :                                 wtid),
      60              :     TALER_JSON_pack_full_payto ("payto_uri",
      61              :                                 payto_uri),
      62              :     GNUNET_JSON_pack_string ("exchange_url",
      63              :                              exchange_url),
      64              :     GNUNET_JSON_pack_uint64 ("transfer_serial_id",
      65              :                              transfer_serial_id),
      66              :     // FIXME: protocol breaking to remove...
      67              :     GNUNET_JSON_pack_bool ("verified",
      68              :                            false),
      69              :     // FIXME: protocol breaking to remove...
      70              :     GNUNET_JSON_pack_bool ("confirmed",
      71              :                            true),
      72              :     GNUNET_JSON_pack_bool ("expected",
      73              :                            expected),
      74              :     GNUNET_JSON_pack_timestamp (
      75              :       "execution_time",
      76              :       GNUNET_TIME_absolute_to_timestamp (execution_time)));
      77           17 :   GNUNET_assert (0 ==
      78              :                  json_array_append_new (ja,
      79              :                                         r));
      80           17 : }
      81              : 
      82              : 
      83              : /**
      84              :  * Manages a GET /private/transfers call.
      85              :  *
      86              :  * @param rh context of the handler
      87              :  * @param connection the MHD connection to handle
      88              :  * @param[in,out] hc context with further information about the request
      89              :  * @return MHD result code
      90              :  */
      91              : MHD_RESULT
      92           12 : TMH_private_get_transfers (const struct TMH_RequestHandler *rh,
      93              :                            struct MHD_Connection *connection,
      94              :                            struct TMH_HandlerContext *hc)
      95              : {
      96           12 :   struct TALER_FullPayto payto_uri = {
      97              :     .full_payto = NULL
      98              :   };
      99           12 :   struct GNUNET_TIME_Timestamp before = GNUNET_TIME_UNIT_FOREVER_TS;
     100           12 :   struct GNUNET_TIME_Timestamp after = GNUNET_TIME_UNIT_ZERO_TS;
     101           12 :   int64_t limit = -20;
     102              :   uint64_t offset;
     103              :   enum TALER_EXCHANGE_YesNoAll expected;
     104              : 
     105              :   (void) rh;
     106           12 :   TALER_MHD_parse_request_snumber (connection,
     107              :                                    "limit",
     108              :                                    &limit);
     109           12 :   if (limit < 0)
     110            8 :     offset = INT64_MAX;
     111              :   else
     112            4 :     offset = 0;
     113           12 :   TALER_MHD_parse_request_number (connection,
     114              :                                   "offset",
     115              :                                   &offset);
     116           12 :   TALER_MHD_parse_request_yna (connection,
     117              :                                "expected",
     118              :                                TALER_EXCHANGE_YNA_ALL,
     119              :                                &expected);
     120           12 :   TALER_MHD_parse_request_timestamp (connection,
     121              :                                      "before",
     122              :                                      &before);
     123           12 :   TALER_MHD_parse_request_timestamp (connection,
     124              :                                      "after",
     125              :                                      &after);
     126              :   {
     127              :     const char *esc_payto;
     128              : 
     129           12 :     esc_payto = MHD_lookup_connection_value (connection,
     130              :                                              MHD_GET_ARGUMENT_KIND,
     131              :                                              "payto_uri");
     132           12 :     if (NULL != esc_payto)
     133              :     {
     134              :       payto_uri.full_payto
     135            4 :         = GNUNET_strdup (esc_payto);
     136            4 :       (void) MHD_http_unescape (payto_uri.full_payto);
     137              :     }
     138              :   }
     139           12 :   TMH_db->preflight (TMH_db->cls);
     140              :   {
     141              :     json_t *ja;
     142              :     enum GNUNET_DB_QueryStatus qs;
     143              : 
     144           12 :     ja = json_array ();
     145           12 :     GNUNET_assert (NULL != ja);
     146           12 :     qs = TMH_db->lookup_transfers (TMH_db->cls,
     147           12 :                                    hc->instance->settings.id,
     148              :                                    payto_uri,
     149              :                                    before,
     150              :                                    after,
     151              :                                    limit,
     152              :                                    offset,
     153              :                                    expected,
     154              :                                    &transfer_cb,
     155              :                                    ja);
     156           12 :     GNUNET_free (payto_uri.full_payto);
     157           12 :     if (0 > qs)
     158              :     {
     159              :       /* Simple select queries should not cause serialization issues */
     160            0 :       GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
     161              :       /* Always report on hard error as well to enable diagnostics */
     162            0 :       GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     163            0 :       return TALER_MHD_reply_with_error (connection,
     164              :                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
     165              :                                          TALER_EC_GENERIC_DB_FETCH_FAILED,
     166              :                                          "transfers");
     167              :     }
     168           12 :     return TALER_MHD_REPLY_JSON_PACK (
     169              :       connection,
     170              :       MHD_HTTP_OK,
     171              :       GNUNET_JSON_pack_array_steal ("transfers",
     172              :                                     ja));
     173              :   }
     174              : }
     175              : 
     176              : 
     177              : /* end of taler-merchant-httpd_track-transfer.c */
        

Generated by: LCOV version 2.0-1