LCOV - code coverage report
Current view: top level - backenddb - insert_kyc_status.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.7 % 43 39
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              :    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 src/backenddb/insert_kyc_status.c
      18              :  * @brief Implementation of the insert_kyc_status function for Postgres
      19              :  * @author Iván Ávalos
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "platform.h"
      23              : #include <taler/taler_dbevents.h>
      24              : #include <taler/taler_pq_lib.h>
      25              : #include "merchant-database/insert_kyc_status.h"
      26              : #include "helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           31 : TALER_MERCHANTDB_insert_kyc_status (
      31              :   struct TALER_MERCHANTDB_PostgresContext *pg,
      32              :   const char *merchant_id,
      33              :   const struct TALER_MerchantWireHashP *h_wire,
      34              :   const char *exchange_url,
      35              :   struct GNUNET_TIME_Timestamp timestamp,
      36              :   struct GNUNET_TIME_Absolute next_time,
      37              :   struct GNUNET_TIME_Relative kyc_backoff,
      38              :   unsigned int exchange_http_status,
      39              :   enum TALER_ErrorCode exchange_ec_code,
      40              :   uint64_t rule_gen,
      41              :   const struct TALER_AccountAccessTokenP *access_token,
      42              :   const json_t *jlimits,
      43              :   bool in_aml_review,
      44              :   bool kyc_ok)
      45              : {
      46           31 :   struct TALER_MERCHANTDB_MerchantKycStatusChangeEventP ev = {
      47           31 :     .header.size = htons (sizeof (ev)),
      48           31 :     .header.type = htons (TALER_DBEVENT_MERCHANT_EXCHANGE_KYC_STATUS_CHANGED),
      49              :     .h_wire = *h_wire
      50              :   };
      51           31 :   struct GNUNET_DB_EventHeaderP hdr = {
      52           31 :     .size = htons (sizeof (hdr)),
      53           31 :     .type = htons (TALER_DBEVENT_MERCHANT_KYC_STATUS_CHANGED)
      54              :   };
      55              :   char *notify_s
      56           31 :     = GNUNET_PQ_get_event_notify_channel (&ev.header);
      57              :   char *notify2_s
      58           31 :     = GNUNET_PQ_get_event_notify_channel (&hdr);
      59           31 :   uint32_t http_status32 = (uint32_t) exchange_http_status;
      60           31 :   uint32_t ec_code32 = (uint32_t) exchange_ec_code;
      61           31 :   struct GNUNET_PQ_QueryParam params[] = {
      62           31 :     GNUNET_PQ_query_param_auto_from_type (h_wire),
      63           31 :     GNUNET_PQ_query_param_string (exchange_url),
      64           31 :     GNUNET_PQ_query_param_timestamp (&timestamp),
      65           31 :     GNUNET_PQ_query_param_uint32 (&http_status32),
      66           31 :     GNUNET_PQ_query_param_uint32 (&ec_code32),
      67              :     NULL != access_token
      68            4 :     ? GNUNET_PQ_query_param_auto_from_type (access_token)
      69           31 :     : GNUNET_PQ_query_param_null (),
      70              :     NULL != jlimits
      71            4 :     ? TALER_PQ_query_param_json (jlimits)
      72           31 :     : GNUNET_PQ_query_param_null (),
      73           31 :     GNUNET_PQ_query_param_bool (in_aml_review),
      74           31 :     GNUNET_PQ_query_param_bool (kyc_ok),
      75           31 :     GNUNET_PQ_query_param_string (notify_s),
      76           31 :     GNUNET_PQ_query_param_string (notify2_s),
      77           31 :     GNUNET_PQ_query_param_uint64 (&rule_gen),
      78           31 :     GNUNET_PQ_query_param_absolute_time (&next_time),
      79           31 :     GNUNET_PQ_query_param_relative_time (&kyc_backoff),
      80              :     GNUNET_PQ_query_param_end
      81              :   };
      82              :   bool no_account;
      83           31 :   struct GNUNET_PQ_ResultSpec rs[] = {
      84           31 :     GNUNET_PQ_result_spec_bool ("no_account",
      85              :                                 &no_account),
      86              :     GNUNET_PQ_result_spec_end
      87              :   };
      88              :   enum GNUNET_DB_QueryStatus qs;
      89              : 
      90           31 :   GNUNET_assert (NULL != pg->current_merchant_id);
      91           31 :   GNUNET_assert (0 == strcmp (merchant_id,
      92              :                               pg->current_merchant_id));
      93           31 :   TMH_PQ_prepare_anon (pg,
      94              :                        "SELECT "
      95              :                        "  out_no_account AS no_account"
      96              :                        " FROM merchant_do_account_kyc_set_status"
      97              :                        "($1, $2, $3, $4, $5, $6, $7::TEXT::JSONB"
      98              :                        ",$8, $9, $10, $11, $12, $13, $14);");
      99           31 :   qs = GNUNET_PQ_eval_prepared_singleton_select (
     100              :     pg->conn,
     101              :     "",
     102              :     params,
     103              :     rs);
     104           31 :   GNUNET_free (notify_s);
     105           31 :   GNUNET_free (notify2_s);
     106           31 :   if (qs <= 0)
     107              :   {
     108            0 :     GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
     109            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
     110            0 :     GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
     111            0 :     return qs;
     112              :   }
     113           31 :   GNUNET_break (! no_account);
     114           31 :   return qs;
     115              : }
        

Generated by: LCOV version 2.0-1