LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_post-private-transfers.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.5 % 33 18
Test Date: 2026-09-04 23:42:01 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2014-2023, 2025, 2026 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 src/backend/taler-merchant-httpd_post-private-transfers.c
      18              :  * @brief implement API for registering wire transfers
      19              :  * @author Marcello Stanisci
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "platform.h"
      23              : #include <jansson.h>
      24              : #include <taler/taler_signatures.h>
      25              : #include <taler/taler_json_lib.h>
      26              : #include <taler/taler_dbevents.h>
      27              : #include "taler-merchant-httpd_get-exchanges.h"
      28              : #include "taler-merchant-httpd_helper.h"
      29              : #include "taler-merchant-httpd_post-private-transfers.h"
      30              : #include "merchant-database/insert_transfer.h"
      31              : 
      32              : 
      33              : /**
      34              :  * How often do we retry the simple INSERT database transaction?
      35              :  */
      36              : #define MAX_RETRIES 5
      37              : 
      38              : 
      39              : enum MHD_Result
      40           10 : TMH_private_post_transfers (const struct TMH_RequestHandler *rh,
      41              :                             struct MHD_Connection *connection,
      42              :                             struct TMH_HandlerContext *hc)
      43              : {
      44              :   struct TALER_FullPayto payto_uri;
      45              :   const char *exchange_url;
      46              :   struct TALER_WireTransferIdentifierRawP wtid;
      47              :   struct TALER_Amount amount;
      48              :   struct GNUNET_JSON_Specification spec[] = {
      49           10 :     TALER_JSON_spec_amount_any ("credit_amount",
      50              :                                 &amount),
      51           10 :     GNUNET_JSON_spec_fixed_auto ("wtid",
      52              :                                  &wtid),
      53           10 :     TALER_JSON_spec_full_payto_uri ("payto_uri",
      54              :                                     &payto_uri),
      55           10 :     TALER_JSON_spec_web_url ("exchange_url",
      56              :                              &exchange_url),
      57           10 :     GNUNET_JSON_spec_end ()
      58              :   };
      59              :   enum GNUNET_GenericReturnValue res;
      60              :   enum GNUNET_DB_QueryStatus qs;
      61              :   bool no_account;
      62              :   bool conflict;
      63              : 
      64           10 :   res = TALER_MHD_parse_json_data (connection,
      65           10 :                                    hc->request_body,
      66              :                                    spec);
      67           10 :   if (GNUNET_OK != res)
      68              :     return (GNUNET_NO == res)
      69              :       ? MHD_YES
      70            0 :       : MHD_NO;
      71           10 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      72              :               "New inbound wire transfer over %s to %s from %s\n",
      73              :               TALER_amount2s (&amount),
      74              :               payto_uri.full_payto,
      75              :               exchange_url);
      76              : 
      77              :   /* Check if transfer data is in database, if not, add it. */
      78           10 :   qs = TALER_MERCHANTDB_insert_transfer (TMH_db,
      79           10 :                                          hc->instance->settings.id,
      80              :                                          exchange_url,
      81              :                                          &wtid,
      82              :                                          &amount,
      83              :                                          payto_uri,
      84              :                                          0 /* no bank serial known! */,
      85              :                                          &no_account,
      86              :                                          &conflict);
      87           10 :   switch (qs)
      88              :   {
      89            0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      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_STORE_FAILED,
      94              :                                        "insert_transfer");
      95            0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      96            0 :     GNUNET_break (0);
      97            0 :     return TALER_MHD_reply_with_error (connection,
      98              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      99              :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
     100              :                                        "insert_transfer");
     101            0 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     102            0 :     GNUNET_break (0);   /* should be impossible */
     103            0 :     return TALER_MHD_reply_with_error (connection,
     104              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     105              :                                        TALER_EC_GENERIC_DB_INVARIANT_FAILURE,
     106              :                                        "insert_transfer");
     107           10 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     108           10 :     break;
     109              :   }
     110           10 :   if (no_account)
     111              :   {
     112            0 :     GNUNET_break_op (0);
     113            0 :     return TALER_MHD_reply_with_error (
     114              :       connection,
     115              :       MHD_HTTP_CONFLICT,
     116              :       TALER_EC_MERCHANT_GENERIC_ACCOUNT_UNKNOWN,
     117            0 :       payto_uri.full_payto);
     118              :   }
     119           10 :   if (conflict)
     120              :   {
     121            0 :     GNUNET_break_op (0);
     122            0 :     return TALER_MHD_reply_with_error (
     123              :       connection,
     124              :       MHD_HTTP_CONFLICT,
     125              :       TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_CONFLICTING_SUBMISSION,
     126              :       NULL);
     127              :   }
     128           10 :   return TALER_MHD_reply_static (connection,
     129              :                                  MHD_HTTP_NO_CONTENT,
     130              :                                  NULL,
     131              :                                  NULL,
     132              :                                  0);
     133              : }
     134              : 
     135              : 
     136              : /* end of taler-merchant-httpd_post-private-transfers.c */
        

Generated by: LCOV version 2.0-1