LCOV - code coverage report
Current view: top level - exchangedb - update_kyc_process_by_row.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 56.8 % 37 21
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022, 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              :  * @file exchangedb/update_kyc_process_by_row.c
      18              :  * @brief Implementation of the update_kyc_process_by_row function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_error_codes.h"
      22              : #include "taler/taler_pq_lib.h"
      23              : #include "exchange-database/update_kyc_process_by_row.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28           10 : TALER_EXCHANGEDB_update_kyc_process_by_row (
      29              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      30              :   uint64_t process_row,
      31              :   const char *provider_name,
      32              :   const struct TALER_NormalizedPaytoHashP *h_payto,
      33              :   const char *provider_account_id,
      34              :   const char *provider_legitimization_id,
      35              :   const char *redirect_url,
      36              :   struct GNUNET_TIME_Absolute expiration,
      37              :   enum TALER_ErrorCode ec,
      38              :   const char *error_message_hint,
      39              :   bool finished)
      40              : {
      41           10 :   uint32_t ec32 = (uint32_t) ec;
      42           10 :   struct GNUNET_PQ_QueryParam params[] = {
      43           10 :     GNUNET_PQ_query_param_uint64 (&process_row),
      44           10 :     GNUNET_PQ_query_param_string (provider_name),
      45           10 :     GNUNET_PQ_query_param_auto_from_type (h_payto), /*3*/
      46              :     (NULL != provider_account_id)
      47            0 :     ? GNUNET_PQ_query_param_string (provider_account_id)
      48           10 :     : GNUNET_PQ_query_param_null (), /*4*/
      49              :     (NULL != provider_legitimization_id)
      50           10 :     ? GNUNET_PQ_query_param_string (provider_legitimization_id)
      51           10 :     : GNUNET_PQ_query_param_null (), /*5*/
      52              :     (NULL != redirect_url)
      53           10 :     ? GNUNET_PQ_query_param_string (redirect_url)
      54           10 :     : GNUNET_PQ_query_param_null (), /*6*/
      55           10 :     GNUNET_PQ_query_param_absolute_time (&expiration),
      56           10 :     GNUNET_PQ_query_param_uint32 (&ec32), /* 8 */
      57              :     (NULL != error_message_hint)
      58            0 :     ? GNUNET_PQ_query_param_string (error_message_hint)
      59           10 :     : GNUNET_PQ_query_param_null (),
      60           10 :     GNUNET_PQ_query_param_bool (finished), /* 10 */
      61              :     GNUNET_PQ_query_param_end
      62              :   };
      63              :   enum GNUNET_DB_QueryStatus qs;
      64              : 
      65           10 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      66              :               "Updating KYC data for %llu (%s)\n",
      67              :               (unsigned long long) process_row,
      68              :               provider_name);
      69           10 :   PREPARE (pg,
      70              :            "update_legitimization_process",
      71              :            "UPDATE legitimization_processes"
      72              :            " SET provider_user_id=$4"
      73              :            "    ,provider_legitimization_id=$5"
      74              :            "    ,redirect_url=$6"
      75              :            "    ,expiration_time=GREATEST(expiration_time,$7)"
      76              :            "    ,error_code=$8"
      77              :            "    ,error_message=$9"
      78              :            "    ,finished=$10"
      79              :            " WHERE"
      80              :            "      h_payto=$3"
      81              :            "  AND legitimization_process_serial_id=$1"
      82              :            "  AND provider_name=$2;");
      83           10 :   qs = GNUNET_PQ_eval_prepared_non_select (
      84              :     pg->conn,
      85              :     "update_legitimization_process",
      86              :     params);
      87           10 :   if (qs <= 0)
      88              :   {
      89            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      90              :                 "Failed to update legitimization process %llu: %d\n",
      91              :                 (unsigned long long) process_row,
      92              :                 qs);
      93            0 :     return qs;
      94              :   }
      95           10 :   if (GNUNET_TIME_absolute_is_future (expiration))
      96              :   {
      97              :     enum GNUNET_DB_QueryStatus qs2;
      98            0 :     struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
      99            0 :       .header.size = htons (sizeof (rep)),
     100            0 :       .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
     101              :       .h_payto = *h_payto
     102              :     };
     103            0 :     uint32_t trigger_type = 1;
     104            0 :     struct GNUNET_PQ_QueryParam params2[] = {
     105            0 :       GNUNET_PQ_query_param_auto_from_type (h_payto),
     106            0 :       GNUNET_PQ_query_param_uint32 (&trigger_type),
     107              :       GNUNET_PQ_query_param_end
     108              :     };
     109              : 
     110            0 :     GNUNET_PQ_event_notify (pg->conn,
     111              :                             &rep.header,
     112              :                             NULL,
     113              :                             0);
     114            0 :     PREPARE (pg,
     115              :              "alert_kyc_status_change",
     116              :              "INSERT INTO kyc_alerts"
     117              :              " (h_payto"
     118              :              " ,trigger_type)"
     119              :              " VALUES"
     120              :              " ($1,$2);");
     121            0 :     qs2 = GNUNET_PQ_eval_prepared_non_select (
     122              :       pg->conn,
     123              :       "alert_kyc_status_change",
     124              :       params2);
     125            0 :     if (qs2 < 0)
     126            0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     127              :                   "Failed to store KYC alert: %d\n",
     128              :                   qs2);
     129              :   }
     130           10 :   return qs;
     131              : }
        

Generated by: LCOV version 2.0-1