LCOV - code coverage report
Current view: top level - backenddb - pg_get_kyc_status.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 26 26
Test Date: 2025-11-06 19:31:41 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 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 backenddb/pg_get_kyc_status.c
      18              :  * @brief Implementation of the get_kyc_status function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include <taler/taler_error_codes.h>
      23              : #include <taler/taler_dbevents.h>
      24              : #include <taler/taler_pq_lib.h>
      25              : #include "pg_get_kyc_status.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           13 : TMH_PG_get_kyc_status (
      31              :   void *cls,
      32              :   struct TALER_FullPayto merchant_account_uri,
      33              :   const char *instance_id,
      34              :   const char *exchange_url,
      35              :   bool *auth_ok,
      36              :   struct TALER_AccountAccessTokenP *access_token,
      37              :   bool *kyc_ok,
      38              :   unsigned int *last_http_status,
      39              :   enum TALER_ErrorCode *last_ec,
      40              :   uint64_t *rule_gen,
      41              :   struct GNUNET_TIME_Timestamp *last_kyc_check,
      42              :   bool *aml_review,
      43              :   json_t **jlimits)
      44              : {
      45           13 :   struct PostgresClosure *pg = cls;
      46           13 :   struct GNUNET_PQ_QueryParam params[] = {
      47           13 :     GNUNET_PQ_query_param_string (merchant_account_uri.full_payto),
      48           13 :     GNUNET_PQ_query_param_string (instance_id),
      49           13 :     GNUNET_PQ_query_param_string (exchange_url),
      50              :     GNUNET_PQ_query_param_end
      51              :   };
      52           13 :   uint32_t h32 = 0;
      53           13 :   uint32_t e32 = 0;
      54           13 :   bool token_is_null = true;
      55           13 :   struct GNUNET_PQ_ResultSpec rs[] = {
      56           13 :     GNUNET_PQ_result_spec_allow_null (
      57              :       GNUNET_PQ_result_spec_auto_from_type ("access_token",
      58              :                                             access_token),
      59              :       &token_is_null),
      60           13 :     GNUNET_PQ_result_spec_uint32 ("exchange_http_status",
      61              :                                   &h32),
      62           13 :     GNUNET_PQ_result_spec_uint32 ("exchange_ec_code",
      63              :                                   &e32),
      64           13 :     GNUNET_PQ_result_spec_uint64 ("last_rule_gen",
      65              :                                   rule_gen),
      66           13 :     GNUNET_PQ_result_spec_bool ("kyc_ok",
      67              :                                 kyc_ok),
      68           13 :     GNUNET_PQ_result_spec_timestamp ("kyc_timestamp",
      69              :                                      last_kyc_check),
      70           13 :     GNUNET_PQ_result_spec_bool ("aml_review",
      71              :                                 aml_review),
      72           13 :     GNUNET_PQ_result_spec_allow_null (
      73              :       TALER_PQ_result_spec_json ("jaccount_limits",
      74              :                                  jlimits),
      75              :       NULL),
      76              :     GNUNET_PQ_result_spec_end
      77              :   };
      78              :   enum GNUNET_DB_QueryStatus qs;
      79              : 
      80           13 :   check_connection (pg);
      81           13 :   PREPARE (pg,
      82              :            "get_kyc_status",
      83              :            "SELECT"
      84              :            " mk.access_token"
      85              :            ",mk.exchange_http_status"
      86              :            ",mk.exchange_ec_code"
      87              :            ",mk.kyc_ok"
      88              :            ",mk.last_rule_gen"
      89              :            ",mk.kyc_timestamp"
      90              :            ",mk.aml_review"
      91              :            ",mk.jaccount_limits::TEXT"
      92              :            " FROM merchant_kyc mk"
      93              :            " WHERE mk.exchange_url=$3"
      94              :            "   AND mk.account_serial="
      95              :            "   (SELECT account_serial"
      96              :            "      FROM merchant_accounts"
      97              :            "     WHERE payto_uri=$1"
      98              :            "       AND merchant_serial="
      99              :            "       (SELECT merchant_serial"
     100              :            "          FROM merchant_instances"
     101              :            "         WHERE merchant_id=$2));");
     102           13 :   *jlimits = NULL;
     103           13 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     104              :                                                  "get_kyc_status",
     105              :                                                  params,
     106              :                                                  rs);
     107           13 :   *last_ec = (enum TALER_ErrorCode) (int) e32;
     108           13 :   *last_http_status = (unsigned int) h32;
     109           13 :   *auth_ok = ! token_is_null;
     110           13 :   return qs;
     111              : }
        

Generated by: LCOV version 2.0-1