LCOV - code coverage report
Current view: top level - bank-lib - fakebank_twg_get_transfers_id.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 23 0.0 %
Date: 2025-06-22 12:09:43 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2024 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or
       6             :   modify it under the terms of the GNU General Public License
       7             :   as published by the Free Software Foundation; either version 3,
       8             :   or (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful,
      11             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public
      16             :   License along with TALER; see the file COPYING.  If not,
      17             :   see <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file bank-lib/fakebank_twg_get_transfers_id.c
      21             :  * @brief routines to return outgoing transfer details
      22             :  * @author Christian Grothoff <christian@grothoff.org>
      23             :  */
      24             : #include "taler/platform.h"
      25             : #include <pthread.h>
      26             : #include "taler/taler_fakebank_lib.h"
      27             : #include "taler/taler_bank_service.h"
      28             : #include "taler/taler_mhd_lib.h"
      29             : #include <gnunet/gnunet_mhd_compat.h>
      30             : #include "fakebank.h"
      31             : #include "fakebank_common_lookup.h"
      32             : #include "fakebank_common_lp.h"
      33             : #include "fakebank_common_parser.h"
      34             : #include "fakebank_twg_get_transfers.h"
      35             : 
      36             : 
      37             : MHD_RESULT
      38           0 : TALER_FAKEBANK_twg_get_transfers_id_ (
      39             :   struct TALER_FAKEBANK_Handle *h,
      40             :   struct MHD_Connection *connection,
      41             :   const char *account,
      42             :   const char *id,
      43             :   void **con_cls)
      44             : {
      45             :   struct Account *acc;
      46             :   unsigned long long row_id;
      47             :   json_t *trans;
      48             : 
      49           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      50             :               "Handling /transfers/%s connection %p\n",
      51             :               id,
      52             :               connection);
      53             :   {
      54             :     char dummy;
      55             : 
      56           0 :     if (1 !=
      57           0 :         sscanf (id,
      58             :                 "%llu%c",
      59             :                 &row_id,
      60             :                 &dummy))
      61             :     {
      62           0 :       return TALER_MHD_reply_with_error (
      63             :         connection,
      64             :         MHD_HTTP_BAD_REQUEST,
      65             :         TALER_EC_GENERIC_PARAMETER_MALFORMED,
      66             :         id);
      67             :     }
      68             :   }
      69           0 :   GNUNET_assert (0 ==
      70             :                  pthread_mutex_lock (&h->big_lock));
      71           0 :   acc = TALER_FAKEBANK_lookup_account_ (h,
      72             :                                         account,
      73             :                                         NULL);
      74           0 :   if (NULL == acc)
      75             :   {
      76           0 :     GNUNET_assert (0 ==
      77             :                    pthread_mutex_unlock (&h->big_lock));
      78           0 :     return TALER_MHD_reply_with_error (connection,
      79             :                                        MHD_HTTP_NOT_FOUND,
      80             :                                        TALER_EC_BANK_UNKNOWN_ACCOUNT,
      81             :                                        account);
      82             :   }
      83             :   {
      84           0 :     struct Transaction *t = h->transactions[row_id % h->ram_limit];
      85             :     char *credit_payto;
      86             : 
      87           0 :     if (t->debit_account != acc)
      88             :     {
      89           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      90             :                   "Invalid ID specified, transaction %llu not with account %s!\n",
      91             :                   (unsigned long long) row_id,
      92             :                   account);
      93           0 :       GNUNET_assert (0 ==
      94             :                      pthread_mutex_unlock (&h->big_lock));
      95           0 :       return MHD_NO;
      96             :     }
      97           0 :     GNUNET_asprintf (&credit_payto,
      98             :                      "payto://x-taler-bank/localhost/%s?receiver-name=%s",
      99           0 :                      t->credit_account->account_name,
     100           0 :                      t->credit_account->receiver_name);
     101           0 :     trans = GNUNET_JSON_PACK (
     102             :       GNUNET_JSON_pack_data_auto (
     103             :         "wtid",
     104             :         &t->subject.debit.wtid),
     105             :       GNUNET_JSON_pack_string (
     106             :         "exchange_base_url",
     107             :         t->subject.debit.exchange_base_url),
     108             :       GNUNET_JSON_pack_timestamp (
     109             :         "timestamp",
     110             :         t->date),
     111             :       TALER_JSON_pack_amount (
     112             :         "amount",
     113             :         &t->amount),
     114             :       GNUNET_JSON_pack_string (
     115             :         "credit_account",
     116             :         credit_payto),
     117             :       GNUNET_JSON_pack_string (
     118             :         "status",
     119             :         "success"));
     120           0 :     GNUNET_assert (NULL != trans);
     121           0 :     GNUNET_free (credit_payto);
     122             :   }
     123           0 :   GNUNET_assert (0 ==
     124             :                  pthread_mutex_unlock (&h->big_lock));
     125           0 :   return TALER_MHD_reply_json (
     126             :     connection,
     127             :     trans,
     128             :     MHD_HTTP_OK);
     129             : }

Generated by: LCOV version 1.16