LCOV - code coverage report
Current view: top level - exchangedb - pg_lookup_kyc_requirement_by_row.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.9 % 33 30
Test Date: 2025-12-28 14:06:02 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/pg_lookup_kyc_requirement_by_row.c
      18              :  * @brief Implementation of the lookup_kyc_requirement_by_row function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/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_lookup_kyc_requirement_by_row.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           14 : TEH_PG_lookup_kyc_requirement_by_row (
      31              :   void *cls,
      32              :   const struct TALER_NormalizedPaytoHashP *h_payto,
      33              :   bool have_pub,
      34              :   union TALER_AccountPublicKeyP *account_pub,
      35              :   enum GNUNET_GenericReturnValue *is_wallet,
      36              :   struct TALER_ReservePublicKeyP *reserve_pub,
      37              :   struct TALER_AccountAccessTokenP *access_token,
      38              :   uint64_t *rule_gen,
      39              :   json_t **jrules,
      40              :   bool *aml_review,
      41              :   bool *kyc_required)
      42              : {
      43           14 :   struct PostgresClosure *pg = cls;
      44           14 :   struct GNUNET_PQ_QueryParam params[] = {
      45           14 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
      46              :     have_pub
      47            0 :     ? GNUNET_PQ_query_param_auto_from_type (account_pub)
      48           14 :     : GNUNET_PQ_query_param_null (),
      49              :     GNUNET_PQ_query_param_end
      50              :   };
      51              :   bool bis_wallet;
      52              :   bool bis_wallet_unknown;
      53              :   bool not_found;
      54           14 :   struct GNUNET_PQ_ResultSpec rs[] = {
      55           14 :     GNUNET_PQ_result_spec_allow_null (
      56              :       GNUNET_PQ_result_spec_auto_from_type ("account_pub",
      57              :                                             account_pub),
      58              :       NULL),
      59           14 :     GNUNET_PQ_result_spec_allow_null (
      60              :       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
      61              :                                             reserve_pub),
      62              :       NULL),
      63           14 :     GNUNET_PQ_result_spec_allow_null (
      64              :       GNUNET_PQ_result_spec_auto_from_type ("access_token",
      65              :                                             access_token),
      66              :       NULL),
      67           14 :     GNUNET_PQ_result_spec_allow_null (
      68              :       /* can be NULL due to LEFT JOIN */
      69              :       TALER_PQ_result_spec_json ("jrules",
      70              :                                  jrules),
      71              :       NULL),
      72           14 :     GNUNET_PQ_result_spec_allow_null (
      73              :       /* can be NULL due to LEFT JOIN */
      74              :       GNUNET_PQ_result_spec_bool ("is_wallet",
      75              :                                   &bis_wallet),
      76              :       &bis_wallet_unknown),
      77           14 :     GNUNET_PQ_result_spec_allow_null (
      78              :       /* can be NULL due to LEFT JOIN */
      79              :       GNUNET_PQ_result_spec_bool ("aml_review",
      80              :                                   aml_review),
      81              :       NULL),
      82           14 :     GNUNET_PQ_result_spec_allow_null (
      83              :       GNUNET_PQ_result_spec_uint64 ("rule_gen",
      84              :                                     rule_gen),
      85              :       NULL),
      86           14 :     GNUNET_PQ_result_spec_bool ("kyc_required",
      87              :                                 kyc_required),
      88           14 :     GNUNET_PQ_result_spec_bool ("not_found",
      89              :                                 &not_found),
      90              :     GNUNET_PQ_result_spec_end
      91              :   };
      92              :   enum GNUNET_DB_QueryStatus qs;
      93              : 
      94           14 :   *jrules = NULL;
      95           14 :   *aml_review = false;
      96           14 :   *is_wallet = GNUNET_SYSERR;
      97           14 :   *rule_gen = 0;
      98           14 :   if (! have_pub)
      99           14 :     memset (account_pub,
     100              :             0,
     101              :             sizeof (*account_pub));
     102           14 :   memset (reserve_pub,
     103              :           0,
     104              :           sizeof (*reserve_pub));
     105           14 :   memset (access_token,
     106              :           0,
     107              :           sizeof (*access_token));
     108           14 :   PREPARE (pg,
     109              :            "lookup_kyc_requirement_by_row",
     110              :            "SELECT "
     111              :            " out_account_pub AS account_pub"
     112              :            ",out_reserve_pub AS reserve_pub"
     113              :            ",out_access_token AS access_token"
     114              :            ",out_jrules::TEXT AS jrules"
     115              :            ",out_is_wallet AS is_wallet"
     116              :            ",out_not_found AS not_found"
     117              :            ",out_aml_review AS aml_review"
     118              :            ",out_kyc_required AS kyc_required"
     119              :            ",out_rule_gen AS rule_gen"
     120              :            " FROM exchange_do_lookup_kyc_requirement_by_row"
     121              :            " ($1, $2);");
     122           14 :   qs = GNUNET_PQ_eval_prepared_singleton_select (
     123              :     pg->conn,
     124              :     "lookup_kyc_requirement_by_row",
     125              :     params,
     126              :     rs);
     127           14 :   if (qs <= 0)
     128            0 :     return qs;
     129           14 :   if (! bis_wallet_unknown)
     130           14 :     *is_wallet = (bis_wallet) ? GNUNET_YES : GNUNET_NO;
     131           14 :   if (not_found)
     132            0 :     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     133           14 :   return qs;
     134              : }
        

Generated by: LCOV version 2.0-1